Compress Then Test: Powerful Kernel Testing in Near-linear Time

Carles Domingo-Enrich, Raaz Dwivedi, Lester Mackey

Abstract

Kernel two-sample testing provides a powerful framework for distinguishing any pair of distributions based on $n$ sample points. However, existing kernel tests either run in $n^2$ time or sacrifice undue power to improve runtime. To address these shortcomings, we introduce Compress Then Test (CTT), a new framework for high-powered kernel testing based on sample compression. CTT cheaply approximates an expensive test by compressing each $n$ point sample into a small but provably high-fidelity coreset. For standard kernels and subexponential distributions, CTT inherits the statistical behavior of a quadratic-time test—recovering the same optimal detection boundary—while running in near-linear time. We couple these advances with cheaper permutation testing, justified by new power analyses; improved time-vs.-quality guarantees for low-rank approximation; and a fast aggregation procedure for identifying especially discriminating kernels. In our experiments with real and simulated data, CTT and its extensions provide 20–200x speed-ups over state-of-the-art approximate MMD tests with no loss of power.

Introduction

Two-sample testing is a fundamental statistical task: determining whether two sets of data originate from the same underlying probability distribution. The gold standard for this task is the Maximum Mean Discrepancy (MMD), a kernel-based metric that is "consistent," meaning it can theoretically distinguish any two distinct distributions given sufficient data.

However, the standard MMD test suffers from a significant computational bottleneck: its runtime scales quadratically ($O(n^2)$) with the number of samples $n$. While previous attempts to mitigate this—such as Block MMD (subsampling) or Random Fourier Features (low-rank approximation)—improve speed, they typically hit a "time-quality trade-off barrier." To achieve the statistical power of the full $O(n^2)$ test, these approximations often require $O(n^2)$ time themselves. The Compress Then Test (CTT) framework is designed to pierce this barrier, delivering high-power testing in near-linear time.

The CTT Framework

CTT achieves its efficiency through a three-step process:

  1. Compression: Instead of processing all $n$ points directly, CTT partitions the data into bins and applies KT-COMPRESS (Kernel Thinning). This creates a "coreset"—a significantly smaller representative set of points that maintains high fidelity to the original distribution.
  2. Estimation: The MMD is calculated using these compressed coresets. The reduced size of the coresets makes this computation extremely fast.
  3. Restricted Permutation Testing: To determine statistical significance, CTT employs a restricted permutation strategy. Rather than shuffling individual points (which would be computationally expensive), it shuffles the coreset bins. This preserves the compression structure and maintains near-linear runtime.

Theoretical Comparison

As shown in the table below, CTT offers a superior runtime-to-separation profile compared to traditional MMD variants. While it matches the $m^{-1/2}$ separation rate of the complete MMD (where $m$ is the number of samples), it does so with a near-linear runtime of $4^g m \log m$ (where $g$ is the compression level).

Theoretical comparison of MMD separation and runtime across different test methods.

Experimental Evaluation

The researchers evaluated CTT across several benchmarks, including synthetic Gaussian distributions and the EMNIST handwritten character dataset.

Key results include:

  • Significant Speedups: CTT and its low-rank extension (LR-CTT) provided 20x to 200x speedups over state-of-the-art approximate MMD tests, such as the Wild Bootstrap Incomplete test, without any loss in statistical power.
  • Efficiency on Real Data: In EMNIST experiments, CTT achieved the same power as a full quadratic-time test while being orders of magnitude faster.
  • Hybrid Performance: The LR-CTT version, which combines compression with low-rank feature maps, often delivered the best overall performance, surpassing both pure compression and pure low-rank methods.
Power vs. Total computation time for Gaussian and Downsampled EMNIST datasets, comparing CTT against standard MMD approximations and low-rank methods.

Conclusion

CTT effectively breaks the $O(n^2)$ curse for kernel two-sample testing. By leveraging high-fidelity coresets and efficient permutation strategies, it recovers the optimal detection boundary of quadratic-time tests in near-linear time. This "Compress Then Test" philosophy holds promise for other large-scale statistical tasks, including independence testing and kernel regression.

Summary updated

BibTeX
@inproceedings{domingoenrich2023compress,
  author = {Carles Domingo-Enrich and Raaz Dwivedi and Lester Mackey},
  title = {{Compress Then Test: Powerful Kernel Testing in Near-linear Time}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2023},
  url = {https://openreview.net/forum?id=gV4sUQfnyz},
}
Figure