Hello all,
I am finding a large discrepancy between the posterior and posterior_predictive samples. This appears to be a similar issue to here where sample_posterior_predictive
is returning samples from the prior. However, I am unable to resolve the behavior by setting mutable=True
. Any ideas on how to fix this? I’ve pasted a toy example of my model below in addition to the code I am using to compare the posterior and posterior_predictive samples.
def toy_heirarchical_model(group, ind_obs, coords, prior_config):
with pm.Model(coords=coords) as model:
group_idx = pm.Data("group_idx", group, dims='obs_id', mutable=True)
obs = pm.Data("obs", ind_obs, dims='obs_id', mutable=True)
room_CV = pm.Gamma(
"room_CV",
alpha=prior_config["room_CV_alpha"],
beta=prior_config["room_CV_beta"]
)
group_CV = pm.Gamma("group_CV", mu=room_CV, sigma=0.03, dims="group")
group_mean = pm.Normal("group_mean",
mu=prior_config['group_means'],
sigma=3.2,
dims="group")
group_sigma = pm.Deterministic("group_sigma", group_mean*group_CV, dims="group")
y_hat = group_mean[group_idx]
sigma_hat = group_sigma[group_idx]
y = pm.Normal("y", mu=y_hat, sigma=sigma_hat, observed=obs, dims="obs_id")
idata = pm.sample_prior_predictive()
idata.extend(pm.sample(tune=5000, draws=5000, target_accept=0.95, nuts_sampler='nutpie', progressbar=True))
idata.extend(pm.sample_posterior_predictive(idata, var_names=['group_mean', 'group_sigma']))
return idata, model
idata, model = toy_heirarchical_model(condition, prop_obs, coords, prior_config)
print(idata.posterior_predictive['group_mean'].values[0,:,0])
print(idata.posterior['group_mean'].values[0,:,0])