Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Advanced linear algebra

Randomized Linear Algebra: Random Projections, Johnson–Lindenstrauss, Randomized SVD

Randomness is a precision tool. Multiplying by a random matrix squeezes huge data into a few dimensions while keeping its geometry, and turns giant SVDs, least-squares problems and trace computations into cheap ones, with guarantees.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A shadow that keeps the distances

Shine a light on a 3-D object and its shadow on the wall is flat. Some information is lost. Now imagine points in a space with thousands of dimensions. Surprisingly, if you cast their “shadow” onto a random lower-dimensional wall, the distances between the points barely change.

This is the Johnson–Lindenstrauss lemma. It’s one of the most useful surprises in mathematics.

Random projection: 500 dimensions → k, distances (almost) kept
0.50.7511.251.5
all 780 pairwise distances kept within ±29.2% · storage 500 → 50 numbers per point (10.0× smaller)
Histogram of (new distance) / (old distance); orange line = perfect. JL guarantee for 40 points at ε = 0.29: k ≥ 4 ln n / (ε²/2 − ε³/3) = 429. The guarantee is conservative; in practice far fewer dimensions already work. Note that d = 500 never enters the formula.
Why engineers care

A Mars rover or a deep-space probe can only send back a trickle of data. Random projections (and their cousin, compressed sensing) let a spacecraft send a short random summary of an image or signal, from which the important structure can be recovered on Earth.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A random projection to fewer dimensions keeps distances…
  2. 2. How many dimensions you need depends on…
  3. 3. A shadow of a 3-D object on a wall has how many dimensions?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Random projection

Take a matrix S∈Rk×dS\in\mathbb R^{k\times d} with independent N(0,1)\mathcal N(0,1) entries and map x↦1kSx\mathbf x\mapsto\frac1{\sqrt k}S\mathbf x. The scaling makes lengths right on average:

E∥1kSx∥2=∥x∥2\mathbb E\Big\lVert\tfrac1{\sqrt k}S\mathbf x\Big\rVert^2 = \lVert\mathbf x\rVert^2

Each output coordinate is a random weighted sum of all the inputs, so it’s a fair “vote” on the length. With kk votes, the average is accurate to about ±2/k\pm\sqrt{2/k}.

How many dimensions?

k ≳ log⁡nε2k\ \gtrsim\ \frac{\log n}{\varepsilon^2}
  • It depends on the number of points nn, only logarithmically.
  • It does not depend on the original dimension dd. That’s the magic: 1,000 points in a million dimensions need the same kk as 1,000 points in 100 dimensions.
  • Halving ε\varepsilon costs 4× the dimensions.
📝 Quick check (Level 1)
0/3 answered
  1. 1. ‖x‖ = 3. The expected ‖(1/√k)Sx‖² = ?
  2. 2. Going from 10³ to 10⁶ points multiplies the needed k by…
  3. 3. Halving ε multiplies k by…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

The Johnson–Lindenstrauss lemma

Lemma (Johnson–Lindenstrauss, 1984; constants from Dasgupta and Gupta, 2003)

For any nn points in Rd\mathbb R^d and 0<ε<10<\varepsilon<1, if k≥4ln⁡nε2/2−ε3/3k\ge\dfrac{4\ln n}{\varepsilon^2/2 - \varepsilon^3/3}, then a random Gaussian map f(x)=Sx/kf(\mathbf x) = S\mathbf x/\sqrt k satisfies (1−ε)∥xi−xj∥2≤∥f(xi)−f(xj)∥2≤(1+ε)∥xi−xj∥2(1-\varepsilon)\lVert\mathbf x_i - \mathbf x_j\rVert^2\le\lVert f(\mathbf x_i) - f(\mathbf x_j)\rVert^2\le(1+\varepsilon)\lVert\mathbf x_i - \mathbf x_j\rVert^2 for all pairs with probability at least 1/n1/n. Repeating the draw a few times makes success virtually certain.

🐍 Exercise 1: random projection of 100 points in 5,000 dimensions
Project with a scaled Gaussian matrix, and measure the worst distortion over all 4,950 pairs for k = 50, 200 and 800.

