Abstract
A common disadvantage in existing distribution-free two-sample testing approaches is that the computational complexity could be high. Specifically, if the sample size is $N$, the computational complexity of those two-sample tests is at least $O(N^2)$. In this paper, we develop an efficient algorithm with complexity $O(N \log N)$ for computing energy statistics in univariate cases. For multivariate cases, we introduce a two-sample test based on energy statistics and random projections, which enjoys the $O(K N \log N)$ computational complexity, where $K$ is the number of random projections. We name our method for multivariate cases as Randomly Projected Energy Statistics (RPES). We can show RPES achieves nearly the same test power with energy statistics both theoretically and empirically. Numerical experiments also demonstrate the efficiency of the proposed method over the competitors.
Introduction
In statistical inference, the two-sample test is a foundational problem: given two sets of data, do they originate from the same underlying distribution? This question is critical across diverse fields, from genomics and sensor networks to financial modeling. While "distribution-free" methods like Energy Statistics (ES) and Maximum Mean Discrepancy (MMD) are favored for their flexibility—requiring no assumptions about the data's distribution—they suffer from a significant computational bottleneck.
Standard implementations of these tests require calculating distances between every possible pair of points, resulting in a computational complexity of $O(N^2)$. As modern datasets scale into the millions, this quadratic growth becomes a "brick wall," rendering traditional methods impractical. This paper introduces Randomly Projected Energy Statistics (RPES), a framework that breaks this barrier by reducing complexity to $O(KN \log N)$.
Breaking the $O(N^2)$ Barrier
The Univariate Shortcut
The authors' first major contribution is an efficient algorithm for one-dimensional data. They demonstrate that for univariate cases, the energy statistic can be computed without exhaustive pairwise comparisons. By first sorting the data—an operation with $O(N \log N)$ complexity—the structure of the data allows the remaining calculations to be performed in linear time. This sorting-based approach transforms a global distance problem into a localized calculation, providing the foundation for scaling to higher dimensions.
Randomly Projected Energy Statistics (RPES)
To address multivariate (high-dimensional) data, the paper introduces the RPES method. The core idea is to project high-dimensional data points onto $K$ different random one-dimensional lines (projections).
For each projection:
- The multivariate data is reduced to a univariate representation.
- The fast $O(N \log N)$ univariate energy statistic is calculated.
- The results from all $K$ projections are averaged to form the final statistic.
By converting one complex $p$-dimensional problem into $K$ simple 1-dimensional problems, the total complexity becomes $O(KN \log N)$. Empirically, a small constant (such as $K=50$) is often sufficient to achieve high accuracy, making the method significantly faster than traditional $O(N^2)$ approaches.
Statistical Power and Significance
A primary concern with random projections is the potential loss of information. However, the authors provide theoretical and empirical evidence that RPES preserves nearly the same statistical power as the full multivariate Energy Statistic. Even in high-dimensional settings (e.g., $p=500$), averaging over random projections effectively captures the differences between distributions.
Furthermore, the authors address the challenge of calculating p-values. Traditional methods often rely on expensive permutation tests to determine significance. RPES utilizes a Gamma distribution approximation to estimate p-values, which avoids the need for thousands of trial iterations and further streamlines the testing pipeline.
Experimental Results
The method was evaluated using synthetic benchmarks designed to test various statistical properties, including shifts in mean, differences in "heavy tails" (t-distributions), and variations in support (uniform distributions).
Key findings include:
- Computational Efficiency: In tests with $N=5,000$ samples, traditional direct methods showed clear quadratic growth in processing time. In contrast, RPES remained nearly instantaneous, demonstrating its readiness for large-scale applications.
- High Power: In high-dimensional settings ($p=50$), RPES outperformed MMD and matched the performance of the full Energy Statistic, particularly in detecting subtle differences in distribution shapes.
- Dimensional Scalability: The results indicate that the number of projections ($K$) required for peak performance does not need to scale linearly with the dimension of the data, maintaining efficiency even as $p$ increases.
Conclusion
RPES offers a powerful alternative for modern two-sample testing, successfully bridging the gap between statistical rigor and computational feasibility. By leveraging sorting-based univariate algorithms and random projections, it provides a scalable solution for "Big Data" contexts where $O(N^2)$ methods fail. Future research may extend this framework to change-point detection and the generation of support points for representing continuous distributions.
Summary updated