A Kernel Test of Goodness of Fit

Kacper Chwialkowski, Heiko Strathmann, Arthur GrettonICML 2016

Introduction

In statistics, a fundamental question is the "goodness-of-fit" test: Did these samples actually come from this specific probability distribution? While classic tests like the Kolmogorov-Smirnov test work well in one-dimensional spaces, they struggle significantly in high-dimensional settings.

Furthermore, modern machine learning frequently deals with "unnormalized" distributions. In these cases, we know the relative shape of the density, but not the scaling factor (the partition function). Traditional goodness-of-fit tests often require calculating complex integrals over the target distribution, which is impossible if the normalization constant is unknown. Previous attempts to solve this, such as using Stein discrepancies, were computationally grueling and required solving complex linear programs.

To address this, researchers have proposed a novel nonparametric statistical test—the Kernel Stein Test (KST)—that determines if a set of data samples matches a target distribution. By combining Stein’s Method with Kernel methods, this test works even when the target distribution's normalization constant is unknown and can handle both independent and correlated data (like MCMC chains).

The Kernel Stein Test (KST)

The elegance of the KST lies in the combination of two mathematical frameworks:

  1. Stein’s Method: This provides a way to characterize a distribution by looking at the expectation of certain functions. Specifically, it uses a "Stein operator" that, when applied to a function, results in an output with zero expectation under the target distribution. Crucially, this operator only depends on the gradient of the log-density ($\nabla \log p$), meaning the problematic normalization constant cancels out entirely.
  2. Reproducing Kernel Hilbert Spaces (RKHS): By selecting "test functions" from an RKHS, the authors transform a complex optimization problem into a simple, closed-form calculation.

The resulting test statistic is a V-statistic, which can be computed in $O(n^2)$ time. To determine if the statistic is "large enough" to reject the null hypothesis, the authors employ a Wild Bootstrap procedure. This is a clever addition because it allows the test to remain valid even when the samples are correlated, such as successive steps in a Markov Chain Monte Carlo (MCMC) algorithm.

Applications and Key Insights

The paper evaluates the test across several scenarios, demonstrating its flexibility and power.

Model Criticism

The test can identify exactly where a model fails to capture the underlying data distribution. For example, the authors used a 1D regression "Solar Dataset" to perform model criticism on Gaussian Process (GP) models. The test correctly identified that a standard Gaussian noise model was a poor fit for the specific heteroscedasticity present in the solar data.

Solar dataset regression showing model fit.

MCMC Convergence Diagnostic

Because the test handles correlated data via the wild bootstrap, it serves as a rigorous "sanity check" for MCMC convergence. It can pinpoint exactly when the bias of an approximate MCMC algorithm becomes statistically significant. In experiments using "Austerity MCMC" (an approximate MCMC algorithm), the test successfully quantified the bias-variance trade-off. As the error tolerance ($\epsilon$) increased, the p-values dropped, indicating a detectable departure from the true posterior.

P-values drop as the error tolerance (epsilon) increases in approximate MCMC.

Additional Evaluations

  • Synthetic Data: The test showed strong sensitivity when comparing Student’s t-distributions against a standard Normal distribution.
  • Nonparametric Density Estimation: The test effectively evaluated the fit of infinite-dimensional exponential family models.

Core Advantages

  • No Sampling Required: Unlike Maximum Mean Discrepancy (MMD) tests, which require generating samples from your model to compare against your data, the Kernel Stein Test only requires the model's gradient. This is a massive advantage for complex models that are difficult to sample from.
  • Calibration and Power: The test correctly maintains the specified false-positive rate (Type I error) even with correlated samples, provided the bootstrap parameters are chosen correctly. In high-dimensional normality tests, it is competitive with specialized tests while offering much greater flexibility for non-Gaussian targets.

Limitations and Future Work

While powerful, the Kernel Stein Test has a few limitations:

  • Computational Complexity: The $O(n^2)$ cost is standard for kernel methods but can become a bottleneck for very large datasets ($n > 10,000$). Future work might involve using random features or Nyström approximations to scale the test to $O(n)$.
  • Kernel Choice: Like all kernel methods, performance depends heavily on the choice of kernel and its hyperparameters (like bandwidth). While the "median trick" is commonly used, developing more principled ways to choose kernels for Stein tests remains an open area of research.
  • High Dimensions: The authors note that in extremely high dimensions, if the target distribution's kernel expectations are known in closed form, traditional MMD-based tests might still be more powerful.

Summary updated

BibTeX
@inproceedings{chwialkowski2016kernel,
  author = {Kacper Chwialkowski and Heiko Strathmann and Arthur Gretton},
  title = {{A Kernel Test of Goodness of Fit}},
  booktitle = {International Conference on Machine Learning},
  year = {2016},
  url = {https://openreview.net/forum?id=BkWs-ibubH},
}
Figure