sampler_hmc: Hamiltonian Monte-Carlo Sampler.

Description Usage Arguments Details Value Examples

View source: R/samplers.R

Description

Hamiltonian Monte-Carlo, also called Hybrid Monte Carlo, is a sampling algorithm that uses Hamiltonian Dynamics to approximate a posterior distribution. Unlike MCMC and MC3, HMC uses not only the current position, but also a sense of momentum, to draw future samples. An introduction to HMC can be read here

Usage

1
sampler_hmc(pdf, start, epsilon = 0.5, L = 10, iterations = 1024)

Arguments

pdf

pdf Probability Density Function of the target distribution.Takes 2 arguments: a vector with a position, and, optionally, a boolean determining whether to return the log density instead.

start

Vector. Starting point for the sampler

epsilon

Size of the leapfrog step

L

Number of leapfrog steps per iteration

iterations

Number of times the sampler runs

Details

This implementations assumes that the momentum is drawn from a normal distribution with mean 0 and identity covariance matrix (p ~ N (0, I) )

Value

Chain with a history of visited places

Examples

1
2
3
# pdfs can be made easily using the make_*_pdf helpers
pd_func <- make_distr6_pdf(distr6::MultivariateNormal$new(mean = c(2,5)))
hmc_results <- sampler_hmc(pd_func, start = c(0,0), epsilon = 1, L = 10, iterations=10)

lucas-castillo/SampleR documentation built on Jan. 1, 2021, 8:25 a.m.