Use case
Suppose I have an observation y_0
at X_0
which I’d like to model with a Gaussian process with hyper params theta
. Suppose I then determine a distribution in the hyper params theta
by hierarchically sampling the marginal.
Now, I’d like to evaluate the log posterior probability of another observation say y_1
at X_1
, averaged over the hyper param distribution,
E_theta [ log P(y_1 | y_0, X_0, X_1, theta) ]
Ideally, I’d draw from the posterior in theta
and calculate log P(y_1 | y_0, X_0, X_1, theta)
and then take the geometric mean.
Question
In pymc3 is there a way to create the tensor representing log P(y_1 | y_0 X_0 X_1 theta)
. Ideally, I would do something like (copy-pastable),
import numpy as np
import pylab as plt
import pymc3 as pm
# Data generation
X0 = np.linspace(0, 10, 100)[:,None]
y0 = X0**(0.5) + np.exp(-X0/5)*np.sin(10*X0)
y0 += 0.1*np.random.normal(size=y0.shape)
y0 = np.squeeze(y0)
# y1
X1 = np.linspace(0, 15, 200)[:,None]
y1 = X1**(0.5) + np.exp(-X1/6)*np.sin(8*X1)
y1 = np.squeeze(y1)
with pm.Model() as model:
l = pm.HalfNormal('l',5.)
cov_func = pm.gp.cov.ExpQuad(1, ls=l)
gp = pm.gp.Marginal(cov_func=cov_func)
y0_ = gp.marginal_likelihood('y0',X0,y0,0.1)
# I think given is not needed because it should be cached from above
y1_ = gp.conditional('y1',X1,given={'X':X0,'y':y0,'noise':0.1})
logp = pm.Deterministic('logp',y1_.logp(y1))
trace = pm.sample(100)
This produce the traceback:
TypeError: can't turn [array([...]) and {} into a dict. cannot convert dictionary update sequence element #0 to a sequence
Any help greatly appreciated!