Probability vector \(p = (p_1, p_2, \dots, p_{n_{\mathcal{I}}})\), where \(p_i\) is the probability of item \(i\) in the stream.
Frequency vector \(\mathbf{N}(t) = (N_1(t), N_2(t), \dots, N_{n_{\mathcal{I}}}(t))\), where \(N_i(t)\) is the number of occurrences of item \(i\) in the stream up to time \(t\).
Goal: Find the frequency vector \(\mathbf{N}(t)\) or its functions (e.g., top-\(k\) items, heavy hitters, etc.) using limited memory \(m \ll n_{\mathcal{I}}\).
Fact: To exactly find \(\mathbf{N}(t)\), we need \(m=\Omega(n_{\mathcal{I}})\) memory.
Approximate Counting
Use sublinear memory \(m \ll n_{\mathcal{I}}\) to maintain an approximate frequency vector \(\hat{\mathbf{N}}(t)\).
Guarantee: \(|\hat{N}_i(t) - N_i(t)| \le \Delta \) for all \(i\).
Approximation: Recovery up to some additive error.
Known Fact: To find \(\mathbf{N}(t)\) up to an additive error using a deterministic algorithm, we need \(m=\Omega(n_{\mathcal{I}})\) memory.
Some fixes
Top-K methods
Focus on maintaining accurate counts for the top-k items.
Randomized algorithms
Use randomization to reduce memory requirements.
Probabilistic guarantees
\(|\hat{N}_i(t) - N_i(t)| \le \epsilon t\) with probability \(1-\delta\).
Misra-Gries (1982): Counter-Based Algorithm
Identify top-\(k\) items.
Match: If item is in a slot \(\implies\) increment its counter.
Empty Slot: If space remains \(\implies\) insert item with count 1.
All Slots Full & New Item Arrives: Decrement ALL counters by 1 and evict any item reaching count 0!
Stream Length: 0
Click Play or Step to process incoming items!
Active Counter Slots (\(k = 3\)):
Slot 1
—
Count: 0
Slot 2
—
Count: 0
Slot 3
—
Count: 0
Status: Ready
Misra-Gries (1982): Counter-Based Algorithm
Identify top-\(k\) items.
Match: If item is in a slot \(\implies\) increment its counter.
Empty Slot: If space remains \(\implies\) insert item with count 1.
All Slots Full & New Item Arrives: Decrement ALL counters by 1 and evict any item reaching count 0!
Some observations
Undercounts: The estimate never exceeds the true frequency.
Estimate bound: For a stream of length \(t\), \(N_i - \frac{t}{k+1} \le \hat N_i \le N_i\).
Not all counts are tracked: Only the \(k\) current candidates have counters; untracked items have estimate 0.
Non-parallelizable: For two streams, non trivial merging is required.
Click Play or Step to send items through both blocks.
Heavy block: \(m_1=2\) buckets
Bucket 0
Item: —V+: 0V−: 0
Bucket 1
Item: —V+: 0V−: 0
Light block: Count-Min Sketch \((d=3,w=4)\)
\(h_1\)
0
0
0
0
\(h_2\)
0
0
0
0
\(h_3\)
0
0
0
0
True: 0 | CMS: 0 + Heavy: 0 = Estimate: 0
Status: Ready
Questions and assumptions
How should the eviction threshold \(\lambda\) be chosen?
What is the error in the count?
What should be the fraction of memory allocated to the Heavy block i.e. what is \(\frac{m_1}{m_1+d \cdot w}\)?
We will answer these questions in the limiting regime as \(t \to \infty\).
Assumptions
The random variables $(R_t)_{t=1}^{\tau}$ are i.i.d. such that $\mathbb{P}(R_t = i) = p_i$, and $p_i>0$.
For any $\ell\in [d]$, $(\beta(i))_{i\in \mathcal{I}}$ and $\left( h_{\ell}(i)\right)_{i\in \mathcal{I}}$ are i.i.d. uniform random variables in $[m_1]$ and $[m_2]$ respectively.
Elastic Sketch algorithm (revisited)
Heavy block:
\(m_1\) buckets
Hash function: \(\beta:\mathcal{I}\to [m_1]\)
Eviction threshold: \(\lambda\)
Consider some bucket $b$
Incoming item
x
\(b = \beta(x)\)
➔
\(S_b\)
\(S_b\)
\(V_b^+\)
\(V_b^-\)
id of the currently elected item
Bucket contents: \(id, V_b^+, V_b^-\)
➔➔
1If \(x = id\)
\(V_b^+ \leftarrow V_b^+ + 1\)
2If \(x \neq id\)
\(V_b^- \leftarrow V_b^- + 1\)
Compare \(V_b^-\) with \(\lambda V_b^+\)
✓If \(V_b^- \le \lambda V_b^+\):keep current \(id\)
✕If \(V_b^- > \lambda V_b^+\):\(x\) replaces current \(id\)
\((S_b, V_b^+)\) sent to Light Block
Heavy Block Bucket Dynamics
State Definition: Let $X_b(t) = (S_b(t), V_b^+(t), V_b^-(t))$ be the state vector of bucket $b$ at step $t$, with eviction threshold metric $U_b(t) = \lambda V_b^+(t) - V_b^-(t)$.