Skip to content

Commit 5f54f30

Browse files
committed
Solved Meta main #524
1 parent d473998 commit 5f54f30

File tree

13 files changed

+99
-65
lines changed

13 files changed

+99
-65
lines changed

_quarto.yml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ website:
1111
site-url: https://turinglang.org/
1212
site-path: "/"
1313
favicon: "assets/favicon.ico"
14-
search:
14+
search:
1515
location: navbar
1616
type: overlay
1717
navbar:
@@ -49,7 +49,7 @@ website:
4949
sidebar:
5050
- text: documentation
5151
collapse-level: 1
52-
contents:
52+
contents:
5353
- section: "Users"
5454
# href: tutorials/index.qmd, This page will be added later so keep this line commented
5555
contents:
@@ -58,10 +58,9 @@ website:
5858

5959
- section: "Usage Tips"
6060
collapse-level: 1
61-
contents:
61+
contents:
6262
- tutorials/docs-10-using-turing-autodiff/index.qmd
6363
- tutorials/usage-custom-distribution/index.qmd
64-
- tutorials/usage-probability-interface/index.qmd
6564
- tutorials/usage-modifying-logprob/index.qmd
6665
- tutorials/usage-generated-quantities/index.qmd
6766
- tutorials/docs-17-mode-estimation/index.qmd
@@ -71,7 +70,7 @@ website:
7170
- tutorials/docs-16-using-turing-external-samplers/index.qmd
7271

7372
- section: "Tutorials"
74-
contents:
73+
contents:
7574
- tutorials/00-introduction/index.qmd
7675
- text: Gaussian Mixture Models
7776
href: tutorials/01-gaussian-mixture-model/index.qmd
@@ -128,7 +127,7 @@ website:
128127
background: "#073c44"
129128
left: |
130129
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>
131-
The contents of this website are © 2024 under the terms of the <a href="https://github.com/TuringLang/Turing.jl/blob/master/LICENCE" target="_blank">MIT License</a>.
130+
The contents of this website are © 2024 under the terms of the <a href="https://github.com/TuringLang/Turing.jl/blob/master/LICENCE" target="_blank">MIT License</a>.
132131
133132
right:
134133
- icon: twitter
@@ -161,6 +160,41 @@ execute:
161160

162161
# Global Variables to use in any qmd files using:
163162
# {{< meta site-url >}}
163+
164164
site-url: https://turinglang.org/
165-
get-started: docs/tutorials/docs-00-getting-started/
166-
tutorials-intro: docs/tutorials/00-introduction/
165+
166+
167+
get-started: tutorials/docs-00-getting-started/
168+
tutorials-intro: tutorials/00-introduction/
169+
gaussian-mixture-model: tutorials/01-gaussian-mixture-model/
170+
logistic-regression: tutorials/02-logistic-regression/
171+
bayesian-neural-network: tutorials/03-bayesian-neural-network/
172+
hidden-markov-model: tutorials/04-hidden-markov-model/
173+
linear-regression: tutorials/05-linear-regression/
174+
infinite-mixture-model: tutorials/06-infinite-mixture-model/
175+
poisson-regression: tutorials/07-poisson-regression/
176+
multinomial-logistic-regression: tutorials/08-multinomial-logistic-regression/
177+
variational-inference: tutorials/09-variational-inference/
178+
bayesian-differential-equations: tutorials/10-bayesian-differential-equations/
179+
probabilistic-pca: tutorials/11-probabilistic-pca/
180+
gplvm: tutorials/12-gplvm/
181+
seasonal-time-series: tutorials/13-seasonal-time-series/
182+
contexts: tutorials/16-contexts/
183+
miniature: tutorial/14-minituring/
184+
contributing-guide: tutorials/docs-01-contributing-guide/
185+
using-turing-abstractmcmc: tutorials/docs-04-for-developers-abstractmc-turing/
186+
using-turing-compiler: tutorials/docs-05-for-developers-compiler/
187+
using-turing-interface: tutorials/docs-06-for-developers-interface/
188+
using-turing-variational-inference: tutorials/docs-07-for-developers-variational-inference/
189+
using-turing-advanced: tutorials/tutorials/docs-09-using-turing-advanced/
190+
using-turing-autodiff: tutorials/docs-10-using-turing-autodiff/
191+
using-turing-dynamichmc: tutorials/docs-11-using-turing-dynamichmc/
192+
using-turing: tutorials/docs-12-using-turing-guide/
193+
using-turing-performance-tips: tutorials/docs-13-using-turing-performance-tips/
194+
using-turing-sampler-viz: tutorials/docs-15-using-turing-sampler-viz/
195+
using-turing-external-samplers: tutorials/docs-16-using-turing-external-samplers/
196+
using-turing-implementing-samplers: tutorials/docs-17-implementing-samplers/
197+
using-turing-mode-estimation: tutorials/docs-17-mode-estimation/
198+
usage-custom-distribution: tutorials/tutorials/usage-custom-distribution/
199+
usage-generated-quantities: tutorials/tutorials/usage-generated-quantities/
200+
usage-modifying-logprob: tutorials/tutorials/usage-modifying-logprob/

