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, ... )
theta_lf
: starting parameter vectorr
: starting momentum vectorepsilon
: 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 matrixconstrain
: Optional vector of which parameters in theta
accept positive values only. Default is that all parameters accept all real numberslastSTEP
: Boolean indicating whether to calculate the last half-step of the momentum update...
: Additional parameters passed to glogPOSTERIORList containing two elements: theta.new
the ending value of theta and r.new
the ending value of the momentum
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)
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.
Useful links