Reputation: 180
is there any reason why the NUTS sampler might be slow or stall? I'm using http://twiecki.github.io/blog/2014/03/17/bayesian-glms-3/ as a basis for some hierachical linear regression work. I've tried starting with find_MAP() and it's still stalls after 100 of the 2000 iterations
my code is
with pm.Model() as hierarchical_model:
# Hyperpriors for group nodes
mu_a = pm.Normal('mu_alpha', mu=0., sd=100**2)
sigma_a = pm.Uniform('sigma_alpha', lower=0, upper=100)
mu_b = pm.Normal('mu_beta', mu=0., sd=100**2)
sigma_b = pm.Uniform('sigma_beta', lower=0, upper=100)
a = pm.Normal('alpha', mu=mu_a, sd=sigma_a, shape=n_dis)
b = pm.Normal('beta', mu=mu_b, sd=sigma_b, shape=n_dis)
# Model error
eps = pm.Uniform('eps', lower=0, upper=100)
actual_est = a[disRefV] + b[disRefV] * data.baseline.values
actual_like = pm.Normal('actual_like', mu=actual_est, sd=eps, observed=data.prepanel)
with hierarchical_model:
start = pm.find_MAP()
step = pm.NUTS()
hierarchical_trace = pm.sample(2000, step, progressbar=True)
many thanks in advance
Upvotes: 3
Views: 2048
Reputation: 1316
NUTS does get stuck sometimes. Did you z-score / standardize your data? That often helped in my experiments. If you are using a hierarchical model you'll probably want to z-score your data according to the group mean, not the individual means.
You can then rescale your posteriors so that they are in the original space (formula 17.1 in the Kruscke book "Doing Baysian Data Analysis").
Upvotes: 3