Hi,
I’m following this tutorial (Fitting a Reinforcement Learning Model to Behavioral Data with PyMC — PyMC example gallery)
and I am trying to pass two matrices as observed
parameters to a CustomDist
logp function.
This is my code
def logp(learning_rate, inv_temp, choices, outcomes):
choices_ = pt.as_tensor_variable(choices, dtype='int32')
outcomes_ = pt.as_tensor_variable(outcomes, dtype='int32')
beliefs = 0.5 * pt.ones((4,), dtype='float64')
choice_probs_ = 0.5 * pt.ones((1,), dtype='float64')
[beliefs, choice_probs], updates = scan(
fn=update_belief,
sequences=[choices_, outcomes_],
non_sequences=[learning_rate, inv_temp],
outputs_info=[beliefs, choice_probs_]
)
ll = np.sum(np.log(choice_probs))
return ll
with pm.Model as m:
# n_trial x 1
choices_ = pm.ConstantData('choices_', choices)
# n_trial x 4
outcomes_ = pm.ConstantData('outcomes_', outcomes)
alpha = pm.Beta(name="alpha", alpha=1, beta=1)
beta = pm.HalfNormal(name="beta", sigma=10)
like = pm.CustomDist('like', alpha, beta, logp=logp, observed={'choices':choices_, 'outcomes':outcomes_})
and I get the following error
Blockquote TypeError: Since
v4.0.0
theobserved
parameter should be of typepd.Series
,np.array
, orpm.Data
. Previous versions allowed passing distribution parameters as a dictionary inobserved
, in the current version these parameters are positional arguments.
Is it possible in v>4.0 of PyMC to pass multiple observed parameters to my logp function?
I can’t find any recent example of it.
Thanks
Filippo