estimate_epsilon: Epsilon estimator for Hamiltonian-based samplers.

Description Usage Arguments Details Value Examples

View source: R/samplers.R

Description

Adapted from Hoffman and Gelman (2014). This function estimates step size (epsilon) for a Hamiltonian-based sampler (e.g. HMC or NUTS).

Usage

1
estimate_epsilon(theta, logf)

Arguments

theta

Vector. Start position of the sampler

logf

Function - given theta, returns the its log probability

Details

This function uses the following heuristic: Starting with an epsilon of 1, do a leapfrog step with a randomly sampled momentum p ~ N(0, I). If the joint density of the new position and momentum pair is not at least half the joint density of the starting position and momentum pair, double epsilon and try again.-

Value

Epsilon to use in a Hamiltonian sampler

Examples

1
2
3
target <- distr6::Normal$new()
log_func <- function (x){return(target$pdf(log=TRUE, data = matrix(x, nrow=1)))}
estimate_epsilon(0, log_func)

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