View source: R/slice_samplers_univariate.R
slice_quantile | R Documentation |
Single update using a quantile slice sampler of Heiner et al. (2024+).
slice_quantile(x, log_target, pseudo)
x |
The current state (as a numeric scalar). |
log_target |
A function taking numeric scalar that evaluates the (potentially unnormalized) log-target density, returning a numeric scalar. |
pseudo |
List containing two functions specifying the pseudo-target distribution:
|
A list containing three elements:
x
is the new state.
u
is the value of the CDF of the psuedo-target associated with the
returned value (also referred to as psi).
nEvaluations
is the number of evaluations of the
target function used to obtain the new state.
Heiner, M. J., Johnson, S. B., Christensen, J. R., and Dahl, D. B. (2024+), "Quantile Slice Sampling," arXiv preprint arXiv:###.
lf <- function(x) dbeta(x, 3, 4, log = TRUE)
pseu <- list(ld = function(x) dbeta(x, shape1 = 1, shape2 = 1, log = TRUE),
q = function(u) qbeta(u, shape1 = 1, shape2 = 1))
draws <- numeric(10) # set to numeric(1e3) for more complete illustration
nEvaluations <- 0L
for (i in seq.int(2, length(draws))) {
out <- slice_quantile(draws[i - 1], log_target = lf, pseudo = pseu)
draws[i] <- out$x
nEvaluations <- nEvaluations + out$nEvaluations
}
nEvaluations / (length(draws) - 1)
plot(density(draws), xlim = c(0, 1))
curve(exp(lf(x)), 0, 1, col = "blue", add = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.