CS599 Graph Analytics
Fall 2021
Lectures 14, 15, 17 10/21,10/26, 11/2
Charalampos E. Tsourakakis �ctsourak@bu.edu
Next few lectures agenda
The Streaming model
Input
-Stream of elements
- Order may be adversarial
- One pass over the stream
Goals�- Compute as accurately as possible statistics of interest
- Key constraint: Minimum space algorithm
- Fast query and update times
10 4 1 10 1 9 3 ...
Moment estimation problem
10 4 1 10 1 9 3 ...
Types of streams
A convenient way to think of the stream is as a sequence of updates of the form (i,Δ) to the histogram x[1,..n] of the universe [n].
Common assumptions: (i) Δ integer (ii) log(mM) = log(n) where |Δ|<=M
Gap!
Morris algorithm
How to save 1 bit?
Let Z be the value of the counter after m increments.
How to save k bits?
Let Z be the value of the counter after m increments.
How to save k bits?
0
1
2
X
…
…
p
p
p
p
1-p
1-p
1-p
Morris algorithm → birth process with adaptive sampling
0
1
2
X
…
…
Why this estimator?
Claim: Define Xn to be the value of the counter after n increments. Then, E[2Xn]=n+1.
Proof (induction)
Base case: If n=0, Xn=0 and thus the claim holds.
Inductive step: By conditional expectation rule E[2Xn+1]=E[E[2Xn+1|Xn]] and the inductive hypothesis, we obtain the following expression:
Properties of Morris algorithm
� E[Z]=m+1
�Corollary: Morris algorithm outputs an unbiased estimator of m. �
�Observation: No improvement in terms of concentration as m grows since Var(Z)/E(Z)2 is constant.
Morris algorithm
Morris+
s
Reducing variance: Morris++
Claim: The space complexity with probability 1-δ is and we obtain an (ε,δ)-approximation scheme to F1 for insert-only streams. ���
…
avg1
avg2
avgt
s
Morris++: Median of t Moris+’s where
Moris+: avg of s independent �Morris counters
Moris+: avg of s independent �Morris counters
Moris+: avg of s independent �Morris counters
Reducing variance: change basis
� E[Z]=m
X
…
1/2X
1 - 1/2X
X
…
1
0
…
X
…
1/(1+a)X
1 - 1/(1+a)X
vs.
deterministic
Morris2
Morris1+a
How to set a?
X
…
1/(1+a)X
1 - 1/(1+a)X
Morris1+a
Optimal Algorithm for F1
Merging Morris Counters
�Merge(c1,c2)
�Intuition: simulating updates in the second counter by observing that in order to have an increase from x to x+1 we need bx updates.
Stream 1
Stream 2
c1
c2
Flajolet-Martin (FM) sketch
�
1 | 1 | 1 | 1 | 0 | x | x |
Flajolet-Martin (FM) sketch
Flajolet-Martin (FM) sketch
Important functions �1. h(x) = hash function that transforms x into a uniform binary string
2. ρ(x) = position of leftmost 0 (e.g., ρ(111010100000)=4)
�Algorithm
0 | 0 | …. | 0 |
Flajolet-Martin (FM) sketch
Stochastic Averaging
Substream id hash value�
Flajolet-Martin theorem
The estimator Z is asymptotically unbiased, i.e., En[Z] → n and the coefficient �
of variation using k bitmasks is �Memory: O(klogn)
Example: can count cardinalities up to 109 with error <=6% using 4kBs of memory (=4096 bytes)**
“Caveat” of their work: Practical implementations of the hash function are not discussed.
* See also Mitzenmacher-Vadhan: Why simple hash functions work: Exploiting the entropy in a data stream
K Minimum Values (kMV) sketch
Basic idea: Use a “good enough” hash function h:[n] → R and the k smallest hashed values.
KMV-Init(k)
KMV-Update(x)�- If x is not in L
L← L U {(x,h(x))}� if |L|>k then remove x with largest h(x) value from L
KMV-Query()
v← largest hash value in L�Return (k-1) R/v
KMV analysis
Let A be the set of distinct elements.
���
�Let’s assume h is chosen from a family of pairwise independent hash functions, and that R is large enough to ensure hash collisions are unlikely to occur (e.g., R=n3)
R
k=3
AMS sketch for Fp
Theorem: For every ε,δ>0, there exists a randomized algorithm A that computes a number Y so that the probability that Y deviates from Fp by more than εFp is at most δ. ��Furthermore, algorithm A uses memory bits.
�
Lower bound: For any fixed p>5, δ<½, any randomized algorithm that outputs a number � �Zp such that
AMS sketch for Fk
Remarks�In order to get an (ε,δ)-approximation scheme we set�and we take the median of s2 variables each being the average of s1 independent Xs.
Reservoir sampling
Improved AMS sketch for F2
AMS sketch
AMS Sketch for F0
Due to the random choice of a,b
In other words, for x,y distinct
AMS Sketch for F0
AMS Sketch for F0
Theorem: For every c>2 there exists an algorithm that outputs an estimate Y of F0 such that the probability that the ratio between Y and F0 is not between 1/c and c is at most 2/c.
Space usage: O(logn) to store the hash functions, O(loglogn) to store r.
�Median trick: the failure probability can become δ using the standard median trick, i.e., repeat the process log(1/δ) times and output the median. This yields a (O(1), δ) approximation scheme. ��Remark: The intuition is the same as FM, namely on average one out of F0 distinct numbers will satisfy ρ(h(x))>=log2(F0), so yields a good approximation of log2(F0).�
Triangle counting via moment estimation
Stream update:(u,v) Virtual stream: (u,v,x1),...,(u,v,xn-2)
Triangle counting via moment estimation