diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 5b3965823..19c40beee 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -12,8 +12,8 @@ Explain the bug, error or mistake, where it is in the notebook, if it happens only once or multiple times... *Note that this issue tracker is about the contents in the notebooks, if -the notebook is instead triggering a bug or error in pymc3, please -report to https://github.com/pymc-devs/pymc3/issues instead* +the notebook is instead triggering a bug or error in pymc, please +report to https://github.com/pymc-devs/pymc/issues instead* ## Expected output If applicable, describe what should happen instead. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 911f97c15..90ec7040d 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,7 +2,7 @@ blank_issues_enabled: false contact_links: - name: PyMC Discourse url: https://discourse.pymc.io/ - about: Ask usage questions about PyMC3 or doubts about the examples here - - name: PyMC3 bug report - url: https://github.com/pymc-devs/pymc3/issues - about: Please report bugs or propose enhancements of the PyMC3 library here. + about: Ask usage questions about PyMC or doubts about the examples. If not sure where to ask, ask on Discourse. + - name: PyMC bug report + url: https://github.com/pymc-devs/pymc/issues + about: Please report bugs or propose enhancements of the PyMC library here. diff --git a/.github/ISSUE_TEMPLATE/notebook-proposal.md b/.github/ISSUE_TEMPLATE/notebook-proposal.md index ef71d4f80..76ac56f55 100644 --- a/.github/ISSUE_TEMPLATE/notebook-proposal.md +++ b/.github/ISSUE_TEMPLATE/notebook-proposal.md @@ -9,7 +9,7 @@ labels: proposal **Title**: Use this also as issue title ## Why should this notebook be added to pymc-examples? -Explain why this topic is interesting and useful to PyMC3 users. +Explain why this topic is interesting and useful to PyMC users. ## Related notebooks Cover related notebooks on which this notebook will build, diff --git a/README.rst b/README.rst index 94a8326f6..130f84708 100644 --- a/README.rst +++ b/README.rst @@ -1,17 +1,17 @@ -.. image:: https://cdn.rawgit.com/pymc-devs/pymc3/master/docs/logos/svg/PyMC3_banner.svg +.. image:: https://cdn.rawgit.com/pymc-devs/pymc/main/docs/logos/svg/PyMC_banner.svg :height: 100px - :alt: PyMC3 logo + :alt: PyMC logo :align: center -PyMC3 Examples +PyMC Examples ============== -Supporting examples and tutorials for PyMC3, the Python package for Bayesian statistical modeling and Probabilistic Machine Learning! +Supporting examples and tutorials for PyMC, the Python package for Bayesian statistical modeling and Probabilistic Machine Learning! Check out the `getting started guide `__, or -`interact with live examples `__ -using Binder! -For questions on PyMC3, head on over to our `PyMC Discourse `__ forum. +interact with live examples using Binder! Each notebook in `PyMC examples gallery +`__ has a binder badge. +For questions on PyMC, head on over to our `PyMC Discourse `__ forum. Contributing ============ @@ -26,15 +26,15 @@ Contact We are using `discourse.pymc.io `__ as our main communication channel. You can also follow us on `Twitter @pymc_devs `__ for updates and other announcements. -To ask a question regarding modeling or usage of PyMC3 we encourage posting to our Discourse forum under the `“Questions” Category `__. You can also suggest feature in the `“Development” Category `__. +To ask a question regarding modeling or usage of PyMC we encourage posting to our Discourse forum under the `“Questions” Category `__. You can also suggest feature in the `“Development” Category `__. To report an issue, please use the following: -- `PyMC3 Examples - Issue Tracker `__. For +- `PyMC Examples - Issue Tracker `__. For issues about the example notebooks, errors in the example codes, outdated information, improvement suggestions... -- `PyMC3 - Issue Tracker `__. For issues, bugs or - feature requests related to the PyMC3 library itself. +- `PyMC - Issue Tracker `__. For issues, bugs or + feature requests related to the PyMC library itself. Finally, if you need to get in touch for non-technical information about the project, `send us an e-mail `__. @@ -46,39 +46,44 @@ If you already know about Bayesian statistics: - `API quickstart guide `__ -- The `PyMC3 tutorial `__ -- `PyMC3 examples `__ and the `API reference `__ +- The `PyMC tutorial `__ +- `PyMC examples `__ and the `API reference `__ -Learn Bayesian statistics with a book together with PyMC3: +Learn Bayesian statistics with a book together with PyMC: ---------------------------------------------------------- - `Probabilistic Programming and Bayesian Methods for Hackers `__ by Cameron Davidson-Pilon: Fantastic book with many applied code examples. - `Doing Bayesian Data Analysis `__ by John Kruschke, as well as the `second edition `__: Principled introduction to Bayesian data analysis. -- `Statistical Rethinking: A Bayesian Course with Examples in R and Stan `__ by Richard McElreath: Comprehensive text on modeling choices and interpretations. +- `Statistical Rethinking: A Bayesian Course with Examples in R and Stan `__ by Richard McElreath: Comprehensive text on modeling choices and interpretations. - `Bayesian Cognitive Modeling `__ by Michael Lee and EJ Wagenmakers: Focused on using Bayesian statistics in cognitive modeling. - `Bayesian Analysis with Python `__ (second edition) by Osvaldo Martin: Great introductory book. (`code `__ and errata). -PyMC3 talks +PyMC talks ----------- -There are also several talks on PyMC3 which are gathered in this `YouTube playlist `__ +There are also several talks on PyMC which are gathered in this `YouTube playlist `__ and as part of `PyMCon 2020 `__ Installation ------------ -To install PyMC3 on your system, see its `installation section here `__ +To install PyMC on your system, see its `installation section here `__ -Citing PyMC3 +Citing PyMC ============ -Salvatier J., Wiecki T.V., Fonnesbeck C. (2016) Probabilistic programming -in Python using PyMC3. PeerJ Computer Science 2:e55 -`DOI: 10.7717/peerj-cs.55 `__. +* To cite the PyMC software, use: -Papers citing PyMC3 + Salvatier J., Wiecki T.V., Fonnesbeck C. (2016) Probabilistic programming + in Python using PyMC3. PeerJ Computer Science 2:e55 + `DOI: 10.7717/peerj-cs.55 `__. + +* To cite specific guides from this collection, use |zenodo|. You'll find page specific + citation instructions at the bottom of each page. + +Papers citing PyMC ------------------- See `Google Scholar `__ for a continuously updated list. @@ -86,7 +91,7 @@ See `Google Scholar `__. +PyMC is a non-profit project under NumFOCUS umbrella. If you want to support PyMC financially, you can donate `here `__. PyMC for enterprise =================== @@ -107,22 +112,12 @@ Sponsors |PyMCLabs| -.. |Binder| image:: https://mybinder.org/badge_logo.svg - :target: https://mybinder.org/v2/gh/pymc-devs/pymc3/master?filepath=%2Fdocs%2Fsource%2Fnotebooks -.. |Build Status| image:: https://github.com/pymc-devs/pymc3/workflows/pytest/badge.svg - :target: https://github.com/pymc-devs/pymc3/actions -.. |Coverage| image:: https://codecov.io/gh/pymc-devs/pymc3/branch/master/graph/badge.svg - :target: https://codecov.io/gh/pymc-devs/pymc3 -.. |Dockerhub| image:: https://img.shields.io/docker/automated/pymc/pymc3.svg - :target: https://hub.docker.com/r/pymc/pymc3 +.. |zenodo| image:: https://zenodo.org/badge/321449673.svg + :target: https://zenodo.org/badge/latestdoi/321449673 .. |NumFOCUS| image:: https://www.numfocus.org/wp-content/uploads/2017/03/1457562110.png :target: http://www.numfocus.org/ -.. |NumFOCUS_badge| image:: https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A - :target: http://www.numfocus.org/ .. |PyMCLabs| image:: https://github.com/pymc-devs/pymc/blob/main/docs/pymc-labs-logo.png :target: https://pymc-labs.io -.. |tidelift| image:: https://img.shields.io/badge/-lifted!-2dd160.svg?colorA=58595b&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAOCAYAAADJ7fe0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAAVhJREFUKBV1kj0vBFEUhmd2sdZHh2IlGhKFQuOviEYiNlFodCqtUqPxA%2FwCjUTnDygkGoVERFQaZFlE9nreO%2BdM5u5wkifvuee892Pu3CyEcA0DeIc%2B9IwftJsR6Cko3uCjguZdjuBZhhwmYDjGrOC96WED41UtsgEdGEAPlmAfpuAbFF%2BFZLfoMfRBGzThDtLgePPwBIpdddGzOArhPHUXowbNptE2www6a%2Fm96Y3pHN7oQ1s%2B13pxt1ENaKzBFWyWzaJ%2BRO0C9Jny6VPSoKjLVbMDC5bn5OPuJF%2BBSe95PVEMuugY5AegS9fCh7BedP45hRnj8TC34QQUe9bTZyh2KgvFk2vc8GIlXyTfsvqr6bPpNgv52ynnlomZJNpB70Xhl%2Bf6Sa02p1bApEfnETwxVa%2Faj%2BW%2FFtHltmxS%2FO3krvpTtTnVgu%2F6gvHRFvG78Ef3kOe5PimJXycY74blT5R%2BAAAAAElFTkSuQmCC - :target: https://tidelift.com/subscription/pkg/pypi-pymc3?utm_source=pypi-pymc3&utm_medium=referral&utm_campaign=enterprise .. |tidelift_learn| image:: https://img.shields.io/badge/-learn%20more-2dd160.svg?color=orange&labelColor=58595b&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAOCAYAAADJ7fe0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAAVhJREFUKBV1kj0vBFEUhmd2sdZHh2IlGhKFQuOviEYiNlFodCqtUqPxA%2FwCjUTnDygkGoVERFQaZFlE9nreO%2BdM5u5wkifvuee892Pu3CyEcA0DeIc%2B9IwftJsR6Cko3uCjguZdjuBZhhwmYDjGrOC96WED41UtsgEdGEAPlmAfpuAbFF%2BFZLfoMfRBGzThDtLgePPwBIpdddGzOArhPHUXowbNptE2www6a%2Fm96Y3pHN7oQ1s%2B13pxt1ENaKzBFWyWzaJ%2BRO0C9Jny6VPSoKjLVbMDC5bn5OPuJF%2BBSe95PVEMuugY5AegS9fCh7BedP45hRnj8TC34QQUe9bTZyh2KgvFk2vc8GIlXyTfsvqr6bPpNgv52ynnlomZJNpB70Xhl%2Bf6Sa02p1bApEfnETwxVa%2Faj%2BW%2FFtHltmxS%2FO3krvpTtTnVgu%2F6gvHRFvG78Ef3kOe5PimJXycY74blT5R%2BAAAAAElFTkSuQmCC :target: https://tidelift.com/subscription/pkg/pypi-pymc3?utm_source=pypi-pymc3&utm_medium=referral&utm_campaign=enterprise .. |tidelift_demo| image:: https://img.shields.io/badge/-request%20a%20demo-2dd160.svg?color=orange&labelColor=58595b&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAOCAYAAADJ7fe0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAAVhJREFUKBV1kj0vBFEUhmd2sdZHh2IlGhKFQuOviEYiNlFodCqtUqPxA%2FwCjUTnDygkGoVERFQaZFlE9nreO%2BdM5u5wkifvuee892Pu3CyEcA0DeIc%2B9IwftJsR6Cko3uCjguZdjuBZhhwmYDjGrOC96WED41UtsgEdGEAPlmAfpuAbFF%2BFZLfoMfRBGzThDtLgePPwBIpdddGzOArhPHUXowbNptE2www6a%2Fm96Y3pHN7oQ1s%2B13pxt1ENaKzBFWyWzaJ%2BRO0C9Jny6VPSoKjLVbMDC5bn5OPuJF%2BBSe95PVEMuugY5AegS9fCh7BedP45hRnj8TC34QQUe9bTZyh2KgvFk2vc8GIlXyTfsvqr6bPpNgv52ynnlomZJNpB70Xhl%2Bf6Sa02p1bApEfnETwxVa%2Faj%2BW%2FFtHltmxS%2FO3krvpTtTnVgu%2F6gvHRFvG78Ef3kOe5PimJXycY74blT5R%2BAAAAAElFTkSuQmCC diff --git a/_static/PyMC3.ico b/_static/PyMC.ico similarity index 100% rename from _static/PyMC3.ico rename to _static/PyMC.ico diff --git a/_static/PyMC.png b/_static/PyMC.png new file mode 100644 index 000000000..3c1c092fe Binary files /dev/null and b/_static/PyMC.png differ diff --git a/_static/binder.svg b/_static/binder.svg new file mode 100644 index 000000000..327f6b639 --- /dev/null +++ b/_static/binder.svg @@ -0,0 +1 @@ + launchlaunchbinderbinder \ No newline at end of file diff --git a/_static/colab.svg b/_static/colab.svg new file mode 100644 index 000000000..c08066ee3 --- /dev/null +++ b/_static/colab.svg @@ -0,0 +1 @@ + Open in ColabOpen in Colab diff --git a/_static/github.svg b/_static/github.svg new file mode 100644 index 000000000..e02d8ed55 --- /dev/null +++ b/_static/github.svg @@ -0,0 +1 @@ + View On GitHubView On GitHub \ No newline at end of file diff --git a/_templates/nb-badges.html b/_templates/nb-badges.html new file mode 100644 index 000000000..168821312 --- /dev/null +++ b/_templates/nb-badges.html @@ -0,0 +1,21 @@ + +{% set gh_basepath = github_user + '/' + github_repo + '/blob/' + github_version + '/' %} +{% set encoded_base = github_user + '%252F' + github_repo %} +{% set gh_binder = github_user + '/' + github_repo + '/' + github_version %} +{% set doc_path_aux = doc_path | trim('/') %} +{% set file_path = doc_path_aux + '/' + pagename + page_source_suffix %} +{% set encoded_path = file_path | replace("/", "%252F") %} + + +
+

