Skip to content

Commit dead25f

Browse files
committed
Fix myst
1 parent c0a7c1d commit dead25f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

examples/howto/marginalizing-models.myst.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ kernelspec:
1212

1313
# Automatic marginalization of discrete variables
1414

15-
PyMC is very amendable to sampling models with discrete latent variables. But if you insist on using the NUTS sampler, you will need to get rid of your discrete variables somehow. The best way to do this is by marginalizing them out, as then you benefit from Rao-Blackwell's theorem and getting a lower variance estimate of your parameters.
15+
PyMC is very amendable to sampling models with discrete latent variables. But if you insist on using the NUTS sampler, you will need to get rid of your discrete variables somehow. The best way to do this is by marginalizing them out, as then you benefit from Rao-Blackwell's theorem and get a lower variance estimate of your parameters.
1616

17-
Unfortunately, the computation to do this is often tedious and unintuitive. Luckily, `pmx` now has supports a way to do this work automatically!
17+
Unfortunately, the computation to do this is often tedious and unintuitive. Luckily, `pmx` now supports a way to do this work automatically!
1818

1919
```{code-cell} ipython3
2020
import arviz as az
@@ -45,7 +45,7 @@ with pmx.MarginalModel() as mixture_model:
4545
y = pm.Normal("y", mu=mu[idx], sigma=1.0)
4646
```
4747

48-
As we can see there are already two ways to specify the same one. One where the choice of mixture is explicit, and the other where we use built-in `NormalMixture` to have a model where choice is not our model. There is nothing unique about the first model other than we initialize with `pmx.MarginalModel` instead of `pm.Model`. This different class is what will allow us to marginalize out variables later.
48+
As we can see there are already two ways to specify the same model. One where the choice of mixture is explicit, and the other where we use the built-in `NormalMixture` distribution to where that choice is not our model. There is nothing unique about the first model other than we initialize it with `pmx.MarginalModel` instead of `pm.Model`. This different class is what will allow us to marginalize out variables later.
4949

5050
```{code-cell} ipython3
5151
plt.hist(pm.draw(y, draws=2000), bins=30, rwidth=0.9);
@@ -102,7 +102,7 @@ mixture_model.recover_marginals(idata);
102102
az.summary(idata)
103103
```
104104

105-
This `idx` variable lets us recover the mixture assignment variable after the fact!
105+
This `idx` variable lets us recover the mixture assignment variable after running the NUTS sampler!
106106

107107
```{code-cell} ipython3
108108
post = idata.posterior
@@ -113,7 +113,7 @@ post.where(post.idx == 0).y.mean().values
113113
post.where(post.idx == 1).y.mean().values
114114
```
115115

116-
One important thing to notice is that this discrete variable has a lower ESS, and particularly for the tail. This means `idx` might not be estimated well particularly for the tails. If this is important, I recommend using the `lp_idx` instead, which is the log-probability of `idx` given sample values on that iteration.
116+
One important thing to notice is that this discrete variable has a lower ESS, and particularly so for the tail. This means `idx` might not be estimated well particularly for the tails. If this is important, I recommend using the `lp_idx` instead, which is the log-probability of `idx` given sample values on each iteration.
117117

118118
+++
119119

@@ -166,11 +166,11 @@ az.summary(before_marg, var_names=["~disasters"], filter_vars="like")
166166
az.summary(after_marg, var_names=["~disasters"], filter_vars="like")
167167
```
168168

169-
As can be seen the ESS improved massively
169+
As before, the ESS improved massively
170170

171171
+++
172172

173-
Finally, let's we will recover the `switchpoint` variable
173+
Finally, let us recover the `switchpoint` variable
174174

175175
```{code-cell} ipython3
176176
az.summary(after_marg, var_names=["~disasters", "~lp"], filter_vars="like")

0 commit comments

Comments
 (0)