Skip to content

update notebook: Update Priors #692

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

Merged
merged 8 commits into from
Aug 5, 2024

Conversation

juanitorduz
Copy link
Collaborator

@juanitorduz juanitorduz commented Aug 4, 2024

Update https://www.pymc.io/projects/examples/en/latest/howto/updating_priors.html to PyMC 5

Related to #115

It was still using PyMC3 and Theano :/


📚 Documentation preview 📚: https://pymc-examples--692.org.readthedocs.build/en/692/

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@juanitorduz juanitorduz added enhancement New notebook planned to be added to the collection docs labels Aug 4, 2024
@juanitorduz juanitorduz self-assigned this Aug 4, 2024

+++

In this notebook, I will show how it is possible to update the priors as new data becomes available. The example is a slightly modified version of the linear regression in the [Getting started with PyMC3](https://github.com/pymc-devs/pymc3/blob/master/docs/source/notebooks/getting_started.ipynb) notebook.
In this notebook, we will show how it is possible to update the priors as new data becomes available.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a note that this is actually a bit sketchy as the MC error can creep in. I think the last plot actually shows that as some posteriors jump.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@OriolAbril
Copy link
Member

I'll try to track the original author. I think this is a very nice usage example for Interpolated. But we should be a bit more clear this isn't really a good idea to do in practice not only for the posterior->kde part, but mostly because Interpolated distributions used as priors are unidimensional and uncorrelated, so even if a perfect fit marginally they don't really incorporate all the information we have from the previous posterior into the model, especially when posterior variables are correlated. I wrote a bit on this a while ago https://oriolabrilpla.cat/en/blog/posts/2022/too-eager-reduction.html#univariate-priors

It might also be nice to show or maybe only mention the functionality in https://www.pymc.io/projects/experimental/en/latest/generated/pymc_experimental.utils.prior.prior_from_idata.html which should probably work better for correlated posteriors close to normal, but probably worse than this approach for not correlated but far from normal (with no clear transformation) posteriors.

@juanitorduz juanitorduz requested a review from twiecki August 5, 2024 17:30
@juanitorduz
Copy link
Collaborator Author

Thanks for the feedback @twiecki and @OriolAbril . In cd0b93b, I added some words of caution (as suggested) and some additional references. I think we should update this notebook as this topic often comes with new practitioners. If we feel the approach can do more harm than good, we can also think about deleting the notebook. (I think we should keep it with these words of caution, but I am easy).

Also, I haven't been able to track the original author since the commit history started after the pymc3 migration.

@OriolAbril
Copy link
Member

Original PR: pymc-devs/pymc#1878

@juanitorduz
Copy link
Collaborator Author

Original PR: pymc-devs/pymc#1878

🙏 Wow! 2017!

from scipy import stats
from theano import as_op
from tqdm.notebook import trange
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does pymc still use tqdm for progressbars? It thought it had been changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses rich now but tqdm is easier to work with for me

@OriolAbril
Copy link
Member

I have added some comments. Some are suggestions on the myst file, but the editing process should continue to be work on the ipynb, save then run pre-commit

juanitorduz and others added 4 commits August 5, 2024 20:11
Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
@juanitorduz
Copy link
Collaborator Author

I have added some comments. Some are suggestions on the myst file, but the editing process should continue to be work on the ipynb, save then run pre-commit

Amazing! Thanks!

Indeed! JupyText to the rescue!

@juanitorduz juanitorduz requested a review from OriolAbril August 5, 2024 18:31
@juanitorduz juanitorduz merged commit 9612052 into pymc-devs:main Aug 5, 2024
2 checks passed
@juanitorduz juanitorduz deleted the update_priors_upgrade branch August 5, 2024 19:53
@juanitorduz
Copy link
Collaborator Author

Thank you @OriolAbril !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs enhancement New notebook planned to be added to the collection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants