Weighted sampling without replacement from data streams

Vladimir Braverman, Rafail Ostrovsky, Gregory Vorsanger

Abstract

Weighted sampling without replacement (SWOR) is a fundamental task in data stream processing. Traditional methods, such as the exponent method, rely on complex transcendental functions that are susceptible to numerical bias due to finite-precision floating-point arithmetic. This paper introduces Cascade Sampling, a novel framework that reduces the $k$-sampling problem to a sequence of unit samplers. By routing elements through a chain of samplers, the algorithm ensures a precise reduction that avoids numerical errors while maintaining theoretical guarantees for correctness and efficiency.

Introduction

In the context of massive data streams, selecting a representative subset of items based on their relative importance (weights) is crucial for efficient analysis. When sampling is performed without replacement, an item can appear at most once in the final set. While algorithms for this task exist, they often suffer from practical implementation issues. Specifically, state-of-the-art methods like those proposed by Efraimidis and Spirakis calculate random keys using the formula $r^{1/w}$. In real-world systems, the limited precision of floating-point hardware introduces rounding errors that bias the sample, especially as stream size or weight variance increases. Cascade Sampling addresses this "finite precision" problem by shifting the complexity from mathematical calculation to algorithmic logic.

Methods

The core of the proposed approach is the Cascade Sampling algorithm. It treats a standard "unit sampler" (an algorithm that maintains a single weighted sample) as a modular black box. To obtain a sample of size $k$, the algorithm maintains $k$ independent unit sampler instances, $\Lambda_1, \Lambda_2, \dots, \Lambda_k$, arranged in a sequence.

When a new element $c$ arrives in the stream, it is first processed by $\Lambda_1$. If $\Lambda_1$ decides to replace its current item $a$ with $c$, the displaced item $a$ is not discarded. Instead, it is "pushed" down to the next sampler in the chain, $\Lambda_2$. This process continues recursively: if a sampler accepts a new item, it passes its previous item to the next unit. If a sampler rejects an item, that item is passed directly to the next unit without displacing the current occupant.

The Cascade Sampling mechanism: an arriving element $c$ replaces $a$ in $\Lambda_1$, and $a$ is then passed down to $\Lambda_2$.

Key Insights

  • Stream Modification: The algorithm effectively simulates sampling without replacement by ensuring that each sampler $\Lambda_i$ only "sees" items that were not selected by the preceding samplers $\Lambda_1 \dots \Lambda_{i-1}$.
  • Black-Box Modularity: Because Cascade Sampling is agnostic to the internal logic of the unit sampler, it can be paired with any existing or future unit sampling algorithm. Improvements in unit sampler efficiency or memory usage translate directly to the cascade.
  • Precision via Logic: By replacing transcendental calculations with simple comparisons and swaps, the authors eliminate the numerical instability inherent in previous methods.

Key Results

The authors provide formal mathematical proofs (Lemma 1 and Theorem 1) demonstrating that the cascade produces a true weighted $k$-sample without replacement. In terms of resource usage, if a unit sampler requires $O(g)$ space and $O(h)$ time per element, the Cascade Sampling framework scales to $O(kg)$ space and $O(kh)$ time. For standard unit samplers, this results in $O(k)$ memory and constant time per element per sampler instance. Crucially, the reduction is "precise," meaning it introduces no additional numerical error beyond the underlying unit sampler's logic.

Conclusion and Future Work

While Cascade Sampling solves the precision problem, it introduces a linear dependency on $k$ for processing time. For very large sample sizes, the $O(k)$ per-element time complexity may become a bottleneck. Future research directions include optimizing the update process to achieve $O(\log k)$ time by skipping samplers unlikely to be updated. Additionally, the authors suggest extending this cascading logic to more complex streaming models, such as sliding windows or streams with item deletions.

Summary updated

BibTeX
@article{braverman2015weighted,
  author = {Vladimir Braverman and Rafail Ostrovsky and Gregory Vorsanger},
  title = {{Weighted sampling without replacement from data streams}},
  journal = {Inf. Process. Lett.},
  year = {2015},
  doi = {10.1016/j.ipl.2015.07.007},
}
Figure