A Kernel Distribution Closeness Testing

Zhijian Zhou, Liuhua Peng, Xunye Tian, Mingming Gong, Feng Liu · Submission to ICLR 2026 · Rejected

TL;DR

While traditional two-sample testing checks if two distributions are strictly identical, real-world machine learning often only requires that two distributions be "close enough." This paper introduces Norm-Adaptive Maximum Mean Discrepancy (NAMMD) to extend Distribution Closeness Testing (DCT) to complex, continuous data like images. By scaling MMD with reproducing kernel Hilbert space (RKHS) norms, NAMMD prevents misleading distance estimates caused by variance differences, provably delivering higher test power and controlled Type-I error.

What Problem Does This Paper Address?

In domain adaptation and out-of-distribution generalization, training and testing distributions are rarely identical ($P \neq Q$). Yet, a model trained on ImageNet often still performs reliably on similar downstream datasets (like Pascal VOC) because the distributions are close.

Standard Two-Sample Testing (TST) tests the strict null hypothesis $H_0: P = Q$, which is overly conservative when evaluating whether distribution shift is practically tolerable. Distribution Closeness Testing (DCT) instead tests a margin-based composite null: $$H_0: d(P, Q) \le \epsilon \quad \text{vs.} \quad H_1: d(P, Q) > \epsilon$$

Existing DCT methods largely rely on Total Variation (TV) distance over finite, discrete 1D support sets, making them difficult to apply directly to high-dimensional continuous data like images.

A natural fix would be using Maximum Mean Discrepancy (MMD). However, the authors discover that MMD alone is not sufficiently informative for DCT: multiple distribution pairs can have the exact same MMD value despite having very different RKHS norms (and thus different internal variances), leading to drastically different levels of statistical distinguishability (p-values).

Methods

1. Norm-Adaptive MMD (NAMMD)

To account for differences in internal distribution concentration, the authors define NAMMD for bounded, shift-invariant kernels ($0 \le \kappa(x, y) \le K$): $$\text{NAMMD}(P, Q; \kappa) = \frac{\|\mu_P - \mu_Q\|_{\mathcal{H}_\kappa}^2}{4K - \|\mu_P\|_{\mathcal{H}_\kappa}^2 - \|\mu_Q\|_{\mathcal{H}_\kappa}^2}$$ Because the RKHS variance of a distribution is $\text{Var}(P; \kappa) = K - \|\mu_P\|_{\mathcal{H}_\kappa}^2$, this formulation is equivalent to scaling the squared MMD by the sum of RKHS variances: $$\text{NAMMD}(P, Q; \kappa) = \frac{\text{MMD}^2(P, Q; \kappa)}{2K + \text{Var}(P; \kappa) + \text{Var}(Q; \kappa)}$$ This normalizes the discrepancy to $[0, 1]$ and dynamically increases when distributions are more concentrated (smaller variance, larger embedding norm).

2. NAMMD-based DCT Hypothesis Test

Under the composite null $H_0: \text{NAMMD}(P, Q; \kappa) \le \epsilon$, samples from $P$ and $Q$ are not interchangeable, meaning permutation testing is invalid. Instead, the authors:

  • Prove an asymptotic normal distribution for the empirical estimator: $\sqrt{m}(\widehat{\text{NAMMD}} - \epsilon) \xrightarrow{d} \mathcal{N}(0, \sigma_{P,Q}^2)$.
  • Construct an explicit U-statistic plug-in variance estimator $\hat{\sigma}_{X,Y}$ converging at rate $\mathcal{O}(1/\sqrt{m})$.
  • Set the rejection threshold using the least-favorable null boundary ($\text{NAMMD} = \epsilon$): $$\hat{\tau}_\alpha = \epsilon + \frac{\hat{\sigma}_{X,Y} N_{1-\alpha}}{\sqrt{m}}$$

Datasets

The authors evaluate their method on synthetic and real benchmark datasets:

  • Synthetic & Tabular:
  • blob: 2D Gaussian mixture.
  • hdgm: 10D High-Dimensional Gaussian Mixture.
  • higgs: 4D benchmark representing particle physics $\phi$-momenta distributions.
  • Image Benchmarks:
  • mnist and cifar10: Pairs of real vs. generative images, as well as PGD-perturbed CIFAR-10 images.
  • Vision Domain Shift Tasks:
  • ImageNet alongside its common test variants: ImageNet-V2, ImageNet-A, ImageNet-R, and ImageNet-SK (Sketch).

Key Insights and Ideas

  • MMD is Variance-Blind: When two distributions have higher RKHS norms, their internal variance is smaller, making them sharper and easier to separate statistically. MMD ignores this internal spread, whereas NAMMD penalizes overlap, aligning the metric directly with statistical distinguishability.
  • Theoretical Power Advantage: In Theorem 9, the authors prove that whenever distribution pairs satisfy a natural norm-growth condition, any rejection made by an MMD-based DCT implies a rejection by NAMMD-based DCT with high probability—and NAMMD can successfully reject in sample regimes where MMD fails.
  • Unlabeled Classifier Monitoring: In practice, setting $\epsilon$ is non-trivial. The authors propose using a known reference pair $(P_1, Q_1)$ with acceptable performance drop to define $\epsilon = \text{NAMMD}(P_1, Q_1)$, allowing practitioners to test if an unlabeled target pair $(P_2, Q_2)$ is within that tolerable margin without ground-truth labels.

Key Results

  • Superiority over Total Variation: On finite discrete distributions, NAMMD-based DCT significantly outperformed Canonne’s state-of-the-art TV-based closeness test (e.g., average test power across five datasets at margin $\epsilon'=0.1$ reached 0.934 for NAMMD vs. 0.800 for Canonne’s test).
  • Outperforming MMD in Closeness Testing: Under identical kernels, NAMMD consistently achieved higher test power than standard MMD across continuous benchmarks (e.g., reaching 0.955 vs. 0.928 average power at $\epsilon = 0.3$).
  • Practical Unlabeled Shift Detection:
  • On ImageNet variants, NAMMD-based DCT matched true accuracy/confidence degradations using small sample sizes ($m \le 250$).
  • On CIFAR-10 under PGD adversarial attacks, using a perturbation magnitude of $4/255$ as the tolerance threshold $\epsilon$, NAMMD preserved Type-I error below $\alpha = 0.05$ for perturbations $\le 4/255$ while achieving notably higher detection power than MMD on stronger perturbations.
  • Computational Efficiency: Multi-kernel NAMMD (NAMMDFuse) matches the execution speed of MMDFuse and is substantially faster than classifier-based two-sample tests (e.g., AutoTST, MMD-D).

Limitations and Future Work

  • Kernel Restrictions: The theoretical connection between larger embedding norms and smaller distribution variance assumes bounded, shift-invariant kernels with positive-definite $\Psi(\cdot)$ where $\Psi(0)=K$ (e.g., Gaussian, Laplace, deep kernels). It does not hold for unbounded polynomial kernels or kernels with positive limits at infinity.
  • Global Kernel Selection: Standard kernel optimization techniques maximize test power for a single fixed pair $(P, Q)$. Systematically finding an optimal kernel across multiple distribution pairs in a DCT setting remains an open challenge.

Summary updated

BibTeX
@misc{zhou2025kernel,
  author = {Zhijian Zhou and Liuhua Peng and Xunye Tian and Mingming Gong and Feng Liu},
  title = {{A Kernel Distribution Closeness Testing}},
  year = {2025},
  eprint = {2507.12843},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.12843},
}

Loading related content...

Figure