Learn R Programming

lineqGPR (version 0.1.1)

tmvrnorm.HMC: "tmvrnorm" Sampler for "HMC" (Hamiltonian Monte Carlo) S3 Class

Description

Sampler for truncated multivariate normal distributions via Hamiltonian Monte Carlo using the package tmg (Pakman and Paninski, 2014).

Usage

# S3 method for HMC
tmvrnorm(object, nsim, control = list(burn.in = 100), ...)

Arguments

object

an object with "HMC" S3 class containing: mu (mean vector), Sigma (covariance matrix), lb (lower bound vector), ub (upper bound vector).

nsim

an integer corresponding to the number of simulations.

control

extra parameters required for the MC/MCMC sampler.

...

further arguments passed to or from other methods.

Value

A matrix with the simulated samples. Samples are indexed by columns.

References

Pakman, A. and Paninski, L. (2014), "Exact Hamiltonian Monte Carlo for truncated multivariate Gaussians". Journal of Computational and Graphical Statistics, 23(2):518-542. [link]

See Also

tmvrnorm.RSM, tmvrnorm.ExpT

Examples

Run this code
# NOT RUN {
n <- 100
x <- seq(0, 1, length = n)
Sigma <- kernCompute(x1 = x, type = "gaussian", par = c(1,0.2))
tmgPar <- list(mu = rep(0,n), Sigma = Sigma + 1e-9*diag(n), lb = rep(-1,n), ub = rep(1,n))
class(tmgPar) <- "HMC"
y <- tmvrnorm(tmgPar, nsim = 10)
matplot(x, y, type = 'l', ylim = c(-1,1),
        main = "Constrained samples using Hamiltonian MC")
abline(h = c(-1,1), lty = 2)

# }

Run the code above in your browser using DataLab