tutorials/01-gaussian-mixture-model/index.qmd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ chains = sample(model, sampler, MCMCThreads(), nsamples, nchains, discard_initia
130130

131131
::: {.callout-warning collapse="true"}
132132
## Sampling With Multiple Threads
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
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
134134
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)
135135
:::
136136

@@ -161,7 +161,7 @@ It can happen that the modes of $\mu_1$ and $\mu_2$ switch between chains.
161161
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.
162162

163163
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$.
165165
`Bijectors.jl` [provides](https://turinglang.org/Bijectors.jl/dev/transforms/#Bijectors.OrderedBijector) an easy transformation (`ordered()`) for this purpose:
166166

167167
```{julia}
@@ -255,7 +255,7 @@ scatter(
255255

256256

257257
## 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
259259
our likelihood:
260260
$$
261261
p(y \mid w, \mu ) = \sum_{k=1}^K w_k p_k(y \mid \mu_k)
@@ -299,11 +299,11 @@ end
299299
::: {.callout-warning collapse="false"}
300300
## Manually Incrementing Probablity
301301

302-
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
303303
usual structure of a Turing model. In most cases, a custom distribution should be used instead.
304304

305305
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.
307307
:::
308308

309309

@@ -312,8 +312,8 @@ perform the marginalization automatically.
312312
We can use Turing's `~` syntax with anything that `Distributions.jl` provides `logpdf` and `rand` methods for. It turns out that the
313313
`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.
314314

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+
317317
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.
318318

319319
The `logpdf` implementation for a `MixtureModel` distribution is exactly the marginalization defined above, and so our model becomes simply:
@@ -330,7 +330,7 @@ end
330330
model = gmm_marginalized(x);
331331
```
332332

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.
334334

335335
```{julia}
336336
#| output: false
@@ -352,21 +352,21 @@ let
352352
end
353353
```
354354

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
356356
the marginalization of our assignment parameter.
357357

358358
```{julia}
359359
plot(chains[["μ[1]", "μ[2]"]], legend=true)
360360
```
361361

362362
## 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.
364364
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:
365365
$$
366366
p(z_i \mid y_i) = \frac{p(y_i \mid z_i) p(z_i)}{\sum_{k = 1}^K \left(p(y_i \mid z_i) p(z_i) \right)}
367367
$$
368368

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
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
370370
posterior predictive assignments from a categorial distribution.
371371
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).
372372
```{julia}
@@ -399,7 +399,7 @@ chains = sample(model, sampler, MCMCThreads(), nsamples, nchains, discard_initia
399399
Given a sample from the marginalized posterior, these assignments can be recovered with:
400400

401401
```{julia}
402-
assignments = mean(generated_quantities(gmm_recover(x), chains));
402+
assignments = mean(generated_quantities(gmm_recover(x), chains));
403403
```
404404

405405
```{julia}

tutorials/04-hidden-markov-model/index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This tutorial illustrates training Bayesian [Hidden Markov Models](https://en.wi
1414

1515
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.
1616

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](../{{<meta using-turing-autodiff>}}) on why this is useful).
1818

1919
```{julia}
2020
# Load libraries.

tutorials/05-linear-regression/index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ end
164164

165165
## Comparing to OLS
166166

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.
168168

169169
```{julia}
170170
# Import the GLM package.

tutorials/06-infinite-mixture-model/index.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ x &\sim \mathrm{Normal}(\mu_z, \Sigma)
8181
\end{align}
8282
$$
8383

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](../{{<meta gaussian-mixture-model>}}) with a slightly different notation.
8585

8686
## Infinite Mixture Model
8787

@@ -149,7 +149,7 @@ end
149149
```{julia}
150150
using Plots
151151
152-
# Plot the cluster assignments over time
152+
# Plot the cluster assignments over time
153153
@gif for i in 1:Nmax
154154
scatter(
155155
collect(1:i),

tutorials/08-multinomial-logistic-regression/index.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ chain
144144

145145
::: {.callout-warning collapse="true"}
146146
## 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.](../../{{<meta using-turing>}})
149149
:::
150150

151151
Since we ran multiple chains, we may as well do a spot check to make sure each chain converges around similar points.

tutorials/09-variational-inference/index.qmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pkg.instantiate();
1313
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)**.
1414

1515
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](../../{{<meta using-turing-variational-inference>}}) or any other resource online (there a lot of great ones).
1717

1818
Using VI in Turing.jl is very straight forward.
1919
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
2626

2727
Thus it's no more work than standard MCMC sampling in Turing.
2828

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](../../{{<meta 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.
3030

3131
We first import the packages to be used:
3232

@@ -248,7 +248,7 @@ plot(p1, p2; layout=(2, 1), size=(900, 500))
248248

249249
## Bayesian linear regression example using ADVI
250250

251-
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 linear-regression>}}) (much of the code is directly lifted), but now with the addition of an approximate posterior obtained using `ADVI`.
252252

