Skip to content

Commit 783e21b

Browse files
fonnesbeckChris Fonnesbecktwiecki
authored
Pathfinder model specification fix (#674)
* Draft update of BNN notebook * Pre-commit fixes * Address reviewer comments * Fixed model specification * Improve plot * Rerun notebook * Fix typo in myst. --------- Co-authored-by: Chris Fonnesbeck <[email protected]> Co-authored-by: Thomas Wiecki <[email protected]>
1 parent 5e42497 commit 783e21b

File tree

3 files changed

+70
-44
lines changed

3 files changed

+70
-44
lines changed

examples/introductory/api_quickstart.myst.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Every probabilistic program consists of observed and unobserved Random Variables
8787
- {ref}`pymc:api_distributions_discrete`
8888
- {ref}`pymc:api_distributions_multivariate`
8989
- {ref}`pymc:api_distributions_mixture`
90-
- {ref}`pymc:api_distributions_rimeseries`
90+
- {ref}`pymc:api_distributions_timeseries`
9191
- {ref}`pymc:api_distributions_censored`
9292
- {ref}`pymc:api_distributions_simulator`
9393

examples/variational_inference/pathfinder.ipynb

Lines changed: 61 additions & 38 deletions
Large diffs are not rendered by default.

examples/variational_inference/pathfinder.myst.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Instructions for installing other packages:
3838

3939
```{code-cell} ipython3
4040
import arviz as az
41+
import matplotlib.pyplot as plt
4142
import numpy as np
4243
import pymc as pm
4344
import pymc_experimental as pmx
@@ -57,22 +58,23 @@ with pm.Model() as model:
5758
mu = pm.Normal("mu", mu=0.0, sigma=10.0)
5859
tau = pm.HalfCauchy("tau", 5.0)
5960
60-
theta = pm.Normal("theta", mu=0, sigma=1, shape=J)
61-
theta_1 = mu + tau * theta
61+
z = pm.Normal("z", mu=0, sigma=1, shape=J)
62+
theta = mu + tau * z
6263
obs = pm.Normal("obs", mu=theta, sigma=sigma, shape=J, observed=y)
6364
```
6465

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

6768
```{code-cell} ipython3
6869
with model:
69-
idata = pmx.fit(method="pathfinder")
70+
idata = pmx.fit(method="pathfinder", num_samples=1000)
7071
```
7172

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

7475
```{code-cell} ipython3
75-
az.plot_trace(idata);
76+
az.plot_trace(idata)
77+
plt.tight_layout();
7678
```
7779

7880
## References
@@ -86,7 +88,8 @@ az.plot_trace(idata);
8688
## Authors
8789

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

9194
+++
9295

0 commit comments

Comments
 (0)