nuts_da: nuts_da

Description Usage Arguments Details Value Author(s) Examples

View source: R/NUTS.R

Description

Function implementing the No-U-Turn Sampler (NUTS)

Usage

1
nuts_da(f, M, Madapt, theta0, delta = 0.6)

Arguments

f

a function returning list with list(logp=logp,grad=grad), logp being the loglikelihood and grad being its gradient

M

the number of samples to generate

Madapt

the number of steps of burn-in/how long to run the dual

theta0

is a vector with the desired initial setting of the parameters.

delta

hould be between 0 and 1, and is a target HMC acceptance probability. Defaults to 0.6 if unspecified.

Details

todo: more detail on arguments and provenance...epsilon

Value

list(samples=samples,epsilon=epsilon), samples being a matrix with columns parameters and rows samples

Author(s)

Pete Dodd

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
rosenbrock <- function(x){
  f <- (1-x[1])^2 + 100*(x[2] - x[1]^2)^2
  g <- c(100*2*(x[2] - x[1]^2)*(-2)*x[1] - 2*(1-x[1]),
  200*(x[2] - x[1]^2) )
  return(list(logp=-f,grad=-g))
}

run <- nuts_da(rosenbrock,10*1e3,1e3,runif(2))

corplot(run$samples,labels=c('x','y'))

petedodd/MCIR documentation built on Jan. 9, 2020, 9:18 a.m.