Sampling from a moving window over streaming data

Brian Babcock, Mayur Datar, Rajeev Motwani

2002 · 334 citations · 5 references

Concepts

TL;DR

Sampling from a moving window of recent items in a data stream is challenging, particularly when the window size varies with time. The study introduces the problem of sampling from such a moving window and proposes two algorithms to address it. The authors present chain‑sample, which extends reservoir sampling to handle element expiration, and priority‑sample, which functions even when the window size changes dynamically. Both algorithms achieve high‑probability memory usage of O(k log n), with chain‑sample also attaining expected O(k) memory.

Abstract

We introduce the problem of sampling from a moving window of recent items from a data stream and develop two algorithms for this problem. The first algorithm, chain-sample, extends reservoir sampling to deal with the expiration of data elements from the sample. The expected memory usage of our algorithm is O(k) when maintaining a sample of size k over a window of the n most recent elements from the data stream, and with high probability the algorithm requires no more than O(k log n) memory.When the number of elements in the window is variable, as is the case when the size of the window is defined as a time duration rather than as a fixed number of data elements, the sampling problem becomes harder. Our second algorithm, priority-sample, works even when the number of elements in the window can vary dynamically over time. With high probability, the priority-sample algorithm uses no more than O(k log n) memory.

References

5