Open chdamianos opened 6 years ago
Sorry this was meant to be posted in another book's issues page. Anyway, in case somebody ends up here looking for the answer I solved my problem by changing the code to:
with pm.Model() as hierarchical_model:
# hyper-priors
alpha_tmp_mu = pm.Normal('alpha_tmp_mu', mu=0, sd=10)
alpha_tmp_sd = pm.HalfNormal('alpha_tmp_sd', 10)
beta_mu = pm.Normal('beta_mu', mu=0, sd=10)
beta_sd = pm.HalfNormal('beta_sd', sd=10)
# a prioris
alpha_tmp = pm.Normal('alpha_tmp', mu=alpha_tmp_mu, sd=alpha_tmp_sd, shape=M)
beta = pm.Normal('beta', mu=beta_mu, sd=beta_sd, shape=M)
epsilon = pm.HalfCauchy('epsilon', 5)
nu = pm.Exponential('nu', 1/30)
y_pred = pm.StudentT('y_pred', mu=alpha_tmp[idx] + beta[idx] * x_centered, sd=epsilon, nu=nu, observed=y_m)
alpha = pm.Deterministic('alpha', alpha_tmp - beta * x_m.mean())
alpha_mu = pm.Deterministic('alpha_mu', alpha_tmp_mu - beta_mu * x_m.mean())
alpha_sd = pm.Deterministic('alpha_sd', alpha_tmp_sd - beta_mu * x_m.mean())
trace_hm = pm.sample(1000, advi_map=True, chains=1, njobs=1)
Sorry this was meant to be posted in another book's issues page. Anyway, in case somebody ends up here looking for the answer I solved my problem by changing the code to:
with pm.Model() as hierarchical_model: # hyper-priors alpha_tmp_mu = pm.Normal('alpha_tmp_mu', mu=0, sd=10) alpha_tmp_sd = pm.HalfNormal('alpha_tmp_sd', 10) beta_mu = pm.Normal('beta_mu', mu=0, sd=10) beta_sd = pm.HalfNormal('beta_sd', sd=10) # a prioris alpha_tmp = pm.Normal('alpha_tmp', mu=alpha_tmp_mu, sd=alpha_tmp_sd, shape=M) beta = pm.Normal('beta', mu=beta_mu, sd=beta_sd, shape=M) epsilon = pm.HalfCauchy('epsilon', 5) nu = pm.Exponential('nu', 1/30) y_pred = pm.StudentT('y_pred', mu=alpha_tmp[idx] + beta[idx] * x_centered, sd=epsilon, nu=nu, observed=y_m) alpha = pm.Deterministic('alpha', alpha_tmp - beta * x_m.mean()) alpha_mu = pm.Deterministic('alpha_mu', alpha_tmp_mu - beta_mu * x_m.mean()) alpha_sd = pm.Deterministic('alpha_sd', alpha_tmp_sd - beta_mu * x_m.mean()) trace_hm = pm.sample(1000, advi_map=True, chains=1, njobs=1)
for now ,the code can not be run.
and I run this code which work for me.trace_hm = pm.sample(1000, init='advi_map', chains=1, njobs=1)
Is that right?
I get an error in chapter 4 when I try to run the code for the hierarchical linear regression model
These are the details of my installation