slice_elliptical: Univariate Elliptical Slice Sampler

View source: R/slice_samplers_univariate.R

slice_ellipticalR Documentation

Univariate Elliptical Slice Sampler

Description

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

Usage

slice_elliptical(x, log_lik, mu, sigma, diagnostics = NULL)

Arguments

x

The current state (as a numeric scalar).

log_lik

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

mu

A numeric scalar with the mean of the supporting normal "prior" distribution.

sigma

A numeric scalar with the standard deviation of the supporting normal "prior" distribution.

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 with two elements:

x is the new state.

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

log_lik <- function(x) dbeta(x, 8, 2, log = TRUE)
lf <- function(x) log_lik(x) + dnorm(x, mean = mu, sd = sig, log = TRUE)
mu <- 0.2
sig <- 0.3
draws <- numeric(10) + 0.5 # set to numeric(1e3) + 0.5 for more complete illustration
nEvaluations <- 0L
for (i in seq.int(2, length(draws))) {
  out <- slice_elliptical(draws[i - 1], log_lik = log_lik, mu = mu, sigma = sig)
  draws[i] <- out$x
  nEvaluations <- nEvaluations + out$nEvaluations
}
nEvaluations / (length(draws) - 1)
plot(density(draws), xlim = c(-0.2, 1.2))
curve(exp(lf(x)) * 4.5, -0.2, 1.2, col = "blue", add = TRUE) # 4.5 to match curve height


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