Neural Sync Active
Matrix Sketching
Registry Synced
Matrix Sketching
127 words
1 min read
Reading compass
Now · 8.1 Frequent Directions
Matrix Sketching
8.1 Frequent Directions
Maintain a sketch of A∈Rn×d that approximates its covariance structure. Processes rows one at a time, keeping only 2k rows.
pythonimport numpy as np def frequent_directions(A, k): n, d = A.shape sketch = np.zeros((2*k, d)) for i in range(n): sketch[0] = A[i] U, S, Vt = np.linalg.svd(sketch, full_matrices=False) delta = S[k-1]**2 S = np.sqrt(S**2 - delta) sketch = np.diag(S[:k]) @ Vt[:k] return sketch
8.2 Count-Min Sketch
Purpose: Approximate frequency counts in a stream.
Structure: d×w table of counters, d hash functions hj mapping items to [w].
Update: For item i, increment C[j][hj(i)] for j=1,…,d.
Query: f^i=minjC[j][hj(i)] (always an overestimate).
Join Discord
PreviousRandomized RegressionNextFrequency Estimation