Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
fonnesbeck committed Dec 14, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
2 parents e4317db + 0b5594e commit bda97af
Showing 12 changed files with 6,213 additions and 671 deletions.
176 changes: 78 additions & 98 deletions examples/case_studies/GEV.ipynb

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions examples/case_studies/GEV.myst.md
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ jupytext:
format_name: myst
format_version: 0.13
kernelspec:
display_name: pymc4-dev
display_name: default
language: python
name: pymc4-dev
name: python3
---

# Generalized Extreme Value Distribution
@@ -42,7 +42,7 @@ import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
import pymc_experimental.distributions as pmx
import pymc_extras.distributions as pmx
import pytensor.tensor as pt
from arviz.plots import plot_utils as azpu
@@ -230,7 +230,3 @@ az.plot_pair(idata, var_names=["μ", "σ", "ξ"], kind="kde", marginals=True, di
%load_ext watermark
%watermark -n -u -v -iv -w -p pytensor,arviz
```

```{code-cell} ipython3
```
565 changes: 236 additions & 329 deletions examples/howto/marginalizing-models.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/howto/marginalizing-models.myst.md
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ jupytext:
format_name: myst
format_version: 0.13
kernelspec:
display_name: pymc-dev
display_name: default
language: python
name: pymc-dev
name: python3
myst:
substitutions:
extra_dependencies: pymc-experimental
@@ -53,7 +53,7 @@ import pytensor.tensor as pt
:::

```{code-cell} ipython3
import pymc_experimental as pmx
import pymc_extras as pmx
```

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

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.
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.

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

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

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.
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.

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

0 comments on commit bda97af

Please sign in to comment.