trajectory: trajectory

View source: R/trajectory.R

trajectoryR Documentation

trajectory

Description

Draws a Langevin trajectory starting from a Gaussian velocity and computes its numerical error. with target density

Pi(x)=exp(-U(x))/C

Given a potential function U and its gradient evaluation, draws a trajectory and computes its numerical error. The trajectory drawn corresponds to the proposal in the sampling algorithm: Metropolis Adjusted Langevin Trajectories (Riou-Durand and Vogrinc 2022). Details available at: https://arxiv.org/abs/2202.13230.

Usage

trajectory(init, U, grad, g, h, L)

Arguments

init

Real vector. Initial values for the Langevin trajectory.

U

A potential function to return the log-density of the distribution to be sampled from, up to an additive constant. It should input a real vector of the same length as init and output a scalar.

grad

A function to return the gradient of the potential. It should input and output a real vector of the same length as init.

g

Non-negative real number. The friction, a.k.a damping parameter. The choice g=0 boils down to Hamiltonian Monte Carlo.

h

Positive real number. The time step.

L

Positive integer. The number of steps per trajectory. The choice L=1 boils down to the Metropolis Adjusted Langevin Algorithm.

Value

Returns a list with the following objects:

path

a matrix whose rows are the successive steps of the trajectory.

draw

a vector containing the output of the trajectory.

num_error

a vector containing the cumulative numerical errors along the path. The numerical error is measured by the energy difference incurred by the leapfrog integrator.

Examples

d=50
sigma=((d:1)/d)^(1/2)
init=rnorm(d)*sigma
U=function(x){sum(0.5*x^2/sigma^2)}
grad=function(x){x/sigma^2}
g=1.5
h=0.20
L=8
trajectory(init,U,grad,g,h,L)

lrioudurand/malt documentation built on July 28, 2022, 11:06 p.m.