The randomized toolbox

Task Randomized method Cost instead of
Top-kk SVD of m×nm\times n AA range finder: Y=AΩY = A\Omega, Q=qr⁡(Y)Q = \operatorname{qr}(Y), SVD of Q⊤AQ^\top A (A2.3-6) O(mnk)O(mnk) vs O(mnmin⁡(m,n))O(mn\min(m,n))
Least squares, N≫dN\gg d sketch-and-solve: min⁡∥S(Ax−b)∥\min\lVert S(A\mathbf x - \mathbf b)\rVert with SS of size m×Nm\times N, m∼d/εm\sim d/\varepsilon a problem N/mN/m times smaller
tr⁡(A)\operatorname{tr}(A) from products only Hutchinson: E[z⊤Az]=tr⁡A\mathbb E[\mathbf z^\top A\mathbf z] = \operatorname{tr}A never forming AA
Kernel methods random Fourier features z(x)⋅z(y)≈k(x,y)z(\mathbf x)\cdot z(\mathbf y)\approx k(\mathbf x,\mathbf y) O(n2)O(n^2) kernel matrix
Nearest-neighbour search JL + locality-sensitive hashing high-dimensional distances

The randomized SVD needs two tricks for accuracy. Oversampling means using k+pk + p random vectors, with p≈5p\approx5–1010. Power iterations, Y=(AA⊤)qAΩY = (AA^\top)^qA\Omega, raise the singular values to the power 2q+12q+1, which sharpens a slowly decaying spectrum.

📝 Quick check (Level 2)
0/3 answered
  1. 1. Variance of ‖Sx‖²/‖x‖² for a Gaussian sketch with k = 200?
  2. 2. Randomized SVD with target rank 10 and oversampling 5 draws how many random vectors?
  3. 3. Hutchinson's estimator for A = diag(1, 2, 3) has expected value…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Why it works: concentration

For a fixed unit vector x\mathbf x, each coordinate of SxS\mathbf x is N(0,1)\mathcal N(0,1) (a sum of Gaussians, by rotation invariance). Hence ∥Sx∥2∼χk2\lVert S\mathbf x\rVert^2\sim\chi^2_k, with mean kk and variance 2k2k. A Chernoff bound on the chi-square distribution gives

Pr⁡[∣1k∥Sx∥2−1∣>ε]≤2exp⁡ ⁣(−k2(ε22−ε33))\Pr\Big[\big\lvert\tfrac1k\lVert S\mathbf x\rVert^2 - 1\big\rvert>\varepsilon\Big]\le2\exp\!\big(-\tfrac k2(\tfrac{\varepsilon^2}2 - \tfrac{\varepsilon^3}3)\big)

Apply this to each of the (n2)\binom n2 difference vectors and use a union bound. Choosing kk as in the lemma makes the total failure probability less than 1. ∎ No property of the data was used, and that’s why dd never appears.

Is log⁡n/ε2\log n/\varepsilon^2 necessary?

Yes. Larsen and Nelson (2017) proved that JL’s dimension is optimal for linear and nonlinear maps alike. Faster variants keep the guarantee with cheaper matrices: sparse ±1 matrices (Achlioptas, 2003), the Fast JL transform (FFT plus random signs, Ailon and Chazelle, 2009) and CountSketch.

Hutchinson’s variance

For Rademacher z\mathbf z (random ±1\pm1), Var⁡(z⊤Az)=2∑i≠jaij2\operatorname{Var}(\mathbf z^\top A\mathbf z) = 2\sum_{i\ne j}a_{ij}^2 for symmetric AA, so the diagonal contributes no noise. For Gaussian z\mathbf z, the variance is 2∥A∥F22\lVert A\rVert_F^2. Averaging mm samples divides the variance by mm. Newer methods (Hutch++, Meyer et al., 2021) combine a randomized low-rank part with Hutchinson to reach error O(1/m)O(1/m).

