










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Counting How Many Elements
Computing “Moments”
Problem
: a data stream consists of
elements chosen from a set of size
Maintain a count of the number ofdistinct elements seen so far.
Obvious approach
: maintain the set of
elements seen.
Real Problem
: what if we do not have
space to store the complete set?
Estimate the count in an unbiased way.
Accept that the count may be in error, but limit the probability that the error islarge.
Pick a hash function
that maps each of
the
elements to log
2
bits, uniformly.
Important that the hash function be (almost)a random permutation of the elements.
For each stream element
, let
) be
the number of trailing 0’s in
Record
= the maximum
) seen.
Estimate = 2
R
R
) is actually infinite.
Probability halves when
R
->
R
+1, but value
doubles.
That means using many hash functions and getting many samples.
How are samples combined?
Average
? What if one very large value?
Median
? All values are a power of 2.
Partition your samples into small groups.
Take the average of groups.
Then take the median of the averages.
th
moment = number of different
elements in the stream.
The problem just considered.
st
moment = sum of the numbers of
elements = length of the stream.
Easy to compute.
nd
moment =
= a
measure of how uneven the distribution is.
Stream of length 100; 11 values appear.
Unsurprising
Surprise # = 910.
Surprising
Surprise # = 8,110.
Assume stream has length
Pick a random time to start, so that any time is equally likely.
Let the chosen time have element
in
the stream.
’s in the
stream starting at the chosen time) – 1).
14
nd
moment is
a
a
2
all times
t
of
number of times the stream element attime
appears from that time on) – 1
a
a
a
a
2
We assumed there was a number
the number of positions in the stream.
But real streams go on forever, so
is
a variable --- the number of elementsseen so far.
The variables
have
as a factor ---
need to scale as
grows.
Suppose we can only store
counts.
We must throw some
’s out as time
goes on.
Objective: each
X
is selected with
probability
k
/
n
.