slice_quantile {qslice} | R Documentation |
Quantile Slice Sampler
Description
Single update using a quantile slice sampler of Heiner et al. (2024+).
Usage
slice_quantile(x, log_target, pseudo)
Arguments
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:
|
Value
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.
References
Heiner, M. J., Johnson, S. B., Christensen, J. R., and Dahl, D. B. (2024+), "Quantile Slice Sampling," arXiv preprint arXiv:###.
Examples
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)