Sample posterior check with pm.Potentials

Hi everybody,

I am trying to do a weighted likelihood following the methods here and @junpenglao. The sampler works but I could not get pm.sample_posterior_check to work. There are couple questions on this forum with no satisfying answer. How to I get a posterior predictive check from a black-box likelihood function like this? Thanks so much.

t = np.arange(N)
w = np.random.uniform(0,1,N)

with pm.Model() as model_StudentsT_weightedLLH:

     a = pm.Normal('a', mu = 80, sigma = 20) #intercept
     b = pm.HalfNormal('b', sigma = 10) #amplitude
     c = pm.Normal('c', mu = 5, sigma = 1) #phase shift
     d = pm.Normal('d', mu = 0.2, sigma = 0.1) #activity coeff
     σ = pm.HalfNormal("σ", sigma=10) 

     μ = a - b * pm.math.cos(np.pi/12 * (t - c)) + d*steps 
     llh_w = pm.Potential('llh_w', w * pm.Normal.dist(mu = μ, sigma = σ).logp(hr))
     pm.sample(10000, return_inferencedata = False, tune = 2000) 
1 Like

Can you provide a working example? I don’t know what N or p are and your code won’t run with arbitrary values. Also, what version of pymc are you using?

1 Like