Slice Sampling

Statistics
Introduced by
Radford M. Neal
Year
2003
Type
MCMC sampling algorithm

What does it do?

Slice sampling is a Markov chain Monte Carlo (MCMC) algorithm presented in full by Radford M. Neal in his 2003 Annals of Statistics paper.

It draws samples from a target distribution by sampling uniformly from the region under the density curve, the 'slice', so it requires no step size or proposal distribution, only an initial bracket width. It is used for Bayesian posterior inference, including when the posterior is known only up to a normalising constant.

The intuition behind the method

Imagine the density function as a landscape of hills. At each step, pick a random height uniformly between zero and the current hill height; this defines a horizontal slice through the landscape. Then pick a new position uniformly at random from anywhere the landscape rises above that height. Repeat and you trace out a path that, in the long run, visits each region in proportion to its probability mass — all without ever deciding how large a step to take.

History

The method is presented in full in Radford M. Neal’s invited Annals of Statistics paper (2003, vol. 31, pp. 705–767), published with discussion. The paper covers univariate and multivariate slice updates, overrelaxation for univariate slices, and reflection for multivariate slices, and it is the main reference for the method among the page’s sources.

When to use it

Choose slice sampling for continuous parameters when Metropolis–Hastings is hard to tune and the unnormalised posterior density can be evaluated. It suits unimodal or weakly multimodal targets and low-to-moderate parameter counts, and it is a natural choice when parameters are updated one at a time. Avoid it for high-dimensional targets, where mixing becomes slow, and for sharply multimodal posteriors whose modes are separated by low-density regions, because the slice can fragment and the chain may stay in one mode. When gradients of the log-density are available and the target is smooth and high-dimensional, Hamiltonian Monte Carlo is usually the better choice.

Limitations and considerations

  • In high dimensions each variable is updated in turn with univariate slices, so mixing slows as the number of parameters grows, and strongly dependent parameters move slowly along correlated directions.
  • When modes are separated by regions whose density falls below the current slice height, the slice becomes disconnected and the chain may not move between modes.
  • Stepping out and shrinking each evaluate the density, so one update can require several evaluations; this makes each iteration costlier than a single Metropolis step when the density is expensive to compute.
  • The univariate version does not use posterior gradients, so for smooth, high-dimensional targets Hamiltonian Monte Carlo is generally more efficient.
  • The default scheme updates one coordinate at a time using univariate stepping-out and shrinkage. Overrelaxation (univariate) and reflection (multivariate) are variants described by Neal (2003) that suppress random walks; they change the autocorrelation of the draws and should be used only after their effect on mixing is checked.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • No step size or proposal distribution is needed: the bracket adapts to the local scale of the density, removing the main tuning task of Metropolis–Hastings.
  • The updates are constructed to leave the target distribution invariant, so the posterior is preserved without a separate accept/reject correction on the slice itself.
  • Neal (2003) notes that slice sampling is often easier to implement than Gibbs sampling and more efficient than simple Metropolis updates, because the magnitude of each change is chosen adaptively.
  • Only unnormalised density evaluations are needed, so posteriors defined up to a normalising constant can be used directly.

Applications

  • Sampling Bayesian posteriors with moderate numbers of parameters when gradients of the log-density are unavailable.
  • Teaching and prototyping, since the univariate update is simple to implement from first principles.
  • Bayesian inference for models with analytically intractable posteriors where Metropolis–Hastings step-size tuning is cumbersome.
  • Sampling from custom unnormalised densities where only density values can be evaluated.
  • Benchmarking MCMC methods, where slice sampling serves as a well-understood baseline.

How it works

How it works

1

An auxiliary uniform variable u is drawn between 0 and the current density value f(θ). This u sets the height of the horizontal slice, and it places the joint distribution over (θ, u) uniformly on the region under the density curve.

Formula
u \mid \theta^{(t)} \sim \mathrm{Uniform}\!\left(0,\, f(\theta^{(t)})\right)
2

