Docsity

Stream Mining: Counting Distinct Elements and Moments in Data Streams, Slides of Data Mining

Partial preview of the text

Download Stream Mining: Counting Distinct Elements and Moments in Data Streams and more Slides Data Mining in PDF only on Docsity!

More Stream-Mining

Counting How Many Elements

Computing “Moments”

Counting Distinct Elements

Problem

: a data stream consists of

elements chosen from a set of size

n

Maintain a count of the number ofdistinct elements seen so far.

Obvious approach

: maintain the set of

elements seen.

Using Small Storage

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.

Flajolet-Martin* Approach

Pick a hash function

h

that maps each of

the

n

elements to log

2

n

bits, uniformly.



Important that the hash function be (almost)a random permutation of the elements.

For each stream element

a

, let

r

a

) be

the number of trailing 0’s in

h

a

Record

R

= the maximum

r

a

) seen.

Estimate = 2

R

  • Really based on a variant due to AMS (Alon, Matias, and Szegedy)

Why It Doesn’t Work

E(

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.

Solution

Partition your samples into small groups.

Take the average of groups.

Then take the median of the averages.

Special Cases

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 =

surprise number

= a

measure of how uneven the distribution is.

Example

: Surprise Number

Stream of length 100; 11 values appear.

Unsurprising

Surprise # = 910.

Surprising

Surprise # = 8,110.

One Random Variable

Assume stream has length

n

Pick a random time to start, so that any time is equally likely.

Let the chosen time have element

a

in

the stream.

X

n

  • ((twice the number of

a

’s in the

stream starting at the chosen time) – 1).

14

Expected Value of

X

nd

moment is

a

m

a

2

E(

X

n

all times

t

of

n

  • (twice the

number of times the stream element attime

t

appears from that time on) – 1

a

n

n

m

a

a

m

a

2

Problem

: Streams Never End

We assumed there was a number

n

the number of positions in the stream.

But real streams go on forever, so

n

is

a variable --- the number of elementsseen so far.

Fixups

The variables

X

have

n

as a factor ---

need to scale as

n

grows.

Suppose we can only store

k

counts.

We must throw some

X

’s out as time

goes on.



Objective: each

X

is selected with

probability

k

/

n

.