sampler_mc3: Metropolis-coupled MCMC sampler (MC3)

Description Usage Arguments Value Examples

View source: R/samplers.R

Description

This sampler is a variant of MCMC in which multiple parallel chains are run at different temperatures. The chains stochastically swap positions which allows the coldest chain to visit regions far from its starting point (unlike in MCMC). Because of this, an MC3 sampler can explore far-off regions, whereas an MCMC sampler may become stuck in a particular point of high density.

Usage

1
2
3
4
5
6
7
8
9
sampler_mc3(
  pdf,
  start,
  nChains = 6,
  iterations = 1024,
  sigma_prop = NULL,
  delta_T = 4,
  swap_all = TRUE
)

Arguments

pdf

Probability Density Function of the posterior distribution. Takes a vector as input

start

Vector. Starting point for the sampler

nChains

number of parallel chains to be run.

iterations

Numeric. Number of times the sampler runs

sigma_prop

Variance of the univariate proposal distribution. For multivariate proposals, covariance matrix of the proposal.

delta_T

numeric, >1. Temperature increment parameter. The bigger this number, the steeper the increase in temperature between the cold chain and the next chain

swap_all

Boolean. If true, every iteration attempts floor(nChains / 2) swaps. If false, only one swap per iteration.

Value

List with:

  1. array of iterations x target_dimensions x nChains,

  2. acceptance ratio for each chain,

  3. history of swaps and

  4. swap ratio.

If nChains == 1 items 3 and 4 are not returned

Examples

1
2
3
4
5
6
7
8
pdf_function <- function(x){return(mvtnorm::dmvnorm(x, mean = c(0,1), sigma = diag(2)))}
mc3_results <- sampler_mc3(
 pdf_function,
 start = c(0,0),
 iterations=10,
 nChains = 3,
 sigma_prop = diag(2) / 8
)

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