The slice S is the set of θ values where the target density is at least u. The next sample must lie in S. Sampling uniformly from the region under the curve and then from the horizontal slice leaves the target distribution invariant, which is why the chain targets the posterior. The resulting chain is asymptotically exact: its draws converge in distribution to the posterior, so convergence must still be checked in practice.

Formula
S = \left\{\theta : f(\theta) \geq u\right\}
3

S is generally not available in closed form, so an interval I = (L, R) around the current point is constructed. A stepping-out or doubling procedure starts from the initial width w and expands L and R until both endpoints fall outside the slice.

Formula
I = (L, R) \supseteq S \cap \text{neighbourhood}(\theta^{(t)})
4

A candidate θ* is drawn uniformly from the bracket I. If f(θ*) ≥ u, the candidate is accepted as the next sample θ^(t+1).

Formula
\theta^{(t+1)} \sim \mathrm{Uniform}(I \cap S)
5

If f(θ*) < u, the candidate lies outside the slice and the bracket is shrunk: L is moved to θ* when θ* lies to the left of the current point, and R is moved to θ* when it lies to the right. A new candidate is drawn from the reduced bracket until one falls inside the slice.

Formula
\text{if } f(\theta^{*}) < u,\text{ shrink } I \text{ to } (L, \theta^{*}) \text{ or } (\theta^{*}, R) \text{ and resample}

Common pitfalls

  • Judging mixing from trace plots alone in high-dimensional problems; a chain can look well behaved while mixing slowly, so effective sample size should be checked.
  • Summarising draws before checking convergence diagnostics (R-hat below 1.01 and adequate ESS).
  • Running the sampler on a sharply multimodal posterior without tempering or a mode-jumping extension, which can leave the chain in a single mode.
  • Reading the bracket width as a fixed step size. It is only a starting guess; stepping out and shrinking adjust the bracket within each update.
  • Treating successive draws as independent. Draws are autocorrelated, so ESS is typically below the raw chain length; overrelaxation variants can produce negatively autocorrelated draws, so the sign of the autocorrelation should be checked rather than assumed.

Frequently asked questions

How does slice sampling differ from Metropolis–Hastings?

Metropolis–Hastings proposes a candidate from a user-specified proposal distribution and accepts or rejects it, and its efficiency depends strongly on the proposal scale. Slice sampling removes this choice: the bracket is built from the density itself, and any candidate inside the slice is accepted. This makes slice sampling easier to apply but does not make it universally faster. For smooth, high-dimensional posteriors, Hamiltonian Monte Carlo often performs better than either.

Does slice sampling converge to the correct posterior?

Neal (2003) shows that the slice updates leave the target distribution invariant, so under the standard conditions for MCMC the chain targets the posterior. Convergence is still asymptotic, so convergence diagnostics such as R-hat and ESS must be checked in practice.

Can slice sampling handle multimodal posteriors?

Only partially. If modes are well separated and the density between them falls below the current slice height, the slice becomes disconnected and the sampler may be unable to move between modes. Extensions such as parallel tempering or a global jump proposal are needed for reliable exploration of strongly multimodal posteriors.

What is the stepping-out width parameter and how should I set it?

The width w is an initial guess for the bracket size around the current point. Neal (2003) shows that the stepping-out and shrinkage procedure gives a valid update for any positive w: if the bracket is too small, stepping out widens it until it covers the slice, and if it is too large, shrinkage narrows it. The value affects efficiency rather than correctness, so different values can be compared empirically by checking mixing.

Related methods

Sources

  1. Neal, R. M. (2003). Slice sampling (with discussion). Annals of Statistics, 31(3), 705–767.

    Open DOI reference
  2. Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian Data Analysis (3rd ed.). CRC Press.

    ISBN: 978-1439840955
  3. Robert, C. P., & Casella, G. (2004). Monte Carlo Statistical Methods (2nd ed.). Springer.

    ISBN: 978-0387212395