I have a question about implementing a Hierarchical model in PyMC using a Black Box loglikelihood function. Specifically, I want to make sure that PyMC is receiving correct inputs from the likelihood function. I have a model with 4 parameters, with one partially pooled across three data sets. I have three data sets, so I need to call the likelihood function for each of them using Potential. This gives me the following code:
# create Op which calls likelihood function and inputs data (rt)
logl0 = LogLike(loglikelihood, rt[0])
logl1 = LogLike(loglikelihood, rt[1])
logl2 = LogLike(loglikelihood, rt[2])
# define dictionary of subjects
coords = {'subjects' : [0,1,2]}
# use PyMC to sample from log-likelihood
with pm.Model(coords = coords) as model:
# define priors
tnd = pm.Uniform("tnd", lower = 0.0, upper = 1.0)
v = pm.Uniform("v", lower = 0.0, upper = 5.0)
sigma = 1.0
a_mu = pm.Normal('a_mu', mu = 2.0, sigma = 0.75)
a_sigma = pm.Normal('a_sigma', mu = 1.0, sigma = 0.25)
a = pm.Normal("a", mu = a_mu, sigma = a_sigma, dims = 'subjects')
# turn priors into tensor variables
phi_pymc00 = at.as_tensor_variable([tnd, v, sigma, a[0]])
phi_pymc01 = at.as_tensor_variable([tnd, v, sigma, a[0]])
phi_pymc02 = at.as_tensor_variable([tnd, v, sigma, a[0]])
phi_pymc10 = at.as_tensor_variable([tnd, v, sigma, a[1]])
phi_pymc11 = at.as_tensor_variable([tnd, v, sigma, a[1]])
phi_pymc12 = at.as_tensor_variable([tnd, v, sigma, a[1]])
phi_pymc20 = at.as_tensor_variable([tnd, v, sigma, a[2]])
phi_pymc21 = at.as_tensor_variable([tnd, v, sigma, a[2]])
phi_pymc22 = at.as_tensor_variable([tnd, v, sigma, a[2]])
# use Potential to call the loglikelihood function
pm.Potential("llh0", logl0(phi_pymc00, phi_pymc01, phi_pymc02))
pm.Potential("llh1", logl1(phi_pymc10, phi_pymc11, phi_pymc12))
pm.Potential("llh2", logl2(phi_pymc20, phi_pymc21, phi_pymc22))
Will calling three potential functions like this cause and issue, or is this the correct way to instantiate my model? It runs without issue, but I don’t know if there is a more correct way to run this. Below is the model graph for reference in case it is helpful.