Back to Streaming Sketching

Randomized Numerical Linear Algebra

September 26, 2026 Wasil Zafar 22 min read

Sketch matrices for regression, low rank, and spectral tasks.

Table of Contents

  1. Matrices Too Large to Hold Still
  2. Subspace Views of Low-Rank Structure
  3. Sampling, Projection and Spectral Error
  4. PCA, Regression and Scientific Data
  5. Design a Randomized Matrix Workflow

Matrices Too Large to Hold Still

Suppose a scientist has a table with a billion observations and thousands of measurements per observation. Classical matrix algorithms can be exact and elegant, yet repeatedly scanning or decomposing that table may dominate the work. Randomized numerical linear algebra replaces the original matrix with a smaller random view that preserves the subspace, product, or low-rank structure needed by the downstream calculation.

The everyday analogy is a carefully designed survey. A naive survey samples people uniformly and may miss a small but influential group. A leverage-aware survey gives higher probability to observations that span unusual directions. A projection takes another route: it mixes all rows or columns into fewer randomized combinations, so every original observation can influence the reduced problem.

For a tiny example, let

$$ A=\begin{bmatrix}1&0\\0&1\\1&1\end{bmatrix},\qquad b=\begin{bmatrix}1\\2\\3\end{bmatrix}. $$

Here $b=A(1,2)^\mathsf T$, so the least-squares residual is zero. Keeping only the first two rows still recovers the solution, but keeping two identical or nearly redundant directions need not. The point is not that row sampling always works; it works when the sample or sketch preserves the column space relevant to every candidate residual.

Matrix multiplication sketches approximate $A^\mathsf TB$ without forming every contribution. Leverage scores identify influential rows or columns. Subspace embeddings preserve norms throughout a fixed subspace. Randomized SVD finds an approximate range before computing a small factorization. Frequent Directions is deterministic: it repeatedly shrinks singular values of a compact matrix and gives covariance-error guarantees in a streaming setting.

From a representative survey to a matrix sketch A large matrix is reduced by row sampling or random projection, solved in small form, and validated against the original objective. Large matrix A influential directions differ Representative view sample by leverageor project all rows S A and S bpreserve needed subspace Small solve regressionSVD / PCAmatrix product cheap decomposition Validate residualspectral errorslice behavior against contract A smaller view is useful only if it preserves the task’s geometry.
ConceptIntuitive meaningExact exampleNon-example or boundaryMain assumptionQuestion answered
Matrix sketchSmaller linear view of a matrix$SA$ has fewer rows than $A$Arbitrary truncation with no preservation claim$S$ matches the required theoremWhat smaller problem can replace the original?
Approximate matrix multiplicationEstimate $A^\mathsf TB$ from samples or projections$(SA)^\mathsf T(SB)\approx A^\mathsf TB$Entrywise equalityNorm, stable-rank, or probability conditions are statedCan a costly product be approximated?
Leverage scoreRow influence on a matrix’s column space$\ell_i=\lVert e_i^\mathsf TU\rVert_2^2$ for orthonormal $U$ spanning $\operatorname{col}(A)$Row norm alone in every matrixScores refer to the relevant subspaceWhich rows deserve higher sampling probability?
Subspace embeddingPreserve all vector norms in a fixed column space$\lVert SAx\rVert_2\approx\lVert Ax\rVert_2$ for every $x$Preserving only each column separatelyFixed subspace and suitable sketch dimensionDoes the reduced regression keep every residual direction?
Randomized SVDFind a probable approximate range, then factor a small matrix$Y=A\Omega$, $Q=\operatorname{orth}(Y)$SVD of unrelated sampled entriesOversampling and spectral structureCan dominant singular directions be found faster?
Frequent DirectionsDeterministic streaming covariance sketch$B^\mathsf TB$ approximates $A^\mathsf TA$Random row reservoirDeclared sketch size and shrink ruleCan second-order structure be summarized in one pass?
Warm-up

Matrices Too Large to Hold Still

