I am new to MCMC and theano, and now I have three equations similar to the following equations：
r1 = ……
r2 = ……
r3 = ……
R_a = r1 + r2
R_b = r1 - r3
R_c = - r2 - r3;
Due to the fact that experimental data of R_a, R_b and R_c is available, so I want to use Likehood of R_a, R_b and R_c to do sampling as follow:
R_a_likehood = pm.Normal(‘R_a_likehood’,mu = R_a_obs, sd = sigma, observed = R_a_data)
R_b_likehood = pm.Normal(‘R_b_likehood’,mu = R_b_obs, sd = sigma, observed = R_b_data)
R_c_likehood = pm.Normal(‘R_c_likehood’,mu = R_c_obs, sd = sigma, observed = R_c_data)
But it seems that only one likehood can be used.
I tried to use np.vstack to combine the array, but I encountered the problem of “ValueError: setting an array element with a sequence.”
So how can I do MCMC sampling with Multiple likelihood functions？
The model code is valid and multiple likelihood will be accounted for - I dont see np.vstack in your code, where and how do you use it? The error seems to raise from there.
Before I use to solve this “Adding” but, now I am interested in knowing how to solve this kind of scenario…
Sorry for the late reply!
This is the original model with three likelihoods (where ‘p’, ‘keq’, ‘R’, ‘T_Bottom’ and ‘r’ are the experimental data), and the equations in the red block is the model I want to simulated, but my professor said that the MCMC model should have only one likelihood.
As a result of which, I try to use np.hstack to combine three ‘r’ into one array as follow:
r_CH4_obs = - r_2 - r_3
r_CO2_obs = r_1 + r_2
r_CO_obs = r_3 - r_1
rrr_obs = np.hstack((r_CH4_obs,r_CO_obs,r_CO2_obs))
rrr_likelihood = pm.Normal('rrr_likelihood',mu = rrr_obs, sd = sigma, observed = rrr0)
As a result of which, Python encounted the error of ‘setting an array element with a sequence.’
So I want to ask for help that how to construct a likelihood function with a vector or matrix to complete the MCMC sampling. Also I would like to find some reference material or literature on this to simulate different multiple likelihood models with MCMC methods. Thanks!
You don’t need to do anything to your code to get the combined likelihood - behind the scenes, PyMC3 is adding together the contributions from the log likelihoods from each of the 3 lines. Creating a single vector variable is admittedly cleaner and easier to follow, but it won’t fundamentally change the results you get.
As for the
ValueError you’re getting, the shapes of the variables you’ve provided in
rrr_likelihood aren’t compatible. Can you print off the shapes of these using