Draw MCMC samples from a model posterior using a static HMC sampler.
sample_tmb_hmc(
iter,
fn,
gr,
init,
L,
eps,
warmup = floor(iter/2),
seed = NULL,
chain = 1,
thin = 1,
control = NULL
)
The number of samples to draw.
A function that returns the log of the posterior density.
A function that returns a vector of gradients of the log of
the posterior density (same as fn
).
A list of lists containing the initial parameter
vectors, one for each chain or a function. It is strongly
recommended to initialize multiple chains from dispersed
points. A of NULL signifies to use the starting values
present in the model (i.e., obj$par
) for all chains.
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 contexts L
can roughly be thought of
as a thinning rate.
The step size. If a numeric value is passed, it will be used
throughout the entire chain. A NULL
value will initiate
sampler_params of eps
using the dual averaging algorithm during
the first warmup
steps.
The number of warmup iterations.
The random seed to use.
The chain number, for printing only.
The thinning rate to apply to samples. Typically not used with NUTS.
A list to control the sampler. See details for further use.
A list containing samples ('par') and algorithm details such as step size adaptation and acceptance probabilities per iteration ('sampler_params').
This function implements algorithm 5 of Hoffman and Gelman
(2014), which includes adaptive step sizes (eps
) via an
algorithm called dual averaging.
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.