View source: R/hyperrectangle_slice.R
| slice_quantile_mv | R Documentation |
Quantile slice sampler for a random vector (Heiner et al., 2026+). The pseudo-target is specified through independent univariate distributions.
slice_quantile_mv(x, log_target, pseudo, diagnostics = NULL)
x |
The current state (as a numeric vector). |
log_target |
A function taking numeric vector that evaluates the log-target density, returning a numeric scalar. |
pseudo |
List of length equal to the number of dimensions in |
diagnostics |
Logical, indicating whether the sampler should be run in diagnostic mode for
informative error handling. When |
A list containing three elements: "x" is the new state, "u" is the vector of values of the pseudo-target CDFs associated with the returned value, and "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. (2026+), "Quantile Slice Sampling," arXiv preprint arXiv:2407.12608 \Sexpr[results=rd]{tools:::Rd_expr_doi("https://doi.org/10.48550/arXiv.2407.12608")}
lf <- function(x) dbeta(x[1], 3, 4, log = TRUE) + dbeta(x[2], 5, 3, log = TRUE)
ps_shsc <- list(c(2, 2), c(2, 1))
ps <- list(
list(ld = function(x) dbeta(x, ps_shsc[[1]][1], ps_shsc[[1]][2], log = TRUE),
p = function(x) pbeta(x, ps_shsc[[1]][1], ps_shsc[[1]][2]),
q = function(x) qbeta(x, ps_shsc[[1]][1], ps_shsc[[1]][2]) ),
list(ld = function(x) dbeta(x, ps_shsc[[2]][1], ps_shsc[[2]][2], log = TRUE),
p = function(x) pbeta(x, ps_shsc[[2]][1], ps_shsc[[2]][2]),
q = function(x) qbeta(x, ps_shsc[[2]][1], ps_shsc[[2]][2]) )
)
n_iter <- 10 # set to 1e4 for more complete illustration
draws <- matrix(0.2, nrow = n_iter, ncol = 2)
draws_u <- draws
draws_u[1,] <- sapply(1:length(ps), function(k) ps[[k]]$p(draws[1,k]))
nEvaluations <- 0L
for (i in seq.int(2, n_iter)) {
out <- slice_quantile_mv(draws[i - 1, ], log_target = lf, pseudo = ps)
draws[i,] <- out$x
draws_u[i,] <- out$u
nEvaluations <- nEvaluations + out$nEvaluations
cat(i, '\r')
}
nEvaluations / (nrow(draws) - 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)
plot(draws_u[,1], draws_u[,2], xlim = c(0, 1))
utility_shrinkslice(u = draws_u[,1], nbins = 30, type = "samples",
plot = TRUE, utility_type = "AUC")
utility_shrinkslice(u = draws_u[,2], nbins = 30, type = "samples",
plot = TRUE, utility_type = "AUC")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.