I’m trying to use PyMC3 to work out an example (exercise 3.3, p 47) from David MacKay’s great book " Information Theory, Inference, and Learning Algorithms" .
I was able to use a crude (manual) grid search approach and it worked OK. I was hoping to learn more about PyMC3 by using it for the same purpose. Here’s what I tried:
import numpy as np
import pymc3 as pm
import arviz as az
import theano.tensor as tt
print(f"Running on PyMC3 v{pm.__version__}")
np.random.seed(451)
x = np.random.exponential(3,size=500)
minx=1
maxx=20
obs = x[np.where(~((x<minx) | (x>maxx)))] # remove values outside range
with pm.Model() as expModel:
λ = pm.Exponential("λ", lam=5)
x = pm.Exponential('x', lam=1/λ, observed=obs)
clip_exp = pm.Potential("clip_exp", tt.switch(((x<minx)|(x>maxx)),-np.inf,0))
trace= pm.sample(2000, tune=1000, return_inferencedata=True)
az.summary(trace)
Sadly it doesn’t appear to have worked:
mean sd hdi_3% hdi_97% mcse_mean mcse_sd ess_mean ess_sd
λ 3.683 0.188 3.333 4.051 0.003 0.002 3268.0 3268.0
Any suggestions would be appreciated!
thank you,
-Steve