Scalable Analytics: Chapter 9
Characteristics of the Data Stream Model
In many modern data mining scenarios, the entire data set is not available in advance. This necessitates stream management, especially when the input rate is controlled by external sources rather than the system itself. Examples include Google search queries or status updates on platforms like Twitter and Facebook. Such data is characterized as being potentially infinite and non-stationary, meaning its statistical properties may change over time.
Input Rate and Storage: Data elements enter the system at a rapid rate through one or more input ports, known as streams. Because the volume is so high, the system cannot store the entire stream in an accessible way (e.g., on disk or in main memory).
Memory Constraints: The fundamental challenge is making critical calculations about the stream using a strictly limited amount of memory, typically secondary memory.
General Stream Processing Architecture:
Processor: Handles the incoming elements (tuples).
Limited Working Storage: Used for immediate processing needs.
Archival Storage: For long-term data that does not need to be accessed quickly.
Query Types: The system must support both \text{Ad-Hoc Queries} (one-time requests) and \text{Standing Queries} (queries that run continuously as new data arrives).
Principal Stream Mining Problems and Applications
There are several core types of queries or operations performed on data streams:
Sampling: Selecting a representative subset of the stream.
Sliding Windows: Performing queries over only the most recent elements.
Filtering: Identifying specific elements of interest from the stream.
Diverse Applications of Stream Mining
Query Streams: Google monitors streams to identify queries that are becoming more frequent over time.
Click Streams: Yahoo analyzes web traffic to detect unusual hits on specific pages within short intervals.
Social Network News Feeds: Platforms like Twitter and Facebook track news feeds to identify trending topics.
Sensor Networks: A central controller monitors data from numerous sensors reporting environmental or mechanical data.
Telephone Call Records: Streams are used for customer billing and calculating settlements between different telecommunications providers.
Network Monitoring: IP packets are monitored at switches to optimize routing protocols or to detect malicious activity, such as denial-of-service (DoS) attacks.
Sampling from a Data Stream
When it is impossible to store an entire stream, maintaining a sample is a primary strategy. There are two distinct sampling problems:
Fixed Proportion Sampling: Sampling a set fraction (e.g., ) of all incoming elements.
Fixed-Size Sampling: Maintaining a random sample of a specific size over a stream of unknown and potentially infinite length. This requires that at any time step , each of the elements seen so far has an equal probability of being in the sample.
Problem 1: Sampling a Fixed Proportion
In a search engine scenario where tuples consist of and we have space for only of the stream, a naïve approach might fail.
Failure of Naïve Sampling: If we store every query with a probability of (by generating a random integer from to and keeping only if the result is ), we cannot accurately answer questions about duplicate queries. For example, if a user issues queries once and queries twice (total queries = ), we would sample singletons and duplicate queries at least once. However, the probability of sampling both queries in a duplicate pair is only . The resulting sample-based estimate for the fraction of duplicates would be , which is incorrect.
Generalized Solution (Sampling by Key): To maintain the integrity of user behavior, we pick a fixed proportion of users rather than queries. We choose a key (e.g., the user ID) and hash it into buckets. To sample a fraction , we keep all tuples whose key hashes to a value at most . This ensures that if a user is selected, all their queries are sampled.
Problem 2: Maintaining a Fixed-Size Sample (Reservoir Sampling)
To maintain a sample of exactly size when the total number of items is unknown, we use the \text{Reservoir Sampling} algorithm.
Algorithm Steps:
Store the first elements of the stream directly into the sample .
When the -th element arrives (n > s), keep it with probability . If it is not kept, it is discarded.
If the -th element is kept, it replaces one of the existing elements in , chosen uniformly at random.
Proof by Induction:
Base Case: After elements, every element is in the sample with probability .
Inductive Step: Assume after elements, each has a probability of of being in the sample. For the -th element, the probability it is included is . For elements already in , the probability they remain in the sample is calculated as:
The total probability that a previous element is in the sample at time is: .
Queries over a Sliding Window
Sliding windows focus on the most recent elements. This is useful for tracking recent trends (e.g., Amazon sales of product in the last transactions). If is extremely large (e.g., billion bits), storing the window explicitly is impossible.
The Counting Bits Problem
We need to estimate the number of in the last bits of a stream where . A simple solution using uniformity assumes the fraction of in the last bits is equal to the total fraction of seen so far (, where is the count of and is the count of ), but this fails if the stream is non-uniform.
The DGIM Method (Datar, Gionis, Indyk, Motwani)
This method provides an approximate answer with an error bound of no more than , using only bits of storage per stream.
Timestamps: Each bit is assigned a timestamp modulo , requiring bits.
Buckets: A bucket consists of the timestamp of its end and the number of between its start and end. The number of (the size) must be a power of .
Bucket Rules:
There can be either one or two buckets for each power-of- size.
Buckets do not overlap in time and are sorted by size.
A bucket is deleted when its end-time is more than units in the past.
Updating Buckets: When a new bit arrives:
If the bit is , no changes are made (except potential deletions of old buckets).
If the bit is , create a new bucket of size . If this results in three buckets of size , combine the oldest two into one bucket of size . If this creates three buckets of size , combine the oldest two into a bucket of size , and so on down the line.
Querying: To estimate the number of in the last bits, sum the sizes of all buckets except the oldest one, and add half the size of the oldest bucket.
Error Proof: If the last bucket has size , an error of at most is made by assuming half its bits are in the window. Since there is at least one bucket of every size smaller than , the total sum is at least . Thus, the error relative to the total is at most . This error can be reduced to by allowing or buckets of each size.
Filtering Data Streams and Bloom Filters
Filtering involves checking if stream elements belong to a predefined set of keys . When is too large for a standard hash table (e.g., billion email addresses in a spam filter), probabilistic methods are used. These methods ensure no false negatives but allow for some false positives.
First Cut Solution Analysis (Throwing Darts)
Consider throwing darts (hash values of items in ) into targets (bits in a bit array ).
The probability a target is not hit by any dart is approximately .
The probability a bit is set to (the false positive rate) is .
Example: With email addresses and an bit array ( bits), the false positive rate is .
Bloom Filters
A Bloom Filter uses independent hash functions .
Initialization: Set all bits in array to . For every member , set for all .
Runtime: For a stream element , if for all , declare that is in . Otherwise, discard it.
Bloom Filter Analysis:
The fraction of bits set to is .
The false positive probability is .
The optimal number of hash functions to minimize false positives is . For a ratio of , the optimal is approximately .
Bloom Filters are efficient and suitable for hardware implementation due to their low memory requirements.