Skip to content

Commit 41b68af

Browse files
committed
remove tags
1 parent 6fd760d commit 41b68af

6 files changed

+407
-709
lines changed

examples/variational_inference/GLM-hierarchical-advi-minibatch.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"# GLM: Mini-batch ADVI on hierarchical regression model\n",
88
"\n",
99
":::{post} Sept 23, 2021\n",
10-
":tags: generalized linear model, hierarchical model, pymc.Minibatch, pymc.Model, pymc.NUTS, pymc.Normal, pymc.Uniform, variational inference\n",
10+
":tags: generalized linear model, hierarchical model, variational inference\n",
1111
":category: intermediate\n",
1212
":::"
1313
]

examples/variational_inference/empirical-approx-overview.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"# Empirical Approximation overview\n",
88
"\n",
99
":::\n",
10-
":tags: pymc.Empirical, variational inference\n",
10+
":tags: variational inference\n",
1111
":category: intermediate\n",
1212
":::\n",
1313
"\n",

examples/variational_inference/variational_api_quickstart.ipynb

+377-685
Large diffs are not rendered by default.

myst_nbs/variational_inference/GLM-hierarchical-advi-minibatch.myst.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.13.8
7+
jupytext_version: 1.13.7
88
kernelspec:
99
display_name: pymc
1010
language: python
@@ -14,7 +14,7 @@ kernelspec:
1414
# GLM: Mini-batch ADVI on hierarchical regression model
1515

1616
:::{post} Sept 23, 2021
17-
:tags: generalized linear model, hierarchical model, pymc.Minibatch, pymc.Model, pymc.NUTS, pymc.Normal, pymc.Uniform, variational inference
17+
:tags: generalized linear model, hierarchical model, variational inference
1818
:category: intermediate
1919
:::
2020

myst_nbs/variational_inference/empirical-approx-overview.myst.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.13.8
7+
jupytext_version: 1.13.7
88
kernelspec:
99
display_name: pymc
1010
language: python
@@ -14,7 +14,7 @@ kernelspec:
1414
# Empirical Approximation overview
1515

1616
:::
17-
:tags: pymc.Empirical, variational inference
17+
:tags: variational inference
1818
:category: intermediate
1919
:::
2020

myst_nbs/variational_inference/variational_api_quickstart.myst.md

+24-18
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ jupytext:
66
format_version: 0.13
77
jupytext_version: 1.13.7
88
kernelspec:
9-
display_name: Python (PyMC3 Dev)
9+
display_name: pymc
1010
language: python
11-
name: pymc3-dev
11+
name: pymc
1212
---
1313

1414
# Variational API quickstart
1515

16+
:tags: variational inference
17+
1618
The variational inference (VI) API is focused on approximating posterior distributions for Bayesian models. Common use cases to which this module can be applied include:
1719

1820
* Sampling from model posterior and computing arbitrary expressions
1921
* Conduct Monte Carlo approximation of expectation, variance, and other statistics
20-
* Remove symbolic dependence on PyMC3 random nodes and evaluate expressions (using `eval`)
22+
* Remove symbolic dependence on PyMC random nodes and evaluate expressions (using `eval`)
2123
* Provide a bridge to arbitrary Theano code
2224

2325
Sounds good, doesn't it?
@@ -26,14 +28,14 @@ The module provides an interface to a variety of inference methods, so you are f
2628

2729
```{code-cell} ipython3
2830
%matplotlib inline
31+
import aesara
2932
import arviz as az
3033
import matplotlib.pyplot as plt
3134
import numpy as np
32-
import pymc3 as pm
33-
import theano
35+
import pymc as pm
3436
3537
np.random.seed(42)
36-
pm.set_tt_rng(42)
38+
pm.set_at_rng(42)
3739
```
3840

3941
## Basic setup
@@ -46,7 +48,7 @@ mu = pm.floatX([-0.3, 0.5])
4648
sd = pm.floatX([0.1, 0.1])
4749
4850
with pm.Model() as model:
49-
x = pm.NormalMixture("x", w=w, mu=mu, sigma=sd, dtype=theano.config.floatX)
51+
x = pm.NormalMixture("x", w=w, mu=mu, sigma=sd)
5052
x2 = x**2
5153
sin_x = pm.math.sin(x)
5254
```
@@ -79,7 +81,7 @@ Let's use the same model:
7981
```{code-cell} ipython3
8082
with pm.Model() as model:
8183
82-
x = pm.NormalMixture("x", w=w, mu=mu, sigma=sd, dtype=theano.config.floatX)
84+
x = pm.NormalMixture("x", w=w, mu=mu, sigma=sd)
8385
x2 = x**2
8486
sin_x = pm.math.sin(x)
8587
```
@@ -106,7 +108,7 @@ help(pm.callbacks.CheckParametersConvergence)
106108
Let's use the default arguments for `CheckParametersConvergence` as they seem to be reasonable.
107109

108110
```{code-cell} ipython3
109-
from pymc3.variational.callbacks import CheckParametersConvergence
111+
from pymc.variational.callbacks import CheckParametersConvergence
110112
111113
with model:
112114
mean_field = pm.fit(method="advi", callbacks=[CheckParametersConvergence()])
@@ -220,8 +222,8 @@ Let's compare results with the NUTS output:
220222
```{code-cell} ipython3
221223
import seaborn as sns
222224
223-
ax = sns.kdeplot(trace["x"], label="NUTS")
224-
sns.kdeplot(approx.sample(10000)["x"], label="ADVI");
225+
ax = sns.kdeplot(trace.posterior["x"].values.flatten(), label="NUTS")
226+
sns.kdeplot(approx.sample(10000).posterior["x"].values.flatten(), label="ADVI");
225227
```
226228

