Your sampler keeps accepting proposals, but successive draws look so similar that the chain provides little new information. This can happen when plausible parameter combinations lie in a long, narrow region. Small random steps move safely across its width but explore its length slowly. Gibbs still needs cycles proportional to the squared length-scale ratio, with no step-size setting to tune away that slowdown.
Changing how proposals are chosen does not remove that geometric obstacle. At correlation 0.99, Gibbs needs roughly 100 cycles per independent sample. We build it alongside slice sampling and Metropolis on the same Gaussian, then compare how conditional draws and density-selected regions affect the chains.
Quick Win: Gibbs in Thirty Lines
For a bivariate Gaussian with , the conditionals are themselves Gaussian:
Gibbs sampling cycles between drawing from these two conditionals. The whole sampler fits in a few lines:
import numpy as np
def gibbs_bivariate_normal(n_cycles, rho, x0=None, rng=None):
rng = rng or np.random.default_rng(42)
sigma = np.sqrt(1 - rho**2)
x = np.array([3.5, -3.5]) if x0 is None else np.asarray(x0, dtype=float).copy()
trace = [x.copy()]
for _ in range(n_cycles):
x[0] = rho * x[1] + sigma * rng.standard_normal() # z1 | z2
trace.append(x.copy())
x[1] = rho * x[0] + sigma * rng.standard_normal() # z2 | z1
trace.append(x.copy())
return np.array(trace)
trace = gibbs_bivariate_normal(40, rho=0.95)
Run it on and the trajectory walks the long axis of the target one axis-aligned step at a time:

Compared to a step-size-tuned random-walk Metropolis sampler on the same target, the difference is visible at 200 steps. Gibbs has settled on the long axis; Metropolis is still making its way out of the corner:

What Just Happened: Gibbs as Metropolis-Hastings With Always-Accept
Gibbs sampling is not a different algorithm. It is Metropolis-Hastings with a specific proposal that makes the acceptance probability identically one.
The construction
Pick one coordinate . Hold the rest, , fixed. Propose a new value for from the full conditional . This is a valid Metropolis-Hastings proposal:
Plug this into the Metropolis-Hastings acceptance ratio. Using the factorisation and noting that , the ratio is:
Every Gibbs proposal is accepted. The work shifts from acceptance bookkeeping to deriving the conditionals and sampling from them.
Why the conditionals are easy in graphical models
The full conditional looks intimidating in general, but for distributions with conditional-independence structure it simplifies dramatically. For a directed graphical model, depends only on 's Markov blanket: its parents, its children, and the co-parents of its children.

For a Bayesian network on hundreds of nodes, the conditional reduces to a small product of factors over the local neighbourhood. This is why Gibbs sampling underpins JAGS, BUGS, and the Bayesian-network pipeline in the clinical decision support post.
The ergodicity caveat
Gibbs is exact only if the chain is ergodic, which requires that none of the conditionals are anywhere zero. A target with isolated regions of zero density (say, two posterior modes separated by a likelihood ridge of exact zero) cannot be visited end-to-end by a Gibbs sampler that makes one-coordinate moves. The chain gets stuck in the basin it starts in. In practice this means: check your conditionals are everywhere positive, or be prepared to switch to a sampler that moves in larger blocks.
Going Deeper: Why Correlation Hurts Gibbs
Gibbs is exact at every step. It is not always efficient. A bivariate-Gaussian analysis is the cleanest illustration. The conditional standard deviation controls the typical step size. The marginal length scale along the long axis is . The number of cycles to obtain an independent sample scales as .
We can verify this numerically. As increases, the autocorrelation of over Gibbs cycles decays more slowly, and the empirical effective sample size collapses linearly with :

