I understand how gaussian processes work in v3, but know I try to run it on v5,I got error, TypeError: sample_posterior_predictive() got an unexpected keyword argument 'vars'
the problem seems comes from here,
with model_reg:
f_pred = gp.conditional(‘f_pred’, X_new)
with model_reg:
pred_samples = pm.sample_posterior_predictive(trace_reg, vars=[f_pred],samples=82)
_, ax = plt.subplots(figsize=(12,5))
ax.plot(X_new, pred_samples[‘f_pred’].T, ‘C1-’, alpha=0.3)
ax.plot(X, y, ‘ko’)
ax.set_xlabel(‘X’)
what should I do to transform them to v5:
np.random.seed(42)
x = np.random.uniform(0, 10, size=15)
y = np.random.normal(np.sin(x), 0.1)
plt.plot(x, y, 'o')
true_x = np.linspace(0, 10, 200)
plt.plot(true_x, np.sin(true_x), 'k--')
plt.xlabel('x')
plt.ylabel('f(x)', rotation=0)
#%%
# A one dimensional column vector of inputs.
X = x[:, None]
with pm.Model() as model_reg:
# hyperprior for lengthscale kernel parameter
ℓ = pm.Gamma('ℓ', 2, 0.5)
# instanciate a covariance function
cov = pm.gp.cov.ExpQuad(1, ls=ℓ)
# instanciate a GP prior
gp = pm.gp.Marginal(cov_func=cov)
# prior
ϵ = pm.HalfNormal('ϵ', 25)
# likelihood
y_pred = gp.marginal_likelihood('y_pred', X=X, y=y, sigma=ϵ)
trace_reg = pm.sample(2000)
az.plot_trace(trace_reg)
X_new = np.linspace(np.floor(x.min()), np.ceil(x.max()), 100)[:,None]
with model_reg:
f_pred = gp.conditional('f_pred', X_new)
with model_reg:
pred_samples = pm.sample_posterior_predictive(trace_reg, vars=[f_pred],samples=82)
_, ax = plt.subplots(figsize=(12,5))
ax.plot(X_new, pred_samples['f_pred'].T, 'C1-', alpha=0.3)
ax.plot(X, y, 'ko')
ax.set_xlabel('X')