Hi any suggestions please??? Thank you
ppc_w = pm.sample_posterior_predictive_w(
[trace_0, trace_2, trace_1],
[model_0, model_1, model_2],
comp.weight.sort_index(ascending=True),
progressbar=True,
)
FutureWarning: The function sample_posterior_predictive_w
has been removed in PyMC 4.3.0. Switch to arviz.stats.weight_predictions
ppc_w = az.stats.weight_predictions(
[trace_0, trace_2, trace_1],
[model_0, model_2, model_1],
comp.weight.sort_index(ascending=True),
progressbar=True
)
TypeError: weight_predictions() got an unexpected keyword argument ‘progressbar’
It looks like arviz.stats.weight_predictions
doesn’t take a progressbar
argument. Did you check the docstring for this function? That’s always a good place to start.
#Posteriors
with model_0:
pp_model0 = pm.sample_posterior_predictive(trace_0)
# Save the idata to a NetCDF file
# Open it here: https://filext.com/online-file-viewer.html
# For the moment all chains and draws are empty, so I guess something is not working in the computations...
idata = pm.sample(return_inferencedata=True)
print (idata)
idata.to_netcdf("C:/Users/Ossama/Model_Muse/filename.nc")
#pp_model0= pm.sample_posterior_predictive(model_0)
print(pp_model0)
with model_1:
pp_model1= pm.sample_posterior_predictive(trace_1)
with model_2:
pp_model2= pm.sample_posterior_predictive(trace_2)
model0= az.from_dict({
'observed_data':{'x': observed_data},
'posterior_predictive': pp_model0
})
model1= az.from_dict({
'observed_data':{'x': observed_data},
'posterior_predictive': pp_model1
})
model2= az.from_dict({
'observed_data':{'x': observed_data},
'posterior_predictive': pp_model2
})
weights= [0.3, 0.7, 0.3]
ppc_w= az.stats.weight_predictions([model0, model1, model2], weights)
print(ppc_w)
I used this now but it shows me another error:
ValueError Traceback (most recent call last)
Cell In[4], line 45
38 model2= az.from_dict({
39 'observed_data':{'x': observed_data},
40 'posterior_predictive': pp_model2
41 })
43 weights= [0.3, 0.7, 0.3]
---> 45 ppc_w= az.stats.weight_predictions([model0, model1, model2], weights)
47 print(ppc_w)
49 #ppc_2 = az.stats.weight_predictions(model2)
50
51 #print(ppc_2)
File ~\anaconda3\Lib\site-packages\arviz\stats\stats.py:2078, in weight_predictions(idatas, weights)
2075 raise ValueError("You should provide a list with at least two InferenceData objects")
2077 if not all("posterior_predictive" in idata.groups() for idata in idatas):
-> 2078 raise ValueError(
2079 "All the InferenceData objects must contain the `posterior_predictive` group"
2080 )
2082 if not all(idatas[0].observed_data.equals(idata.observed_data) for idata in idatas[1:]):
2083 raise ValueError("The observed data should be the same for all InferenceData objects")
ValueError: All the InferenceData objects must contain the `posterior_predictive` group
I don’t think you need to do all those az.from_dict
calls. pm.sample_posterior_predictive
will return an InferenceData object with a posterior_predictive
group.