The Randomized SVD

Math 123: Mathematical Aspects of Data Analysis – Fall 2026

Published

November 24, 2026

Where we are

The Johnson–Lindenstrauss lemma says that for any fixed points \(\bfx_1,\ldots,\bfx_n\in\Rbb^d\), the map \(f(\bfx)=\bfG\bfx/\sqrt k\), with \(\bfG\in\Rbb^{k\times d}\) a matrix of independent \(N(0,1)\) entries, keeps every pairwise distance within a factor \(1\pm\epsilon\) once \(k\gtrsim\log(n)/\epsilon^2\), with high probability. Two features made it work: the random matrix is drawn without looking at the data, and Gaussians are well behaved enough that we can compute exactly what happens to each fixed vector.

Today we make the same move for a matrix. Instead of keeping distances, we use a random Gaussian matrix to find the top \(k\) singular directions of a large matrix \(\bfA\), which is what PCA, classical MDS, and every other spectral method we have seen actually needs. The main reference is the survey of Halko et al. (2011), which is very readable. Code and experiments for everything below are in the randomized SVD example.

The problem

Throughout, \(\bfA\in\Rbb^{n\times d}\) has rank \(r\) and SVD \[ \bfA=\bfU_r\Sigma_r\bfV_r^\top=\sum_{i=1}^r\sigma_i\bfu_i\bfv_i^\top, \qquad \sigma_1\geq\cdots\geq\sigma_r>0, \] and \(\bfA_k=\bfU_k\Sigma_k\bfV_k^\top\) is its rank-\(k\) truncated SVD. By the Eckart–Young theorem, \(\bfA_k\) is the best approximation of rank at most \(k\): \[ \min_{\operatorname{rank}(\bfB)\leq k}\|\bfA-\bfB\|_F =\|\bfA-\bfA_k\|_F =\Big(\sum_{j>k}\sigma_j^2\Big)^{1/2}. \] This is the benchmark! No method can do better!

The trouble is cost. A full SVD of an \(n\times d\) matrix takes on the order of \(nd\min(n,d)\) operations. For \(n=10^6\) and \(d=10^4\) that is about \(10^{14}\) operations, for a matrix with “only” \(10^{10}\) entries, and we usually want just \(k=10\) or \(100\) directions out of the \(10^4\) it computes.

The randomized SVD splits the work into two stages.

  • Stage A. Find a matrix \(\bfQ\in\Rbb^{n\times\ell}\) with orthonormal columns, with \(\ell\) a little larger than \(k\), such that \(\bfA\approx\bfQ\bfQ^\top\bfA\).
  • Stage B. Use \(\bfQ\) to compute an SVD of \(\bfQ\bfQ^\top\bfA\), exactly.

Since \(\bfQ^\top\bfQ=\bfI_\ell\), the matrix \(\bfQ\bfQ^\top\) is the orthogonal projection onto \(\operatorname{range}(\bfQ)\), so \(\bfQ\bfQ^\top\bfA\) projects each column of \(\bfA\) onto that subspace. Stage A is where the randomness lives, and where all of the approximation error comes from. Stage B is cheap, deterministic linear algebra, so we do it first.

Stage B: from a basis to an SVD

Proposition 1 (An SVD of the projected matrix) Let \(\bfQ\in\Rbb^{n\times\ell}\) have orthonormal columns, and let \(\bfB=\bfQ^\top\bfA\in\Rbb^{\ell\times d}\) have (thin) SVD \(\bfB=\widetilde\bfU\Sigma\bfV^\top\), with \(\widetilde\bfU\in\Rbb^{\ell\times\ell}\) orthogonal. Then \[ \bfQ\bfQ^\top\bfA=(\bfQ\widetilde\bfU)\,\Sigma\,\bfV^\top \] is an SVD of \(\bfQ\bfQ^\top\bfA\).

Proof. Clearly \(\bfQ\bfQ^\top\bfA=\bfQ\bfB=(\bfQ\widetilde\bfU)\Sigma\bfV^\top\), and \(\Sigma\) and \(\bfV\) already have the right form. It remains to check that \(\bfU=\bfQ\widetilde\bfU\) has orthonormal columns: \[ \bfU^\top\bfU =\widetilde\bfU^\top\bfQ^\top\bfQ\,\widetilde\bfU =\widetilde\bfU^\top\widetilde\bfU =\bfI_\ell. \]

The matrix \(\bfB\) is short and wide, \(\ell\times d\) with \(\ell\) small, so its SVD is cheap: about \(d\ell^2\) operations. So once we have a good \(\bfQ\), the rest is easy, and the quality of the final answer is the quality of the approximation \(\bfA\approx\bfQ\bfQ^\top\bfA\).

Stage A: sampling the range