Let the rows of $A$ be $a_1=(1,0)$, $a_2=(0,1)$, and $a_3=(1,1)$.

  1. Compute $A^\mathsf TA=a_1^\mathsf Ta_1+a_2^\mathsf Ta_2+a_3^\mathsf Ta_3=\begin{bmatrix}2&1\\1&2\end{bmatrix}$.
  2. Uniformly sample one row. If $a_1$ is selected and rescaled by $\sqrt3$, the product estimate is $3a_1^\mathsf Ta_1=\begin{bmatrix}3&0\\0&0\end{bmatrix}$—unbiased over the random row but poor in this realization.
  3. Averaging many independent samples reduces variance, while nonuniform sampling can prioritize influential rows and rescale by their sampling probabilities.
  4. Explain why “unbiased” does not mean one sample is accurate and why rescaling is necessary.

Reflection: row $a_3$ has the largest norm, but leverage depends on the whole column space. What could make row norm and leverage give different sampling priorities?

Subspace Views of Low-Rank Structure

Let $A\in\mathbb R^{m\times n}$ have singular value decomposition $A=U\Sigma V^\mathsf T$. The best rank-$k$ approximation under both spectral and Frobenius norms is $A_k=U_k\Sigma_kV_k^\mathsf T$. Its errors are

$$ \lVert A-A_k\rVert_2=\sigma_{k+1},\qquad \lVert A-A_k\rVert_F^2=\sum_{j>k}\sigma_j^2. $$

A randomized range finder draws a test matrix $\Omega\in\mathbb R^{n\times(k+p)}$, forms $Y=A\Omega$, and computes an orthonormal basis $Q$ for the columns of $Y$. It then works with the small matrix $B=Q^\mathsf TA$. If $Q$ captures the leading left singular subspace, $QB$ approximates $A$. Oversampling $p$ reduces the risk that random test vectors poorly excite an important direction. Power iterations use $(AA^\mathsf T)^qA\Omega$ to amplify spectral gaps, at the cost of passes and possible numerical stabilization needs.

For a full-column-rank matrix $A$, the leverage scores of its rows are the diagonal entries of the projector $UU^\mathsf T$, where $U$ spans $\operatorname{col}(A)$. They satisfy $0\le\ell_i\le1$ and $\sum_i\ell_i=\operatorname{rank}(A)$. Sampling rows proportionally to approximate leverage scores protects rare but geometrically important directions better than uniform sampling when coherence is high.

A $(1\pm\varepsilon)$ subspace embedding $S$ for $\operatorname{col}(A)$ satisfies

$$ (1-\varepsilon)\lVert Ax\rVert_2^2\le\lVert SAx\rVert_2^2\le(1+\varepsilon)\lVert Ax\rVert_2^2 $$

for every $x$. For least squares, the relevant subspace often includes both $A$ and $b$, because residuals are $Ax-b$. Preserving only columns of $A$ individually does not preserve every linear combination.

Frequent Directions processes rows into a fixed-size matrix $B$. When full, it computes an SVD, subtracts a common squared singular-value threshold, and discards the directions shrunk to zero. It never overstates directional energy: for every unit vector $x$, $0\le\lVert Ax\rVert_2^2-\lVert Bx\rVert_2^2$ is bounded in terms of the tail energy and sketch size under the chosen theorem.

Randomized Numerical Linear Algebra: Subspace Views of Low-Rank Structure
flowchart TD
    A[Large matrix A] --> B{Target task}
    B -->|Low rank| C[Random test matrix Omega]
    C --> D[Range sample Y equals A Omega]
    D --> E[Orthonormal basis Q]
    E --> F[Small matrix Q transpose A]
    F --> G[Approximate SVD]
    B -->|Regression| H[Embed span of A and b]
    H --> I[Solve sketched least squares]
    B -->|Row sampling| J[Estimate leverage scores]
    J --> K[Sample and rescale influential rows]
    B -->|Streaming covariance| L[Frequent Directions]
    L --> M[Deterministic shrinkage]
    G --> N[Low-rank error guarantee]
    I --> O[Residual guarantee]
    K --> O
    M --> P[Directional covariance guarantee]
    classDef navy fill:#17365D,color:#fff,stroke:#17365D;
    classDef teal fill:#147D84,color:#fff,stroke:#0D565B;
    classDef crimson fill:#C6284D,color:#fff,stroke:#861B35;
    classDef purple fill:#6C3BAA,color:#fff,stroke:#472675;
    class A,B navy;
    class C,D,E,H,J,L purple;
    class F,I,K,M teal;
    class G,N,O,P crimson;
