Issues while using sample_posterior_predictive _w to compute probability or weights

Hi all,

I have one doubt regarding 'sample_posterior_predictive function. Actually I wish to compute the weights(probability) of predicted samples. So I used the function
“pymc3.sampling.sample_posterior_predictive_w(trace)”.
But when I’m trying to run this , an error occured. Its like

AttributeError Traceback (most recent call last)
in
----> 1 ppc_w = pm.sample_posterior_predictive_w(trace, 1000, model_particle,progressbar=False)

~/.local/lib/python3.6/site-packages/pymc3/sampling.py in sample_posterior_predictive_w(traces, samples, models, weights, random_seed, progressbar)
1786 traces = [dataset_to_point_dict(trace) for trace in traces]
1787 else:
-> 1788 n_samples = [len(i) * i.nchains for i in traces]
1789
1790 if models is None:

~/.local/lib/python3.6/site-packages/pymc3/sampling.py in (.0)
1786 traces = [dataset_to_point_dict(trace) for trace in traces]
1787 else:
-> 1788 n_samples = [len(i) * i.nchains for i in traces]
1789
1790 if models is None:

AttributeError: ‘dict’ object has no attribute ‘nchains’

Can anybody help me to resolve this error. Thanks in advance

How to calculate the weights (probability) of posterior function generated using pymc3.model().Is this the correct method?

I suspect that you are passing a single trace object, whereas sample_posterior_predictive_w() takes a list of traces (see the documentation). sample_posterior_predictive_w() allows you to sample from a set of posteriors according to the supplied weights, as one might do when doing model averaging .

1 Like

Thanks a lot. I didn’t notice that exactly.
Let me try in that way