Draw MCMC samples from a model posterior using a static HMC sampler.
Source:R/sample_tmb_deprecated.R
sample_tmb_hmc.Rd
Draw MCMC samples from a model posterior using a static HMC sampler.
Usage
sample_tmb_hmc(
iter,
fn,
gr,
init,
L,
eps,
warmup = floor(iter/2),
seed = NULL,
chain = 1,
thin = 1,
control = NULL
)
Arguments
- iter
The number of samples to draw.
- fn
A function that returns the log of the posterior density.
- gr
A function that returns a vector of gradients of the log of the posterior density (same as
fn
).- init
Can be either a list containing a vector for each chain, a function which returns a vector of parameters, or NULL which specifies to use the MLE as stored in the admodel.hes file. It is generally recommended to use dispersed initial values to improve diagnostic checks (starting from the same point makes it less likely to find multiple modes).
- L
The number of leapfrog steps to take. The NUTS algorithm does not require this as an input. If
L=1
this function will perform Langevin sampling. In some contextsL
can roughly be thought of as a thinning rate.- eps
The step size. If a numeric value is passed, it will be used throughout the entire chain. A
NULL
value will initiate sampler_params ofeps
using the dual averaging algorithm during the firstwarmup
steps.- warmup
The number of warmup iterations.
- seed
The random seed to use.
- chain
The chain number, for printing only.
- thin
The thinning rate to apply to samples. Typically not used with NUTS.
- control
A list to control the sampler. See details for further use.
Value
A list containing samples ('par') and algorithm details such as step size adaptation and acceptance probabilities per iteration ('sampler_params').
Details
This function implements algorithm 5 of Hoffman and Gelman
(2014), which includes adaptive step sizes (eps
) via an
algorithm called dual averaging.
References
Neal, R. M. (2011). MCMC using Hamiltonian dynamics. Handbook of Markov Chain Monte Carlo.
Hoffman and Gelman (2014). The No-U-Turn sampler: Adaptively setting path lengths in Hamiltonian Monte Carlo. J. Mach. Learn. Res. 15:1593-1623.
Hoffman and Gelman (2014). The No-U-Turn sampler: Adaptively setting path lengths in Hamiltonian Monte Carlo. J. Mach. Learn. Res. 15:1593-1623.