Skip to content

Commit

Permalink
Notebook: sampler_stats; update links, clean up sections (pymc-devs#426)
Browse files Browse the repository at this point in the history
* adding myst file

* remove notebook from pre-commit exception and fix

* fix extra url link

Co-authored-by: Oriol (ZBook) <oriol.abril.pla@gmail.com>
  • Loading branch information
reshamas and OriolAbril authored Nov 5, 2022
1 parent 6a5a980 commit 5c07d60
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ repos:
examples/case_studies/blackbox_external_likelihood.ipynb|
examples/case_studies/blackbox_external_likelihood_numpy.ipynb|
examples/case_studies/item_response_nba.ipynb|
examples/diagnostics_and_criticism/sampler-stats.ipynb|
examples/gaussian_processes/GP-MaunaLoa2.ipynb|
examples/generalized_linear_models/GLM-logistic.ipynb|
examples/generalized_linear_models/GLM-out-of-sample-predictions.ipynb|
Expand Down
39 changes: 22 additions & 17 deletions examples/diagnostics_and_criticism/sampler-stats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
"(sampler_stats)=\n",
"# Sampler Statistics\n",
"\n",
"When checking for convergence or when debugging a badly behaving\n",
"sampler, it is often helpful to take a closer look at what the\n",
"sampler is doing. For this purpose some samplers export\n",
"statistics for each generated sample.\n",
"\n",
":::{post} May 31, 2022\n",
":tags: diagnostics \n",
":tags: diagnostics\n",
":category: beginner\n",
":author: Meenal Jhajharia, Christian Luhmann\n",
":::"
Expand Down Expand Up @@ -65,6 +60,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"When checking for convergence or when debugging a badly behaving sampler, it is often helpful to take a closer look at what the sampler is doing. For this purpose some samplers export statistics for each generated sample.\n",
"\n",
"As a minimal example we sample from a standard normal distribution:"
]
},
Expand Down Expand Up @@ -151,7 +148,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"- `Note`: NUTS provides the following statistics( these are internal statistics that the sampler uses, you don't need to do anything with them when using PyMC3, to learn more about them, [check this page](https://docs.pymc.io/api/inference.html#module-pymc3.step_methods.hmc.nuts)."
"- `Note`: NUTS provides the following statistics (these are internal statistics that the sampler uses, you don't need to do anything with them when using PyMC, to learn more about them, {class}`pymc.NUTS`."
]
},
{
Expand Down Expand Up @@ -695,7 +692,7 @@
"metadata": {},
"source": [
"Some points to `Note`:\n",
"- Some of the sample statistics used by NUTS are renamed when converting to `InferenceData` to follow [ArviZ's naming convention](https://arviz-devs.github.io/arviz/schema/schema.html#sample-stats), while some are specific to PyMC3 and keep their internal PyMC3 name in the resulting InferenceData object.\n",
"- Some of the sample statistics used by NUTS are renamed when converting to `InferenceData` to follow {ref}`ArviZ's naming convention <arviz:schema>`, while some are specific to PyMC3 and keep their internal PyMC3 name in the resulting InferenceData object.\n",
"- `InferenceData` also stores additional info like the date, versions used, sampling time and tuning steps as attributes."
]
},
Expand Down Expand Up @@ -1746,6 +1743,22 @@
");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Authors\n",
"* Updated by Meenal Jhajharia in April 2021 ([pymc-examples#95](https://github.com/pymc-devs/pymc-examples/pull/95))\n",
"* Updated to v4 by Christian Luhmann in May 2022 ([pymc-examples#338](https://github.com/pymc-devs/pymc-examples/pull/338))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Watermark"
]
},
{
"cell_type": "code",
"execution_count": 16,
Expand Down Expand Up @@ -1777,14 +1790,6 @@
"%watermark -n -u -v -iv -w"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Updated by Meenal Jhajharia\n",
"* Updated by Christian Luhmann"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1813,7 +1818,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
"version": "3.9.10"
}
},
"nbformat": 4,
Expand Down
26 changes: 13 additions & 13 deletions myst_nbs/diagnostics_and_criticism/sampler-stats.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ kernelspec:
(sampler_stats)=
# Sampler Statistics

When checking for convergence or when debugging a badly behaving
sampler, it is often helpful to take a closer look at what the
sampler is doing. For this purpose some samplers export
statistics for each generated sample.

:::{post} May 31, 2022
:tags: diagnostics
:tags: diagnostics
:category: beginner
:author: Meenal Jhajharia, Christian Luhmann
:::
Expand All @@ -43,6 +38,8 @@ az.style.use("arviz-darkgrid")
plt.rcParams["figure.constrained_layout.use"] = False
```

When checking for convergence or when debugging a badly behaving sampler, it is often helpful to take a closer look at what the sampler is doing. For this purpose some samplers export statistics for each generated sample.

As a minimal example we sample from a standard normal distribution:

```{code-cell} ipython3
Expand All @@ -57,7 +54,7 @@ with model:
idata = pm.sample(2000, tune=1000, init=None, step=step, chains=4)
```

- `Note`: NUTS provides the following statistics( these are internal statistics that the sampler uses, you don't need to do anything with them when using PyMC3, to learn more about them, [check this page](https://docs.pymc.io/api/inference.html#module-pymc3.step_methods.hmc.nuts).
- `Note`: NUTS provides the following statistics (these are internal statistics that the sampler uses, you don't need to do anything with them when using PyMC, to learn more about them, {class}`pymc.NUTS`.

```{code-cell} ipython3
idata.sample_stats
Expand Down Expand Up @@ -94,7 +91,7 @@ The sample statistics variables are defined as follows:
+++

Some points to `Note`:
- Some of the sample statistics used by NUTS are renamed when converting to `InferenceData` to follow [ArviZ's naming convention](https://arviz-devs.github.io/arviz/schema/schema.html#sample-stats), while some are specific to PyMC3 and keep their internal PyMC3 name in the resulting InferenceData object.
- Some of the sample statistics used by NUTS are renamed when converting to `InferenceData` to follow {ref}`ArviZ's naming convention <arviz:schema>`, while some are specific to PyMC3 and keep their internal PyMC3 name in the resulting InferenceData object.
- `InferenceData` also stores additional info like the date, versions used, sampling time and tuning steps as attributes.

```{code-cell} ipython3
Expand Down Expand Up @@ -189,15 +186,18 @@ az.plot_density(
);
```

## Authors
* Updated by Meenal Jhajharia in April 2021 ([pymc-examples#95](https://github.com/pymc-devs/pymc-examples/pull/95))
* Updated to v4 by Christian Luhmann in May 2022 ([pymc-examples#338](https://github.com/pymc-devs/pymc-examples/pull/338))

+++

## Watermark

```{code-cell} ipython3
%load_ext watermark
%watermark -n -u -v -iv -w
```

* Updated by Meenal Jhajharia
* Updated by Christian Luhmann

+++

:::{include} ../page_footer.md
:::

0 comments on commit 5c07d60

Please sign in to comment.