This package implements the robust adaptive metropolis (RAM) sampler described in Vihola (2012) for the Julia language.
RAM_sample function runs a MCMC sampler on a given log target function. The arguments for the functions are as follows:
RAM_sample(logtarget, x0, M0, n; opt_α=0.234, γ=2/3, q=Normal(), show_progress=true)
logtargetthis must be a callable that accepts one parameter which is a vector of values to evaluate the log target function on. The function passed must return the log value of the target function.
x0is a vector of initial values at which the sampler will start the MCMC algorithm. The length of the vector controls the dimensionality of the problem.
M0is the initial co-variance matrix that the sampler should use to scale the new proposal.
M0can be passed in many different ways:
- a scalar: an isotropic covariance matrix with diagonal elements
AbstractVector: a diagonal covariance matrix with diagonal elements
AbstractPDMat): a value of any of these types will be interpreted directly as the covariance matrix.
n: the number of elements to be sampled, i.e. the length of the chain.
opt_α: the target acceptance rate the algorithm is trying to hit.
γ: a parameter for the computation of the step size sequence.
q: the proposal distribution.
show_progress: a flag that controls whether a progress bar is shown.
The function returns a
NamedTuple with three elements:
Matrixwith the result chain. Each row is one sample, the columns correspond to the dimensions of the problem.
acceptance_rate: the acceptance rate for the overall chain.
M: the last co-variance matrix used in the algorithm.
A simple example of using the function is
using Distributions, RobustAdaptiveMetropolisSampler chain, accrate, S = RAM_sample( p -> logpdf(Normal(3., 2), p), # log target function [0.], # Initial value 0.5, # Use an isotropic covariance matrix with diagonal elements abs2(0.5) 100_000 # Number of runs )