Skip to content

Using DynamicHMC

Turing supports the use of DynamicHMC as a sampler through the DynamicNUTS function.

To use the DynamicNUTS function, you must import the DynamicHMC package as well as Turing. Turing does not formally require DynamicHMC but will include additional functionality if both packages are present.

Here is a brief example of how to apply DynamicNUTS:

# Import Turing and DynamicHMC.
using DynamicHMC, Turing

# Model definition.
@model function gdemo(x, y)
   ~ InverseGamma(2, 3)
  m ~ Normal(0, sqrt())
  x ~ Normal(m, sqrt())
  y ~ Normal(m, sqrt())
end

# Pull 2,000 samples using DynamicNUTS.
chn = sample(gdemo(1.5, 2.0), DynamicNUTS(), 2000)