Randomized range finding captures a leading matrix subspace A large matrix multiplies a random test matrix to produce a small range sample. Orthonormalization yields Q, which separates captured structure from residual error. A: m × n large matrix × Ω k+p random probes Y=AΩ sampled range Project with QQᵀ captured: QQᵀAresidual: (I−QQᵀ)A bound residual norm Random probes must excite every important right-singular direction.
Definition or theoremExact scopeRequired assumptionsWhat it does not implyCounterexample or consequence
Eckart–Young–MirskyTruncated SVD is optimal rank-$k$ approximation in spectral and Frobenius normsStandard real/complex matrix normsIt is cheap to compute for enormous matricesExact SVD may require expensive passes and communication
Leverage scoresDiagonal of the projector onto the column space; scores sum to rankOrthonormal basis for the relevant subspaceLarge row norm always means high leverageA large row aligned with many duplicates may have modest leverage
Subspace embeddingSimultaneous norm preservation for every vector in a fixed subspaceSketch dimension and distribution match subspace rank and error targetIndividual column preservation is sufficientTwo preserved columns can have a badly distorted difference
Randomized range finder$Q$ captures the dominant range with high probability or in expectationSuitable random $\Omega$, oversampling, and spectral assumptions of theoremExact top singular vectors for every matrixFlat spectrum can require more rank or power iterations
Power iterationAmplifies ratio between leading and trailing singular valuesExtra passes and stable orthogonalizationFree accuracy improvementRoundoff can erase weak directions without reorthogonalization
Frequent DirectionsDeterministic covariance/directional-energy error boundCorrect shrinkage, sketch size, and streaming arithmeticAn unbiased random sample of rowsIt deliberately shrinks all retained singular values

The low-rank problem is fundamentally about a subspace: a basis $Q$ is useful when the residual $(I-QQ^\mathsf T)A$ is small. Randomization is a method for discovering that subspace cheaply; the guarantee must name the norm, target rank, oversampling, probability, and spectral assumptions.

Sampling, Projection and Spectral Error

For approximate matrix multiplication, write $A^\mathsf TB$ as a sum of outer products of corresponding rows. Sample row index $i$ with probability $p_i$, and use the rescaled outer product $a_i^\mathsf Tb_i/p_i$. Its expectation is the full product. Repeating and averaging reduces variance. Probabilities proportional to suitable row-norm products or leverage-like quantities reduce the influence of any one rescaled sample. Unbiasedness alone does not control spectral or Frobenius error.

For regression, suppose $S$ preserves the span of $A$ and $b$. Every residual $Ax-b$ lies in that subspace, so

$$ (1-\varepsilon)\lVert Ax-b\rVert_2^2\le\lVert S(Ax-b)\rVert_2^2\le(1+\varepsilon)\lVert Ax-b\rVert_2^2. $$

If $\widetilde x$ minimizes the sketched residual and $x_\star$ minimizes the original, comparing the two inequalities yields an approximate original objective. The proof uses preservation for all candidate residuals, not only for $x_\star$.

Randomized low-rank analysis decomposes error into the optimal tail $A-A_k$ and failure to capture the leading range. Spectral error focuses on the worst direction and is sensitive to a single missed singular vector; Frobenius error aggregates energy and may remain small when one direction is moderately wrong. Always match the norm to the application.

Frequent Directions offers a deterministic alternative. When a sketch $B$ fills, compute $B=U\Sigma V^\mathsf T$, choose a threshold $\delta$ from a trailing squared singular value, and replace singular values by $\sqrt{\max(\sigma_i^2-\delta,0)}$. The removed energy is charged uniformly across directions, yielding a telescoping covariance-error bound. Changing the threshold or omitting rescaling changes the theorem.

