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 = β[0] + β[0]*D + β[1]*R + β[2]*I + β[3]*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 = β[0] + β[1]*A + β[2]*B + β[3]*C + β[4]*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