Abstract
We propose a framework to construct practical kernel-based two-sample tests from the family of $f$-divergences. The test statistic is computed from the witness function of a regularized variational representation of the divergence, which we estimate using kernel methods. The proposed test is adaptive over hyperparameters such as the kernel bandwidth and the regularization parameter. We provide theoretical guarantees for statistical test power across our family of $f$-divergence estimates. While our test covers a variety of $f$-divergences, we bring particular focus to the Hockey-Stick divergence, motivated by its applications to differential privacy auditing and machine unlearning evaluation. For two-sample testing, experiments demonstrate that different $f$-divergences are sensitive to different localized differences, illustrating the importance of leveraging diverse statistics. For machine unlearning, we propose a relative test that distinguishes true unlearning failures from safe distributional variations.
Introduction
Two-sample testing is a cornerstone of statistical inference, asking whether two sets of samples originate from the same underlying distribution. In modern machine learning, the Maximum Mean Discrepancy (MMD) has become the standard tool for this task. However, MMD is primarily sensitive to smooth, global variations in distributions. In many critical applications—such as detecting localized anomalies in physics data or auditing the strict privacy budgets of differential privacy—MMD lacks the necessary sensitivity.
This paper introduces a flexible framework for building kernel-based tests using the broader family of $f$-divergences, including KL divergence, $\chi^2$, and the Hockey-Stick divergence. By moving beyond MMD, we can tailor statistical tests to specific types of distributional shifts, significantly improving detection power in specialized domains.
The Regularized Variational Framework
Estimating $f$-divergences from finite samples is traditionally difficult due to the non-smooth nature of the optimization problems involved. We overcome this by utilizing a regularized variational representation of the divergence. Our approach involves:
- Variational Formulation: We express the divergence's "witness function" as a functional of the likelihood ratio between the two distributions.
- Kernel-Based Estimation: We employ a closed-form, $\ell_2$-regularized kernel estimator to approximate the likelihood ratio, ensuring computational tractability.
- Adaptive Aggregation ($f$-Agg): To avoid the manual tuning of hyperparameters like kernel bandwidth, we use an aggregation method that computes the test across multiple configurations and adaptively combines them to maintain high statistical power.
Experimental Evaluation
Detecting Localized Anomalies in Physics
In high-energy physics, researchers often look for a "bump" (representing new particles) against a known background spectrum. We evaluated our framework on the Expo-1D dataset, where the alternative distribution contains a localized Gaussian bump. As shown in the results below, our regularized $\chi^2$ test (DrMMD) and the adaptive $f$-Agg test significantly outperform standard MMD, which struggles to detect such localized shifts.
Auditing Differential Privacy
Auditing differential privacy (DP) mechanisms requires measuring the Hockey-Stick (HS) divergence. Our framework allows for efficient auditing with remarkably few samples. In tests against flawed implementations of the Sparse Vector Technique (SVT), our HS-based test detected privacy violations using only 500 to 5,000 samples, whereas previous state-of-the-art methods often required millions of samples to achieve similar results.
Machine Unlearning: A Three-Sample Relative Test
A critical contribution of this work is identifying a flaw in current machine unlearning evaluations. Standard two-sample tests often penalize valid unlearning algorithms because they are sensitive to benign statistical noise (e.g., differences in training steps or batch sizes between the unlearned and retrained models).
To address this, we propose a three-sample relative test. Instead of requiring the unlearned model to be identical to a retrained model, we test if the unlearned model is statistically closer to a retrained model than it is to the original model containing the forgotten data. This shift from absolute to relative similarity prevents safe unlearning methods from being incorrectly flagged as failures.
Conclusion
By leveraging the variational properties of $f$-divergences and kernel methods, we provide a robust and adaptive framework for two-sample testing. Our results demonstrate that specialized divergences like $\chi^2$ and Hockey-Stick offer superior performance in physics and privacy auditing, respectively. Furthermore, our proposed relative test for machine unlearning provides a more realistic and fair evaluation metric for the field.
Summary updated