zigzagHMC: Sample from a truncated Gaussian distribution

View source: R/zigzagHMC.R

zigzagHMCR Documentation

Sample from a truncated Gaussian distribution

Description

Generate MCMC samples from a d-dimensional truncated Gaussian distribution with element-wise truncations using the Zigzag Hamiltonian Monte Carlo sampler (Zigzag-HMC).

Usage

zigzagHMC(
  n,
  burnin = 0,
  mean,
  cov,
  prec = NULL,
  lowerBounds,
  upperBounds,
  init = NULL,
  step = NULL,
  nutsFlg = FALSE,
  rSeed = 1
)

Arguments

n

number of samples after burn-in.

burnin

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

mean

a d-dimensional mean vector.

cov

a d-by-d covariance matrix of the Gaussian distribution. At least one of prec and cov should be provided.

prec

a d-by-d precision matrix of the Gaussian distribution.

lowerBounds

a d-dimensional vector specifying the lower bounds. -Inf is accepted.

upperBounds

a d-dimensional vector specifying the upper bounds. Inf is accepted.

init

a d-dimensional vector of the initial value. init must satisfy all constraints. If init = NULL, a random initial value will be used.

step

step size for Zigzag-HMC or Zigzag-NUTS (if nutsFlg = TRUE). Default value is the empirically optimal choice: sqrt(2)(lambda)^(-1/2) for Zigzag-HMC and 0.1(lambda)^(-1/2) for Zigzag-NUTS, where lambda is the minimal eigenvalue of the precision matrix.

nutsFlg

logical. If TRUE the No-U-Turn sampler will be used (Zigzag-NUTS).

rSeed

random seed (default = 1).

Value

an (n + burnin)*d matrix of samples. The first burnin samples are from the user specified warm-up iterations.

References

\insertRef

nishimura2021hamiltonianhdtg

\insertRef

nishimura2020discontinuoushdtg

Examples

set.seed(1)
d <- 10
A <- matrix(runif(d^2)*2-1, ncol=d)
covMat <- t(A) %*% A
initial <- rep(1, d)
results <- zigzagHMC(n = 1000, burnin = 1000, mean = rep(0, d), cov = covMat,
lowerBounds = rep(0, d), upperBounds = rep(Inf, d))


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

Related to zigzagHMC in hdtg...