I’d like to use a L2-norm likelihood function
P(d|m) \propto exp \frac{||d-f(m)||^2}{\sigma^2}
where d is the observed data, m are my parameters and f is the external function that returns simulated data. So can I just write an customized Theano function to return the difference between d and f(m) and inside pm.Model() use Normal()?
import theano.tensor as tt
from theano.compile.ops import as_op
@as_op(itypes=[tt.lscalar], otypes=[tt.lscalar])
def myFunc(X,V):
smod[0,2:] = X
smod[1,2:] = V
d1 = myBlackBox.calcD(smod)
d0 = myBlackBox.getObserved()
return (d1-d0)**2.sum()
with pm.Model as model:
X = pm.Normal('X', mu=X_pr, sd=100, shape=len(X_pr))
V = pm.Normal('V', mu=V_pr, sd=50, shape=len(V_pr))
like = myFunc(X,V)
obs = pm.Normal('obs', mu=like, observed=d0)
trace = pm.sample(10000)