Unexpected results

Is it wrong to expect this very simple model gives me a joint distribution like a line for the posterior? What I get is actually my prior.

import numpy as np
import pymc3 as pm
import theano
import matplotlib.pyplot as plt
#%%
y=4
y_er=.1
y_observed=y_er*np.random.randn(5)+y
#%%
with pm.Model() as m:
    a = pm.Uniform('a', 0, 5)
    b = pm.Uniform('b', 0, 5)
    yhat = a+b
    sigma = pm.HalfCauchy('sd', .1)
    step=pm.NUTS()
    obs = pm.Normal('obs', yhat, sigma,observed=y_observed)
#%%
trace = pm.sample(model=m,draws=2000,tune=1000,skip=500,njobs=1,step=step)
a_pos=trace['a']
b_pos=trace['b']
plt.figure()
plt.scatter(a_pos,b_pos,color='red',alpha=.1)
plt.xlabel('a')
plt.ylabel('b')

Figure_4

It seems to me you are sampling from the prior, because you are defining the step before defining the likelihood, if you write:

    obs = pm.Normal('obs', yhat, sigma,observed=y_observed)
    step=pm.NUTS()

you will get the correct result.

BTW, you can just let PyMC3 choose the step for you by just writing.

    trace = pm.sample(2000)
2 Likes

Good catch! What a typo! Thank you Osvaldo!