Skip to content
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

Extras update #752

Merged
merged 25 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1f02291
Draft update of BNN notebook
fonnesbeck May 6, 2022
d274a08
Pre-commit fixes
fonnesbeck May 6, 2022
3897626
Merge branch 'main' into bnn_update
fonnesbeck May 30, 2022
bad197e
Address reviewer comments
fonnesbeck May 30, 2022
4ad5e16
Merge branch 'fonnesbeck-bnn_update'
fonnesbeck May 30, 2022
287de21
Merge remote-tracking branch 'upstream/main'
Jul 22, 2022
80d58f9
Merge remote-tracking branch 'upstream/main'
Sep 15, 2022
aa2412d
Merge branch 'main' of github.com:fonnesbeck/pymc-examples
Feb 1, 2023
95328be
Merge remote-tracking branch 'upstream/main'
Feb 1, 2023
8b2effe
Merge remote-tracking branch 'upstream/main'
Feb 3, 2023
ecbca86
Merge remote-tracking branch 'upstream/main'
fonnesbeck Mar 17, 2023
2b1faab
Merge remote-tracking branch 'upstream/main'
fonnesbeck Apr 11, 2023
e7bbd7c
Merge remote-tracking branch 'upstream/main'
fonnesbeck Jun 30, 2023
dd4bf34
Merge remote-tracking branch 'upstream/main'
fonnesbeck Nov 17, 2023
5a56149
Merge remote-tracking branch 'upstream/main'
fonnesbeck Nov 19, 2023
1c85de6
Merge remote-tracking branch 'upstream/main'
fonnesbeck Mar 10, 2024
9e804eb
Merge remote-tracking branch 'upstream/main'
fonnesbeck Jul 17, 2024
fae292f
Merge remote-tracking branch 'upstream/main'
fonnesbeck Jul 18, 2024
7c214ef
Merge remote-tracking branch 'upstream/main'
fonnesbeck Sep 11, 2024
92f15dc
Merge remote-tracking branch 'upstream/main'
fonnesbeck Sep 16, 2024
4b8070d
Additional edits
fonnesbeck Sep 23, 2024
037964d
Removed bivariate example; updated formatting
fonnesbeck Sep 24, 2024
e4317db
Merge remote-tracking branch 'upstream/main'
fonnesbeck Dec 14, 2024
a28bed5
Updated GEV
fonnesbeck Dec 14, 2024
aadea65
Changed pymc_experimental to pymc_extras
fonnesbeck Dec 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading