View source: R/slice_samplers_univariate.R
slice_stepping_out | R Documentation |
Single update for the univariate slice sampler of Neal (2003) using the "stepping out" procedure, followed by the "shrinkage" procedure.
slice_stepping_out(x, log_target, w, max = Inf)
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. |
w |
A numeric scalar tuning the algorithm which gives the typical slice width. This is a main tuning parameter of the algorithm. |
max |
The maximum number of times to step out. Setting |
A list with two elements:
x
is the new state.
nEvaluations
is the number of evaluations of the target function used to obtain the new
state.
Neal, R. M. (2003), "Slice sampling," The Annals of Statistics, 31, 705-767. \Sexpr[results=rd]{tools:::Rd_expr_doi("https://doi.org/10.1214/aos/1056562461")}
lf <- function(x) dbeta(x, 3, 4, log = TRUE)
draws <- numeric(10) + 0.5 # set to numeric(1e3) for more complete illustration
nEvaluations <- 0L
for (i in seq.int(2, length(draws))) {
out <- slice_stepping_out(draws[i - 1], log_target = lf, w = 0.7, max = Inf)
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.