UUtah Data Mining | Fall 2026 | L12: Steaming & Sampling
Overview
Streaming algorithms process an ordered sequence of items while retaining only a small summary, making them useful for routers, high-traffic websites, and datasets too large to fit in memory. The lecture develops uniform reservoir sampling for one or K items, with and without replacement, and weighted sampling, including a one-item weighted reservoir update and priority sampling for weighted samples without replacement.
Key takeaways
- A streaming algorithm updates a compact summary as each item arrives, targeting space polynomial in log m and log |U| instead of storing all m items.
- One-item reservoir sampling selects each of the first i stream items with probability exactly 1/i by replacing the current sample with probability 1/i.
- For K-item uniform sampling without replacement, accept item i with probability K/i and, when accepted, evict a uniformly random reservoir item; each seen item then has inclusion probability K/i.
- Weighted one-item reservoir sampling replaces the current choice with item j at probability wⱼ divided by cumulative weight, enabling proportional-to-weight selection in one pass.
- Uniform samples capture common, well-supported structure but can miss rare outliers; algorithms that must detect anomalies need a different summary strategy.
- Priority sampling handles weighted selection without replacement by ranking items with random weight-dependent priorities and retaining the K smallest.
Chapters
- The new section introduces streaming algorithms as a way to handle very large data under memory constraints.
- Sampling is the main topic, with variants distinguished by whether sampling is weighted and whether repeats are allowed.
- The clustering homework is due the following Tuesday; TA hours are available early in the week.
- The midterm is scheduled for the following Thursday, covers material before streaming, and emphasizes major concepts.
- Students may bring a reference sheet; preparing it is intended to help identify key ideas and formulas from earlier lectures.
- The input is written as an ordered stream A₁, A₂, …, Aₘ, with each item drawn from a domain U.
- The order of arrival may be adversarial: an algorithm cannot assume items arrive in a convenient order.
- The stream model focuses on limited memory rather than storing the entire input as a vector.
- A streaming algorithm maintains a compact summary S and updates it from Sᵢ₋₁ when item Aᵢ arrives.
- The target space is polynomial in log m and log |U|, rather than proportional to the full stream size.
- Cluster centers illustrate a lossy summary: they represent the data without preserving every original point.
- Internet routers process packets containing source and destination IP addresses but cannot store every packet that passes through.
- A compact running summary can help monitor traffic patterns and identify possible distributed denial-of-service attacks.
- The router example motivates extracting useful statistics while packets continue to arrive.
- Busy websites and apps generate many clicks, searches, and page interactions that can be summarized without retaining every event.
- For a dataset on disk or in the cloud, a one-pass summary can avoid loading the full dataset into computer memory.
- Sequential streaming can reduce costly data movement; time-series and online prediction are related settings, though not identical to the strict streaming model.
- To track the average of real-valued items A₁ through Aᵢ, maintain both the count Cᵢ = i and the running sum Sᵢ.
- Update the sum with Sᵢ = Sᵢ₋₁ + Aᵢ, then recover the average as Sᵢ / Cᵢ.
- Keeping the current average alone is insufficient for a straightforward update; the count and sum form a compact, updateable summary.
- A random sample is a general-purpose summary that tends to retain evidence of large, well-supported clusters.
- Rare outliers may be missed, so uniform sampling is a poor choice when finding exceptional or abnormal points is the goal.
- In simple one-dimensional cases, tracking the maximum directly may be more appropriate than relying on a random sample.
- With replacement, independent draws may select the same item multiple times, producing an IID sample.
- Without replacement, every selected item is distinct, but the draws are not independent.
- The difference is small when the sample is tiny relative to the population, but matters more for large samples or weighted selection.
- Initialize the reservoir with A₁, then process each later item Aᵢ using a fresh uniform random value U.
- Replace the reservoir with Aᵢ when U < 1/i, so the new item is selected with probability 1/i.
- The algorithm stores one item and a count while producing a uniform sample from the items seen so far.
- At step i, the new item Aᵢ enters the reservoir with probability 1/i.
- For any earlier item Aⱼ, induction gives probability 1/(i−1) of being retained before the update.
- The earlier item survives with probability 1−1/i, making its updated probability (1/(i−1)) × ((i−1)/i) = 1/i.
- Run K independent copies of the one-item reservoir algorithm, each using separate randomness.
- The resulting K draws are IID; different copies may select the same stream item.
- This direct parallel construction gives a with-replacement sample without changing the single-item algorithm.
- Initialize the reservoir with the first K distinct items, then process each later item Aᵢ.
- Select Aᵢ for the reservoir with probability K/i; if selected, evict one of the K current items uniformly at random.
- After processing i items, each item has probability K/i of appearing in the reservoir, which is a uniform sample without replacement.
- For item Aⱼ with nonnegative weight wⱼ, weighted sampling selects it with probability wⱼ divided by the total weight seen so far.
- The cumulative weight can be maintained as the stream arrives, much like maintaining a count or sum.
- Weighted selection appears in k-means++, where squared distance guides selection, and in importance sampling to focus samples on consequential items.
- Initialize the reservoir to A₁ and the cumulative weight to w₁; update the total as each new weight arrives.
- For item Aⱼ, replace the current reservoir with probability wⱼ divided by the updated cumulative weight.
- Independent copies extend the method to K weighted draws with replacement.
- Weighted sampling without replacement needs a different method because the replacement decision depends on the current selected set.
- Assign each item a random priority based on its weight and a uniform random value; an exponential-race form uses −ln(Uⱼ)/wⱼ.
- Maintain the K smallest priorities in a priority queue; this yields a weighted sample without replacement, with expected amortized O(1) maintenance time per item.
Transcript excerpt
0:17 Welcome back everyone. So let's get started. Um but today we're gonna u um we're going to start a new section on streaming algorithms. This is kind of a kind of way of modeling some really key um so scenarios in the data mining for dealing with very large data. Uh so we'll look specifically at this streaming model which is a kind of acute well-defined model that that it does actually model real things but it also kind of reveals a lot of the core structure in algorithms when we do want to scale things up. So we'll talk about some kind of extensions to this model. ideas we will apply under this setting
1:05 we'll be able to port and um um into a lot of other settings as well and um so within this thing we'll look at the problem of just sampling so how do we do like a good uh um like a good sample of data this um um this will be the main topic today and there there are a bunch of variants of how you do samplings we'll we'll try and break these down so you understand the differences Um uh okay before we get started let's look at the um so the schedule the homework on similarity is almost graded. I hope to have this out by the end of the week. That'd be tomorrow. Um so uh um and so then if there are questions about the
1:55 the grading on any of the assignments, you can file a regrade request u um um inside grade scope um um if that happens. Um [clears throat] so and then the clustering homework is going to be due on Tuesday next week. Uh so so we've we've already covered all the lectures on clustering. So um um
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, UofU Data Science.