NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Testing Goodness of Fit of Conditional Density Models with Kernels

Wittawat Jitkrittum, Heishiro Kanagawa, Bernhard Schölkopf

Introduction

Evaluating how well a conditional density model $p(y|x)$ matches observed data is a fundamental challenge in machine learning and econometrics. Traditional goodness-of-fit tests often struggle with high-dimensional data, require intermediate density estimation, or fail when the model's normalizing constant is intractable. This paper introduces two novel nonparametric tests—Kernel Conditional Stein Discrepancy (KCSD) and Finite Set Conditional Discrepancy (FSCD)—that address these limitations by leveraging Stein operators and kernel methods.

Methodology: Stein Operators and Kernel Discrepancies

The core innovation lies in using the Langevin Stein operator, which depends only on the "score function" (the derivative of the log-density). This allows the tests to evaluate models without needing to compute the normalizing constant, making them applicable to complex energy-based models and deep generative architectures.

Kernel Conditional Stein Discrepancy (KCSD)

KCSD provides a global measure of fit. It defines a "Stein witness function" within a Reproducing Kernel Hilbert Space (RKHS) to quantify the discrepancy between the model and the data distribution across the entire input space. It is particularly effective when model errors are distributed throughout the domain.

Finite Set Conditional Discrepancy (FSCD)

FSCD offers a more localized approach by evaluating the discrepancy at a specific set of "test locations" in the input space. A key advantage of FSCD is the ability to optimize these locations to maximize the test's power.

Illustration of the power criterion for selecting test locations $v$ in FSCD.

As illustrated above, the power criterion (green line) can be used to identify optimal test locations $v$ where the model discrepancy is most detectable. This makes FSCD not just a statistical test, but a diagnostic tool that pinpoints exactly where a model fails to match reality.

Experimental Evaluation

The authors evaluated KCSD and FSCD against several baselines, including Maximum Mean Discrepancy (MMD) and Zheng's CDF-based test, using both synthetic and real-world datasets.

Synthetic Benchmarks

Three Gaussian models were used to test different error scenarios:

  1. Linear Gaussian Model (LGM): A null hypothesis ($H_0$) case to verify that the tests do not produce false alarms.
  2. Heteroscedastic Gaussian Model (HGM): A case with localized variance errors to test the ability to find "local" discrepancies.
  3. Quadratic Gaussian Model (QGM): A case with global structural mismatch where the relationship is curved but the candidate model is linear.
Rejection rates for LGM ($H_0$), HGM ($H_1$), and QGM ($H_1$) across varying sample sizes.

The results demonstrate that KCSD and optimized FSCD variants consistently outperform traditional methods. As shown in the figure, KCSD excels in detecting global errors (QGM), while FSCD-opt is highly effective at identifying localized glitches (HGM). Importantly, all tests maintained the correct type-I error rate in the LGM scenario.

Real-World Application: NYC Taxi Data

The tests were applied to a Mixture Density Network (MDN) trained on 5 million records of NYC taxi trip data. FSCD successfully flagged regions in Manhattan where the MDN failed to capture the multi-modal nature of drop-off locations, providing valuable insights into model limitations in complex, real-world environments.

Conclusion

The proposed KCSD and FSCD tests represent a significant advancement in conditional density model evaluation. By eliminating the need for normalizing constants and providing interpretable diagnostics through optimized test locations, these methods offer a robust framework for validating modern generative models. Future work will focus on reducing computational complexity from $O(n^2)$ to $O(n)$ and extending the framework to discrete data types.

Summary updated

BibTeX
@inproceedings{jitkrittum2020testing,
  author = {Wittawat Jitkrittum and Heishiro Kanagawa and Bernhard Schölkopf},
  title = {{Testing Goodness of Fit of Conditional Density Models with Kernels}},
  booktitle = {Conference on Uncertainty in Artificial Intelligence},
  year = {2020},
  url = {https://openreview.net/forum?id=_mmij6G0Irz},
}
Figure