malt | R Documentation |
Implements the sampling algorithm: Metropolis Adjusted Langevin Trajectories (MALT) as described in Riou-Durand and Vogrinc (2022).
malt(init, U, grad, n, g, h, L, warm = FALSE)
init |
Real vector. Initial values for the sampling algorithm. |
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 |
grad |
A function to return the gradient of the potential. It should input and output a real vector of the same length as |
n |
The number of samples to be generated. Positive integer. |
g |
The friction, a.k.a damping parameter. Non-negative real number. The choice g=0 boils down to Hamiltonian Monte Carlo. |
h |
The time step. Positive real number. |
L |
The number of steps per trajectory. Positive integer. The choice L=1 boils down to the Metropolis Adjusted Langevin Algorithm. |
warm |
Should the chain be warmed up? Logical. If TRUE, the samples are generated after a warm-up phase of n successive trajectories. The first half of the warm-up phase is composed by unadjusted trajectories. |
Generates approximate samples from a distribution with density
Pi(x)=exp(-U(x))/C
A Markov chain is generated by drawing successive Langevin trajectories. Each trajectory starts from a fresh Gaussian velocity and is faced with an accept-reject test known as Metropolis adjustment. The Hamiltonian Monte Carlo (HMC) algorithm is recovered as a particular case when the damping parameter is set to zero. A positive choice of damping can ensure robustness of tuning, see Riou-Durand and Vogrinc (2022) for further details.
Returns a list with the following objects:
samples |
a matrix whose rows are the samples generated. |
draw |
a vector corresponding to the last draw of the chain. |
accept |
the acceptance rate of the chain. An acceptance rate close to zero/one indicates that the time step chosen is respectively too large/small. Optimally, the time step should be tuned to obtain an acceptance rate slightly above 65%. |
param |
the input parameters of the malt algorithm. |
Riou-Durand and Vogrinc (2022). Available at: https://arxiv.org/abs/2202.13230.
trajectory
, which draws a Langevin trajectory and computes the numerical error along the path.
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} n=10^4 g=1.5 h=0.20 L=8 malt(init,U,grad,n,g,h,L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.