Sample from posterior distributions using the No U-turn Sampler (NUTS). For details see the original NUTS paper and the more recent introduction.
This crate was developed as a faster replacement of the sampler in PyMC, to be used with the new numba backend of PyTensor. The python wrapper for this sampler is nutpie.
Usage
use ;
use Error;
use thread_rng;
// Define a function that computes the unnormalized posterior density
// and its gradient.
// The density might fail in a recoverable or non-recoverable manner...
// We get the default sampler arguments
let mut settings = default;
// and modify as we like
settings.num_tune = 1000;
settings.maxdepth = 3; // small value just for testing...
// We instanciate our posterior density function
let logp_func = PosteriorDensity ;
let math = new;
let chain = 0;
let mut rng = thread_rng;
let mut sampler = settings.new_chain;
// Set to some initial position and start drawing samples.
sampler.set_position.expect;
let mut trace = vec!; // Collection of all draws
for _ in 0..2000
Users can also implement the Model
trait for more control and parallel sampling.
Implementation details
This crate mostly follows the implementation of NUTS in Stan and PyMC, only tuning of mass matrix and step size differs somewhat.