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

Spectral Regularized Kernel Two-Sample Tests

Omar Hagrass, Bharath K. Sriperumbudur, Bing LiarXiv 2022

Abstract

Over the last decade, an approach that has gained a lot of popularity to tackle nonparametric testing problems on general (i.e., non-Euclidean) domains is based on the notion of reproducing kernel Hilbert space (RKHS) embedding of probability distributions. The main goal of our work is to understand the optimality of two-sample tests constructed based on this approach. First, we show the popular MMD (maximum mean discrepancy) two-sample test to be not optimal in terms of the separation boundary measured in Hellinger distance. Second, we propose a modification to the MMD test based on spectral regularization by taking into account the covariance information (which is not captured by the MMD test) and prove the proposed test to be minimax optimal with a smaller separation boundary than that achieved by the MMD test. Third, we propose an adaptive version of the above test which involves a data-driven strategy to choose the regularization parameter and show the adaptive test to be almost minimax optimal up to a logarithmic factor. Moreover, our results hold for the permutation variant of the test where the test threshold is chosen elegantly through the permutation of the samples. Through numerical experiments on synthetic and real data, we demonstrate the superior performance of the proposed test in comparison to the MMD test and other popular tests in the literature.

Introduction

The "two-sample problem" is a fundamental challenge in statistics: given two sets of data, do they originate from the same probability distribution ($P=Q$) or different ones ($P \neq Q$)? While classical methods like the $t$-test or Kolmogorov-Smirnov test are effective for univariate or simple Euclidean data, modern datasets—ranging from high-dimensional images to complex graphs—require more sophisticated tools.

In recent years, the Maximum Mean Discrepancy (MMD) has emerged as the standard for this task. MMD works by mapping distributions into a Reproducing Kernel Hilbert Space (RKHS) and measuring the distance between their "mean embeddings." However, MMD possesses a significant theoretical limitation: it is inherently biased toward "smooth" differences. Because the integral operators associated with kernels have decaying eigenvalues, MMD effectively down-weights high-frequency differences between distributions. Consequently, if $P$ and $Q$ differ only in fine-grained details, MMD may fail to detect the discrepancy unless provided with an impractical amount of data.

The Spectral Regularization Approach

To address the sub-optimality of MMD, we introduce Spectral Regularized Kernel Two-Sample Tests. This framework modifies the MMD statistic by incorporating the covariance information of the distributions, effectively "leveling the playing field" between low- and high-frequency components.

Methodology

The core of our approach involves applying a spectral regularizer (such as Tikhonov regularization, $g_\lambda(x) = (x + \lambda)^{-1}$) to the covariance operator. This prevents the high-frequency components from being ignored, magnifying subtle differences that standard MMD misses. The process involves:

  1. Covariance Incorporation: Unlike MMD, which only considers mean embeddings, our statistic utilizes the covariance operator to normalize the differences in the RKHS.
  2. Sample Splitting: To ensure mathematical tractability and computational efficiency, the data is split: one portion estimates the covariance operator, while the other estimates the mean embeddings.
  3. Permutation Testing: Because the null distribution of this regularized statistic is complex, we employ a permutation approach to determine the rejection threshold in a data-driven manner.
  4. Adaptation: Since the ideal regularization parameter $\lambda$ depends on the unknown smoothness of the difference between $P$ and $Q$, we developed an adaptive test that aggregates results over multiple $\lambda$ values, maintaining near-optimal performance across various scenarios.

Theoretical Contributions

Our primary theoretical contribution is the proof of minimax optimality on general domains. We demonstrate that MMD is sub-optimal in a minimax sense, meaning there is a fundamental limit to the smallness of the differences it can detect.

Specifically, while MMD achieves a separation rate of approximately $(N+M)^{-2\theta/(2\theta+1)}$, our spectral regularized test achieves a significantly faster rate of $(N+M)^{-4\theta\beta/(4\theta\beta+1)}$, where $\beta$ represents the decay rate of the kernel's eigenvalues. This makes our method the first kernel-based test proven to be minimax optimal on non-Euclidean domains, whereas previous optimal tests were largely restricted to $\mathbb{R}^d$ with translation-invariant kernels.

Empirical Performance

We evaluated the spectral regularized test against synthetic and real-world benchmarks, including Gaussian and Cauchy distributions, directional data on a unit sphere, and the MNIST handwritten digit dataset.

  • High-Dimensional Sensitivity: In Gaussian shift experiments ($d=100$), our test maintained high power even as the performance of MMD-based competitors, such as MMDAgg, declined.
  • Fine-Grained Detection: On the "Perturbed Uniform" benchmark—where a uniform distribution is modified by high-frequency "wiggles"—the spectral regularization successfully captured differences that standard MMD ignored.
  • Real-World Application: On MNIST, the test outperformed the Energy test and MMDAgg in difficult tasks, such as distinguishing between highly similar mixtures of digits (e.g., comparing all digits against only odd digits).

Conclusion and Future Work

By incorporating covariance information and spectral regularization, we have developed a two-sample test that is both theoretically optimal and practically superior for complex data. While our current implementation uses sample splitting to facilitate theoretical proofs, future work will explore versions of the test that utilize the full dataset for both mean and covariance estimation. Additionally, extending the adaptive framework to handle an infinite family of kernels remains a promising avenue for further research.

Full Citation: Omar Hagrass, Bharath K. Sriperumbudur, and Bing Li. "Spectral Regularized Kernel Two-Sample Tests." arXiv:2212.09201v3 [math.ST] (2024).

Summary updated

BibTeX
@misc{hagrass2022spectral,
  author = {Omar Hagrass and Bharath K. Sriperumbudur and Bing Li},
  title = {{Spectral Regularized Kernel Two-Sample Tests}},
  year = {2022},
  eprint = {2212.09201},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2212.09201},
}
Figure