Frequent Directions shrinkage step A full sketch has singular values. A common squared threshold is subtracted, the smallest direction becomes zero, and remaining directions form the next compact sketch. Full sketch B singular values σᵢ Shrink squared energy δ = trailing σ²σ'ᵢ = √max(σᵢ²−δ,0) same charge in every direction Compact next sketch one direction freed Shrinkage loses energy deliberately but bounds cumulative directional loss.
Randomized Numerical Linear Algebra: Sampling, Projection and Spectral Error
flowchart TD
    A[State target: product, regression, or rank k] --> B[Choose sketch family and size]
    B --> C{Sampling or projection?}
    C -->|Sampling| D[Probabilities cover influential rows or columns]
    D --> E[Rescale sampled contributions]
    E --> F[Unbiased estimator plus concentration]
    C -->|Projection| G[Embed the relevant fixed subspace]
    G --> H[Preserve every candidate residual]
    H --> I[Compare sketched optimum with original optimum]
    B --> J{Streaming deterministic option?}
    J -->|Yes| K[Frequent Directions shrinkage]
    K --> L[Charge discarded energy across directions]
    F --> M[Norm-specific product bound]
    I --> N[Regression objective bound]
    L --> O[Covariance and low-rank bound]
    D -. uniform sampling misses high leverage .-> X[Failure]
    G -. embed only individual columns .-> Y[Failure]
    classDef navy fill:#17365D,color:#fff,stroke:#17365D;
    classDef teal fill:#147D84,color:#fff,stroke:#0D565B;
    classDef crimson fill:#C6284D,color:#fff,stroke:#861B35;
    classDef purple fill:#6C3BAA,color:#fff,stroke:#472675;
    class A,B,C,J navy;
    class D,G,K purple;
    class E,F,H,I,L teal;
    class M,N,O teal;
    class X,Y crimson;
Worked Derivation

Sampling, Projection and Spectral Error

Let $A$ have rows $a_1=(2,0)$ and $a_2=(0,1)$. Then $A^\mathsf TA=\operatorname{diag}(4,1)$.

  1. Uniformly sample one row, so $p_1=p_2=1/2$, and estimate with $a_i^\mathsf Ta_i/p_i$.
  2. If row one is chosen, the estimate is $\operatorname{diag}(8,0)$; if row two is chosen, it is $\operatorname{diag}(0,2)$.
  3. Averaging the two outcomes gives $\operatorname{diag}(4,1)$, so the estimator is unbiased, but either single outcome has large spectral error.
  4. Sample with probabilities proportional to squared row norms: $p_1=4/5$, $p_2=1/5$. The possible estimates become $\operatorname{diag}(5,0)$ and $\operatorname{diag}(0,5)$. Variance in the dominant first direction is reduced, though one sample remains insufficient for a full spectral approximation.
  5. Repeat $s$ times and average. State that concentration and sample complexity—not unbiasedness alone—must support the chosen error probability.

Assumption-breaking variation: sample nonuniformly but forget division by $p_i$. Compute the expectation and show that high-probability rows are systematically overweighted.

Analytical toolWhat it establishesAssumptionsTightness or limitationRepresentative failure case
Outer-product expectationSampled product estimator is unbiasedPositive probabilities and inverse-probability rescalingNo high-probability error bound by itselfOne high-norm row dominates variance
Matrix concentrationSpectral deviation of sums of random matricesIndependence or matching dependence control and bounded summandsConstants and intrinsic dimension matterHeavy-tailed rescaled samples violate bounds
Leverage samplingProtects influential subspace directionsAccurate upper bounds on leverage and enough samplesComputing exact scores may itself be expensiveUniform sampling misses one rare basis direction
Subspace embedding proofPreserves all regression residuals in a fixed spanEmbed span of $A$ and $b$ with declared probabilityObjective guarantee need not imply coefficient accuracy under ill-conditioningNearly singular $A$ gives unstable coefficients
Range-finder residualMeasures missed portion $(I-QQ^\mathsf T)A$Random probes, oversampling, and theorem-specific spectrumSpectral guarantee can be weaker than Frobenius guaranteeOne missed singular direction dominates operator norm
Frequent Directions chargingDeterministic covariance-loss boundExact shrink rule and sufficient sketch rowsShrinkage is biased downwardChanging the threshold invalidates the telescope

