Hamiltonian Monte-Carlo, also called Hybrid Monte Carlo, is a sampling algorithm that uses Hamiltonian Dynamics to approximate a posterior distribution. Unlike MH and MC3, HMC uses not only the current position, but also a sense of momentum, to draw future samples. An introduction to HMC can be read in Betancourt (2018) .

sampler_hmc(
  start,
  distr_name = NULL,
  distr_params = NULL,
  epsilon = 0.5,
  L = 10,
  iterations = 1024,
  weights = NULL,
  custom_density = NULL
)

Arguments

start

Vector. Starting position of the sampler.

distr_name

Name of the distribution from which to sample from.

distr_params

Distribution parameters.

epsilon

Size of the leapfrog step

L

Number of leapfrog steps per iteration

iterations

Number of iterations of the sampler.

weights

If using a mixture distribution, the weights given to each constituent distribution. If none given, it defaults to equal weights for all distributions.

custom_density

Instead of providing names, params and weights, the user may prefer to provide a custom density function.

Value

A named list containing

  1. Samples: the history of visited places (an n x d matrix, n = iterations; d = dimensions)

  2. Momentums: the history of momentum values (an n x d matrix, n = iterations; d = dimensions). Nothing is proposed in the first iteration (the first iteration is the start value) and so the first row is NA

  3. Acceptance Ratio: The proportion of proposals that were accepted.

Details

This implementations assumes that the momentum is drawn from a normal distribution with mean 0 and identity covariance matrix (p ~ N (0, I)). Hamiltonian Monte Carlo does not support discrete distributions.

This algorithm has been used to model human data in Aitchison and Lengyel (2016) , Castillo et al. (2024) and Zhu et al. (2022) among others.

References

Aitchison L, Lengyel M (2016). “The Hamiltonian Brain: Efficient Probabilistic Inference with Excitatory-Inhibitory Neural Circuit Dynamics.” PLOS Computational Biology, 12(12), e1005186. doi:10.1371/journal.pcbi.1005186 .

Betancourt M (2018). “A Conceptual Introduction to Hamiltonian Monte Carlo.” http://arxiv.org/abs/1701.02434.

Castillo L, León-Villagrá P, Chater N, Sanborn A (2024). “Explaining the Flaws in Human Random Generation as Local Sampling with Momentum.” PLOS Computational Biology, 20(1), 1–24. doi:10.1371/journal.pcbi.1011739 .

Zhu J, León-Villagrá P, Chater N, Sanborn AN (2022). “Understanding the Structure of Cognitive Noise.” PLoS Computational Biology, 18(8), e1010312. doi:10.1371/journal.pcbi.1010312 .

Examples

result <- sampler_hmc(
    distr_name = "norm", distr_params = c(0,1), 
    start = 1, epsilon = .01, L = 100
    )
cold_chain <- result$Samples