Skip to content

Pathfinder model specification fix #674

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

Merged
merged 21 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/introductory/api_quickstart.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Every probabilistic program consists of observed and unobserved Random Variables
- {ref}`pymc:api_distributions_discrete`
- {ref}`pymc:api_distributions_multivariate`
- {ref}`pymc:api_distributions_mixture`
- {ref}`pymc:api_distributions_rimeseries`
- {ref}`pymc:api_distributions_timeseries`
- {ref}`pymc:api_distributions_censored`
- {ref}`pymc:api_distributions_simulator`

Expand Down
99 changes: 61 additions & 38 deletions examples/variational_inference/pathfinder.ipynb

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions examples/variational_inference/pathfinder.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Instructions for installing other packages:

```{code-cell} ipython3
import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
import pymc_experimental as pmx
Expand All @@ -57,22 +58,23 @@ with pm.Model() as model:
mu = pm.Normal("mu", mu=0.0, sigma=10.0)
tau = pm.HalfCauchy("tau", 5.0)

theta = pm.Normal("theta", mu=0, sigma=1, shape=J)
theta_1 = mu + tau * theta
z = pm.Normal("z", mu=0, sigma=1, shape=J)
theta = mu + tau * z
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh 🤦

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChatGPT?

obs = pm.Normal("obs", mu=theta, sigma=sigma, shape=J, observed=y)
```

Next, we call `pmx.fit()` and pass in the algorithm we want it to use.

```{code-cell} ipython3
with model:
idata = pmx.fit(method="pathfinder")
idata = pmx.fit(method="pathfinder", num_samples=1000)
```

Just like `pymc.sample()`, this returns an idata with samples from the posterior. Note that because these samples do not come from an MCMC chain, convergence can not be assessed in the regular way.

```{code-cell} ipython3
az.plot_trace(idata);
az.plot_trace(idata)
plt.tight_layout();
```

## References
Expand All @@ -86,7 +88,8 @@ az.plot_trace(idata);
## Authors

* Authored by Thomas Wiecki on Oct 11 2022 ([pymc-examples#429](https://github.com/pymc-devs/pymc-examples/pull/429))
* Re-execute notebook, by Reshama Shaikh on Feb 5, 2023
* Re-execute notebook by Reshama Shaikh on Feb 5, 2023
* Bug fix by Chris Fonnesbeck on Jul 17, 2024

+++

Expand Down
Loading