+ + View On GitHub + + + Open In Binder + + + Open In Colab +

+
diff --git a/_templates/page.html b/_templates/page.html new file mode 100644 index 000000000..e3378a723 --- /dev/null +++ b/_templates/page.html @@ -0,0 +1,26 @@ +{%- extends "layout.html" %} +{% block body %} + +{% if pagename in ablog %} + {% include "nb-badges.html" %} +{% endif %} + + {{ body }} + + +{% if pagename in ablog %} + {% set post = ablog[pagename] %} +
    +
  • + {% for coll in post.author %} + {% if coll|length %} + {{ coll }} + {% if loop.index < post.author|length %},{% endif %} + {% else %} + {{ coll }} + {% if loop.index < post.author|length %},{% endif %} + {% endif %} + {% endfor %}. "{{ title.split(' — ')[0] }}". In: PyMC Examples. Ed. by PyMC Team. DOI: {{ doi_code }}
  • +
+{% endif %} +{% endblock %} diff --git a/_templates/postcard.html b/_templates/postcard.html new file mode 100644 index 000000000..f7c3956e7 --- /dev/null +++ b/_templates/postcard.html @@ -0,0 +1,30 @@ +{% if pagename in ablog %} + {% set fa = ablog.fontawesome %} + {% set post = ablog[pagename] %} +

