View source: R/slice_samplers_univariate.R
| slice_elliptical | R Documentation |
Algorithm 1 of Nishihara et al. (2014) of the elliptical slice sampler of Murray et al. (2010).
slice_elliptical(x, log_lik, mu, sigma, diagnostics = NULL)
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 |
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.
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
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.