Documente Academic
Documente Profesional
Documente Cultură
Data Streams
In many data mining situations, we know the
entire data set in advance
Stream Management is important when the
input rate is controlled externally:
Google queries
Twitter or Facebook status updates
We can think of the data as infinite and nonstationary (the distribution changes over time)
Ad-Hoc
Queries
Standing
Queries
. . . 1, 5, 2, 7, 0, 9, 3
Output
. . . a, r, v, t, y, h, b
Processor
. . . 0, 0, 1, 0, 1, 1, 0
time
Streams Entering
Limited
Working
Storage
Archival
Storage
Applications (1)
Mining query streams
Google wants to know what queries are more
frequent today than yesterday
Applications (2)
Sensor Networks
Many sensors feeding into a central controller
10
Naive solution:
Generate a random integer in [0..9] for each query
Store the query if the integer is 0, otherwise discard
11
18d/100 = ((1/10*9/10)+(9/10*1/10))*d
So the sample-based answer is: d/(10s+19d)
12
13
Generalized Solution
Stream of tuples with keys:
Key is some subset of each tuples components
14
15
16
Proof: By Induction
We prove this by induction:
Assume that after n elements, the sample contains
each element seen so far with probability s/n
We need to show that after seeing element n+1 the
sample maintains the property
17
Proof: By Induction
After n elements, the sample S contains each
element seen so far with probability s/n
Now element n+1 arrives
For elements already in S, probability of
remaining in S is:
s
s
s 1
n
(1
)(
)(
)
n 1
n 1 s
n 1
Element in the
Element
n+1
At Element
timen+1
n discarded
tuples not
indiscarded
S were
there with prob. s/n
sample not picked
Time nn+1 tuple stayed in S with prob. n/(n+1)
So prob. tuple is in S at time n+1 =
18
19
20
Sliding Windows
A useful model of stream processing is that
queries are about a window of length N
the N most recent elements received
Interesting case: N is so large it cannot be
stored in memory, or even on disk
Or, there are so many streams that windows
for all cannot be stored
22
N=6
qwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnm
Past
Future
23
Obvious solution:
Store the most recent N bits
When new bit comes in, discard the N +1st bit
010011011101010110110110
Past
Future
24
Future
25
Future
Maintain 2 counters:
S: number of 1s
Z: number of 0s so far
26
DGIM(Datar-Gionis-Indyk-Motwani)
Method
Store O(log2N ) bits per stream
Gives approximate answer, never off by
more than 50%
Error factor can be reduced to any fraction > 0, with
more complicated algorithm and proportionally more
stored bits
27
6
Window of width
16 has 6 1s
10
4
3
2
2
1
1 0
001110001010010001011011011100101011001101
N
We can construct the count of the last N bits, except we are
not sure how many of the last 6 are included.
Centre for Distributed Computing, Jadavpur University
28
Whats Good?
Stores only O(log2N ) bits
O(log N ) counts of log2N bits each
29
10
4
1
1 0
001110001010010001011011011100101011001101
30
N
Centre for Distributed Computing, Jadavpur
University
01010110001011010101010101011010101010101110101010111010100010110
N
31
DGIM: Timestamps
Each bit in the stream has a timestamp,
starting 1, 2,
Record timestamps modulo N (the window
size), so we can represent any relevant
timestamp in O(log2N) bits
32
DGIM: Buckets
Constraint on buckets:
Number of 1s must be a power of 2
That explains the O(log log N) in (2)
33
34
At least 1 of
size 16. Partially
beyond window.
2 of
size 8
2 of
size 4
1 of
size 2
2 of
size 1
1010110001011010101010101011010101010101110101010111010100010110
N
Properties we maintain:
- Either one or two buckets with the same power-of-2 number of 1s
- Buckets do not overlap in timestamps
- Buckets are sorted by size
Centre for Distributed Computing, Jadavpur University
35
36
2.
3.
4.
37
10101100010110101010101010110101010101011101010101110101000101100
0101100010110101010101010110101010101011101010101110101000101100
01011000101101010101010101101010101010111010101011101010001011001
1100010110101010101010110101010101011101010101110101000101100101
1100010110101010101010110101010101011101010101110101000101100101
11000101101010101010101101010101010111010101011101010001011001011
Centre for Distributed Computing, Jadavpur University
38
How to Query?
2.
39
At least 1 of
size 16. Partially
beyond window.
2 of
size 8
2 of
size 4
1 of
size 2
2 of
size 1
1010110001011010101010101011010101010101110101010111010100010110
N
40
01010110001011010101010101011010101010101110101010111010100010110
N
41
Extensions
Can we use the same trick to answer queries
How many 1s in the last k? where k < N ?
A: Find earliest bucket B that at overlaps with k.
Number of 1s is the sum of sizes of more recent buckets
+ size of B
1010110001011010101010101011010101010101110101010111010100010110
k
42
43