harmonicHMC: Sample from a truncated Gaussian distribution with the...

View source: R/harmonicHMC.R

harmonicHMCR Documentation

Sample from a truncated Gaussian distribution with the harmonic HMC

Description

Generate MCMC samples from a d-dimensional truncated Gaussian distribution with constraints Fx+g >= 0 using the Harmonic Hamiltonian Monte Carlo sampler (Harmonic-HMC).

Usage

harmonicHMC(
  n,
  burnin = 0,
  mean,
  choleskyFactor,
  F,
  g,
  init,
  time = c(pi/8, pi/2),
  precFlg,
  diagnosticMode = FALSE
)

Arguments

n

number of samples after burn-in.

burnin

number of burn-in samples (default = 0).

mean

a d-dimensional mean vector.

choleskyFactor

upper triangular matrix R from Cholesky decomposition of precision or covariance matrix into R^TR.

F

F matrix (k-by-d matrix where k is the number of linear constraints).

g

g vector (k-dimensional).

init

a d-dimensional vector of the initial value. init must satisfy all constraints.

time

HMC integration time for each iteration. Can either be a scalar value for a fixed time across all samples, or a length 2 vector of a lower and upper bound for uniform distribution from which the time is drawn from for each iteration.

precFlg

logical. whether choleskyFactor is from precision (TRUE) or covariance matrix (FALSE).

diagnosticMode

logical. TRUE for also returning the bounce distances for each sample.

Value

List of samples: (n + burnin) x d matrix of samples (including burnin samples) and bounceDistances: list of bounces for each sample (only present if diagnosticMode is TRUE).

References

\insertRef

pakman2014exacthdtg

Examples

set.seed(1)
d <- 10
A <- matrix(runif(d^2)*2 - 1, ncol=d)
Sigma <- t(A) %*% A
R <- cholesky(Sigma)
mu <- rep(0, d)
F <- diag(d)
g <- rep(0,d)
initial <- rep(1, d)
results <- harmonicHMC(1000, 1000, mu, R, F, g, initial, precFlg = FALSE)

hdtg documentation built on Aug. 7, 2022, 1:06 a.m.

Related to harmonicHMC in hdtg...