leapfrog.Rd
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 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 |
List containing two elements: theta.new
the ending value of theta and r.new
the ending value of the momentum
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.
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)#> $theta.new #> [1] 0.003425262 -0.002263951 -0.000395666 #> #> $r.new #> [1] 0.36441092 -0.22888346 -0.03657306 #>