PCA, Regression and Scientific Data

For an approachable PCA task, randomized range finding can compress a tall matrix of student measurements before an SVD. The leading components summarize variance, but interpreting them as causal traits remains unjustified. Centering, scaling, missing values, and categorical encodings define the matrix and can matter more than the sketch.

For large regression, a subspace embedding reduces billions of rows to a manageable problem. It can preserve the residual objective while coefficients remain sensitive if the design is ill-conditioned. Ridge regularization changes the relevant augmented system and must be included in the sketching analysis.

For scientific data, low-rank structure can reveal latent modes in telescope, climate, genomics, or simulation matrices. A weak spectral gap may make individual singular vectors unstable even when the low-rank subspace and reconstruction error are stable. Domain conclusions should reflect subspace uncertainty, not overinterpret one basis orientation.

Adversarial or misleading cases include rare high-leverage observations, drift after sampling probabilities are estimated, corrupted rows with huge norms, and adaptive workloads that respond to a fixed public sketch. A global Frobenius guarantee can hide one scientifically critical direction; a small regression residual can coexist with biased data collection.

Randomized matrix workflow with modeling and numerical trust boundaries Data preparation feeds a versioned sketch, then a small matrix solve and validation. Risks include scaling, high leverage, numerical instability, and semantic overinterpretation. Data matrixrows × featuresunits + missingness Preparecenter / scaledefine objective Sketchsample / project / FDseed + size Small solveSVD / regressionstable arithmetic Auditoriginalobjective Data riskscale, bias, missingness Sketch riskhigh leverage, drift Inference riskill-conditioning, causality Validate numerical error separately from scientific meaning.
Case Study

PCA, Regression and Scientific Data: Randomized Numerical Linear Algebra

Consider centered observations

$$ A=\begin{bmatrix}2&0\\-2&0\\0&1\\0&-1\end{bmatrix}. $$

  1. Compute $A^\mathsf TA=\operatorname{diag}(8,2)$. The first coordinate is the leading principal direction.
  2. The singular values are $\sqrt8$ and $\sqrt2$. The best rank-one squared Frobenius residual is $2$, while the squared spectral residual is also $2$.
  3. If a row sample keeps only the last two rows, it concludes incorrectly that the second coordinate is the only active direction. Uniform small samples can miss high-energy structure.
  4. A randomized range sample that mixes all columns has a probability of exciting both singular directions; oversampling and validation reduce failure risk.

Model selection: exact SVD is preferable for this tiny matrix. Use randomized methods only when data movement or decomposition dominates.

Success criteria: derive the covariance, singular values, rank-one direction, and both residual norms; then state a validation rule comparing $\lVert A-QQ^\mathsf TA\rVert_F$ and $\lVert A-QQ^\mathsf TA\rVert_2$ with the optimal tail.

Production

PCA, Regression and Scientific Data: Randomized Numerical Linear Algebra

A genomics pipeline receives a sparse matrix with $m=80$ million observations and $n=20{,}000$ features. It needs rank-$k=100$ structure and ridge regression, permits two passes over distributed storage, targets Frobenius error within $1.1$ times the best rank-100 error, and requires regression objective inflation below $2\%$.

Design: benchmark a randomized range finder with oversampling $p\in\{20,40\}$ and one stabilized power iteration; use a compatible subspace embedding for the ridge-augmented regression system; and compare with a one-pass Frequent Directions configuration when a second pass is operationally expensive. Version preprocessing, transform seed, precision, and sketch size.

