 Model specification problem?

So I’ve had some good luck implementing a bunch of models. But there’s one that I’m having trouble getting to work (ie sample). It dies before sampling with a very long bit cryptic error message. One salient point is: ValueError: Bad initial energy: inf. The model might be misspecified. I’m fairly sure it’s just something basic wrong with the way how I’ve written the model.

with pm.Model() as model:
# Priors
β = pm.Normal('beta', mu=0, sd=10, shape=4)
α = pm.Exponential('alpha', lam=1)
ϵ = 0.01

D = data['B']-data['A']
R = (data['B']-data['A'])/data['A']
T = data['DB']-data['DA']
I = ((data['B']-data['A'])**(1./(data['DB']-data['DA'])))-1.
diff = β + β*D + β*R + β*I + β*T

# Choice function: psychometric
P_chooseB = pm.Deterministic('P_chooseB', choice_func_psychometric2(α, ϵ, diff))
# Likelihood of observations
r_likelihood = pm.Bernoulli('r_likelihood', p=P_chooseB, observed=data['R'])

I have a very similar one (below) working fine, so I’m being a bit blind to what it might be.

with pm.Model() as model:
# Priors
β = pm.Normal('beta', mu=0, sd=1, shape=5)
α = pm.Exponential('alpha', lam=1)
ϵ = 0.01

A = data['B']-data['A']
B = (data['B']-data['A'])/((data['B']+data['A'])/2)
C = data['DB']-data['DA']
D = (data['DB']-data['DA'])/((data['DB']+data['DA'])/2)
diff = β + β*A + β*B + β*C + β*D

# Choice function: psychometric
P_chooseB = pm.Deterministic('P_chooseB', choice_func_psychometric2(α, ϵ, diff))
# Likelihood of observations
r_likelihood = pm.Bernoulli('r_likelihood', p=P_chooseB, observed=data['R'])

Any thoughts?

Have you check out the diagnostic mentioned here:

Most likely I would say is the Deterministic node P_chooseB being outside of [0, 1] (the support of p in Bernoulli)

Ah! The problem is that data['B']-data['A'] is sometimes negative, so the power in

I = ((data['B']-data['A'])**(1./(data['DB']-data['DA'])))-1.

causes I to be a complex number when data['B']-data['A']<0

1 Like