Hamiltonian Monte Carlo Algorithm
Module containing Markov Chains Monte Carlo sampler utilizing Hamiltonian Monte Carlo (HMC) algorithm. HMC uses Hamiltonian dynamics to sample by moving a particle through the posterior to perform numerical integration that is then corrected by Metropolis acceptance criterion.
- class monte.hamiltonian_mc.HamiltonianMC(log_posterior, log_posterior_gradient)[source]
Bases:
BaseSampler- __init__(log_posterior, log_posterior_gradient) None[source]
Initializes the problem sampler object
- Parameters:
log_posterior (callable) – Log-probability of the target distribution to be sampled from
log_posterior_gradient (callable) – Log-probability of the gradient of the target distribution to be sampled from
- sample(iter, warmup, theta, epsilon, l, metric=None, lag=1, **kwargs)[source]
Samples from the log_posterior distribution
- Parameters:
iter (int) – Number of iterations of the algorithm
warmup (int) – Number of warmup steps of the algorithm. These are discarded so that the only samples recorded are the ones obtained after the Markov chain has reached the stationary distribution
theta (ndarray) – Vector of initial values of parameter(s)
epsilon (float) – Discretization time or timestep
l (int) – Number of leapfrog steps taken
metric (ndarray) – Covariance matrix of the momentum vector sampling distribution
lag (int, optional) – Sampler lag. Parameter specifying every how many iterations will the sample be recorded. Used to limit autocorrelation of the samples. If lag=1, every sample is recorded, if lag=3 each third sample is recorded, etc. , defaults to 1
- Returns:
Numpy arrays of samples and acceptance information for every algorithm iteration.
- Return type:
ndarray, ndarray