Notebook metadata

+ +
    + {% if post.category %} +
  • + + {% for coll in post.category %} {% if coll|length %} + {{ coll }}{% if loop.index < + post.category|length %},{% endif %} {% else %}{{ coll }}{% if loop.index < + post.category|length %},{% endif %}{% endif %} {% endfor %} +
  • + {% endif %} + {% if post.tags %} +
  • + + {% if post.tags|length > 1 %} + {% else %} + {% endif %} + + {% for coll in post.tags %} {% if coll|length %} + {{ coll }}{% if loop.index < + post.tags|length %}{% endif %} {% else %}{{ coll }}{% if loop.index < + post.tags|length %}{% endif %}{% endif %} {% endfor %} +
  • + {% endif %} +
+{% endif %} diff --git a/_templates/postcard2.html b/_templates/postcard2.html new file mode 100644 index 000000000..523d69d18 --- /dev/null +++ b/_templates/postcard2.html @@ -0,0 +1,83 @@ +{% if post.published and post.date != post.update %} +
  • + {% if fa %}{% else %}{{ + gettext('Update') }}:{% endif %} + {{ post.update.strftime(ablog.post_date_format) }} +
  • +{% endif %} {% if post.location %} +
  • + {% if fa %}{% else %}{{ + gettext('Location') }}:{% endif %} + {% for coll in post.location %} {% if coll|length %} + {{ coll }}{% if loop.index < + post.location|length %},{% endif %} {% else %}{{ coll }}{% if loop.index < + post.location|length %},{% endif %}{% endif %} {% endfor %} +
  • +{% endif %} {% if post.language %} +
  • + {% if fa %}{% else %}{{ + gettext('Language') }}:{% endif %} + {% for coll in post.language %} {% if coll|length %} + {{ coll }}{% if loop.index < + post.language|length %},{% endif %} {% else %}{{ coll }}{% if loop.index < + post.language|length %},{% endif %}{% endif %} {% endfor %} +
  • +{% endif %} {% if post.category %} +
  • + {% if fa %}{% else %}{{ + gettext('Category') }}:{% endif %} + {% for coll in post.category %} {% if coll|length %} + {{ coll }}{% if loop.index < + post.category|length %},{% endif %} {% else %}{{ coll }}{% if loop.index < + post.category|length %},{% endif %}{% endif %} {% endfor %} +
  • +{% endif %} {% if post.tags %} +
  • + {% if post.tags|length > 1 %}{% if fa %}{% + else %}{{ gettext('Tags') }}:{% endif %} {% else %}{% if fa %}{% else %}{{ gettext('Tag') }}:{% endif %}{% endif %} + {% for coll in post.tags %} {% if coll|length %} + {{ coll }}{% if loop.index < + post.tags|length %}{% endif %} {% else %}{{ coll }}{% if loop.index < + post.tags|length %}{% endif %}{% endif %} {% endfor %} +
  • +{% endif %} {% if ablog.disqus_shortname and (ablog[pagename].published or +ablog.disqus_drafts) %} +
  • + + {% if fa %}{% endif %} + + {% if not fa %}Comments{% endif %} +
  • +{% endif %} diff --git a/examples/bibliography.md b/examples/bibliography.md deleted file mode 100644 index ff9f2df07..000000000 --- a/examples/bibliography.md +++ /dev/null @@ -1,6 +0,0 @@ -# General Bibliography - -:::{bibliography} -:all: - -::: diff --git a/examples/case_studies/blackbox_external_likelihood.ipynb b/examples/case_studies/blackbox_external_likelihood.ipynb index b14893ba5..d2148b0bf 100644 --- a/examples/case_studies/blackbox_external_likelihood.ipynb +++ b/examples/case_studies/blackbox_external_likelihood.ipynb @@ -73,7 +73,7 @@ "However, this is not necessarily that simple if you have a model function, or probability distribution, that, for example, relies on an external code that you have little/no control over (and may even be, for example, wrapped `C` code rather than Python). This can be problematic went you need to pass parameters set as PyMC3 distributions to these external functions; your external function probably wants you to pass it floating point numbers rather than PyMC3 distributions!\n", "\n", "```python\n", - "import pymc3 as pm:\n", + "import pymc3 as pm\n", "from external_module import my_external_func # your external function!\n", "\n", "# set up your model\n", diff --git a/examples/case_studies/conditional-autoregressive-model.ipynb b/examples/case_studies/conditional-autoregressive-model.ipynb index 7d979f857..646f5ab17 100644 --- a/examples/case_studies/conditional-autoregressive-model.ipynb +++ b/examples/case_studies/conditional-autoregressive-model.ipynb @@ -122,7 +122,7 @@ "\n", "The classical `WinBUGS` implementation (more information [here](http://glau.ca/?p=340)):\n", "\n", - "```python\n", + "```stan\n", "model\n", "{\n", " for (i in 1 : regions) {\n", @@ -2854,7 +2854,7 @@ "metadata": {}, "source": [ "Then in the `Stan` model:\n", - "```\n", + "```stan\n", "model {\n", " phi ~ multi_normal_prec(zeros, tau * (D - alpha * W));\n", " ...\n", @@ -3004,7 +3004,7 @@ "Note that in the node $\\phi \\sim \\mathcal{N}(0, [D_\\tau (I - \\alpha B)]^{-1})$, we are computing the log-likelihood for a multivariate Gaussian distribution, which might not scale well in high-dimensions. We can take advantage of the fact that the covariance matrix here $[D_\\tau (I - \\alpha B)]^{-1}$ is **sparse**, and there are faster ways to compute its log-likelihood. \n", "\n", "For example, a more efficient sparse representation of the CAR in `Stan`:\n", - "```python\n", + "```stan\n", "functions {\n", " /**\n", " * Return the log probability of a proper conditional autoregressive (CAR) prior \n", @@ -3040,9 +3040,9 @@ " - tau * (phit_D * phi - alpha * (phit_W * phi)));\n", " }\n", "}\n", - "```python\n", - "with the data transformed in the model:\n", "```\n", + "with the data transformed in the model:\n", + "```stan\n", "transformed data {\n", " int W_sparse[W_n, 2]; // adjacency pairs\n", " vector[n] D_sparse; // diagonal of D (number of neigbors for each site)\n", @@ -3073,7 +3073,7 @@ "}\n", "```\n", "and the likelihood:\n", - "```\n", + "```stan\n", "model {\n", " phi ~ sparse_car(tau, alpha, W_sparse, D_sparse, lambda, n, W_n);\n", "}\n", @@ -3297,6 +3297,7 @@ "In `Stan`, there is an option to write a `generated quantities` block for sample generation. Doing the similar in pymc3, however, is not recommended. \n", "\n", "Consider the following simple sample:\n", + "\n", "```python\n", "# Data\n", "x = np.array([1.1, 1.9, 2.3, 1.8])\n", @@ -3312,9 +3313,12 @@ " p = pm.Deterministic('p', pm.math.sigmoid(mu))\n", " count = pm.Binomial('count', n=10, p=p, shape=10)\n", "```\n", + "\n", "where we intended to use \n", + "\n", "```python\n", - "count = pm.Binomial('count', n=10, p=p, shape=10)```\n", + "count = pm.Binomial('count', n=10, p=p, shape=10)\n", + "```\n", "to generate posterior prediction. However, if the new RV added to the model is a discrete variable it can cause weird turbulence to the trace. You can see [issue #1990](https://github.com/pymc-devs/pymc3/issues/1990) for related discussion." ] }, @@ -3486,7 +3490,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -3500,7 +3504,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.6" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/examples/conf.py b/examples/conf.py index c029a2b99..8f21fedcd 100644 --- a/examples/conf.py +++ b/examples/conf.py @@ -1,27 +1,10 @@ -# Configuration file for the Sphinx documentation builder. -# -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) - +import os # -- Project information ----------------------------------------------------- - -project = "PyMC3" +project = "PyMC" copyright = "2021, PyMC Community" author = "PyMC Community" - # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be @@ -36,6 +19,7 @@ "sphinxext.opengraph", "sphinx_copybutton", "sphinxcontrib.bibtex", + "sphinx_codeautolink", ] # List of patterns, relative to source directory, that match files and @@ -78,32 +62,56 @@ "search_bar_text": "Search...", "navbar_end": ["search-field.html", "navbar-icon-links.html"], "external_links": [ - {"name": "Learning", "url": "https://pymc3.readthedocs.io/en/latest/learn.html"}, - {"name": "API", "url": "https://pymc3.readthedocs.io/en/latest/api.html"}, + {"name": "Learning", "url": "https://docs.pymc.io/en/stable/learn.html"}, + {"name": "API", "url": "https://docs.pymc.io/en/stable/api.html"}, ], } +version = os.environ.get("READTHEDOCS_VERSION", "") +version = version if "-" in version else "main" +html_context = { + "github_url": "https://github.com", + "github_user": "pymc-devs", + "github_repo": "pymc-examples", + "github_version": version, + "doc_path": "examples/", + "sandbox_repo": f"pymc-devs/pymc-sandbox/{version}", + "doi_url": "https://doi.org/10.5281/zenodo.5654871", + "doi_code": "10.5281/zenodo.5654871", +} -html_favicon = "../_static/PyMC3.ico" + +html_favicon = "../_static/PyMC.ico" +html_logo = "../_static/PyMC.png" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["../_static"] +templates_path = ["../_templates"] +# Workaround to make the whole sidebar scrollable. See https://github.com/pydata/pydata-sphinx-theme/issues/500 +# ideally the tagcloud, categories and ads would be added from here in conf.py html_sidebars = { - "**": ["sidebar-nav-bs.html", "tagcloud.html", "categories.html"], + "**": [ + # "sidebar-nav-bs.html", + "postcard.html", + "tagcloud.html", + "categories.html", + "sidebar-ethical-ads.html", + ], } # ablog config -# blog_baseurl = "https://predictablynoisy.com" +blog_baseurl = "https://examples.pymc.io" blog_title = "PyMC Examples" blog_path = "blog" -# fontawesome_included = True +fontawesome_included = True # post_redirect_refresh = 1 # post_auto_image = 1 # post_auto_excerpt = 2 # MyST config -myst_enable_extensions = ["colon_fence", "deflist", "dollarmath", "amsmath"] +myst_enable_extensions = ["colon_fence", "deflist", "dollarmath", "amsmath", "substitution"] +jupyter_execute_notebooks = "off" # bibtex config bibtex_bibfiles = ["references.bib"] @@ -114,17 +122,30 @@ # ogp_site_url = "https://predictablynoisy.com" # ogp_image = "https://predictablynoisy.com/_static/profile-bw.png" -# Temporarily stored as off until we fix it -jupyter_execute_notebooks = "off" +# codeautolink config +from IPython.core.inputtransformer2 import TransformerManager + + +def ipython_cell_transform(source): + out = TransformerManager().transform_cell(source) + return source, out + + +# codeautolink +codeautolink_custom_blocks = { + "ipython3": ipython_cell_transform, +} +codeautolink_autodoc_inject = False +codeautolink_concat_default = True # intersphinx mappings intersphinx_mapping = { "aesara": ("https://aesara.readthedocs.io/en/latest/", None), "arviz": ("https://arviz-devs.github.io/arviz/", None), - # "mpl": ("https://matplotlib.org/", None), - # "numpy": ("https://numpy.org/doc/stable/", None), - # "pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None), - "pymc3": ("https://docs.pymc.io/", None), - # "scipy": ("https://docs.scipy.org/doc/scipy/reference/", None), - # "xarray": ("http://xarray.pydata.org/en/stable/", None), + "mpl": ("https://matplotlib.org/", None), + "numpy": ("https://numpy.org/doc/stable/", None), + "pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None), + "pymc": ("https://docs.pymc.io/en/stable/", None), + "scipy": ("https://docs.scipy.org/doc/scipy/reference/", None), + "xarray": ("http://xarray.pydata.org/en/stable/", None), } diff --git a/examples/getting_started.ipynb b/examples/getting_started.ipynb index a8cb82929..4cc794ab1 100644 --- a/examples/getting_started.ipynb +++ b/examples/getting_started.ipynb @@ -253,7 +253,7 @@ "\n", "Following instantiation of the model, the subsequent specification of the model components is performed inside a `with` statement:\n", "\n", - "```python\n", + "```\n", "with basic_model:\n", "```\n", "This creates a *context manager*, with our `basic_model` as the context, that includes all statements until the indented block ends. This means all PyMC3 objects introduced in the indented code block below the `with` statement are added to the model behind the scenes. Absent this context manager idiom, we would be forced to manually associate each of the variables with `basic_model` right after we create them. If you try to create a new random variable without a `with model:` statement, it will raise an error since there is no obvious model for the variable to be added to.\n", @@ -3821,6 +3821,14 @@ "%load_ext watermark\n", "%watermark -n -u -v -iv -w" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + ":::{include} page_footer.md\n", + ":::" + ] } ], "metadata": { @@ -3840,7 +3848,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.6" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/examples/index.md b/examples/index.md index 62fbc5a59..46bf0e87d 100644 --- a/examples/index.md +++ b/examples/index.md @@ -11,5 +11,4 @@ via the search bar. :::{toctree} :maxdepth: 2 blog -bibliography ::: diff --git a/examples/page_footer.md b/examples/page_footer.md new file mode 100644 index 000000000..8cfa05b89 --- /dev/null +++ b/examples/page_footer.md @@ -0,0 +1,35 @@ +## License notice +All the notebooks in this example gallery are provided under the +[MIT License](https://github.com/pymc-devs/pymc-examples/blob/main/LICENSE) +which allows modification, and redistribution for any +use provided the copyright and license notices are preserved. + +## Citing PyMC examples + +To cite this notebook, use the DOI provided by Zenodo for the pymc-examples repository. + +:::{important} +Many notebooks are adapted from other sources: blogs, books... In such cases you should +cite the original source as well. + +Also remember to cite the relevant libraries used by your code. +::: + +Here is an citation template in bibtex: + +```bibtex +@incollection{citekey, + author = "" + title = "", + editor = "PyMC Team", + booktitle = "PyMC examples", + doi = "10.5281/zenodo.5654871" +} +``` + +which once rendered could look like: + + + diff --git a/examples/pymc3_howto/sampling_compound_step.ipynb b/examples/pymc3_howto/sampling_compound_step.ipynb index 137e703f1..1ae8c1e3d 100644 --- a/examples/pymc3_howto/sampling_compound_step.ipynb +++ b/examples/pymc3_howto/sampling_compound_step.ipynb @@ -63,10 +63,10 @@ " rv1 = ... # random variable 1 (continuous)\n", " rv2 = ... # random variable 2 (continuous)\n", " rv3 = ... # random variable 3 (categorical)\n", - " ...\n", + " #...\n", " step1 = pm.Metropolis([rv1, rv2])\n", " step2 = pm.CategoricalGibbsMetropolis([rv3])\n", - " trace = pm.sample(..., step=[step1, step2]...)\n", + " trace = pm.sample(..., step=[step1, step2])\n", "```\n", "The compound step now contains a list of `methods`. At each sampling step, it iterates over these methods, taking a `point` as input. In each step a new `point` is proposed as an output, if rejected by the Metropolis-Hastings criteria the original input `point` sticks around as the output. " ] @@ -678,11 +678,6 @@ "The concern with mixing discrete and continuous sampling is that the change in discrete parameters will affect the continuous distribution's geometry so that the adaptation (i.e., the tuned mass matrix and step size) may be inappropriate for the Hamiltonian Monte Carlo sampling. HMC/NUTS is hypersensitive to its tuning parameters (mass matrix and step size). Another issue is that we also don't know how many iterations we have to run to get a decent sample when the discrete parameters change. Though it hasn't been fully evaluated, it seems that if the discrete parameter is in low dimensions (e.g., 2-class mixture models, outlier detection with explicit discrete labeling), the mixing of discrete sampling with HMC/NUTS works OK. However, it is much less efficient than marginalizing out the discrete parameters. And sometimes it can be observed that the Markov chains get stuck quite often. In order to evaluate this more properly, one can use a simulation-based method to look at the posterior coverage and establish the computational correctness, as explained in [Cook, Gelman, and Rubin 2006](https://amstat.tandfonline.com/doi/abs/10.1198/106186006x136976)." ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -724,7 +719,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -738,7 +733,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.2" + "version": "3.9.7" }, "latex_envs": { "LaTeX_envs_menu_present": true, diff --git a/examples/splines/spline.ipynb b/examples/splines/spline.ipynb index d68e7b370..906948870 100644 --- a/examples/splines/spline.ipynb +++ b/examples/splines/spline.ipynb @@ -4,16 +4,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Splines in PyMC3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "# Splines in PyMC3\n", + "\n", ":::{post} Oct 8, 2021 \n", ":tags: patsy, pymc3.Deterministic, pymc3.Exponential, pymc3.Model, pymc3.Normal, regression, spline\n", ":category: beginner\n", + ":author: Joshua Cook, Tyler James Burch\n", ":::" ] }, @@ -28,7 +24,7 @@ "Often, the model we want to fit is not a perfect line between some $x$ and $y$.\n", "Instead, the parameters of the model are expected to vary over $x$.\n", "There are multiple ways to handle this situation, one of which is to fit a *spline*.\n", - "The spline is effectively multiple individual lines, each fit to a different section of $x$, that are tied togehter at their boundaries, often called *knots*.\n", + "The spline is effectively multiple individual lines, each fit to a different section of $x$, that are tied together at their boundaries, often called *knots*.\n", "Below is an exmaple of how to fit a spline using the Bayesian framework [PyMC3](https://docs.pymc.io).\n", "\n", "Below is a full working example of how to fit a spline using the probabilitic programming language PyMC3.\n", @@ -1535,14 +1531,28 @@ "%load_ext watermark\n", "%watermark -n -u -v -iv -w -p theano,xarray,patsy" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + ":::{include} ../page_footer.md\n", + ":::" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { - "celltoolbar": "Tags", "kernelspec": { - "display_name": "pymc_1010", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "pymc_1010" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/requirements-docs.txt b/requirements-docs.txt index 64f877a14..73a72ccd8 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -6,3 +6,4 @@ sphinx-copybutton sphinxcontrib-bibtex ablog sphinxext-opengraph +sphinx-codeautolink