slice_elliptical_mv: Multivariate Elliptical Slice Sampler

View source: R/elliptical_slice_multivariate.R

slice_elliptical_mvR Documentation

Multivariate Elliptical Slice Sampler

Description

Algorithm 1 of Nishihara et al. (2014) of the elliptical slice sampler of Murray et al. (2010).

Usage

slice_elliptical_mv(x, log_lik, mu, Sig, is_chol = FALSE, diagnostics = NULL)

Arguments

x

The current state (as a numeric vector).

log_lik

A function taking numeric vector that evaluates the natural logarithm of the "likelihood" L(x) part of the unnormalized target density L(x) * Normal(x; mu, Sig). Returns a numeric scalar.

mu

Numeric vector with the mean of the supporting normal "prior" distribution.

Sig

Positive definite covariance matrix of the supporting normal "prior" distribution. Alternatively, a lower-triangular matrix with the Cholesky factor of the covariance matrix (for faster computation).

is_chol

Logical, is the supplied Sig in Cholesky (lower triangular) format? Default is false.

diagnostics

Logical, indicating whether the sampler should be run in diagnostic mode for informative error handling. When diagnostics is NULL, it is reset to match the value of getOption("qslice.diagnostics") which defaults to FALSE if the option is not set. Default for diagnostics is NULL.

Value

A list containing two elements: x is the new state and nEvaluations is the number of evaluations of the log-likelihood function used to obtain the new state.

References

Murray, I., Adams, R., and MacKay, D., (2010), "Elliptical Slice Sampling," in Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics, JMLR Workshop and Conference Proceedings. https://proceedings.mlr.press/v9/murray10a

Nishihara, R., Murray, I., and Adams, R. P. (2014), "Parallel MCMC with Generalized Elliptical Slice Sampling," Journal of Machine Learning Research, 15, 2087-2112. https://jmlr.org/papers/v15/nishihara14a.html

Examples

mu <- c(0.5, 0.5)
Sig <- matrix(c(0.5, 0.25, 0.25, 0.5), nrow = 2)
SigL <- t(chol(Sig))
log_lik <- function(x) dbeta(x[1], 3, 4, log = TRUE) + dbeta(x[2], 5, 3, log = TRUE)
lf <- function(x) log_lik(x) - 0.5 * drop(crossprod(forwardsolve(SigL, x - mu)))
n_iter <- 10 # set to 1e3 for more complete illustration
draws <- matrix(0.3, nrow = n_iter, ncol = 2)
nEvaluations <- 0L
for (i in seq.int(2, n_iter)) {
  out <- slice_elliptical_mv(draws[i - 1,], log_lik = log_lik,
              mu = mu, Sig = SigL, is_chol = TRUE)
  draws[i,] <- out$x
  nEvaluations <- nEvaluations + out$nEvaluations
}
nEvaluations / (n_iter - 1)
plot(draws[,1], draws[,2], xlim = c(0, 1))
hist(draws[,1], freq = FALSE); curve(dbeta(x, 3, 4), col = "blue", add = TRUE)
hist(draws[,2], freq = FALSE); curve(dbeta(x, 5, 3), col = "blue", add = TRUE)


qslice documentation built on Oct. 22, 2026, 1:06 a.m.