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

A Martingale Kernel Two-Sample Test

Anirban Chatterjee, Aaditya Ramdas

TL;DR

Kernel two-sample testing using Maximum Mean Discrepancy (MMD) typically requires computationally burdensome permutations or resampling to calibrate because its null distribution depends on the unknown underlying data distribution. This paper introduces the martingale MMD (mMMD), an $O(n^2)$ test statistic that estimates the witness function sequentially from past data. This construction yields a martingale difference sequence whose studentized test statistic converges to a simple standard normal distribution $\mathcal{N}(0, 1)$ under the null, completely bypassing the need for resampling while retaining high power.

What Problem Does This Paper Address?

Given independent samples $X_1, \dots, X_n \sim P$ and $Y_1, \dots, Y_n \sim Q$, two-sample testing assesses whether $H_0: P = Q$ versus $H_1: P \neq Q$. Kernel MMD embeds probability distributions into a Reproducing Kernel Hilbert Space (RKHS) and measures the distance between their mean embeddings.

While the standard quadratic-time MMD test has high statistical power, its null limiting distribution is an intractable infinite weighted sum of centered $\chi^2$ random variables, where the weights depend on the unknown data distribution $P$. Consequently, determining critical rejection thresholds requires running hundreds of permutations or bootstrap iterations—imposing massive computational bottlenecks for large datasets. Faster alternatives exist (e.g., linear-time MMD, block MMD, or sample-splitting "cross-MMD"), but they sacrifice significant statistical power or require splitting data in halves.

Methods

The paper derives mMMD by rethinking the MMD witness function $f_0 \propto \nu_P - \nu_Q$:

  • Martingale Difference Formulation: Rather than using all data globally to construct a single estimate, at each step $i \in \{2, \dots, n\}$, the authors estimate the unnormalized witness function using only previous observations: $$\hat{f}_i = \frac{1}{i} \sum_{j=1}^{i-1} [K(X_j, \cdot) - K(Y_j, \cdot)]$$
  • Test Statistic ($T_n$): By evaluating each new sample pair $(X_i, Y_i)$ against $\hat{f}_i$ and averaging across $i$, the terms form a zero-mean martingale difference sequence under $H_0$: $$T_n = \frac{1}{n} \sum_{i=2}^n \langle \hat{f}_i, K(X_i, \cdot) - K(Y_i, \cdot) \rangle_{\mathcal{K}}$$
  • Self-Normalization ($\eta_n$): Normalizing $T_n$ by its empirical conditional variance $\sigma_n$ yields $\eta_n = T_n / \sigma_n$. Applying Berry–Esseen bounds for self-normalized martingales guarantees that $\eta_n \xrightarrow{d} \mathcal{N}(0, 1)$ under $H_0$, allowing the test to reject when $\eta_n > z_{1-\alpha}$ without resampling or sample splitting.
  • Extensions:
  • Multi-kernel mMMD ($\text{mmMMD}$): Combining $r$ kernels produces a Mahalanobis-type test statistic that asymptotically follows a $\chi^2_r$ distribution.
  • Interpolation Family ($T_{n,\gamma}$): A generalized class using weights $1/i^\gamma$ interpolates continuously between classical quadratic MMD ($\gamma=0$) and mMMD ($\gamma=1$).
  • Martingale Energy Distance: Specializing the kernel recovers a permutation-free energy distance test.

Datasets

The authors evaluated the method across simulated benchmarks and one real-world dataset:

  • Synthetic Normal and Heavy-Tailed Data:
  • Null validation on standard normal distributions $\mathcal{N}_d(0, I_d)$ and multivariate $t$-distributions $t_d(10)$ across dimensions $d \in \{10, 20, 50, 100, 200, 250, 500\}$.
  • Power experiments under mean-shift alternatives $P = \mathcal{N}_d(0, I_d)$ vs. $Q = \mathcal{N}_d(\mu_{d,j,\varepsilon}, I_d)$ in dimensions $d \in \{10, 50, 100\}$.
  • Minimax local alternative simulations with 1D Gaussians separated by an $L_2$ gap $\Delta_n \in \{n^{-1/5}, n^{-1/4}\}$.
  • Real-World Benchmark:
  • MNIST digit database (pairs of digit subsets partitioned into 5 difficulty groups, from dissimilar pairs like $\{2,4,8,9\}$ vs. $\{3,4,7,9\}$ to heavily overlapping digit pools).

Key Insights and Ideas

  • Order-dependent witness estimation converts U-statistics into martingales: Standard MMD is a degenerate U-statistic. By forcing the $i$-th term to depend strictly on the historical sample mean embedding up to $i-1$, the statistic becomes a martingale difference sum whose limiting distribution is standard Gaussian rather than a data-dependent mixture of chi-squares.
  • Resampling-free calibration with full sample efficiency: Unlike cross-MMD, which splits samples into halves to achieve Gaussianity, mMMD uses all available data sequentially, avoiding arbitrary data-splitting loss.
  • Gaussian limiting distribution under the alternative: Under $H_1$, a properly centered and scaled $T_n$ also converges to a normal distribution with asymptotic variance $5\,\text{Var}(h(Z))$, remarkably close to the factor of $4$ in the standard quadratic MMD estimator.

Key Results

  • Computational Efficiency: At sample size $n = 300$, permutation MMD (200 permutations) required $0.8335 \pm 0.0501$ seconds, whereas mMMD required only $0.0072 \pm 0.0023$ seconds—a speedup of over $115\times$ with zero permutation overhead.
  • Statistical Power: In both Gaussian mean-shift benchmarks and MNIST experiments, mMMD matched the power of cross-MMD, significantly outperformed linear MMD (LMMD) and block MMD (BMMD), and lagged only slightly behind permutation-based quadratic MMD.
  • Small-Sample Stability: At small sample sizes ($n = 10$), block and split-sample methods suffered severe Type-I error inflation, whereas mMMD maintained nominal Type-I control ($\alpha = 0.05$).

Limitations and Future Work

  • Data-Dependent Bandwidths: Asymptotic Gaussianity theorems currently assume fixed or sample-size-dependent kernels ($K_n$) that do not depend on the observed samples. Although using data-driven bandwidth heuristics (like the median heuristic) worked well empirically, formal theoretical guarantees for data-dependent kernels remain open.
  • Minimax Optimality for $\gamma = 1$: The generalized family $T_{n,\gamma}$ is proven to be minimax rate-optimal against Sobolev alternatives when $\gamma \le 1/2$. Proving minimax rate-optimality for mMMD ($\gamma = 1$) remains an open analytical question, though empirical tests show it performs on par with minimax-optimal methods.
  • Future Directions: Adapting the martingale formulation to kernel independence testing, exploring optimal multi-kernel combinations, and integrating mMMD with near-linear kernel approximations such as Random Fourier Features.

Summary updated

BibTeX
@inproceedings{chatterjee2026martingale,
  author = {Anirban Chatterjee and Aaditya Ramdas},
  title = {{A Martingale Kernel Two-Sample Test}},
  booktitle = {ALT},
  year = {2026},
  url = {https://openreview.net/forum?id=l6dWLKPvkR},
}
Figure