You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Solved Meta main #524
* Restore the 'probability-interface' line as per feedback in PR review [#530](#530 (comment))
* Fixes#524: Add Quarto Meta Variables
- Added `<meta doc-base-url>` to replace `..` or `../..` usage across tutorials.
- As per feedback from @penelopeysm, added an anchor to the specific part of the docs for the tutorial.
- Included the `probability-interface` tutorial in the context.
- Ensured no unnecessary whitespace changes to keep the pull request clean and focused.
* Fixes#524: Added Necessary Quarto Meta Variables
- Implemented all required Quarto meta variables, as suggested by @yebai.
- These changes include the addition of all necessary meta variables identified up to this point.
- Future adjustments can be made as needed to accommodate any further requirements.
* Fix docs base link
* Remove trailing slashes, add prob interface variable
* Re-add site-url variable
* Use doc-base-url throughout
---------
Co-authored-by: Penelope Yong <[email protected]>
Turing is created by <a href="http://mlg.eng.cam.ac.uk/hong/" target="_blank">Hong Ge</a>, and lovingly maintained by the <a href="https://github.com/TuringLang/Turing.jl/graphs/contributors" target="_blank">core team</a> of volunteers. <br>
The `sample()` call above assumes that you have at least `nchains` threads available in your Julia instance. If you do not, the multiple chains
133
+
The `sample()` call above assumes that you have at least `nchains` threads available in your Julia instance. If you do not, the multiple chains
134
134
will run sequentially, and you may notice a warning. For more information, see [the Turing documentation on sampling multiple chains.](https://turinglang.org/dev/docs/using-turing/guide/#sampling-multiple-chains)
135
135
:::
136
136
@@ -161,7 +161,7 @@ It can happen that the modes of $\mu_1$ and $\mu_2$ switch between chains.
161
161
For more information see the [Stan documentation](https://mc-stan.org/users/documentation/case-studies/identifying_mixture_models.html). This is because it's possible for either model parameter $\mu_k$ to be assigned to either of the corresponding true means, and this assignment need not be consistent between chains.
162
162
163
163
That is, the posterior is fundamentally multimodal, and different chains can end up in different modes, complicating inference.
164
-
One solution here is to enforce an ordering on our $\mu$ vector, requiring $\mu_k > \mu_{k-1}$ for all $k$.
164
+
One solution here is to enforce an ordering on our $\mu$ vector, requiring $\mu_k > \mu_{k-1}$ for all $k$.
165
165
`Bijectors.jl`[provides](https://turinglang.org/Bijectors.jl/dev/transforms/#Bijectors.OrderedBijector) an easy transformation (`ordered()`) for this purpose:
166
166
167
167
```{julia}
@@ -255,7 +255,7 @@ scatter(
255
255
256
256
257
257
## Marginalizing Out The Assignments
258
-
We can write out the marginal posterior of (continuous) $w, \mu$ by summing out the influence of our (discrete) assignments $z_i$ from
258
+
We can write out the marginal posterior of (continuous) $w, \mu$ by summing out the influence of our (discrete) assignments $z_i$ from
When possible, use of `Turing.@addlogprob!` should be avoided, as it exists outside the
302
+
When possible, use of `Turing.@addlogprob!` should be avoided, as it exists outside the
303
303
usual structure of a Turing model. In most cases, a custom distribution should be used instead.
304
304
305
305
Here, the next section demonstrates the perfered method --- using the `MixtureModel` distribution we have seen already to
306
-
perform the marginalization automatically.
306
+
perform the marginalization automatically.
307
307
:::
308
308
309
309
@@ -312,8 +312,8 @@ perform the marginalization automatically.
312
312
We can use Turing's `~` syntax with anything that `Distributions.jl` provides `logpdf` and `rand` methods for. It turns out that the
313
313
`MixtureModel` distribution it provides has, as its `logpdf` method, `logpdf(MixtureModel([Component_Distributions], weight_vector), Y)`, where `Y` can be either a single observation or vector of observations.
314
314
315
-
In fact, `Distributions.jl` provides [many convenient constructors](https://juliastats.org/Distributions.jl/stable/mixture/) for mixture models, allowing further simplification in common special cases.
316
-
315
+
In fact, `Distributions.jl` provides [many convenient constructors](https://juliastats.org/Distributions.jl/stable/mixture/) for mixture models, allowing further simplification in common special cases.
316
+
317
317
For example, when mixtures distributions are of the same type, one can write: `~ MixtureModel(Normal, [(μ1, σ1), (μ2, σ2)], w)`, or when the weight vector is known to allocate probability equally, it can be ommited.
318
318
319
319
The `logpdf` implementation for a `MixtureModel` distribution is exactly the marginalization defined above, and so our model becomes simply:
@@ -330,7 +330,7 @@ end
330
330
model = gmm_marginalized(x);
331
331
```
332
332
333
-
As we've summed out the discrete components, we can perform inference using `NUTS()` alone.
333
+
As we've summed out the discrete components, we can perform inference using `NUTS()` alone.
334
334
335
335
```{julia}
336
336
#| output: false
@@ -352,21 +352,21 @@ let
352
352
end
353
353
```
354
354
355
-
`NUTS()` significantly outperforms our compositional Gibbs sampler, in large part because our model is now Rao-Blackwellized thanks to
355
+
`NUTS()` significantly outperforms our compositional Gibbs sampler, in large part because our model is now Rao-Blackwellized thanks to
356
356
the marginalization of our assignment parameter.
357
357
358
358
```{julia}
359
359
plot(chains[["μ[1]", "μ[2]"]], legend=true)
360
360
```
361
361
362
362
## Inferred Assignments - Marginalized Model
363
-
As we've summed over possible assignments, the associated parameter is no longer available in our chain.
363
+
As we've summed over possible assignments, the associated parameter is no longer available in our chain.
364
364
This is not a problem, however, as given any fixed sample $(\mu, w)$, the assignment probability — $p(z_i \mid y_i)$ — can be recovered using Bayes rule:
This quantity can be computed for every $p(z = z_i \mid y_i)$, resulting in a probability vector, which is then used to sample
369
+
This quantity can be computed for every $p(z = z_i \mid y_i)$, resulting in a probability vector, which is then used to sample
370
370
posterior predictive assignments from a categorial distribution.
371
371
For details on the mathematics here, see [the Stan documentation on latent discrete parameters](https://mc-stan.org/docs/stan-users-guide/latent-discrete.html).
Copy file name to clipboardExpand all lines: tutorials/04-hidden-markov-model/index.qmd
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ This tutorial illustrates training Bayesian [Hidden Markov Models](https://en.wi
14
14
15
15
In this tutorial, we assume there are $k$ discrete hidden states; the observations are continuous and normally distributed - centered around the hidden states. This assumption reduces the number of parameters to be estimated in the emission matrix.
16
16
17
-
Let's load the libraries we'll need. We also set a random seed (for reproducibility) and the automatic differentiation backend to forward mode (more [here](https://turinglang.org/dev/docs/using-turing/autodiff) on why this is useful).
17
+
Let's load the libraries we'll need. We also set a random seed (for reproducibility) and the automatic differentiation backend to forward mode (more [here]( {{<metadoc-base-url>}}/{{<metausing-turing-autodiff>}} ) on why this is useful).
18
18
19
19
```{julia}
20
20
# Load libraries.
@@ -125,7 +125,7 @@ We will use a combination of two samplers ([HMC](https://turinglang.org/dev/docs
125
125
126
126
In this case, we use HMC for `m` and `T`, representing the emission and transition matrices respectively. We use the Particle Gibbs sampler for `s`, the state sequence. You may wonder why it is that we are not assigning `s` to the HMC sampler, and why it is that we need compositional Gibbs sampling at all.
127
127
128
-
The parameter `s` is not a continuous variable. It is a vector of **integers**, and thus Hamiltonian methods like HMC and [NUTS](https://turinglang.org/dev/docs/library/#Turing.Inference.NUTS) won't work correctly. Gibbs allows us to apply the right tools to the best effect. If you are a particularly advanced user interested in higher performance, you may benefit from setting up your Gibbs sampler to use [different automatic differentiation](https://turinglang.org/dev/docs/using-turing/autodiff#compositional-sampling-with-differing-ad-modes) backends for each parameter space.
128
+
The parameter `s` is not a continuous variable. It is a vector of **integers**, and thus Hamiltonian methods like HMC and [NUTS](https://turinglang.org/dev/docs/library/#Turing.Inference.NUTS) won't work correctly. Gibbs allows us to apply the right tools to the best effect. If you are a particularly advanced user interested in higher performance, you may benefit from setting up your Gibbs sampler to use [different automatic differentiation]( {{<metadoc-base-url>}}/{{<metausing-turing-autodiff>}}#compositional-sampling-with-differing-ad-modes) backends for each parameter space.
Copy file name to clipboardExpand all lines: tutorials/05-linear-regression/index.qmd
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -164,7 +164,7 @@ end
164
164
165
165
## Comparing to OLS
166
166
167
-
A satisfactory test of our model is to evaluate how well it predicts. Importantly, we want to compare our model to existing tools like OLS. The code below uses the [GLM.jl]() package to generate a traditional OLS multiple regression model on the same data as our probabilistic model.
167
+
A satisfactory test of our model is to evaluate how well it predicts. Importantly, we want to compare our model to existing tools like OLS. The code below uses the [GLM.jl](https://juliastats.org/GLM.jl/stable/) package to generate a traditional OLS multiple regression model on the same data as our probabilistic model.
Copy file name to clipboardExpand all lines: tutorials/06-infinite-mixture-model/index.qmd
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ x &\sim \mathrm{Normal}(\mu_z, \Sigma)
81
81
\end{align}
82
82
$$
83
83
84
-
which resembles the model in the [Gaussian mixture model tutorial](https://turinglang.org/stable/tutorials/01-gaussian-mixture-model/) with a slightly different notation.
84
+
which resembles the model in the [Gaussian mixture model tutorial]( {{<metadoc-base-url>}}/{{<metagaussian-mixture-model>}}) with a slightly different notation.
Copy file name to clipboardExpand all lines: tutorials/08-multinomial-logistic-regression/index.qmd
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -144,8 +144,8 @@ chain
144
144
145
145
::: {.callout-warning collapse="true"}
146
146
## Sampling With Multiple Threads
147
-
The `sample()` call above assumes that you have at least `nchains` threads available in your Julia instance. If you do not, the multiple chains
148
-
will run sequentially, and you may notice a warning. For more information, see [the Turing documentation on sampling multiple chains.](https://turinglang.org/dev/docs/using-turing/guide/#sampling-multiple-chains)
147
+
The `sample()` call above assumes that you have at least `nchains` threads available in your Julia instance. If you do not, the multiple chains
148
+
will run sequentially, and you may notice a warning. For more information, see [the Turing documentation on sampling multiple chains.]( {{<metadoc-base-url>}}/{{<metausing-turing>}}#sampling-multiple-chains)
149
149
:::
150
150
151
151
Since we ran multiple chains, we may as well do a spot check to make sure each chain converges around similar points.
Copy file name to clipboardExpand all lines: tutorials/09-variational-inference/index.qmd
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Pkg.instantiate();
13
13
In this post we'll have a look at what's know as **variational inference (VI)**, a family of _approximate_ Bayesian inference methods, and how to use it in Turing.jl as an alternative to other approaches such as MCMC. In particular, we will focus on one of the more standard VI methods called **Automatic Differentation Variational Inference (ADVI)**.
14
14
15
15
Here we will focus on how to use VI in Turing and not much on the theory underlying VI.
16
-
If you are interested in understanding the mathematics you can checkout [our write-up](../../tutorials/docs-07-for-developers-variational-inference/) or any other resource online (there a lot of great ones).
16
+
If you are interested in understanding the mathematics you can checkout [our write-up]( {{<metadoc-base-url>}}/{{<metausing-turing-variational-inference>}} ) or any other resource online (there a lot of great ones).
17
17
18
18
Using VI in Turing.jl is very straight forward.
19
19
If `model` denotes a definition of a `Turing.Model`, performing VI is as simple as
@@ -26,7 +26,7 @@ q = vi(m, vi_alg) # perform VI on `m` using the VI method `vi_alg`, which retur
26
26
27
27
Thus it's no more work than standard MCMC sampling in Turing.
28
28
29
-
To get a bit more into what we can do with `vi`, we'll first have a look at a simple example and then we'll reproduce the [tutorial on Bayesian linear regression](../../tutorials/05-linear-regression/) using VI instead of MCMC. Finally we'll look at some of the different parameters of `vi` and how you for example can use your own custom variational family.
29
+
To get a bit more into what we can do with `vi`, we'll first have a look at a simple example and then we'll reproduce the [tutorial on Bayesian linear regression]( {{<metadoc-base-url>}}/{{<metalinear-regression>}}) using VI instead of MCMC. Finally we'll look at some of the different parameters of `vi` and how you for example can use your own custom variational family.
This is simply a duplication of the tutorial on [Bayesian linear regression](../../tutorials/05-linear-regression/) (much of the code is directly lifted), but now with the addition of an approximate posterior obtained using `ADVI`.
251
+
This is simply a duplication of the tutorial on [Bayesian linear regression]({{< meta doc-base-url >}}/{{<metalinear-regression>}}) (much of the code is directly lifted), but now with the addition of an approximate posterior obtained using `ADVI`.
252
252
253
253
As we'll see, there is really no additional work required to apply variational inference to a more complex `Model`.
So it seems like the "full" ADVI approach, i.e. no mean-field assumption, obtain the same modes as the mean-field approach but with greater uncertainty for some of the `coefficients`. This
766
766
767
767
```{julia}
768
-
# Unfortunately, it seems like this has quite a high variance which is likely to be due to numerical instability,
769
-
# so we consider a larger number of samples. If we get a couple of outliers due to numerical issues,
768
+
# Unfortunately, it seems like this has quite a high variance which is likely to be due to numerical instability,
769
+
# so we consider a larger number of samples. If we get a couple of outliers due to numerical issues,
0 commit comments