leapfrog function

Leapfrog Algorithm for Hamiltonian Monte Carlo

Leapfrog Algorithm for Hamiltonian Monte Carlo

Runs a single iteration of the leapfrog algorithm. Typically called directly from hmc

leapfrog( theta_lf, r, epsilon, glogPOSTERIOR, Minv, constrain, lastSTEP = FALSE, ... )

Arguments

  • theta_lf: starting parameter vector
  • r: starting momentum vector
  • epsilon: Step-size parameter for leapfrog
  • glogPOSTERIOR: Function to calculate and return the gradient of the log posterior given a vector of values of theta
  • Minv: Inverse Mass matrix
  • constrain: Optional vector of which parameters in theta accept positive values only. Default is that all parameters accept all real numbers
  • lastSTEP: Boolean indicating whether to calculate the last half-step of the momentum update
  • ...: Additional parameters passed to glogPOSTERIOR

Returns

List containing two elements: theta.new the ending value of theta and r.new the ending value of the momentum

Examples

set.seed(321) X <- cbind(1, rnorm(10)) y <- rnorm(10) p <- runif(3) - 0.5 leapfrog(rep(0,3), p, 0.01, g_linear_posterior, diag(3), FALSE, X=X, y=y)

References

Neal, Radford. 2011. MCMC Using Hamiltonian Dynamics. In Handbook of Markov Chain Monte Carlo, edited by Steve Brooks, Andrew Gelman, Galin L. Jones, and Xiao-Li Meng, 116–62. Chapman; Hall/CRC.

  • Maintainer: Samuel Thomas
  • License: GPL-3
  • Last published: 2020-10-05

Useful links