How do we find a few vectors that span the important part of \(\operatorname{range}(\bfA)\) without computing the SVD? Multiply \(\bfA\) by a random vector. Let \(\bfomega\in\Rbb^d\) have independent \(N(0,1)\) entries. Using the SVD, \[ \bfA\bfomega=\sum_{i=1}^r\sigma_i\,(\bfv_i^\top\bfomega)\,\bfu_i. \] This is a random vector in \(\operatorname{range}(\bfA)\), and its component along \(\bfu_i\) has size proportional to \(\sigma_i\). So \(\bfA\bfomega\) is tilted towards the top singular directions, provided the random coefficients \(\bfv_i^\top\bfomega\) are not themselves lopsided. The next lemma says they are as well behaved as possible.

A rotation fact about Gaussians

The JL example showed that for a single fixed vector \(\bfv\), the inner product \(\bfv^\top\bfomega\) is \(N(0,\|\bfv\|^2)\), by the rule for sums of independent Gaussians. It also showed that inner products with different rows of \(\bfG\) are independent, because they use disjoint sets of entries. Here we need something new: the inner products \(\bfv_1^\top\bfomega,\ldots,\bfv_r^\top\bfomega\) all use the same entries of \(\bfomega\), so the earlier argument for independence does not apply.

Lemma 1 (Gaussians are rotation invariant) Let \(\bfV\in\Rbb^{d\times r}\) have orthonormal columns \(\bfv_1,\ldots,\bfv_r\), and let \(\bfOmega\in\Rbb^{d\times\ell}\) have independent \(N(0,1)\) entries. Then \(\bfV^\top\bfOmega\in\Rbb^{r\times\ell}\) also has independent \(N(0,1)\) entries. In particular (\(\ell=1\)), if \(\bfomega\in\Rbb^d\) has independent \(N(0,1)\) entries, then \(\bfv_1^\top\bfomega,\ldots,\bfv_r^\top\bfomega\) are independent \(N(0,1)\).

So the picture is: a standard Gaussian vector looks the same in every orthonormal basis, so in the basis of right singular vectors its coordinates \(g_i=\bfv_i^\top\bfomega\) are again independent standard Gaussians, and \[ \bfA\bfomega=\sum_{i=1}^r\sigma_ig_i\bfu_i, \qquad g_1,\ldots,g_r\text{ independent }N(0,1). \]

Example 1 (A sample is weighted by the singular values) If \(\bfA\) has singular values \(100\), \(10\), and \(1\), then \(\bfA\bfomega=100\,g_1\bfu_1+10\,g_2\bfu_2+g_3\bfu_3\). The coefficient of \(\bfu_1\) is typically ten times that of \(\bfu_2\) and a hundred times that of \(\bfu_3\), so a single sample \(\bfA\bfomega\) already points mostly along \(\bfu_1\).

Many samples at once

One sample finds one direction; to find \(k\), take \(\ell\geq k\) samples at once. Draw \(\bfOmega\in\Rbb^{d\times\ell}\) with independent \(N(0,1)\) entries, form the sketch \[ \underbrace{\bfY}_{n\times\ell}=\underbrace{\bfA}_{n\times d}\,\underbrace{\bfOmega}_{d\times\ell}, \] and let \(\bfQ\) have orthonormal columns spanning \(\operatorname{range}(\bfY)\). In exact arithmetic, Gram–Schmidt on the columns of \(\bfY\) produces \(\bfQ\); numerically, one uses a QR factorization, np.linalg.qr(Y), which does the same thing stably.

When \(\bfA\) is exactly low rank, this already recovers everything. To prove it, we need one more fact about Gaussian matrices.

Lemma 2 (Square Gaussian matrices are invertible) If \(\bfG\in\Rbb^{k\times k}\) has independent \(N(0,1)\) entries, then \(\bfG\) is invertible with probability \(1\).

The Gaussian distribution matters here. A \(k\times k\) matrix with independent random \(\pm1\) entries is singular with positive probability: for instance, its first two columns are equal with probability \(2^{-k}\).

Theorem 1 (Exactly low rank: one sketch is enough) Suppose \(\operatorname{rank}(\bfA)=k\) and \(\ell\geq k\). Then with probability \(1\), \(\operatorname{range}(\bfY)=\operatorname{range}(\bfA)\), and so \(\bfQ\bfQ^\top\bfA=\bfA\).

Proof. Each column of \(\bfY=\bfA\bfOmega\) is \(\bfA\) times a vector, so \(\operatorname{range}(\bfY)\subseteq\operatorname{range}(\bfA)\). Since \(\operatorname{range}(\bfA)\) has dimension \(k\), it suffices to show that \(\operatorname{range}(\bfY)\) also has dimension \(k\).

