Hello,
I’m trying to calibrate a time-dependant deterministic model following this dynamics: z_t | \theta_1, \theta_2, \theta_3 = f(z_{t-1}, (\theta_1, \theta_2, \theta_3)) where f is some deterministic (non linear) function and (\theta_1, \theta_2, \theta_3) are the parameters I want to calibrate using a bayesian approach.
The idea was to define the likelihood function like this : Y_t | (\theta_1, \theta_2, \theta_3) \sim N( z_t | (\theta_1, \theta_2, \theta_3) , \sigma) where Y_t is my observation at time t (seen as a RandomVariable distributed from the likelihood), z_t my model prediction and \sigma is the (fixed) error of measure.
The troubles come when I try to declare the likelihood. I compute the model predictions, store them in a numpy.array and give them to the pymc3.Normal() function.
obs = pm.Normal('observations', mu=simus, sigma=measure_error, observed=data) # simus contains the predictions for each date at which a measure was done
it raises a
ValueError: setting an array element with a sequence.
I defined the same model using pymc2 and the inference worked well. Here is the code where I define the model (the inference was performed in an other file that imported the model):
# priors
theta1 = pymc.Beta('theta1', alpha=alpha_t1, beta=beta_t1)
theta2 = pymc.Beta('theta2', alpha=alpha_t2, beta=beta_t2)
theta3 = pymc.Normal('theta3', mu=mu_t3, tau=sig_t3)
# apply markov model using random variables as parameters for the dates of measures
@pymc.deterministic # decorator allows to return a pymc.Deterministic object
def wrap_simu(th1=theta1, th2=theta2, th3=theta3):
params = {'theta1': th1, 'theta2': th2, 'theta3': th3}
simus = run_simu(params) # returns an array containing the predictions
return simus
# likelihood (observations are distributed from likelihood)
obs = pymc.Normal('obs', mu=wrap_simu, tau=measure_error, value=measures, observed=True)
I also tried to use a Deterministic variable with pymc3:
simus = pm.Deterministic('simus', run_simu(z0, final_t, dates, theta1, theta2, theta3))
but it raises:
TypeError: order not understood
I know that my pymc3 code fails because I don’t use proper Theano objects but I don’t know how to cast the numy.array containing my model predictions into a theano.vector (the theano.shared()
did not work).
So, does anyone have an idea of how to proceed ?
Thank you very much.