Getting Started
Installation
To use Turing, you need to install Julia first and then install Turing.
Install Julia
You will need to install Julia 1.3 or greater, which you can get from the official Julia website.
Install Turing.jl
Turing is an officially registered Julia package, so you can install a stable version of Turing by running the following in the Julia REPL:
julia> ] add Turing
You can check if all tests pass by running
julia> ] test Turing
Example
Here’s a simple example showing the package in action:
using Turing
using StatsPlots
# Define a simple Normal model with unknown mean and variance.
@model function gdemo(x, y)
s² ~ InverseGamma(2, 3)
m ~ Normal(0, sqrt(s²))
x ~ Normal(m, sqrt(s²))
y ~ Normal(m, sqrt(s²))
end
# Run sampler, collect results
chn = sample(gdemo(1.5, 2), HMC(0.1, 5), 1000)
# Summarise results
describe(chn)
# Plot and save results
p = plot(chn)
savefig("gdemo-plot.png")