AI Glossary / Probabilistic machine learning / Intermediate

Slice sampling

Definition

Slice sampling is a Markov chain Monte Carlo method that samples a distribution by introducing an auxiliary height beneath its unnormalized density curve. A horizontal slice at that height defines the region available for the next update. Repeating valid height and position updates produces a chain with the desired target distribution under suitable conditions.

What it means

Suppose a probability density is known only up to a multiplicative constant. Slice sampling can work with that unnormalized function, avoiding calculation of the normalizing integral. Instead of proposing a fixed-distance random jump and checking a density ratio, it uses a randomly selected density level to guide a move.

The method is a family of algorithms, not one universal implementation. In one dimension, a slice can be an interval or a union of intervals. Multivariate and specialized variants use different ways of exploring a slice. Correctly preserving the target distribution matters more than simply finding any point above the selected height.

How it works

Let f(x) be proportional to the target density and let x_0 be the current state. Draw a height y uniformly between zero and f(x_0). This defines the slice S_y containing all x for which f(x)>y. The ideal next position is a uniform draw from that entire slice.

Exact uniform sampling from S_y can be difficult. Practical one-dimensional methods construct a bracket around the current point, expand it using a valid stepping-out or doubling scheme and sample within it. Rejected candidates can shrink the bracket according to rules that preserve the appropriate slice distribution. Some constructions need additional acceptance conditions.

The auxiliary joint distribution is uniform under f, whose marginal in x is proportional to f(x). This explains the method's basis. In several dimensions, one can update coordinates conditionally or use a suitable multivariate slice method. Strong dependencies and separated modes still affect exploration, even when each update is valid.

Three practical examples

1. Bayesian scalar parameters: sample a conditional distribution whose density is evaluable but whose normalizing constant or inverse cumulative distribution is inconvenient.

2. Hierarchical models: use slice updates for selected continuous hyperparameters within a larger sampling scheme. Diagnose whether coordinate updates explore correlated parameter combinations adequately.

3. Teaching MCMC: compare an exact slice calculation for a simple density with a practical bracket-and-shrink implementation. Check both the stationary distribution and the correlation between successive draws.

Think of it this way

Think of drawing a horizontal line through a hill, then selecting a location from the land above that line. Higher lines give smaller eligible regions; lower lines can allow wider moves. The analogy illustrates a density slice. It does not justify arbitrary movement among eligible points or guarantee easy travel between separate hills.

Worked example

Take the unnormalized standard-normal density f(x)=exp(-x squared/2). Suppose the chain currently sits at x_0=1, where f(x_0)=exp(-0.5), approximately 0.60653. Stipulate a valid height draw y=exp(-2), approximately 0.13534, which lies below the current density.

The slice condition exp(-x squared/2)>exp(-2) is equivalent to x squared<4, giving the interval (-2,2). Because this toy slice is known exactly, draw a new position uniformly from it. A uniform random number u=0.7 gives x_new=-2+4 × 0.7=0.8.

The new density is exp(-0.32), approximately 0.72615, which exceeds the selected height. A candidate x=2.5 would fail because exp(-3.125), approximately 0.04394, is below that height. This demonstrates one exact-slice update, not a full Monte Carlo run. The next iteration draws a new height beneath f(0.8); it does not keep using the same interval forever. No density normalizing constant was needed.

Illustrative case study

Fictional case: Elm Inference replaces a hand-tuned random-walk update for a scalar model parameter with a slice sampler. The first implementation selects a convenient point inside each slice rather than following the prescribed uniform-preserving update. Its trace looks smooth, but a reference problem reveals biased output.

The team adopts a validated bracket-and-shrink procedure and compares multiple chains with a known simple target. It also measures the number of density evaluations per useful draw. This fictional case illustrates correctness and efficiency checks, not a guarantee that slice sampling improves every model.

Common misconceptions and mistakes

Slice sampling is not rejection sampling directly from the target distribution, and successive retained values are generally dependent. A sampler that eventually finds an acceptable point has not automatically implemented the correct transition. Bracket construction, shrinkage and any extra acceptance tests depend on the selected algorithm.

Avoiding a conventional Metropolis acceptance ratio does not mean the method avoids rejected trial points or computational tuning. Bracket widths and expansion limits can affect cost. Coordinatewise updates may mix poorly in highly correlated distributions, and disconnected slices can create mode-exploration difficulties. A trace that moves frequently can still fail to represent the full target.

Business use

Consider slice sampling when evaluating an unnormalized density is straightforward and its geometry suits the available update. Compare its density-evaluation cost with alternatives, rather than focusing only on the number of retained iterations. Constrained supports and transformations should be handled consistently with the target density.

Validate implementation on tractable distributions and inspect effective sample sizes and agreement across chains for the real model. Record bracket and stepping settings if they affect reproducibility. Communicate posterior uncertainty only after checking that the chain explores the relevant regions; slice sampling cannot compensate for a misspecified statistical model.

People also ask

Does it require the normalized density?

No. A positive multiplicative normalization constant is unnecessary when the algorithm uses the unnormalized density consistently.

Is the next sample independent of the current one?

Generally not. The current state determines the range for the auxiliary height, creating a Markov-chain update.

Must the slice be one interval?

No. For multimodal targets it can have multiple disconnected components, which complicates practical exploration.

Check your understanding

Why is x=2.5 outside the example's slice even though its density is positive?

Answer: Membership requires density above the particular height exp(-2), not merely above zero. At 2.5 the density is approximately 0.04394, which is too low.

Related terms

  • Markov chain Monte Carlo
  • Conditional distribution
  • Effective sample size
  • auxiliary variable
  • unnormalized density
  • stepping out
  • bracket shrinkage
  • multimodality

Learn next

Derive the exact normal-density slice in the example, then inspect a validated stepping-out and shrinkage algorithm. Next compare a unimodal target with a separated mixture to see how slice geometry affects mixing.

More in Probabilistic machine learning

  • Sequential model-based optimization - Sequential model-based optimization, or SMBO, is an approach to optimizing an expensive objective by repeatedly fitting a surrogate model, using it to...
  • Sequential Monte Carlo approximate Bayesian computation - Sequential Monte Carlo approximate Bayesian computation, or SMC-ABC, uses successive populations of weighted parameter samples to approximate Bayesian...
  • Shampoo optimizer - Shampoo is an adaptive gradient optimizer that uses the matrix or tensor structure of model parameters to build manageable preconditioners.
  • Sliced score matching - Sliced score matching is a method for learning a probability distribution's score by comparing score vectors along random directions.
  • Smoothing inference with twisted objectives - Smoothing inference with twisted objectives, or SIXO, is a method for learning probabilistic sequence models using sequential Monte Carlo targets that...
  • Sparse variational Gaussian process - A sparse variational Gaussian process is an approximate Gaussian process model that represents posterior information using a smaller set of inducing...

Sources

Neal, Slice Sampling, author manuscript: https://arxiv.org/pdf/physics/0009028

The auxiliary-height construction and valid slice-update distinction were checked in the primary manuscript. The normal-density calculation and fictional implementation case are original illustrations. Independent review consulted the auxiliary-variable construction and invariant slice-update requirement in Neal’s manuscript.

Previous: Slice Next: Sliced inverse regression

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer