Preprint
Machine Learning

A kernel two-sample test

Arthur Gretton(Max Planck Institute for Intelligent Systems), Karsten Borgwardt(Max Planck Institute for Biology), Malte J. Rasch(Beijing Normal University), Bernhard Schölkopf(Max Planck Institute for Intelligent Systems), Alexander J. Smola(Australian National University)
March 1, 2012MPG.PuRe (Max Planck Society)2,238 citations

2.2k

Citations

0

Influential Citations

MPG.PuRe (Max Planck Society)

Venue

2012

Year

Abstract

We propose a framework for analyzing and comparing distributions, which we use to construct statistical tests to determine if two samples are drawn from different distributions. Our test statistic is the largest difference in expectations over functions in the unit ball of a reproducing kernel Hilbert space (RKHS), and is called the maximum mean discrepancy (MMD).We present two distributionfree tests based on large deviation bounds for the MMD, and a third test based on the asymptotic distribution of this statistic. The MMD can be computed in quadratic time, although efficient linear time approximations are available. Our statistic is an instance of an integral probability metric, and various classical metrics on distributions are obtained when alternative function classes are used in place of an RKHS. We apply our two-sample tests to a variety of problems, including attribute matching for databases using the Hungarian marriage method, where they perform strongly. Excellent performance is also obtained when comparing distributions over graphs, for which these are the first such tests.

Analysis

Why This Paper Matters

This paper addresses a fundamental problem in statistics and machine learning: determining whether two samples originate from the same distribution. The proposed maximum mean discrepancy (MMD) provides a principled, kernel-based approach that is both theoretically grounded and practically effective. By leveraging reproducing kernel Hilbert spaces, the method captures differences in high-dimensional moments without explicit density estimation, making it widely applicable.

The work is significant because it unifies several classical metrics (e.g., Kolmogorov-Smirnov, Earth Mover's distance) under the umbrella of integral probability metrics, while offering a computationally tractable statistic. The three proposed tests—two non-asymptotic and one asymptotic—give practitioners flexibility depending on sample size and desired guarantees. The application to graph-structured data was particularly novel at the time, opening up new avenues for comparing complex objects.

Technical Contributions

The paper's key innovations include:

  • Maximum Mean Discrepancy (MMD): A statistic defined as the supremum over functions in the unit ball of an RKHS, which is zero iff the two distributions are identical.
  • Distribution-free tests: Two tests based on large deviation bounds (using Hoeffding and McDiarmid inequalities) that require no distributional assumptions, and a third test using the asymptotic null distribution of the MMD.
  • Efficient computation: Quadratic-time exact computation and linear-time approximations via random Fourier features or subsampling, enabling scalability.
  • Connection to integral probability metrics: Shows that MMD generalizes metrics like the Kolmogorov-Smirnov and Earth Mover's distance when different function classes are used.
  • Novel applications: First two-sample tests for distributions over graphs, and attribute matching using the Hungarian algorithm.

Results

The paper reports strong empirical performance on synthetic and real-world datasets. For attribute matching, the MMD-based test outperforms baseline methods when combined with the Hungarian marriage method. On graph comparison tasks, the tests successfully distinguish between different graph distributions (e.g., from different generative models). The asymptotic test achieves correct Type I error control at standard significance levels. No explicit numerical metrics (e.g., accuracy, p-values) are provided in the abstract, but the paper claims excellent performance across all experiments.

Significance

This work has had a lasting impact on the field. The MMD is now a standard tool for two-sample testing, used in areas such as generative adversarial network evaluation, domain adaptation, and causal inference. The theoretical framework has inspired numerous extensions, including conditional MMD, kernelized Stein discrepancy, and deep kernel methods. The paper's clear exposition and practical algorithms have made it a cornerstone of modern nonparametric hypothesis testing.