Skip to content

Commit 0b5594e

Browse files
fonnesbeckChris Fonnesbeck
and
Chris Fonnesbeck
authored
Extras update (#752)
* Draft update of BNN notebook * Pre-commit fixes * Address reviewer comments * Additional edits * Removed bivariate example; updated formatting * Updated GEV * Changed pymc_experimental to pymc_extras --------- Co-authored-by: Chris Fonnesbeck <[email protected]>
1 parent a3f03a0 commit 0b5594e

12 files changed

+6213
-671
lines changed

examples/case_studies/GEV.ipynb

+78-98
Large diffs are not rendered by default.

examples/case_studies/GEV.myst.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ jupytext:
55
format_name: myst
66
format_version: 0.13
77
kernelspec:
8-
display_name: pymc4-dev
8+
display_name: default
99
language: python
10-
name: pymc4-dev
10+
name: python3
1111
---
1212

1313
# Generalized Extreme Value Distribution
@@ -42,7 +42,7 @@ import arviz as az
4242
import matplotlib.pyplot as plt
4343
import numpy as np
4444
import pymc as pm
45-
import pymc_experimental.distributions as pmx
45+
import pymc_extras.distributions as pmx
4646
import pytensor.tensor as pt
4747
4848
from arviz.plots import plot_utils as azpu
@@ -230,7 +230,3 @@ az.plot_pair(idata, var_names=["μ", "σ", "ξ"], kind="kde", marginals=True, di
230230
%load_ext watermark
231231
%watermark -n -u -v -iv -w -p pytensor,arviz
232232
```
233-
234-
```{code-cell} ipython3
235-
236-
```

examples/howto/marginalizing-models.ipynb

+236-329
Large diffs are not rendered by default.

examples/howto/marginalizing-models.myst.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ jupytext:
55
format_name: myst
66
format_version: 0.13
77
kernelspec:
8-
display_name: pymc-dev
8+
display_name: default
99
language: python
10-
name: pymc-dev
10+
name: python3
1111
myst:
1212
substitutions:
1313
extra_dependencies: pymc-experimental
@@ -53,7 +53,7 @@ import pytensor.tensor as pt
5353
:::
5454

5555
```{code-cell} ipython3
56-
import pymc_experimental as pmx
56+
import pymc_extras as pmx
5757
```
5858

5959
```{code-cell} ipython3
@@ -84,7 +84,7 @@ with pmx.MarginalModel() as explicit_mixture:
8484
plt.hist(pm.draw(y, draws=2000, random_seed=rng), bins=30, rwidth=0.9);
8585
```
8686

87-
The other way is where we use the built-in {class}`NormalMixture <pymc.NormalMixture>` distribution. Here the mixture assignment is not an explicit variable in our model. There is nothing unique about the first model other than we initialize it with {class}`pmx.MarginalModel <pymc_experimental.MarginalModel>` instead of {class}`pm.Model <pymc.model.core.Model>`. This different class is what will allow us to marginalize out variables later.
87+
The other way is where we use the built-in {class}`NormalMixture <pymc.NormalMixture>` distribution. Here the mixture assignment is not an explicit variable in our model. There is nothing unique about the first model other than we initialize it with {class}`pmx.MarginalModel <pymc_extras.MarginalModel>` instead of {class}`pm.Model <pymc.model.core.Model>`. This different class is what will allow us to marginalize out variables later.
8888

8989
```{code-cell} ipython3
9090
with pm.Model() as prebuilt_mixture:
@@ -121,7 +121,7 @@ az.summary(idata)
121121

122122
As we can see, the `idx` variable is gone now. We also were able to use the NUTS sampler, and the ESS has improved.
123123

124-
But {class}`MarginalModel <pymc_experimental.MarginalModel>` has a distinct advantage. It still knows about the discrete variables that were marginalized out, and we can obtain estimates for the posterior of `idx` given the other variables. We do this using the {meth}`recover_marginals <pymc_experimental.MarginalModel.recover_marginals>` method.
124+
But {class}`MarginalModel <pymc_extras.MarginalModel>` has a distinct advantage. It still knows about the discrete variables that were marginalized out, and we can obtain estimates for the posterior of `idx` given the other variables. We do this using the {meth}`recover_marginals <pymc_extras.MarginalModel.recover_marginals>` method.
125125

126126
```{code-cell} ipython3
127127
explicit_mixture.recover_marginals(idata, random_seed=rng);

0 commit comments

Comments
 (0)