I forgot to mention, but I used GP with student likelihood, same as TP.
And here is the whole code:
with pm.Model() as model:
c = pm.Normal('c', mu=0, sd=0.5)
η = pm.HalfNormal("η", sd=1)
ℓ = pm.HalfNormal("ℓ", sd=0.5)
ν = pm.Gamma("ν", alpha=2, beta=0.1, shape=2)
cov = η**2 * pm.gp.cov.ExpQuad(1, ℓ)
gp = pm.gp.Latent(mean_func=pm.gp.mean.Constant(c),
cov_func=cov)
# comment the above line and uncomment below to switch from GP to TP
# gp = pm.gp.TP(mean_func=pm.gp.mean.Constant(c),
# cov_func=cov,
# nu=ν[0])
f = gp.prior('f', X=x_train[:, None])
σ = pm.HalfNormal("σ", sd=0.5)
y_ = pm.StudentT("y", mu=f, lam=1.0/σ, nu=ν[1], observed=y_train)
trace = pm.sample(njobs=3)
x_pred = np.linspace(x_train.min() - 1, x_train.max() + 1, 100)
y_pred = gp.conditional('y_pred', Xnew=x_pred[:, None])
samples = pm.sample_ppc(trace, vars=[y_pred], samples=1000)
and then
plt.plot(x_train, y_train, '.')
l, = plt.plot(x_pred, np.median(samples['y_pred'], 0))
plt.fill_between(x_pred, *np.percentile(samples['y_pred'], [16, 84], 0), alpha=0.4, color=l.get_color())
plt.fill_between(x_pred, *np.percentile(samples['y_pred'], [2.5, 97.5], 0), alpha=0.2, color=l.get_color())
to get the prediction plots from the first post. The data:
x_train = [ -2.91991786, -2.75564682, -2.65434634, -2.62149213,
-2.44079398, -2.04106776, -1.89322382, -1.71526352,
-1.52361396, -1.39493498, -1.25256674, -1.03080082,
-0.71594798, -0.64750171, -0.03422313, 0.0807666 ,
0.19575633, 0.38740589, 0.80903491, 1.19233402,
1.26899384, 1.50718686, 1.82477755, 2.04106776,
2.04106776, 2.17522245, 2.34770705, 2.55852156,
2.73100616, 3.19096509, 3.34428474, 3.45927447,
3.51676934, 3.70841889, 5.51540041, 6.5229295 ,
6.96098563, 7.48117728, 7.5797399 , 7.9247091 ,
8.36550308, 10.47364819, 13.02258727]
y_train = [ 0.70423359, 0.72200438, 0.77554082, 0.70194589, 0.64435481,
0.99989352, 0.66998084, 0.55096063, 0.50594506, 0.54125961,
0.56752747, 0.37616882, 0.43905362, 0.5621031 , 0.47422528,
0.51995446, 0.47248769, 0.59128824, 0.69214369, 0.55897017,
0.66306419, 0.61727744, 0.56153796, 0.50519954, 0.46369249,
0.45691936, 0.60405043, 0.44529634, 0.52326453, 0.28551515,
0.37393222, 0.6092491 , 0.52784151, 0.61273912, 0.64628011,
0.5829985 , 0.76831989, 0.17223425, 1.25646104, 0.81781078,
0.44856902, 0.55787261, 0.33272409]