Skip to content

Possible conflicting keywords in sample_posterior_predictive #5990

@davidsuculum

Description

@davidsuculum

In PyMC discourse, I asked this this, and I reproduce here my code for convenience:

X = np.array([32, 38, 94, 83, 99, 78])
y = np.array([1702, 1514, 683, 269, 900, 86])
y = (y - np.mean(y)) / np.std(y)
X = (X - np.mean(X))/np.std(X)

with pm.Model() as d_model:
    # Specify the covariance function.
    vert = 1*pm.HalfNormal("vert", sigma=1)
    l = pm.HalfNormal(name='l', sigma=1)
    cov_func = vert**2 * pm.gp.cov.Matern32(1, ls=l)

    # Specify the GP. The default mean function is zero.
    #gp = pm.gp.Marginal(mean_init, cov_func=cov_func)
    gp = pm.gp.Marginal(cov_func=cov_func)

    # Place a GP prior over the function f and do the noise:
    sigma = pm.HalfNormal("sigma", sigma=1)
    y_ = gp.marginal_likelihood("y_", X=X, y=y.flatten(), noise=sigma)

    # MCMC:
    trace = pm.sample(10000, chains=3, tune=1000, target_accept=0.99)

X_new = np.linspace(-1.5, 1.5, 500)
X_new = X_new.reshape(-1,1)
with d_model:
    f_p = gp.conditional("f_p", X_new)
    pred_samples = pm.sample_posterior_predictive(trace, samples=10, keep_size=False) 

And I obtain the error

ValueError: conflicting sizes for dimension 'chain': length 1 on the data but length 3 on coordinate 'chain'

In the PyMC discourse link it was suggested to not use samples and keep_size, which effectively solved the issue. It was also suggested that samples in sample_posterior_predicitive is going to be deprecated. Anyway, here it is, as an issue in github, as it was suggested to me.

Versions and main components

  • PyMC/PyMC3 Version: PyMC 4.0.1
  • Aesara/Theano Version: aesara=2.7.3
  • Python Version: 3.7.4
  • Operating system: Linux CentOS 7
  • How did you install PyMC/PyMC3: (conda/pip) admin installation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions