Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/just-cameron/TuringTest.
Something went wrong. Try again.
---
---
<a id='Guide-1'></a>
# Guide
<a id='Basics-1'></a>
## Basics
<a id='Introduction-1'></a>
### Introduction
A probabilistic program is Julia code wrapped in a `@model` macro. It can use arbitrary Julia code, but to ensure correctness of inference it should not have external effects or modify global state. Stack-allocated variables are safe, but mutable heap-allocated objects may lead to subtle bugs when using task copying. To help avoid those we provide a Turing-safe datatype `TArray` that can be used to create mutable arrays in Turing programs.
To specify distributions of random variables, Turing programs should use the `~` notation:
`x ~ distr` where `x` is a symbol and `distr` is a distribution. If `x` is undefined in the model function, inside the probabilistic program, this puts a random variable named `x`, distributed according to `distr`, in the current scope. `distr` can be a value of any type that implements `rand(distr)`, which samples a value from the distribution `distr`. If `x` is defined, this is used for conditioning in a style similar to [Anglican](https://probprog.github.io/anglican/index.html) (another PPL). In this case, `x` is an observed value, assumed to have been drawn from the distribution `distr`. The likelihood is computed using `logpdf(distr,y)`. The observe statements should be arranged so that every possible run traverses all of them in exactly the same order. This is equivalent to demanding that they are not placed inside stochastic control flow.
Available inference methods include Importance Sampling (IS), Sequential Monte Carlo (SMC), Particle Gibbs (PG), Hamiltonian Monte Carlo (HMC), Hamiltonian Monte Carlo with Dual Averaging (HMCDA) and The No-U-Turn Sampler (NUTS).
<a id='Simple-Gaussian-Demo-1'></a>
### Simple Gaussian Demo
Below is a simple Gaussian demo illustrate the basic usage of Turing.jl.
```julia
# Import packages.
using Turing
using StatPlots
# Define a simple Normal model with unknown mean and variance.
@model gdemo(x, y) = begin
…