Hi all, I’m new to bayesian statistical modeling and trying to fit parameters of a reinforcement learning model using self-generated data. No matter how I change the prior, I keep running into this error message:
/python3.9/site-packages/pymc3/step_methods/hmc/quadpotential.py:224: RuntimeWarning: divide by zero encountered in true_divide
np.divide(1, self._stds, out=self._inv_stds)
/python3.9/site-packages/pymc3/step_methods/hmc/quadpotential.py:203: RuntimeWarning: invalid value encountered in multiply
return np.multiply(self._var, x, out=out)
What might be the possible reasons of these warning?
Below are my code of update function and model:
def update_RW(stim_matrix,shock_matrix,vS,combined_v,lr,no_subjects):
"""
update function of Rescorla-Wagner model, will be used in pymc3 model estimation
"""
pe = shock_matrix - vS[tt.arange(no_subjects), stim_matrix]
# vS is a list of [[v for CS-, v for CS+],...] where shape = (no_subjects,2)
vS = tt.set_subtensor(vS[tt.arange(no_subjects),stim_matrix], vS[tt.arange(no_subjects),stim_matrix] + lr * pe)
#if stim = 1, append v for cs+, else append v for cs-
combined_v = tt.set_subtensor(combined_v[tt.arange(no_subjects),0], (tt.switch(tt.eq(stim_matrix,1),
vS[tt.arange(no_subjects),1], vS[tt.arange(no_subjects),0])))
return vS, combined_v
with pm.Model() as RW_model:
beta0 = pm.Normal('beta0',0, 1)
beta1 = pm.Normal('beta1',0, 1)
lr_hypermu = pm.Normal('lr_hypermu', 0,1)
lr_hypersd = pm.HalfCauchy('lr_hypersd',beta=5)
lr = pm.Bound(pm.Normal, lower=0.0, upper=1.0)('lr',mu=lr_hypermu, sigma=lr_hypersd, shape=no_subjects)
vS = 0.5 * tt.ones((no_subjects,2), dtype='float64')
combined_v = 0.5 * tt.ones((no_subjects,1), dtype='float64')
outputs, updates = theano.scan(
fn=update_RW,
sequences=[stim_matrix, shock_matrix],
outputs_info=[vS, combined_v],
non_sequences=[lr, no_subjects])
combined_v_ = outputs[1].reshape(est_scr_matrix.shape)
est_scr_model = combined_v_* beta0 + beta1
eps = pm.HalfNormal('eps', 5)
scrs = pm.Normal('scrs',est_scr_model,eps,observed=est_scr_matrix)
trace = pm.sample(target_accept=0.9, chains=4, cores=10, return_inferencedata=True)