Since \(\bfA=\bfU_k\Sigma_k\bfV_k^\top\), \[ \bfY=\bfU_k\Sigma_k\bfG, \qquad \bfG=\bfV_k^\top\bfOmega\in\Rbb^{k\times\ell}. \] By Lemma 1, \(\bfG\) has independent \(N(0,1)\) entries. Its first \(k\) columns form a \(k\times k\) matrix with independent \(N(0,1)\) entries, which is invertible with probability \(1\) by Lemma 2. When this happens, those \(k\) columns already span \(\Rbb^k\), so \(\operatorname{range}(\bfG)=\Rbb^k\). Then \[ \operatorname{range}(\bfY) =\{\bfU_k\Sigma_k\bfG\bfc:\bfc\in\Rbb^\ell\} =\{\bfU_k\Sigma_k\bfx:\bfx\in\Rbb^k\} =\operatorname{span}(\sigma_1\bfu_1,\ldots,\sigma_k\bfu_k). \] The vectors \(\sigma_1\bfu_1,\ldots,\sigma_k\bfu_k\) are nonzero and orthogonal, hence linearly independent, so this span has dimension \(k\). This proves \(\operatorname{range}(\bfY)=\operatorname{range}(\bfA)\).

Finally, \(\operatorname{range}(\bfQ)=\operatorname{range}(\bfY)=\operatorname{range}(\bfA)\), so every column of \(\bfA\) lies in \(\operatorname{range}(\bfQ)\). The orthogonal projection \(\bfQ\bfQ^\top\) leaves vectors in \(\operatorname{range}(\bfQ)\) unchanged, so \(\bfQ\bfQ^\top\bfA=\bfA\).

When \(\ell>k\), the sketch \(\bfY\) has \(\ell\) columns but rank only \(k\), so a matrix \(\bfQ\) with orthonormal columns spanning \(\operatorname{range}(\bfY)\) has only \(k\) columns. In practice np.linalg.qr(Y) still returns \(\ell\) orthonormal columns, whose span contains \(\operatorname{range}(\bfY)\). The last step of the proof only needs \(\operatorname{range}(\bfA)\subseteq\operatorname{range}(\bfQ)\), so the conclusion \(\bfQ\bfQ^\top\bfA=\bfA\) holds either way.

Approximately low rank: oversample

Real matrices are almost never exactly low rank; more typically, \(\sigma_{k+1},\sigma_{k+2},\ldots\) are small but not zero. Then each sample has the form \[ \bfA\bfomega =\underbrace{\sum_{i\leq k}\sigma_ig_i\bfu_i}_{\text{what we want}} +\underbrace{\sum_{j>k}\sigma_jg_j\bfu_j}_{\text{tail}}, \] and the tail tilts each sample slightly away from \(\operatorname{range}(\bfU_k)\). With exactly \(\ell=k\) samples there is no room to correct for this. The fix is to oversample: take \(\ell=k+p\) samples, with a small \(p\) such as \(5\) or \(10\). The following theorem, which we state without proof, says this is enough.

Theorem 2 (Average error of the randomized range finder (Halko et al. 2011, Theorem 10.5)) Let \(k,p\geq2\) with \(k+p\leq\min(n,d)\), let \(\bfOmega\in\Rbb^{d\times(k+p)}\) have independent \(N(0,1)\) entries, and let \(\bfQ\) have orthonormal columns spanning \(\operatorname{range}(\bfA\bfOmega)\). Then \[ \Ebb\,\|\bfA-\bfQ\bfQ^\top\bfA\|_F \leq\sqrt{1+\frac{k}{p-1}}\;\Big(\sum_{j>k}\sigma_j^2\Big)^{1/2}. \]

The right side is a constant times the Eckart–Young optimum, and the constant does not depend on \(n\), \(d\), or the singular values at all. For \(k=p=10\) it is \(\sqrt{1+10/9}\approx1.45\), and taking \(p=k+1\) gives exactly \(\sqrt2\), for every \(k\). Halko et al. (2011) also prove that the error is very unlikely to be much larger than its mean, so a single draw of \(\bfOmega\) is reliable; this is the same story as for Johnson–Lindenstrauss. In the experiments, the observed error is well below the bound.

Truncating back to rank \(k\)

The matrix \(\bfQ\bfQ^\top\bfA\) has rank up to \(k+p\), so its error can even be smaller than the Eckart–Young optimum for rank \(k\). To return a genuine rank-\(k\) approximation, we keep only the top \(k\) singular triples from Proposition 1, which is the same as replacing \(\bfB\) by its truncated SVD \(\bfB_k\). This costs little.