Two takeaways. First, the scaling is real. At the sampler needs roughly 100 cycles per independent sample. Second, the scaling is independent of how cleverly you tune anything: there is no step size to choose.
Two patches: over-relaxation and blocking
There are two practical fixes. Over-relaxation (Adler 1981) replaces the Gibbs draw with a deterministic reflection biased toward the opposite side of the conditional mean:
For , the new value is on the opposite side of from the old one, so the chain is encouraged to traverse the distribution rather than diffuse around the mean. The marginals are unchanged.
Blocking Gibbs (Jensen et al. 1995) updates groups of variables jointly, sampling from rather than one coordinate at a time. When the variables in block are strongly correlated with each other but only weakly with the rest, blocking removes the worst within-block correlations. The cost is that you need a tractable joint conditional for the block, which often means the block has to have conjugate structure.
When Gibbs cannot help: HMC's domain
Both fixes leave the basic geometry intact. For a multivariate Gaussian with a correlation length orders of magnitude larger than , even blocked Gibbs walks the long axis. The way out is to abandon coordinate updates entirely. Hamiltonian Monte Carlo (Neal 2011) introduces auxiliary momentum variables and uses gradient information to take long, almost-independent steps. HMC is what underpins NUTS in PyMC, Stan, and the approximate inference comparison post. It deserves its own post; the decision in this post is between MH, Gibbs, and slice.
Slice Sampling: Adaptive Step Size by Construction
Slice sampling (Neal 2003) takes a different approach to fixing random walk. Instead of choosing a step size, it lets the target's local shape choose for you.
The auxiliary-variable trick
Augment with a uniform variable :
The marginal over is , the original target. So sampling uniformly from the area under the unnormalised density and discarding gives a draw from . Slice sampling alternates between two updates:
- Given current , draw . This sets a horizontal "slice" through the density.
- Given , draw a new uniformly from the slice .
The first step is trivial: is a number, draw uniform below it. The second is the algorithm's hard part. The slice is generally a union of intervals (for multimodal targets, the slice may include disconnected segments) and there is no closed-form way to sample from it.
Stepping out and shrinking
Neal (2003) gives a rejection-style procedure. Place an interval of width around , step out by extending each end by until the endpoints are outside the slice, then shrink by drawing candidates uniformly inside the bracket and contracting the bracket toward whenever a candidate lands outside the slice. The first candidate inside the slice is the new sample.
def slice_sampler_1d(p_unnorm, x0, n_steps, w=2.0, rng=None):
rng = rng or np.random.default_rng(42)
x = float(x0)
trace = [x]
for _ in range(n_steps):
u = rng.uniform(0, p_unnorm(x)) # draw the slice level
L = x - w * rng.uniform() # initial bracket
R = L + w
while p_unnorm(L) > u: L -= w # step-out left
while p_unnorm(R) > u: R += w # step-out right
while True: # shrink + accept
z_new = rng.uniform(L, R)
if p_unnorm(z_new) > u:
x = z_new
break
(L, R) = (z_new, R) if z_new < x else (L, z_new)
trace.append(x)
return np.array(trace)
The whole loop is six lines of essentials. Watch one step on a bimodal target. The slice level (teal dashed) carves a horizontal line; the bracket steps out (purple), candidates (red ×) get rejected and the bracket shrinks; the accepted point (green) lands in the slice:

Run for 4,000 steps and the histogram recovers both modes cleanly:

The crucial property is that the slice width adapts. When the chain is in a region where is broad and flat, the slice is wide and the bracket steps out a long way: large moves at low cost. When is sharply peaked, the slice is narrow and the bracket stays small. There is no step-size hyperparameter to tune. The width controls only the initial bracket and amortises across step-out iterations; setting it to roughly the target's typical scale is enough.
Multivariate slice sampling
Slice sampling extends to multivariate targets componentwise: update one coordinate at a time using the univariate slice sampler on the conditional . This is the slice analogue of Gibbs and inherits Gibbs's correlation problem. Genuinely multivariate slice samplers exist (elliptical slice sampling for Gaussian priors, Murray et al. 2010).
Three Methods on a Shared Problem
Pick the bivariate Gaussian with and run all three samplers for matched effort. The story holds:

