Testing with Non-identically Distributed Samples

Shivam Garg, Chirag Pabbaraju, Kirankumar Shiragur, Gregory Valiant

Introduction

In classical distribution testing, the standard assumption is that data is independent and identically distributed (i.i.d.). Under this framework, researchers have developed highly efficient "sublinear" algorithms capable of testing properties like uniformity or identity using far fewer samples than the size of the distribution's support ($k$).

However, modern data collection often violates the i.i.d. assumption. In Federated Learning, data is distributed across heterogeneous users; in time-series analysis, distributions may drift chronologically. This research investigates property testing when samples are independent but not identical (i.n.i.d.). Specifically, we consider a set of distributions $p_1, p_2, \dots, p_T$ over a discrete support of size $k$, where we obtain $c$ independent draws from each. The goal is to test properties of the average distribution, $p_{\mathrm{avg}} = \frac{1}{T} \sum p_i$.

The Problem: Heterogeneity and the $c=1$ Barrier

When we only have one sample per source ($c=1$), the problem of testing $p_{\mathrm{avg}}$ becomes significantly harder. The paper demonstrates a sharp lower bound: with $c=1$, $\Theta(k/\varepsilon^2)$ samples are necessary to test properties like uniformity. This matches the complexity of learning the distribution entirely.

Without multiple samples from the same source, an algorithm cannot distinguish between a single uniform distribution and a collection of distinct point masses that happen to average out to a uniform-looking set of samples. In this regime, the sublinear advantages of distribution testing vanish.

The Phase Transition at $c=2$

The core contribution of this work is identifying a "phase transition" that occurs when we obtain just one additional sample per source. For $c \ge 2$, the authors show that it is possible to recover the sublinear sample complexity of the i.i.d. setting.

The $c=2$ Estimator

The breakthrough relies on a new estimator for the $\ell_2$ norm of the average distribution. The algorithm focuses on "collisions"—instances where two samples take the same value. Crucially, the estimator distinguishes between two types of collisions:

  1. Within-source collisions: Two samples drawn from the same distribution $p_i$ are identical.
  2. Across-source collisions: Samples drawn from two different distributions $p_i$ and $p_j$ are identical.

By leveraging the knowledge of which sample came from which source (source-awareness), the estimator can account for the internal variance of individual sources, allowing it to accurately test $p_{\mathrm{avg}}$ even when the individual $p_i$ are highly heterogeneous.

Source-Awareness vs. Pooled Estimators

A significant technical finding is that the algorithm must know the source of each sample to achieve sublinear complexity. The authors prove that "pooled" estimators—which ignore source metadata and treat all samples as a single multiset—fail to perform sublinear uniformity testing even when $c=2$. Specifically, for any constant $\rho > 0$, no pooled tester can succeed in the linear regime with $\rho k$ samples. This highlights a fundamental "pooled penalty" and suggests that preserving source metadata is essential for efficient testing in heterogeneous environments.

Key Results and Complexity

Uniformity and Identity Testing

For $c \ge 2$, the authors achieve a sample complexity of $O(\sqrt{k}/\varepsilon^2 + 1/\varepsilon^4)$. This matches the optimal i.i.d. complexity when $\varepsilon \ge k^{-1/4}$. This result proves that as long as we have two samples per entity, heterogeneity does not inherently make testing harder than the i.i.d. case.

Closeness Testing

The research extends these techniques to testing the closeness of two average distributions ($p_{\mathrm{avg}}$ and $q_{\mathrm{avg}}$). Given $c=3$ samples from each source, the authors achieve a complexity of $O(k^{2/3}/\varepsilon^{8/3})$. This matches the $k$-dependence of the optimal i.i.d. closeness tester.

The Poissonization Paradox

Interestingly, the paper notes that if the number of samples per source is not fixed but follows a Poisson distribution with mean 1, sublinear testing becomes possible again. This is because, in a Poisson process, some sources will naturally provide two or more samples by chance, providing the necessary collision data to bypass the $c=1$ impossibility result.

Conclusion and Future Directions

This work establishes the fundamental limits of testing under heterogeneity. It demonstrates that while a single sample per source forces us into the expensive regime of distribution learning, a second sample per source—combined with source-aware algorithms—restores the efficiency of sublinear testing.

Future work may look to close the remaining gaps in $\varepsilon$-dependence and explore whether $c=2$ is sufficient for closeness testing (currently requiring $c=3$). Additionally, exploring "smooth" heterogeneity—where distributions change gradually rather than arbitrarily—could provide further insights into real-world data streams.

Summary updated

BibTeX
@article{garg2025testing,
  author = {Shivam Garg and Chirag Pabbaraju and Kirankumar Shiragur and Gregory Valiant},
  title = {{Testing with Non-identically Distributed Samples}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=FUzvztzBlW},
}
Figure