Proposition 2 (The cost of truncating) Let \(\bfQ\in\Rbb^{n\times\ell}\) have orthonormal columns, \(\bfB=\bfQ^\top\bfA\), and \(\bfB_k\) the rank-\(k\) truncated SVD of \(\bfB\). Then \[ \|\bfA-\bfQ\bfB_k\|_F\leq\|\bfA-\bfQ\bfQ^\top\bfA\|_F+\|\bfA-\bfA_k\|_F. \]

Proof. Write \(\bfA-\bfQ\bfB_k=(\bfA-\bfQ\bfQ^\top\bfA)+\bfQ(\bfB-\bfB_k)\) and use the triangle inequality. Multiplying by \(\bfQ\) does not change the Frobenius norm, since \(\|\bfQ\bfy\|_2=\|\bfy\|_2\) for each column \(\bfy\). So it suffices to show \(\|\bfB-\bfB_k\|_F\leq\|\bfA-\bfA_k\|_F\). The matrix \(\bfQ^\top\bfA_k\) has rank at most \(k\), so by Eckart–Young applied to \(\bfB\), \[ \|\bfB-\bfB_k\|_F \leq\|\bfB-\bfQ^\top\bfA_k\|_F =\|\bfQ^\top(\bfA-\bfA_k)\|_F =\|\bfQ\bfQ^\top(\bfA-\bfA_k)\|_F \leq\|\bfA-\bfA_k\|_F. \] The last step applies the Pythagorean property of projections to each column of \(\bfA-\bfA_k\): projecting a vector can only shorten it.

Combined with Theorem 2, the rank-\(k\) output has expected error at most \(\big(1+\sqrt{1+k/(p-1)}\big)\) times the optimum. This bound is pessimistic: in the experiments, truncating raises the error by at most about a quarter, and often by only a few percent.

The algorithm

Algorithm 1 (Randomized SVD) Input: \(\bfA\in\Rbb^{n\times d}\), a target rank \(k\), and an oversampling parameter \(p\) (default \(p=10\)). Let \(\ell=k+p\).

  1. Draw \(\bfOmega\in\Rbb^{d\times\ell}\) with independent \(N(0,1)\) entries.
  2. Form \(\bfY=\bfA\bfOmega\), and compute \(\bfQ\in\Rbb^{n\times\ell}\) with orthonormal columns spanning \(\operatorname{range}(\bfY)\).
  3. Form \(\bfB=\bfQ^\top\bfA\in\Rbb^{\ell\times d}\), and its SVD \(\bfB=\widetilde\bfU\Sigma\bfV^\top\).
  4. Set \(\bfU=\bfQ\widetilde\bfU\), and return the first \(k\) columns of \(\bfU\) and \(\bfV\) and the first \(k\) singular values.
TipThe randomized SVD in NumPy
import numpy as np


def randomized_svd(A, k, p=10, rng=None):
    rng = np.random.default_rng(rng)
    Omega = rng.standard_normal((A.shape[1], k + p))
    Q, _ = np.linalg.qr(A @ Omega)  # orthonormal basis for range(A Omega)
    U_tilde, s, Vt = np.linalg.svd(Q.T @ A, full_matrices=False)
    return (Q @ U_tilde)[:, :k], s[:k], Vt[:k]

What it costs

With \(\ell=k+p\), and counting multiplications:

Step Operations
\(\bfY=\bfA\bfOmega\) \(nd\ell\)
\(\bfQ\) from \(\bfY\) (QR) about \(n\ell^2\)
\(\bfB=\bfQ^\top\bfA\) \(nd\ell\)
SVD of \(\bfB\) about \(d\ell^2\)
\(\bfU=\bfQ\widetilde\bfU\) \(n\ell^2\)

Since \(\ell\ll\min(n,d)\), the two products with \(\bfA\) dominate, for a total of about \(2nd\ell\), compared with \(nd\min(n,d)\) for the full SVD. For \(n=10^6\), \(d=10^4\), and \(\ell=20\), that is \(4\times10^{11}\) instead of \(10^{14}\), about \(250\) times less work.

The operation count understates the advantage. The algorithm touches \(\bfA\) only through the two products \(\bfA\bfOmega\) and \(\bfQ^\top\bfA\), so

  • if \(\bfA\) is sparse, each product costs only as much as the number of nonzero entries;
  • if \(\bfA\) is too large for memory, it can be read from disk in blocks of rows, in two passes;
  • matrix–matrix products are the operation computers do fastest, and they parallelize well.

When the singular values of \(\bfA\) decay slowly, the tail in each sample is large, and the basic algorithm can be noticeably worse than the exact SVD. The standard fix, power iterations, is in the power iterations example.

References

Halko, N., P. G. Martinsson, and J. A. Tropp. 2011. “Finding Structure with Randomness: Probabilistic Algorithms for Constructing Approximate Matrix Decompositions.” SIAM Review 53 (2): 217–88. https://doi.org/10.1137/090771806.