View source: R/elliptical_slice_multivariate.R
| slice_genelliptical_mv | R Documentation |
Generalized Elliptical Slice Sampler, Algorithm 2 of Nishihara et al. (2014)
slice_genelliptical_mv(
x,
log_target,
mu,
Sig,
df,
is_chol = FALSE,
diagnostics = NULL
)
x |
The current state (as a numeric vector). |
log_target |
A function taking numeric vector that evaluates the natural logarithm of the unnormalized target density. Returns a numeric scalar. |
mu |
A numeric vector with the location parameter of the Student t pseudo-target. |
Sig |
Positive definite scale matrix of the Student t pseudo-target. Alternatively, a lower-triangular matrix with the Cholesky factor of the scale matrix (for faster computation). |
df |
Degrees of freedom of Student t pseudo-target. |
is_chol |
Logical, is the supplied |
diagnostics |
Logical, indicating whether the sampler should be run in diagnostic mode for
informative error handling. When |
A list containing two elements: x is the new state and nEvaluations
is the number of evaluations of the target function used to obtain the new
state.
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
lf <- function(x) dbeta(x[1], 3, 4, log = TRUE) + dbeta(x[2], 5, 3, log = TRUE)
n_iter <- 10 # set to 1e4 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_genelliptical_mv(draws[i - 1,], log_target = lf,
mu = c(0.5, 0.5), Sig = matrix(c(0.5, 0.25, 0.25, 0.5), nrow = 2),
df = 5)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.