Exercise 3.1: Show E‖Sx‖² = k‖x‖² for Gaussian S

E∥Sx∥2=∑rE(∑jsrjxj)2=∑r∑jxj2 E[srj2]=k∥x∥2\mathbb E\lVert S\mathbf x\rVert^2 = \sum_r\mathbb E\big(\sum_js_{rj}x_j\big)^2 = \sum_r\sum_jx_j^2\,\mathbb E[s_{rj}^2] = k\lVert\mathbf x\rVert^2. The cross terms vanish because the entries are independent with mean 0.

📝 Quick check (Level 3)
0/3 answered
  1. 1. ‖Sx‖² for unit x and Gaussian S (k rows) follows…
  2. 2. How many difference vectors does the union bound cover for 100 points?
  3. 3. Is the log n / ε² dimension optimal?

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Randomized numerical linear algebra in practice

Halko, Martinsson and Tropp (2011) made randomized SVD a standard tool. It’s what sklearn’s randomized_svd and many PCA implementations use on large data. Their bound, for oversampling p≥2p\ge2, is

E∥A−QQ⊤A∥≤(1+kp−1)σk+1+ek+pp(∑j>kσj2)1/2\mathbb E\lVert A - QQ^\top A\rVert\le\Big(1 + \sqrt{\tfrac{k}{p-1}}\Big)\sigma_{k+1} + \frac{e\sqrt{k+p}}{p}\Big(\sum_{j>k}\sigma_j^2\Big)^{1/2}

Randomized solvers (Blendenpik, LSRN) beat LAPACK on huge least-squares problems, and sketching is used for streaming data and for low-memory optimizer states.

🐍 Exercise 2 (research): Hutchinson trace estimation
Estimate tr(A) using only matrix–vector products, with Rademacher and Gaussian probes. Check the 1/√m error decay. This is how Hessian traces and log-determinants are estimated in deep learning.

Where randomness pays off

  • Machine learning at scale: random features for kernels (Rahimi and Recht, 2007, the NeurIPS test-of-time award), sketching for second-order optimizers, Hessian trace and spectrum estimates for loss-landscape analysis (Hutchinson, stochastic Lanczos), and low-rank gradient compression (PowerSGD, A2.3-6).
  • Compressed sensing (Candès, Romberg and Tao, 2006; Donoho, 2006): random measurements of a sparse signal allow exact recovery from far fewer samples. It has been applied to MRI, single-pixel cameras and spaceborne imaging.
  • Robotics: random projections speed up nearest-neighbour lookups for place recognition and loop closure in SLAM. Sketched Gaussian processes and Kalman filters scale estimation to many sensors.
  • Privacy: random projections underlie some differentially private releases of data summaries.

References

  1. W. Johnson, J. Lindenstrauss (1984). “Extensions of Lipschitz mappings into a Hilbert space.” Contemporary Mathematics, 26.
  2. S. Dasgupta, A. Gupta (2003). “An elementary proof of a theorem of Johnson and Lindenstrauss.” Random Structures & Algorithms, 22(1).
  3. D. Achlioptas (2003). “Database-friendly random projections.” Journal of Computer and System Sciences, 66(4).
  4. A. Rahimi, B. Recht (2007). “Random features for large-scale kernel machines.” NeurIPS.
  5. M. Hutchinson (1990). “A stochastic estimator of the trace of the influence matrix for Laplacian smoothing splines.” Communications in Statistics – Simulation and Computation, 19(2).
  6. N. Halko, P.-G. Martinsson, J. Tropp (2011). “Finding structure with randomness.” SIAM Review, 53(2).
  7. K. G. Larsen, J. Nelson (2017). “Optimality of the Johnson–Lindenstrauss lemma.” FOCS.
  8. P.-G. Martinsson, J. Tropp (2020). “Randomized numerical linear algebra: Foundations and algorithms.” Acta Numerica, 29.
  9. E. Candès, J. Romberg, T. Tao (2006). “Robust uncertainty principles: exact signal reconstruction from highly incomplete frequency information.” IEEE Transactions on Information Theory, 52(2).