Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
fonnesbeck committed Jul 18, 2024
2 parents 9e804eb + 783e21b commit fae292f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 44 deletions.
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
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

0 comments on commit fae292f

Please sign in to comment.