-
-
Notifications
You must be signed in to change notification settings - Fork 269
Re run marginalised gaussian notebook #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re run marginalised gaussian notebook #4
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
15f077d
to
d15dadc
Compare
Is this ready for review? |
d15dadc
to
a58cdb8
Compare
@AlexAndorra yup! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small change to make it even better, and then it'll be ready for merge 😉
View / edit / reply to this conversation on ReviewNB AlexAndorra commented on 2020-12-19T12:35:44Z Even better, use See https://arviz-devs.github.io/arviz/api/generated/arviz.from_pymc3_predictions.html#arviz.from_pymc3_predictions and https://docs.pymc.io/notebooks/multilevel_modeling.html (cell 51) MarcoGorelli commented on 2020-12-19T13:22:52Z Sure, thanks! Would the idea then be to use
AlexAndorra commented on 2020-12-19T18:31:45Z Mmmh no, you should be able to just do MarcoGorelli commented on 2020-12-19T19:26:31Z I think I'm misunderstanding - for a small reproducible example, I tried with pm.Model() as mcve: x = pm.Normal('x') y = pm.Normal('y', mu=x, observed=[1,2,3,4,5]) trace = pm.sample(return_inferencedata=True) pp = pm.sample_posterior_predictive(trace=trace) trace = az.from_pymc3_predictions(pp, idata_orig=trace) az.plot_ppc(trace) and got ~/miniconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/arviz/plots/ppcplot.py in plot_ppc(data, kind, alpha, mean, color, figsize, textsize, data_pairs, var_names, filter_vars, coords, flatten, flatten_pp, num_pp_samples, random_seed, jitter, animated, animation_kwargs, legend, ax, backend, backend_kwargs, group, show) 182 for groups in ("{}_predictive".format(group), "observed_data"): 183 if not hasattr(data, groups): --> 184 raise TypeError( 185 ' AlexAndorra commented on 2020-12-19T19:54:36Z Interesting... Does the following work? pp = pm.sample_posterior_predictive(trace.posterior) trace = az.from_pymc3_predictions(pp, idata_orig=trace) (notice the Otherwise, does this work? pp = pm.sample_posterior_predictive(trace=trace) az.from_pymc3_predictions(pp, idata_orig=trace, inplace=True) And finally you can try: pp = pm.sample_posterior_predictive(trace.posterior) az.from_pymc3_predictions(pp, idata_orig=trace, inplace=True) I'm curious about which combination will work, and if that may actually reveal a bug MarcoGorelli commented on 2020-12-20T08:04:10Z None of them work for me. To reproduce, start with import pymc3 as pm import arviz as az Then, for the first code snippet you provided: with mcve: For the second one: with mcve: For the third one: with mcve: AlexAndorra commented on 2020-12-20T14:24:36Z Ok I think I got it!
So, in your minimal example, you just have to do: with mcve: pp = pm.sample_posterior_predictive(trace, keep_size=True) trace.add_groups(posterior_predictive=pp) Now, if you display And now MarcoGorelli commented on 2020-12-20T21:08:04Z Works now, thank you so much! AlexAndorra commented on 2020-12-20T21:56:44Z Thanks for persevering :D |
View / edit / reply to this conversation on ReviewNB AlexAndorra commented on 2020-12-19T12:35:44Z And then you don't need the casting to InferenceData here ;) |
Sure, thanks! Would the idea then be to use
View entire conversation on ReviewNB |
Mmmh no, you should be able to just do View entire conversation on ReviewNB |
I think I'm misunderstanding - for a small reproducible example, I tried with pm.Model() as mcve: x = pm.Normal('x') y = pm.Normal('y', mu=x, observed=[1,2,3,4,5]) trace = pm.sample(return_inferencedata=True) pp = pm.sample_posterior_predictive(trace=trace) trace = az.from_pymc3_predictions(pp, idata_orig=trace) az.plot_ppc(trace) and got ~/miniconda3/envs/pymc3-dev-py38/lib/python3.8/site-packages/arviz/plots/ppcplot.py in plot_ppc(data, kind, alpha, mean, color, figsize, textsize, data_pairs, var_names, filter_vars, coords, flatten, flatten_pp, num_pp_samples, random_seed, jitter, animated, animation_kwargs, legend, ax, backend, backend_kwargs, group, show) 182 for groups in ("{}_predictive".format(group), "observed_data"): 183 if not hasattr(data, groups): --> 184 raise TypeError( 185 ' View entire conversation on ReviewNB |
Interesting... Does the following work? pp = pm.sample_posterior_predictive(trace.posterior) (notice the Otherwise, does this work? pp = pm.sample_posterior_predictive(trace=trace) And finally you can try: pp = pm.sample_posterior_predictive(trace.posterior) I'm curious about which combination will work, and if that may actually reveal a bug View entire conversation on ReviewNB |
None of them work for me. To reproduce, start with import pymc3 as pm import arviz as az Then, for the first code snippet you provided: with mcve: For the second one: with mcve: For the third one: with mcve: View entire conversation on ReviewNB |
Ok I think I got it!
So, in your minimal example, you just have to do: with mcve: pp = pm.sample_posterior_predictive(trace, keep_size=True) trace.add_groups(posterior_predictive=pp) Now, if you display And now View entire conversation on ReviewNB |
Works now, thank you so much! View entire conversation on ReviewNB |
Thanks for persevering :D View entire conversation on ReviewNB |
Use inferencedata, use
pm.transforms.ordered
to address non-identifiability