Two practical lessons emerge:
- Per-step quality: Gibbs and slice both produce roughly i.i.d. samples at low correlation; MH produces correlated samples even with optimal step-size tuning. At high correlation () all three componentwise samplers collapse, which is the regime where HMC matters.
- Wall-clock: Gibbs wins by an order of magnitude when the conditionals are tractable, because each draw is a single Gaussian sample. Slice pays for stepping-out and shrinking even when is well-chosen. MH is fast per step but produces fewer effective samples per step.
The decision rule is short:
| Use | When |
|---|---|
| Random-walk MH | Conditionals not tractable, target unimodal, dimension small. Always tune step size to roughly the proposal-acceptance sweet spot (~25% in high D, ~50% in 1D) |
| Gibbs sampling | Conditionals are tractable (typically: graphical models, conjugate hierarchical models, Bayesian networks). Default first choice |
| Slice sampling | Conditionals are evaluable but not tractable; you don't want to tune a step size; targets may be multimodal in low D |
| Blocking Gibbs | Conditionals tractable, but variables form correlated groups |
| HMC / NUTS | Continuous, differentiable target with strong correlations; problem is otherwise intractable to coordinate samplers |
Foundations
Gibbs sampling traces to Geman and Geman (1984), an image-restoration paper that gave the algorithm its name (after Josiah Willard Gibbs's work in statistical physics, since the joint distribution being sampled is analogous to a Gibbs distribution). As shown above, it is a special case of Metropolis-Hastings in which every proposal is accepted.
The bivariate-Gaussian mixing analysis is one of the few cases in MCMC where you can write the mixing time in closed form: the number of steps needed to obtain an independent sample is of order . This is the result we verified empirically above. The over-relaxation and blocking-Gibbs extensions are due to Adler (1981) and Jensen, Kong & Kjærulff (1995) respectively.
Slice sampling is Radford Neal's contribution: Slice Sampling (Annals of Statistics, 2003). It provides an adaptive step size that is automatically adjusted to match the characteristics of the distribution. The auxiliary-variable construction, the stepping-out scheme, and the shrinking-region rejection all appear in Neal's paper with full derivations and convergence proofs.
For practical implementations, the PyMC documentation on slice sampling is a useful reference, and the wider Markov-chain Monte Carlo literature is covered comprehensively in Brooks, Gelman, Jones, and Meng's Handbook of Markov Chain Monte Carlo (2011), which is the modern successor to Gilks et al. (1996).
Limitations and Pitfalls
The trade-offs to keep in mind when choosing between these samplers:
- Gibbs assumes tractable conditionals. If is not in a sampleable family, Gibbs degenerates to plain Metropolis-Hastings inside each conditional update (Metropolis-within-Gibbs), which loses the always-accept property and reintroduces step-size tuning.
- Both Gibbs and componentwise slice are random-walk in disguise. They escape the random-walk problem of MH by replacing it with a different problem (correlation-driven slow mixing). For correlated targets the only fundamental escape is HMC or another method that uses gradient information.
- Slice's parameter still matters in practice. The theory says any produces a valid sampler, but a that is much smaller than the target's scale leads to many step-out iterations per sample. A much larger than the target's scale leads to many shrink iterations. A factor-of-two error in is fine; orders of magnitude slows the sampler considerably.
- Ergodicity requires positive conditionals. Both Gibbs and slice can fail on targets with isolated zero-density regions. Most real Bayesian posteriors satisfy ergodicity; carefully constructed adversarial examples (mixtures with vanishing component overlap) do not.
- None of these solve the multimodal problem in high dimensions. Slice handles 1D bimodal targets cleanly because the slice can include disconnected intervals. In the chain still has to walk between modes via low-density regions. Tempering and parallel chain methods are the standard cures.
The natural sequels here are HMC for the correlation/gradient escape, and reversible-jump or replica-exchange MCMC for transdimensional and multimodal targets. The sampling-methods post covers what to do when MCMC is overkill for the problem.
Interactive Tools
- Markov Chain Simulator: visualise the kind of Markov chain that underpins MCMC samplers, with stationary distributions and mixing times.
- Distribution Explorer: sample from the conditional distributions Gibbs uses, and visualise the slice levels through any 1D density.
- Bayes' Theorem Calculator: the prior-likelihood-posterior arithmetic that Gibbs and slice are sampling from.
Related Posts
For gradient-based posterior sampling, the Hamiltonian Monte Carlo tutorial compares trajectories, step sizes and sampling behaviour.
Sampling Methods Compared: Inverse-CDF, Rejection, Importance: The basic sampling methods this post builds on. Inverse-CDF is what slice sampling reduces to inside each step's stepping-out region.
MCMC Metropolis-Hastings: Island Hopping Guide: the random-walk Metropolis sampler whose limitations Gibbs and slice cure.
MCMC for Mixture Models: Inferring Earthquake Regimes: Gibbs sampling on a real-world Poisson-mixture posterior with discrete latent variables.
Bayesian Networks for Clinical Decision Support: Gibbs sampling's natural home, with conditional distributions defined by graph structure.
Approximate Inference: From MCMC to Variational Bayes: the deterministic alternative when sampling is too slow.
Custom Likelihoods in PyMC: One-Inflated Beta Regression: The kind of awkward custom-likelihood posterior these MCMC samplers exist to handle.







