Measuring Sample Quality with Stein's Method

Jackson Gorham, Lester W. Mackey

Overview

This paper introduces a novel, computationally efficient method to measure how well a set of samples represents a target probability distribution. Unlike traditional metrics that fail when a sampling method is intentionally biased for speed, this approach—based on "Stein discrepancy"—provides a rigorous bound on error that accounts for both variance and asymptotic bias. This makes it a powerful diagnostic tool for tuning modern, high-speed Markov chain Monte Carlo (MCMC) algorithms.

The Problem with Traditional Diagnostics

In Bayesian inference, MCMC is frequently used to estimate expectations. Traditionally, these algorithms are designed to be "exact," meaning that given enough time, they will converge to the true distribution. However, for massive datasets, exact MCMC is often prohibitively slow. To bypass this bottleneck, researchers increasingly rely on "biased" MCMC methods (like Stochastic Gradient Langevin Dynamics), which trade a degree of accuracy for massive gains in computational speed.

The core issue is that standard "health checks" for samples—such as Effective Sample Size (ESS) or trace plots—assume the sampler will eventually be exact. They measure how much the samples fluctuate (variance) but are entirely blind to whether the samples are fluctuating around the wrong target (bias). Consequently, practitioners have lacked a reliable way to choose hyperparameters or determine when a biased sampler has actually converged to a useful approximation.

Transforming Theory into Practice

The authors adapt Stein’s Method—traditionally a theoretical framework used to prove mathematical theorems about probability—into a practical engineering tool through several key innovations:

  1. The Stein Operator: They utilize the "Langevin operator," which only requires knowing the gradient of the log-density of the target distribution. Crucially, this bypasses the need to know the distribution's "normalizing constant" (the notoriously difficult denominator in Bayes' Rule).
  2. Stein Discrepancy: They define a quality measure based on the maximum difference between sample and target expectations over a large class of test functions. If this discrepancy is small, the samples are a good fit for the target distribution.
  3. Optimization via Linear Programming: To make this computable, the search for the "worst-case" test function is framed as a Linear Program (LP).
Stein discrepancy correctly identifies when samples diverge from the target distribution, plateauing for mismatched samples while converging for true samples.
  1. Geometric Spanners: A naive implementation would require comparing every sample point to every other point ($O(n^2)$ constraints), which is computationally unfeasible for large datasets. The authors employ "geometric spanners"—sparse graphs that preserve distances—to reduce the number of constraints to $O(n \log n)$, allowing the method to scale efficiently.
  2. Decoupling: By choosing the $\ell_1$ norm, the high-dimensional problem can be broken down into $d$ independent, parallelizable LPs.

Key Insights and Results

The paper evaluates the method across several benchmarks, including synthetic targets (Standard Normal distributions and Bimodal Gaussian Mixture Models), a real-world Prostate Cancer dataset for Bayesian logistic regression, and deterministic sequences like Sobol and Kernel Herding.

ESS is Blind to Bias

The most striking insight is that Effective Sample Size (the industry standard) can actively encourage the selection of worse parameters. In their SGLD experiment, ESS suggested a large step size because it produced "uncorrelated" samples, even though those samples were wildly inaccurate. The Stein discrepancy correctly identified the intermediate step size that properly balanced speed and accuracy.

Quantifying the Bias-Variance Tradeoff

On the prostate cancer dataset, the authors demonstrated that their metric could explicitly quantify when a fast, biased sampler stops being advantageous compared to a slow, exact one as the computational budget increases.

Convergence Rates and Universal Applicability

Because the metric is agnostic to how the samples were generated, it can compare random MCMC chains against deterministic sequences. The metric correctly recovered the theoretical convergence rates for deterministic sequences (e.g., $n^{-1}$ for Sobol), validating that the "spanner" approximation does not sacrifice mathematical integrity.

Comparison of discrepancy measures showing convergence rates as the number of sample points increases.

Limitations and Future Work

While a significant leap forward, the method has limitations:

  • Computational Overhead: Even with spanners, solving a Linear Program for every diagnostic check is more computationally expensive than calculating a simple mean or variance.
  • High Dimensions: Although the $\ell_1$ trick allows for parallelization, complexity still grows with the dimension $d$. The authors note that the "constant" in their bounds depends on the dimension, which might impact performance in extremely high-dimensional spaces.
  • Choice of Stein Set: The results depend on the specific class of test functions (the "Stein set") chosen. While the authors advocate for a parameter-free version, different sets might be more appropriate for specific types of distributions, such as heavy-tailed versus light-tailed targets.

Summary updated

BibTeX
@inproceedings{gorham2015measuring,
  author = {Jackson Gorham and Lester W. Mackey},
  title = {{Measuring Sample Quality with Stein's Method}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2015},
}
Figure