227229
Again, we see that ADVI is not able to cope with multimodality; we can instead use SVGD, which generates an approximation based on a large number of particles.
@@ -237,9 +239,9 @@ with model:
237239
```
238240

239241
```{code-cell} ipython3
240-
ax = sns.kdeplot(trace["x"], label="NUTS")
241-
sns.kdeplot(approx.sample(10000)["x"], label="ADVI")
242-
sns.kdeplot(svgd_approx.sample(2000)["x"], label="SVGD");
242+
ax = sns.kdeplot(trace.posterior["x"].values.flatten(), label="NUTS")
243+
sns.kdeplot(approx.sample(10000).posterior["x"].values.flatten(), label="ADVI")
244+
sns.kdeplot(svgd_approx.sample(2000).posterior["x"].values.flatten(), label="SVGD");
243245
```
244246

245247
That did the trick, as we now have a multimodal approximation using SVGD.
@@ -263,6 +265,10 @@ a_sample = svgd_approx.sample_node(a)
263265
a_sample.eval()
264266
```
265267

268+
```{code-cell} ipython3
269+
aesara.dprint(a)
270+
```
271+
266272
```{code-cell} ipython3
267273
a_sample.eval()
268274
```
@@ -273,7 +279,7 @@ a_sample.eval()
273279

274280
Every call yields a different value from the same theano node. This is because it is **stochastic**.
275281

276-
By applying replacements, we are now free of the dependence on the PyMC3 model; instead, we now depend on the approximation. Changing it will change the distribution for stochastic nodes:
282+
By applying replacements, we are now free of the dependence on the PyMC model; instead, we now depend on the approximation. Changing it will change the distribution for stochastic nodes:
277283

278284
```{code-cell} ipython3
279285
sns.kdeplot(np.array([a_sample.eval() for _ in range(2000)]))
@@ -373,7 +379,7 @@ with pm.Model() as iris_model:
373379
```
374380

375381
### Applying replacements in practice
376-
PyMC3 models have symbolic inputs for latent variables. To evaluate an espression that requires knowledge of latent variables, one needs to provide fixed values. We can use values approximated by VI for this purpose. The function `sample_node` removes the symbolic dependenices.
382+
PyMC models have symbolic inputs for latent variables. To evaluate an espression that requires knowledge of latent variables, one needs to provide fixed values. We can use values approximated by VI for this purpose. The function `sample_node` removes the symbolic dependenices.
377383

378384
`sample_node` will use the whole distribution at each step, so we will use it here. We can apply more replacements in single function call using the `more_replacements` keyword argument in both replacement functions.
379385

@@ -459,7 +465,7 @@ So, `Tracker` allows us to monitor our approximation and choose good training sc
459465
## Minibatches
460466
When dealing with large datasets, using minibatch training can drastically speed up and improve approximation performance. Large datasets impose a hefty cost on the computation of gradients.
461467

462-
There is a nice API in pymc3 to handle these cases, which is available through the `pm.Minibatch` class. The minibatch is just a highly specialized Theano tensor:
468+
There is a nice API in pymc to handle these cases, which is available through the `pm.Minibatch` class. The minibatch is just a highly specialized Theano tensor:
463469

464470
```{code-cell} ipython3
465471
issubclass(pm.Minibatch, theano.tensor.TensorVariable)
@@ -504,7 +510,7 @@ Now let's use minibatches. At every iteration, we will draw 500 random values:
504510

505511
> Remember to set `total_size` in observed
506512
507-
**total_size** is an important parameter that allows pymc3 to infer the right way of rescaling densities. If it is not set, you are likely to get completely wrong results. For more information please refer to the comprehensive documentation of `pm.Minibatch`.
513+
**total_size** is an important parameter that allows pymc to infer the right way of rescaling densities. If it is not set, you are likely to get completely wrong results. For more information please refer to the comprehensive documentation of `pm.Minibatch`.
508514

509515
```{code-cell} ipython3
510516
X = pm.Minibatch(data, batch_size=500)

0 commit comments

Comments
 (0)