Hello, PyMC-community!
I am trying to build a model, one of the components being Gaussian Process.
However, once I am trying to get out-of-sample predictions (pm.sample_posterior_predictive(idata)
), I am getting some shape mismatch error:
Input dimension mismatch: (input[1].shape[0] = 5, input[2].shape[0] = 10)
I previously got acquainted to some solutions in threads related to shape mismatch, when using pm.sample_posterior_predictive()
, (e.g here and here) like adding dims, changing shapes for all variables, setting shape=mu.shape for observed
, but they do not seem to work for me.
The code is here:
import numpy as np
import pymc as pm
integer_time = np.arange(0,10)
future_integer_time = np.arange(0,5)
with pm.Model() as model:
x = pm.MutableData(name="x", value=[1,5,6,4,2,3,4,7,8,9], dims='obs_id')
y = pm.MutableData(name="y", value=[11,52,61,43,22,34,41,76,83,92], dims='obs_id') # y = 10*x + noise, here always positive
beta = pm.Normal("beta", mu=0, sigma=500)
sigma = pm.HalfNormal("sigma", sigma=500)
eta = pm.HalfNormal(name=f'eta', sigma=10)
ls = pm.HalfNormal(name=f'ls', sigma=10)
cov_func = eta**2 * pm.gp.cov.Matern52(1, ls=ls)
gp = pm.gp.HSGP(m=[30], c=1.2, cov_func=cov_func)
gp_rv = gp.prior('gp_rv',integer_time[:,None])
mu = pm.Deterministic('mu', beta * x + gp_rv, dims='obs_id')
obs = pm.Normal("obs", mu=mu, sigma=sigma, observed=y, dims='obs_id') # also tried to add shape=mu.shape, but does not seem to work
idata = pm.sample()
# Want to get mu predictions for new data
with model:
pm.set_data( {'x': [4,7,3,9,1]} ) # Also tried adding 'y': [0,0,0,0,0]
gp_rv_pred = gp.conditional("gp_rv_pred", Xnew=future_integer_time[:, None])
posterior_pred = pm.sample_posterior_predictive(idata)
Thanks so much in advance!
PS. Using 5.19.0, but tried later versions.