Evidence: exact or high-accuracy baselines on representative subsets; residual Frobenius and spectral norms; principal-angle stability; regression objective and coefficient sensitivity; high-leverage and rare-cohort behavior; pass count, network shuffle, peak memory, and p95 runtime; multiple seeds; missing-data and outlier stress tests; and drift after instrument changes.

Risks: a small Frobenius error can hide one scientific direction, weak spectral gaps make component identities unstable, coefficient accuracy can degrade under ill-conditioning, and biased data remain biased after sketching. Preserve audit samples and report subspace uncertainty rather than treating randomized components as ground truth.

Decision: deploy only if confidence bounds meet both low-rank and regression objectives across critical cohorts and the speedup exceeds sketch construction and validation costs. Otherwise keep the deterministic or hybrid pipeline for sensitive analyses.

Design a Randomized Matrix Workflow

Start from the output guarantee, not the fashionable sketch. Specify the matrix shape and access pattern, target task, rank or subspace dimension, norm, relative or additive error, failure probability, passes, precision, and adversary model. Then select sampling, projection, randomized range finding, or deterministic shrinkage and validate the result on the original objective.

Practice

Practice: Design a Randomized Matrix Workflow

Use $A=\begin{bmatrix}2&0\\0&1\\0&1\end{bmatrix}$ and target rank $k=1$.

Tier 1 — Definitions. Define leverage score, subspace embedding, approximate matrix multiplication, randomized range finder, spectral error, Frobenius error, and Frequent Directions. State one quantifier or assumption for each.

Tier 2 — Exact baseline. Compute $A^\mathsf TA=\operatorname{diag}(4,2)$, singular values $2$ and $\sqrt2$, and best rank-one residuals $\lVert A-A_1\rVert_2=\sqrt2$ and $\lVert A-A_1\rVert_F=\sqrt2$.

Tier 3 — Sampling. Derive squared row-norm probabilities $(2/3,1/6,1/6)$. For one sampled row, write the rescaled covariance estimator and verify unbiasedness. Explain why one sample cannot preserve both directions.

Tier 4 — Counterexamples. Construct: uniform sampling that misses a rare high-leverage row; a sketch preserving each column norm but distorting their difference; a flat spectrum where top singular-vector identity is unstable; and a non-rescaled nonuniform sample that is biased.

Tier 5 — Method choice. Choose among leverage sampling, dense or sparse projection, randomized SVD, and Frequent Directions for (a) static regression, (b) two-pass low-rank approximation, and (c) one-pass streaming covariance. Name error norm, passes, and verification.

Tier 6 — Professional artifact. Produce a workflow contract including matrix dimensions and sparsity, preprocessing, task, $k$, oversampling $p$, power iterations, sketch size, $\varepsilon$, $\delta$, norm, pass and communication budget, seed/precision versioning, baseline sample, high-leverage tests, drift metrics, and rollback condition.

Debugging prompts: if regression residual rises, confirm the span includes $b$; if components change across seeds, inspect spectral gaps and oversampling; if sampling variance is large, inspect leverage and rescaling; if Frequent Directions overstates energy, audit shrinkage because the standard guarantee is one-sided; if results differ by machine, inspect precision and orthogonalization.

Stretch goal: compare the same low-rank result under Frobenius and spectral objectives. Show how a method may pass one and fail the other, then justify which norm the application actually needs.

Rubric (10 points): definitions and theorem scopes 2; exact baseline 2; sampling derivation 2; valid counterexamples 2; measurable workflow contract 2. Full credit requires separating objective accuracy, coefficient/vector stability, and domain interpretation.

Decision checklist: define the matrix task, fixed subspace or rank, error norm, probability, passes, precision, and validation objective; handle leverage and conditioning; version randomness and preprocessing; and test residuals on the original data. Unbiased is not concentrated, low Frobenius error is not low spectral error, and an accurate numerical subspace is not a causal explanation. These tools extend dimensionality reduction toward streaming covariance, large-scale regression, low-rank optimization, and graph or scientific matrix analytics.

Next in the Series

In Graph Streaming, we'll explore Summarize massive graphs from edge updates..