253253
As we'll see, there is really no additional work required to apply variational inference to a more complex `Model`.
254254

@@ -599,7 +599,7 @@ println("Training set:
599599
VI loss: $vi_loss1
600600
Bayes loss: $bayes_loss1
601601
OLS loss: $ols_loss1
602-
Test set:
602+
Test set:
603603
VI loss: $vi_loss2
604604
Bayes loss: $bayes_loss2
605605
OLS loss: $ols_loss2")
@@ -765,8 +765,8 @@ plot(p1, p2; layout=(1, 2), size=(800, 2000))
765765
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
766766

767767
```{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,
770770
# these kind affect the mean prediction greatly.
771771
z = rand(q_full_normal, 10_000);
772772
```
@@ -795,7 +795,7 @@ println("Training set:
795795
VI loss: $vi_loss1
796796
Bayes loss: $bayes_loss1
797797
OLS loss: $ols_loss1
798-
Test set:
798+
Test set:
799799
VI loss: $vi_loss2
800800
Bayes loss: $bayes_loss2
801801
OLS loss: $ols_loss2")

tutorials/14-minituring/index.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Thus depending on the inference algorithm we want to use different `assume` and
8282
We can achieve this by providing this `context` information as a function argument to `assume` and `observe`.
8383

8484
**Note:** *Although the context system in this tutorial is inspired by DynamicPPL, it is very simplistic.
85-
We expand this mini Turing example in the [contexts](../16-contexts) tutorial with some more complexity, to illustrate how and why contexts are central to Turing's design. For the full details one still needs to go to the actual source of DynamicPPL though.*
85+
We expand this mini Turing example in the [contexts](../{{<meta contexts>}}) tutorial with some more complexity, to illustrate how and why contexts are central to Turing's design. For the full details one still needs to go to the actual source of DynamicPPL though.*
8686

8787
Here we can see the implementation of a sampler that draws values of unobserved variables from the prior and computes the log-probability for every variable.
8888

@@ -189,7 +189,7 @@ function assume(context::SamplingContext{<:MHSampler}, varinfo, dist, var_id)
189189
sampler = context.sampler
190190
old_value = varinfo.values[var_id]
191191
192-
# propose a random-walk step, i.e, add the current value to a random
192+
# propose a random-walk step, i.e, add the current value to a random
193193
# value sampled from a Normal distribution centered at 0
194194
value = rand(context.rng, Normal(old_value, sampler.sigma))
195195
logp = Distributions.logpdf(dist, value)

tutorials/docs-00-getting-started/index.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Getting Started
33
engine: julia
4-
aliases:
4+
aliases:
55
- ../../
66
---
77

@@ -82,5 +82,5 @@ The underlying theory of Bayesian machine learning is not explained in detail in
8282
A thorough introduction to the field is [*Pattern Recognition and Machine Learning*](https://www.springer.com/us/book/9780387310732) (Bishop, 2006); an online version is available [here (PDF, 18.1 MB)](https://www.microsoft.com/en-us/research/uploads/prod/2006/01/Bishop-Pattern-Recognition-and-Machine-Learning-2006.pdf).
8383
:::
8484

85-
The next page on [Turing's core functionality](../../tutorials/docs-12-using-turing-guide/) explains the basic features of the Turing language.
86-
From there, you can either look at [worked examples of how different models are implemented in Turing](../../tutorials/00-introduction/), or [specific tips and tricks that can help you get the most out of Turing](../../tutorials/docs-17-mode-estimation/).
85+
The next page on [Turing's core functionality](../../{{<meta using-turing>}}) explains the basic features of the Turing language.
86+
From there, you can either look at [worked examples of how different models are implemented in Turing](../../{{<meta tutorials-intro>}}), or [specific tips and tricks that can help you get the most out of Turing](../../{{<meta using-turing-mode-estimation>}}).

0 commit comments

Comments
 (0)