AI Glossary / Probabilistic machine learning / Advanced
Stein discrepancy
Definition
A Stein discrepancy measures how strongly a candidate distribution violates identities that should hold under a target probability distribution. It combines a target-specific Stein operator with a chosen class of test functions. It can assess approximate samples using the target's score without needing its normalization constant in common continuous-density constructions.
What it means
Suppose an algorithm claims to sample from a complicated posterior distribution. Comparing a few averages is useful, but it may miss systematic errors. A Stein discrepancy supplies a broader collection of checks derived from the target itself.
There is no single universal Stein discrepancy. The operator, function class, domain, and normalization convention define the measure. Some formulations report a discrepancy; others report its square. Kernel Stein discrepancies use a reproducing kernel Hilbert space to make the optimization over functions tractable. They are members of the wider family, not synonyms for every Stein construction.
How it works
For a smooth one-dimensional target density p, a common operator maps f to f'(x) + f(x) times the derivative of log p(x). Appropriate boundary and integrability conditions ensure its expectation under p is zero.
Evaluate this transformed function under a candidate distribution q. A discrepancy takes the largest absolute expectation over a controlled class of functions. Restricting the class prevents arbitrary rescaling from making the value meaningless. In practice, sample averages replace expectations.
The derivative of log p is unchanged if p is multiplied by an unknown constant independent of x. That is why normalized target probabilities may be unnecessary. However, the method still needs a suitable score and valid operator assumptions. Kernel choices affect what departures are detectable and whether a vanishing discrepancy implies convergence. Finite-sample statistics also need an appropriate reference distribution before they become calibrated tests.
Three practical examples
1. Sampling evaluation: compare approximate posterior samples from competing algorithms against the same target score. Keep the discrepancy construction and evaluation budget fixed to make the comparison interpretable.
2. Model checking: assess whether observations are consistent with a specified smooth probabilistic model. Account for fitted parameters and sample dependence when deciding how to calibrate the test.
3. Approximation development: monitor a variational approximation using checks that depend on the target density's shape. Treat the results as additional evidence rather than a replacement for inspecting task-relevant predictions and important modes.
Think of it this way
Think of checking a machine against a set of balance equations. A correctly operating machine should satisfy the equations on average. A discrepancy asks how badly the strongest permitted check fails. A limited set of checks can miss a defect, so the checks themselves are part of the design, not an incidental detail.
Worked example
Consider an original deliberately restricted example. The target is a standard normal distribution. Its score is minus x, so the Stein operator is T f(x) = f'(x) minus x f(x).
Choose only functions f(x) = a + bx with a squared plus b squared at most 1. For a candidate distribution with finite second moment, the expected operator value is minus aE(X) + b[1 minus E(X squared)]. Maximizing its absolute value over this unit disk gives the square root of E(X) squared plus [1 minus E(X squared)] squared.
If the candidate is Gaussian with mean 1 and variance 1, its second moment is 2. The restricted discrepancy is therefore the square root of 2, approximately 1.4142. If the candidate is Gaussian with mean 0 and variance 4, the value is 3.
Now use a candidate placing equal probability at minus 1 and plus 1. Its mean is zero and second moment is 1, so the restricted value is zero even though this two-point distribution is not standard normal. This is not a full kernel Stein discrepancy. It demonstrates exactly why a sufficiently informative function class and its theoretical conditions matter.
Illustrative case study
Fictional case: Harbor Analytics evaluates two posterior approximation methods for a demand model. Both reproduce the posterior mean of one coefficient, but analysts want evidence about broader distributional accuracy. They select a documented Stein discrepancy, use the same target score implementation, and compare repeated runs at equal computational budgets.
The team also examines predictive tails and whether separate runs explore the same modes. Before interpreting a small score as success, it checks the kernel's assumptions and sample dependence. A disagreement between predictive checks and the discrepancy triggers investigation of both the approximation and the diagnostic. This fictional case describes an evaluation protocol without asserting a benchmark outcome.
Common misconceptions and mistakes
A zero value for a restricted diagnostic need not establish equality of distributions. Small empirical values do not automatically provide a p-value or an error bound for every business quantity. Normalization-free computation does not mean the target score is always inexpensive. Also distinguish a nonnegative population squared discrepancy from an unbiased finite-sample estimator, which can sometimes be negative.
Business use
The practical value is a diagnostic for probabilistic systems whose normalized densities are difficult to evaluate. Teams should record the target score, operator, test-function class or kernel, estimator, and calibration method. Scores from different constructions should not be ranked as though they share a common scale. The relevant question is whether the diagnostic detects errors that matter for the intended probabilistic decisions.
People also ask
Does it require samples from the target?
Common score-based constructions do not; they use target information through the score.
Is the score a model accuracy percentage?
No. Here it means the gradient of log density with respect to the variable.
Does every kernel guarantee convergence detection?
No. Such guarantees depend on the target and kernel assumptions.
Check your understanding
Answer: 1.
Why does an unknown normalization constant disappear?
Answer: Its log is constant with respect to x, so differentiation removes it.
Answer: 2.
What did the two-point example show?
Answer: Checking only the first two moments can miss major distributional differences.
Answer: 3.
Why constrain test functions?
Answer: Otherwise multiplying a function by an arbitrary constant could inflate the discrepancy without changing the underlying mismatch.
Related terms
- Markov chain Monte Carlo
- Reproducing kernel Hilbert space
- Stein operator
- score function
- kernel Stein discrepancy
- goodness-of-fit test
- variational inference
Learn next
Derive the normal target's Stein identity by integration by parts. Then examine how a kernel expands the available checks and study the conditions under which kernel Stein discrepancies detect non-convergence.
More in Probabilistic machine learning
- Spike-and-slab distribution - A spike-and-slab distribution is a mixture with one component concentrated at or near zero and another spread over a broader range.
- Stationary kernel - A stationary kernel is a covariance function whose value depends on the displacement between two inputs, rather than their absolute locations.
- Statistical linear regression - Statistical linear regression, in nonlinear Bayesian estimation, approximates a relationship between uncertain variables by an affine transformation plus an...
- Stochastic gradient Hamiltonian Monte Carlo - Stochastic gradient Hamiltonian Monte Carlo, or SGHMC, is a posterior sampling method that combines momentum-based dynamics with gradients estimated from...
- Stochastic neighbor embedding - Stochastic neighbor embedding, or SNE, is a nonlinear dimensionality-reduction method that represents objects in a lower-dimensional space by trying to...
- Stochastic variational inference - Stochastic variational inference, or SVI, uses stochastic optimization to fit a tractable approximation to a Bayesian posterior distribution.
Sources
Liu, Lee and Jordan, A Kernelized Stein Discrepancy for Goodness-of-fit Tests, explains the score-based operator and kernel construction: https://proceedings.mlr.press/v48/liub16.pdf
Gorham and Mackey, Measuring Sample Quality with Kernels, studies convergence-detection limitations and sufficient conditions: https://proceedings.mlr.press/v70/gorham17a/gorham17a.pdf
The restricted linear-function calculation and Harbor Analytics case are original; the case is fictional. Independent review consulted Liu and colleagues’ operator and discrepancy definitions and Gorham–Mackey’s convergence-detection limitations.
Previous: Steering kernel Next: Stem and leaf plot