leapfrog {hmclearn} | R Documentation |
Leapfrog Algorithm for Hamiltonian Monte Carlo
Description
Runs a single iteration of the leapfrog algorithm. Typically called directly from hmc
Usage
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 |
glogPOSTERIOR |
Function to calculate and return the gradient of the log posterior given a vector of values of |
Minv |
Inverse Mass matrix |
constrain |
Optional vector of which parameters in |
lastSTEP |
Boolean indicating whether to calculate the last half-step of the momentum update |
... |
Additional parameters passed to glogPOSTERIOR |
Value
List containing two elements: theta.new
the ending value of theta and r.new
the ending value of the momentum
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.
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)