The power method
The whole book is also in the PDF.
This chapter extends the eigendecomposition story of Chapter 4 to arbitrary matrices via the Singular Value Decomposition, then explores the relationship between both decompositions and optimization. We reframe the search for a matrix’s dominant eigenvector as an optimization problem, specifically the maximization of a quadratic form over the unit sphere. This perspective naturally gives rise to the Power Method, an elegant and efficient iterative algorithm, which we derive, analyze, and extend with the concept of deflation to find multiple eigenpairs. In the next chapter, we will reverse our viewpoint, using eigendecomposition as a powerful analytical lens to understand optimization.
Keywords. Eigenvalue Decomposition | Singular Value Decomposition | Optimization | Power Method | Deflation | Rank-One Approximation | Rayleigh Quotient | Pseudoinverse | Condition Number
5.1 From Eigendecomposition to the Singular Value Decomposition
Chapter 4 built the theory of eigendecomposition \(\mathbf{A} = \mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^{-1}\) and then immediately confessed two limitations. First, the spectral theorem only diagonalizes symmetric matrices, in the cleaner orthonormal form \(\mathbf{A} = \mathbf{Q}\boldsymbol{\Lambda}\mathbf{Q}^\top\) (with \(\mathbf{Q}\) orthogonal); for non-symmetric \(\mathbf{A}\), the eigenvectors \(\mathbf{V}\) need not be orthogonal and may not even be real. Second, the Moore–Penrose pseudoinverse was stated as \(\mathbf{A}^\dagger = (\mathbf{A}^\top\mathbf{A})^{-1}\mathbf{A}^\top\), which is well-defined only when \(\mathbf{A}\) has full column rank.
But the matrices we actually encounter in AI are almost never square or symmetric. A feature matrix \(\mathbf{X} \in \mathbb{R}^{n \times d}\) has \(n \gg d\). A user–movie rating matrix has hundreds of thousands of rows and tens of thousands of columns. A word-document matrix in natural-language processing has millions of rows and billions of columns. Eigendecomposition simply does not apply.
The Singular Value Decomposition (SVD) extends the same diagonalize-by-a-change-of-basis idea to arbitrary matrices: any shape, any rank, no symmetry required. It is the single most important matrix decomposition in numerical linear algebra and in AI.
5.1.1 The SVD: Statement
Definition 5.1 (Singular Value Decomposition). For every matrix \(\mathbf{A} \in \mathbb{R}^{m \times n}\) there exist orthogonal matrices \(\mathbf{U} \in \mathbb{R}^{m \times m}\) and \(\mathbf{V} \in \mathbb{R}^{n \times n}\) and a diagonal matrix \(\boldsymbol{\Sigma} \in \mathbb{R}^{m \times n}\) such that
\[ \mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top. \]The diagonal entries \(\sigma_1 \geq \sigma_2 \geq \cdots \geq \sigma_r > 0 = \sigma_{r+1} = \cdots = \sigma_{\min(m,n)}\) are the singular values of \(\mathbf{A}\), with \(r = \mathrm{rank}(\mathbf{A})\). The columns of \(\mathbf{U}\) are the left singular vectors; the columns of \(\mathbf{V}\) are the right singular vectors.
The SVD has three remarkable features that the eigendecomposition lacks: (a) it exists for every matrix without exception, (b) the factors \(\mathbf{U}\) and \(\mathbf{V}\) are always orthogonal (so \(\mathbf{U}^{-1} = \mathbf{U}^\top\) and \(\mathbf{V}^{-1} = \mathbf{V}^\top\): inverting them is free), and (c) the singular values are uniquely determined and non-negative.
5.1.2 Geometric Interpretation: Rotate \(\to\) Scale \(\to\) Rotate
The factorization \(\mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top\) decomposes the linear map \(\mathbf{x} \mapsto \mathbf{A}\mathbf{x}\) into three geometric steps:
- \(\mathbf{V}^\top \mathbf{x}\): an orthogonal change of basis in the input space (rotation + possibly reflection).
- \(\boldsymbol{\Sigma}(\mathbf{V}^\top \mathbf{x})\): axis-aligned scaling: multiply coordinate \(i\) by \(\sigma_i\) (when \(m \neq n\), this step also adds or drops coordinates to change the dimension).
- \(\mathbf{U}(\boldsymbol{\Sigma}\mathbf{V}^\top \mathbf{x})\): an orthogonal change of basis in the output space.
From here on we call \(\mathbf{U}\) and \(\mathbf{V}\) rotations, though they may also reflect. What matters is that they do not change lengths (Chapter 4). A unit sphere in \(\mathbb{R}^n\) is mapped to an ellipsoid in \(\mathbb{R}^m\) whose semi-axes have lengths \(\sigma_i\) in the directions \(\mathbf{u}_i\). The matrix \(\mathbf{A}\) “stretches space” by the factor \(\sigma_1\) in the most-stretched direction, by \(\sigma_2\) in the next-most-stretched direction orthogonal to the first, and so on. This is the cleanest geometric story available for a general linear transformation.
Chapter 3 measured the size of a matrix by its entries. This picture gives another measure: what the matrix does to vectors. The spectral norm of a matrix \(\mathbf{M}\) is its largest stretch:
\[ \begin{aligned} \|\mathbf{M}\|_2 = \max_{\|\mathbf{x}\|_2 = 1} \|\mathbf{M}\mathbf{x}\|_2 = \sigma_1(\mathbf{M}). \end{aligned} \]The reason: the two rotations do not change lengths, and the scaling step multiplies coordinate \(i\) by \(\sigma_i\). So \(\mathbf{M}\) stretches a unit vector by at most \(\sigma_1\), and by exactly \(\sigma_1\) along \(\mathbf{v}_1\). Careful: this is not the Frobenius norm \(\|\mathbf{M}\|_F\), which Chapter 3 called the matrix \(\ell_2\)-norm. For the \(2 \times 2\) identity, \(\|\mathbf{I}\|_2 = 1\) but \(\|\mathbf{I}\|_F = \sqrt{2}\). We will use the spectral norm for approximation errors and for the condition number, both below.
5.1.3 Connection to the Spectral Theorem
The SVD is not pulled from thin air: it follows from the spectral theorem of Chapter 4 applied to the symmetric matrices \(\mathbf{A}^\top\mathbf{A}\) and \(\mathbf{A}\mathbf{A}^\top\). Substituting \(\mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top\),
\[ \mathbf{A}^\top\mathbf{A} = \mathbf{V}\boldsymbol{\Sigma}^\top\mathbf{U}^\top\mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top = \mathbf{V}\boldsymbol{\Sigma}^\top\boldsymbol{\Sigma}\mathbf{V}^\top. \]This is the eigendecomposition of \(\mathbf{A}^\top\mathbf{A}\): its eigenvectors are the right singular vectors \(\mathbf{v}_i\), and its eigenvalues are \(\sigma_i^2\). Symmetrically, \(\mathbf{A}\mathbf{A}^\top = \mathbf{U}\boldsymbol{\Sigma}\boldsymbol{\Sigma}^\top\mathbf{U}^\top\) has eigenvectors \(\mathbf{u}_i\) and the same non-zero eigenvalues \(\sigma_i^2\).
This gives a conceptually clean (if numerically suboptimal) algorithm: form \(\mathbf{A}^\top\mathbf{A}\), eigendecompose it to extract \((\sigma_i^2, \mathbf{v}_i)\), and recover \(\mathbf{u}_i = \mathbf{A}\mathbf{v}_i / \sigma_i\). The Power Method and deflation of this chapter, built for symmetric matrices, carry out this route when run on \(\mathbf{A}^\top\mathbf{A}\), without ever forming it; the last part of the deflation section shows how. Why the route through \(\mathbf{A}^\top\mathbf{A}\) is numerically suboptimal is explained with the condition number below.
Example 5.1 (A \(2\times 3\) matrix decomposed by hand). Let
\[ \mathbf{A} = \begin{bmatrix} 3 & 1 & 1 \\ -1 & 3 & 1 \end{bmatrix}. \]We use the smaller side: form \(\mathbf{A}\mathbf{A}^\top = \begin{bmatrix} 11 & 1 \\ 1 & 11 \end{bmatrix}\). Its characteristic polynomial \((11 - \lambda)^2 - 1 = 0\) gives eigenvalues \(\lambda \in \{12, 10\}\), so \(\sigma_1 = 2\sqrt{3} \approx 3.46\) and \(\sigma_2 = \sqrt{10} \approx 3.16\). The eigenvectors, which are the columns of \(\mathbf{U}\), are \(\mathbf{u}_1 = (1,1)^\top/\sqrt{2}\) and \(\mathbf{u}_2 = (1,-1)^\top/\sqrt{2}\). The right singular vectors then come from \(\mathbf{v}_i = \mathbf{A}^\top \mathbf{u}_i / \sigma_i\):
\[ \begin{aligned} \mathbf{v}_1 &= \tfrac{1}{\sqrt{6}}(1, 2, 1)^\top, \quad \mathbf{v}_2 = \tfrac{1}{\sqrt{5}}(2, -1, 0)^\top. \end{aligned} \]A third right singular vector lives in the nullspace of \(\mathbf{A}\): \(\mathbf{v}_3 = (1, 2, -5)^\top/\sqrt{30}\). The reader can verify \(\mathbf{A}\mathbf{v}_3 = \mathbf{0}\) and that \(\mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top\) recovers \(\mathbf{A}\).
5.1.4 Thin SVD and Low-Rank Approximation
When \(\mathbf{A}\) has rank \(r < \min(m,n)\) (or when we only care about the leading directions), we can drop the trailing zero singular values. The thin SVD writes
\[ \mathbf{A} = \sum_{i=1}^{r} \sigma_i \mathbf{u}_i \mathbf{v}_i^\top, \]expressing \(\mathbf{A}\) as a sum of \(r\) rank-1 matrices, each carrying “weight” \(\sigma_i\). The rank-\(k\) truncation keeps only the largest \(k\) terms:
\[ \mathbf{A}_k = \sum_{i=1}^{k} \sigma_i \mathbf{u}_i \mathbf{v}_i^\top. \]Keeping the \(k\) largest terms gives the best rank-\(k\) approximation. To make “best” precise, we state it as an optimization problem. We look for the matrix \(\mathbf{B}\) of rank at most \(k\) that is closest to \(\mathbf{A}\). Distance is the Frobenius norm of Chapter 3: square every entry, add them up, take the square root.
The truncation \(\mathbf{A}_k\) is a sum of \(k\) rank-one matrices, so its rank is at most \(k\): it is a candidate.
Theorem 5.1 (Eckart–Young). The rank-\(k\) truncation \(\mathbf{A}_k\) solves problem (5.1): no matrix of rank at most \(k\) is closer to \(\mathbf{A}\). The smallest possible error is the sum of the squared singular values that \(\mathbf{A}_k\) leaves out:
\[ \begin{aligned} \|\mathbf{A} - \mathbf{A}_k\|_F^2 = \sum_{i > k} \sigma_i^2 . \end{aligned} \]With the spectral norm in place of the Frobenius norm, the smallest value of \(\|\mathbf{A} - \mathbf{B}\|_2\) is \(\sigma_{k+1}\) (no squares and no sum), and \(\mathbf{A}_k\) again reaches it.
Dropping a term costs exactly its squared weight. Two different terms have matrix inner product zero (Chapter 3): for \(i \neq j\),
\[ \begin{aligned} \langle \sigma_i\mathbf{u}_i\mathbf{v}_i^\top, \sigma_j\mathbf{u}_j\mathbf{v}_j^\top \rangle = \sigma_i\sigma_j(\mathbf{u}_i^\top\mathbf{u}_j)(\mathbf{v}_i^\top\mathbf{v}_j) = 0 . \end{aligned} \]Chapter 3’s identity for the norm of a sum, \(\|\mathbf{M}_1 + \mathbf{M}_2\|_F^2 = \|\mathbf{M}_1\|_F^2 + 2\langle \mathbf{M}_1, \mathbf{M}_2 \rangle + \|\mathbf{M}_2\|_F^2\), then says that their squared norms add up. Each term has \(\|\sigma_i\mathbf{u}_i\mathbf{v}_i^\top\|_F^2 = \sigma_i^2\), because \(\mathbf{u}_i\) and \(\mathbf{v}_i\) have length 1. Hence \(\|\mathbf{A}\|_F^2 = \sigma_1^2 + \dots + \sigma_r^2\), and dropping term \(i\) loses exactly \(\sigma_i^2\). To lose the least, drop the smallest. The theorem claims more: no matrix of rank at most \(k\), built from any vectors, gets closer. We do not prove that part. The next section proves one special case from scratch: \(k = 1\), a symmetric \(\mathbf{A}\), and \(\mathbf{B}\) of the form \(\lambda\mathbf{x}\mathbf{x}^\top\).
Example 5.2 (Eckart–Young on a small matrix). Take the matrix of Example 5.1, \(\mathbf{A} = \begin{bmatrix} 3 & 1 & 1 \\ -1 & 3 & 1 \end{bmatrix}\), with \(\sigma_1^2 = 12\) and \(\sigma_2^2 = 10\). Its best rank-one approximation keeps the first term:
\[ \begin{aligned} \mathbf{A}_1 = \sigma_1\mathbf{u}_1\mathbf{v}_1^\top = 2\sqrt{3} \cdot \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ 1 \end{bmatrix} \frac{1}{\sqrt{6}}\begin{bmatrix} 1 & 2 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 2 & 1 \\ 1 & 2 & 1 \end{bmatrix}, \end{aligned} \]because \(2\sqrt{3}/(\sqrt{2}\sqrt{6}) = 2\sqrt{3}/\sqrt{12} = 1\). The theorem predicts the error \(\sigma_2^2 = 10\). Check: \(\mathbf{A} - \mathbf{A}_1 = \left[\begin{smallmatrix} 2 & -1 & 0 \\ -2 & 1 & 0 \end{smallmatrix}\right]\), and the squares of its entries add up to \(4 + 1 + 0 + 4 + 1 + 0 = 10\). Two other rank-one guesses do worse:
- keep the first row of \(\mathbf{A}\) and set the second to zero: the error is \((-1)^2 + 3^2 + 1^2 = 11\);
- keep the second term \(\sigma_2\mathbf{u}_2\mathbf{v}_2^\top\) instead of the first: the error is \(\sigma_1^2 = 12\).
By the theorem, no rank-one matrix gets below \(10\).
Storage cost: \(\mathbf{A}_k\) requires \(k(m + n + 1)\) floating-point numbers, vs \(mn\) for \(\mathbf{A}\). For an image of size \(256 \times 256\), the rank-50 truncation requires \(50 \cdot 513 \mathrel{=} 25{,}650\) numbers vs \(65{,}536\) for the original, about \(2.6\) times fewer. How much error remains depends on the image. For two standard test photographs (“camera” from scikit-image and “ascent” from SciPy), shrunk to \(256 \times 256\) by averaging each \(2 \times 2\) block of pixels, the relative error \(\|\mathbf{A} - \mathbf{A}_{50}\|_F / \|\mathbf{A}\|_F\) is about \(4\%\) and \(9\%\). Natural images compress well because their singular values decay fast.
Low-rank approximations of an image
A 64 x 64 test image (smooth waves, a disk and a diagonal band), its singular values, and the error of the best rank-k approximation for every k.
1n = 64
2i, j = np.meshgrid(np.arange(n), np.arange(n), indexing="ij")
3img = (np.sin(i / 7) * np.cos(j / 11) # smooth waves
4 + ((i - 32) ** 2 + (j - 32) ** 2 < 15 ** 2) # a disk
5 + 0.5 * (abs(i - j) < 4)) # a diagonal band
6U, s, Vt = np.linalg.svd(img)
7err = [np.sum(s[k:] ** 2) / np.sum(s ** 2) for k in range(n + 1)] # best rank-k, relative
8for k in (1, 5, 10, 20):
9 print(f"rank {k:2}: {k * (2 * n + 1):5} numbers instead of {n * n}, relative error {err[k]:.4f}")
rank 1: 129 numbers instead of 4096, relative error 0.1120 rank 5: 645 numbers instead of 4096, relative error 0.0266 rank 10: 1290 numbers instead of 4096, relative error 0.0129 rank 20: 2580 numbers instead of 4096, relative error 0.0033
The relative error of the best rank-k approximation against k, on a log scale. Rank 10 keeps 1,290 numbers instead of 4,096 and misses 1.3% of the image (measured by the sum of squared entries). The error is exactly the share of the squared singular values left out, as the Eckart–Young theorem says (Example 5.2).
Recorded on an Apple M1 Max laptop, macOS 26.6.2, Python 3.13.7, NumPy 2.4.6, 2026-11-30.
5.1.5 Pseudoinverse via SVD
Chapter 4 met three kinds of linear systems \(\mathbf{A}\mathbf{x} = \mathbf{b}\): square and invertible (exactly one solution), tall (usually no solution), and fat (usually infinitely many solutions). It also met the Moore–Penrose pseudoinverse \(\mathbf{A}^\dagger\), one matrix meant to handle all of them, but gave its formula only for tall matrices with independent columns. The SVD gives the general formula.
The goal. We ask two things of \(\mathbf{x} = \mathbf{A}^\dagger\mathbf{b}\), in this order. First, \(\mathbf{A}\mathbf{x}\) should be as close to \(\mathbf{b}\) as possible: \(\mathbf{x}\) should make \(\|\mathbf{A}\mathbf{x} - \mathbf{b}\|_2\) smallest. We call such an \(\mathbf{x}\) a best fit (a least-squares solution, Chapter 4). Second, among all best fits, we want the shortest. When \(\mathbf{A}\mathbf{x} = \mathbf{b}\) has exact solutions, the first wish keeps all of them and the second picks one.
Definition 5.2 (Minimum-norm solution). When \(\mathbf{A}\mathbf{x} = \mathbf{b}\) has many solutions, its minimum-norm solution is the shortest one: the solution \(\mathbf{x}\) with the smallest length \(\|\mathbf{x}\|_2\).
Example 5.3 (The shortest solution of a fat system). Chapter 4 solved \(\mathbf{A}\mathbf{x} = \mathbf{b}\) with \(\mathbf{A} = \left[\begin{smallmatrix} 1 & 1 & 1 \\ 0 & 1 & 2 \end{smallmatrix}\right]\) and \(\mathbf{b} = [3, 4]^\top\), that is, \(x_1 + x_2 + x_3 = 3\) and \(x_2 + 2x_3 = 4\), and found a whole line of solutions, \(\mathbf{x}(t) = [t-1, 4-2t, t]^\top\) for any number \(t\). Write it as \(\mathbf{x}(t) = [-1, 4, 0]^\top + t\mathbf{d}\) with \(\mathbf{d} = [1, -2, 1]^\top\). Which solution is shortest? Its squared length is a parabola in \(t\):
\[ \begin{aligned} \|\mathbf{x}(t)\|_2^2 = (t-1)^2 + (4-2t)^2 + t^2 = 6t^2 - 18t + 17. \end{aligned} \]The derivative \(12t - 18\) is zero at \(t = 3/2\), so the minimum-norm solution is \(\mathbf{x}^\star = [1/2, 1, 3/2]^\top\), with squared length \(3.5\). The two solutions Chapter 4 picked, at \(t = 0\) and \(t = 2\), have squared lengths \(17\) and \(5\).
The geometry: \(\mathbf{A}\mathbf{d} = \mathbf{0}\), so moving along \(\mathbf{d}\) never changes \(\mathbf{A}\mathbf{x}\). We call such a \(\mathbf{d}\) a sliding direction; together, the sliding directions form the nullspace of \(\mathbf{A}\). The derivative of \(\|\mathbf{x}(t)\|_2^2\) is also \(2\mathbf{x}(t)^\top\mathbf{d}\), so the shortest solution is the one perpendicular to the sliding direction: \((\mathbf{x}^\star)^\top\mathbf{d} = 1/2 - 2 + 3/2 = 0\).
The pseudoinverse from the SVD. The SVD writes \(\mathbf{A}\) as three steps: rotate with \(\mathbf{V}^\top\), multiply coordinate \(i\) by \(\sigma_i\), rotate with \(\mathbf{U}\). To undo \(\mathbf{A}\), run the steps backwards: rotate back with \(\mathbf{U}^\top\), divide coordinate \(i\) by \(\sigma_i\), rotate back with \(\mathbf{V}\). This is Chapter 4’s recipe \(\mathbf{Q}\boldsymbol{\Lambda}^{-1}\mathbf{Q}^\top\) (go into the special basis, invert the scaling, come back), with one basis for the inputs and another for the outputs.
Two kinds of output directions cannot be undone. A direction \(\mathbf{u}_i\) with \(\sigma_i = 0\) is never reached, because \(\mathbf{A}\) collapses the matching input direction \(\mathbf{v}_i\) to zero. And a tall matrix never reaches its extra output directions \(\mathbf{u}_{n+1}, \dots, \mathbf{u}_m\), which have no \(\sigma_i\) at all. The pseudoinverse sends both kinds to zero; we show next that this choice meets both wishes. In formulas, \(\boldsymbol{\Sigma}^\dagger \in \mathbb{R}^{n \times m}\) is \(\boldsymbol{\Sigma}\) transposed, with each non-zero \(\sigma_i\) replaced by \(1/\sigma_i\). For the \(2 \times 3\) matrix of Example 5.1,
\[ \begin{aligned} \boldsymbol{\Sigma} = \begin{bmatrix} 2\sqrt{3} & 0 & 0 \\ 0 & \sqrt{10} & 0 \end{bmatrix}, \qquad \boldsymbol{\Sigma}^\dagger = \begin{bmatrix} 1/(2\sqrt{3}) & 0 \\ 0 & 1/\sqrt{10} \\ 0 & 0 \end{bmatrix}. \end{aligned} \]Then
\[ \mathbf{A}^\dagger = \mathbf{V}\boldsymbol{\Sigma}^\dagger\mathbf{U}^\top = \sum_{i=1}^{r} \frac{1}{\sigma_i}\mathbf{v}_i\mathbf{u}_i^\top, \]where \(r\) is the number of non-zero singular values: the thin SVD of \(\mathbf{A}\), with \(\mathbf{u}_i\) and \(\mathbf{v}_i\) swapped and each weight inverted.
Why the SVD formula meets both wishes. Work in the bases of the SVD. Write \(\mathbf{c} = \mathbf{U}^\top\mathbf{b}\), so that \(\mathbf{b} = \mathbf{U}\mathbf{c}\), and \(\mathbf{y} = \mathbf{V}^\top\mathbf{x}\), so that \(\mathbf{A}\mathbf{x} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{y}\). Then \(\mathbf{A}\mathbf{x} - \mathbf{b} = \mathbf{U}(\boldsymbol{\Sigma}\mathbf{y} - \mathbf{c})\), and \(\mathbf{U}\) does not change lengths. The vector \(\boldsymbol{\Sigma}\mathbf{y}\) has entries \(\sigma_1 y_1, \dots, \sigma_r y_r\), followed by zeros. So
\[ \begin{aligned} \|\mathbf{A}\mathbf{x} - \mathbf{b}\|_2^2 = \|\boldsymbol{\Sigma}\mathbf{y} - \mathbf{c}\|_2^2 = \sum_{i=1}^{r} (\sigma_i y_i - c_i)^2 + \sum_{i=r+1}^{m} c_i^2 . \end{aligned} \]- Best fit. The second sum does not depend on \(\mathbf{x}\): those parts of \(\mathbf{b}\) are out of reach for every \(\mathbf{x}\). The first sum is zero when \(y_i = c_i/\sigma_i\). So a best fit matches every reachable part of \(\mathbf{b}\) and gives up on the rest.
- Shortest. The coordinates \(y_{r+1}, \dots, y_n\) do not appear at all: moving along \(\mathbf{v}_{r+1}, \dots, \mathbf{v}_n\) never changes \(\mathbf{A}\mathbf{x}\) (these are the sliding directions). Since \(\|\mathbf{x}\|_2^2 = \|\mathbf{y}\|_2^2 = y_1^2 + \dots + y_n^2\), the shortest best fit sets them to zero.
The choices \(y_i = c_i/\sigma_i\) for \(i \leq r\) and \(y_i = 0\) for \(i > r\) are exactly \(\mathbf{y} = \boldsymbol{\Sigma}^\dagger\mathbf{c}\), that is, \(\mathbf{x} = \mathbf{V}\boldsymbol{\Sigma}^\dagger\mathbf{U}^\top\mathbf{b} = \mathbf{A}^\dagger\mathbf{b}\). So, for every matrix:
\(\mathbf{x}^\star = \mathbf{A}^\dagger\mathbf{b}\) is the shortest vector among those that bring \(\mathbf{A}\mathbf{x}\) as close to \(\mathbf{b}\) as possible.
Required for every \(\mathbf{b}\), this sentence pins down a single matrix \(\mathbf{A}^\dagger\). It is one standard definition of the Moore–Penrose pseudoinverse, and the SVD is how we compute it. In NumPy, np.linalg.pinv(A) computes \(\mathbf{A}^\dagger\) from the SVD, and np.linalg.\allowbreak lstsq(\allowbreak A, b, rcond=None)[0] is \(\mathbf{A}^\dagger\mathbf{b}\) (the function returns a tuple; its first entry is the answer).
Four cases, one rule. Every formula for \(\mathbf{A}^\dagger\) you may meet is this rule in a special case. The table below collects them.
| The matrix \(\mathbf{A}\) | The trouble | What \(\mathbf{x}^\star = \mathbf{A}^\dagger\mathbf{b}\) is | Formula for \(\mathbf{A}^\dagger\) |
|---|---|---|---|
| square, invertible | none | the unique solution | \(\mathbf{A}^{-1}\) |
| tall, independent columns | usually no solution | the least-squares solution | \((\mathbf{A}^\top\mathbf{A})^{-1}\mathbf{A}^\top\) |
| fat, independent rows | infinitely many solutions | the minimum-norm solution | \(\mathbf{A}^\top(\mathbf{A}\mathbf{A}^\top)^{-1}\) |
| rank below both \(m\) and \(n\) | both troubles, usually at once | the shortest best fit | \(\mathbf{V}\boldsymbol{\Sigma}^\dagger\mathbf{U}^\top\) |
Case 1: square and invertible. All \(\sigma_i > 0\), nothing is collapsed, and \(\boldsymbol{\Sigma}^\dagger = \boldsymbol{\Sigma}^{-1}\). Then \(\mathbf{A}^\dagger = \mathbf{V}\boldsymbol{\Sigma}^{-1}\mathbf{U}^\top\). Multiplying out gives \((\mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top)(\mathbf{V}\boldsymbol{\Sigma}^{-1}\mathbf{U}^\top) = \mathbf{I}\), so \(\mathbf{A}^\dagger = \mathbf{A}^{-1}\), and \(\mathbf{x}^\star\) is the unique solution. For a symmetric matrix, this is Chapter 4’s solve with \(\mathbf{Q}\boldsymbol{\Lambda}^{-1}\mathbf{Q}^\top\).
Case 2: tall, with independent columns (Chapter 4’s overdetermined case). No input direction is collapsed (\(r = n\)), so only the first wish acts: \(\mathbf{x}^\star\) is the least-squares solution. The gradient of \(\|\mathbf{A}\mathbf{x} - \mathbf{b}\|_2^2\) is \(2\mathbf{A}^\top(\mathbf{A}\mathbf{x} - \mathbf{b})\). Chapter 3 wrote the same gradient as \(-\frac{2}{n}\mathbf{A}^\top(\mathbf{y} - \mathbf{A}\mathbf{w})\): its \(\mathbf{w}\) is our \(\mathbf{x}\), its \(\mathbf{y}\) is our \(\mathbf{b}\), and its extra factor divides by the number of rows. Setting it to zero gives the normal equations \(\mathbf{A}^\top\mathbf{A}\mathbf{x} = \mathbf{A}^\top\mathbf{b}\). They say that the error \(\mathbf{b} - \mathbf{A}\mathbf{x}\) is perpendicular, or “normal”, to every column of \(\mathbf{A}\). Independent columns make \(\mathbf{A}^\top\mathbf{A}\) invertible: if \(\mathbf{A}^\top\mathbf{A}\mathbf{x} = \mathbf{0}\), then \(\|\mathbf{A}\mathbf{x}\|_2^2 = \mathbf{x}^\top\mathbf{A}^\top\mathbf{A}\mathbf{x} = 0\), so \(\mathbf{A}\mathbf{x} = \mathbf{0}\), so \(\mathbf{x} = \mathbf{0}\) because the columns are independent. Hence
\[ \begin{aligned} \mathbf{A}^\dagger = (\mathbf{A}^\top\mathbf{A})^{-1}\mathbf{A}^\top, \end{aligned} \]the formula of Chapter 4. Example: Chapter 4’s system with rows \([1, 0]\), \([0, 1]\), \([1, 1]\) and \(\mathbf{b} = [2, 3, 6]^\top\) has \(\mathbf{A}^\top\mathbf{A} = \left[\begin{smallmatrix} 2 & 1 \\ 1 & 2 \end{smallmatrix}\right]\) and \(\mathbf{A}^\top\mathbf{b} = [8, 9]^\top\), so
\[ \begin{aligned} \mathbf{x}^\star = \frac{1}{3}\begin{bmatrix} 2 & -1 \\ -1 & 2 \end{bmatrix}\begin{bmatrix} 8 \\ 9 \end{bmatrix} = \begin{bmatrix} 7/3 \\ 10/3 \end{bmatrix}. \end{aligned} \]Then \(\mathbf{A}\mathbf{x}^\star = [7/3, 10/3, 17/3]^\top\) misses each entry of \(\mathbf{b}\) by \(1/3\), and no \(\mathbf{x}\) does better. The error \(\mathbf{b} - \mathbf{A}\mathbf{x}^\star = [-1/3, -1/3, 1/3]^\top\) is perpendicular to both columns, as promised.
Case 3: fat, with independent rows (Chapter 4’s underdetermined case). Every output direction is reachable (\(r = m\)), so exact solutions exist and only the second wish acts: \(\mathbf{x}^\star\) is the minimum-norm solution. Here
\[ \begin{aligned} \mathbf{A}^\dagger = \mathbf{A}^\top(\mathbf{A}\mathbf{A}^\top)^{-1}. \end{aligned} \]The formula comes from the geometry of Example 5.3: the shortest solution has no part along any sliding direction. Combinations of the rows, \(\mathbf{x} = \mathbf{A}^\top\mathbf{w}\), have this property, because every row is perpendicular to every sliding direction \(\mathbf{d}\) (\(\mathbf{A}\mathbf{d} = \mathbf{0}\) says so, row by row). Two solutions differ by a sliding direction, since \(\mathbf{A}(\mathbf{x}' - \mathbf{x}) = \mathbf{b} - \mathbf{b} = \mathbf{0}\). So any other solution is \(\mathbf{x} + \mathbf{d}\), and by Pythagoras \(\|\mathbf{x} + \mathbf{d}\|_2^2 = \|\mathbf{x}\|_2^2 + \|\mathbf{d}\|_2^2\), which is larger. Plugging \(\mathbf{x} = \mathbf{A}^\top\mathbf{w}\) into \(\mathbf{A}\mathbf{x} = \mathbf{b}\) gives \(\mathbf{A}\mathbf{A}^\top\mathbf{w} = \mathbf{b}\), so \(\mathbf{w} = (\mathbf{A}\mathbf{A}^\top)^{-1}\mathbf{b}\) (\(\mathbf{A}\mathbf{A}^\top\) is invertible by the argument of Case 2, applied to the rows). In Example 5.3,
\[ \begin{aligned} \mathbf{A}\mathbf{A}^\top &= \begin{bmatrix} 3 & 3 \\ 3 & 5 \end{bmatrix}, \quad \mathbf{w} = \frac{1}{6}\begin{bmatrix} 5 & -3 \\ -3 & 3 \end{bmatrix}\begin{bmatrix} 3 \\ 4 \end{bmatrix} = \begin{bmatrix} 1/2 \\ 1/2 \end{bmatrix}, \\ \mathbf{x}^\star &= \mathbf{A}^\top\mathbf{w} = \begin{bmatrix} 1/2 \\ 1 \\ 3/2 \end{bmatrix}, \end{aligned} \]the same shortest solution that the parabola gave.
A bonus: gradient descent finds the shortest solution by itself. Run Chapter 2’s gradient descent on \(\|\mathbf{A}\mathbf{x} - \mathbf{b}\|_2^2\), with a small enough step size \(\eta\), starting at \(\mathbf{x} = \mathbf{0}\). Each step adds \(-2\eta\mathbf{A}^\top(\mathbf{A}\mathbf{x} - \mathbf{b})\), a combination of the rows of \(\mathbf{A}\), so the iterates never move along a sliding direction. For Example 5.3 they approach \([1/2, 1, 3/2]^\top\), the shortest solution. (Started elsewhere, they keep whatever part along \(\mathbf{d}\) they started with.) For a linear model with more weights than data points, the fat case, this says which of the many perfect fits (there are many whenever the data points are independent) gradient descent picks when it starts from zero.
Case 4: rank below both \(m\) and \(n\) (dependent columns and dependent rows). The best fits always form a whole family, and usually part of \(\mathbf{b}\) is also out of reach. Neither formula above works, because \(\mathbf{A}^\top\mathbf{A}\) and \(\mathbf{A}\mathbf{A}^\top\) are not invertible. The SVD formula still does.
5.1.6 Singular Values and the Condition Number
Chapter 4 measured how dangerous it is to solve \(\mathbf{A}\mathbf{x} = \mathbf{b}\) with the condition number \(\kappa(\mathbf{A}) = |\lambda_{\max}|/|\lambda_{\min}|\), the ratio of the largest to the smallest eigenvalue in absolute value, for a symmetric \(\mathbf{A}\). Two questions remain: where does this ratio come from, and what replaces it when \(\mathbf{A}\) is not symmetric? The SVD answers both. Here \(\mathbf{A}\) is square (\(n \times n\)) and invertible, and we write \(\sigma_{\max} = \sigma_1\) and \(\sigma_{\min} = \sigma_n\) for its largest and smallest singular values.
What we want to measure. Suppose \(\mathbf{b}\) carries a small error \(\delta\mathbf{b}\) (one symbol: the error in \(\mathbf{b}\)), from a measurement or from rounding. Then the solution moves by \(\delta\mathbf{x} = \mathbf{A}^{-1}\delta\mathbf{b}\). We compare relative sizes, because an error of \(0.01\) matters for an answer of size \(1\) but not for one of size \(1{,}000\). We want the worst possible value of
\[ \begin{aligned} \frac{\text{relative change in } \mathbf{x}}{\text{relative change in } \mathbf{b}} = \frac{\|\delta\mathbf{x}\|_2 / \|\mathbf{x}\|_2}{\|\delta\mathbf{b}\|_2 / \|\mathbf{b}\|_2}. \end{aligned} \]The answer. Two facts from the rotate, scale, rotate picture bound this ratio.
- \(\mathbf{A}\) stretches any vector by at most \(\sigma_{\max}\), so \[ \begin{aligned} \|\mathbf{b}\|_2 = \|\mathbf{A}\mathbf{x}\|_2 \leq \sigma_{\max}\|\mathbf{x}\|_2 . \end{aligned} \]
- \(\mathbf{A}^{-1} = \mathbf{V}\boldsymbol{\Sigma}^{-1}\mathbf{U}^\top\) rotates, divides coordinate \(i\) by \(\sigma_i\), and rotates, so it stretches any vector by at most \(1/\sigma_{\min}\): \[ \begin{aligned} \|\delta\mathbf{x}\|_2 = \|\mathbf{A}^{-1}\delta\mathbf{b}\|_2 \leq \|\delta\mathbf{b}\|_2/\sigma_{\min} . \end{aligned} \]
Divide the second inequality by \(\|\mathbf{x}\|_2\), and use the first in the form \(1/\|\mathbf{x}\|_2 \leq \sigma_{\max}/\|\mathbf{b}\|_2\):
\[ \begin{aligned} \frac{\|\delta\mathbf{x}\|_2}{\|\mathbf{x}\|_2} \leq \frac{\sigma_{\max}}{\sigma_{\min}} \cdot \frac{\|\delta\mathbf{b}\|_2}{\|\mathbf{b}\|_2}. \end{aligned} \]The amplification factor is the condition number
\[ \kappa(\mathbf{A}) = \frac{\sigma_{\max}}{\sigma_{\min}} = \|\mathbf{A}\|_2 \|\mathbf{A}^{-1}\|_2 . \]The bound is reached. Take \(\mathbf{x}\) along \(\mathbf{v}_1\), the direction that \(\mathbf{A}\) stretches most. Take \(\delta\mathbf{b}\) along \(\mathbf{u}_n\), the direction that \(\mathbf{A}^{-1}\) stretches most (\(\mathbf{A}^{-1}\mathbf{u}_n = \mathbf{v}_n/\sigma_n\)).
We write \(\kappa\), as in Chapter 4, because this is the same quantity: for a symmetric matrix the two agree (shown next). The subscript \(2\) on the norms records that lengths were measured with the 2-norm (\(\|\mathbf{A}\|_2 = \sigma_{\max}\) and \(\|\mathbf{A}^{-1}\|_2 = 1/\sigma_{\min}\) are spectral norms), and a different norm gives a different number. When nobody says otherwise, “the condition number” means this one; it is what np.linalg.cond(A) returns.
The connection to Chapter 4. For a symmetric matrix, \(\mathbf{A}\mathbf{q}_i = \lambda_i\mathbf{q}_i = |\lambda_i|(\pm\mathbf{q}_i)\), with the sign of \(\lambda_i\). So the spectral theorem already gives an SVD, once the eigenpairs are listed by decreasing \(|\lambda_i|\): \(\mathbf{v}_i = \mathbf{q}_i\), \(\mathbf{u}_i = \pm\mathbf{q}_i\), and \(\sigma_i = |\lambda_i|\). Hence
\[ \begin{aligned} \frac{\sigma_{\max}}{\sigma_{\min}} = \frac{|\lambda_{\max}|}{|\lambda_{\min}|}. \end{aligned} \]The condition number of this section is Chapter 4’s \(\kappa\), extended from symmetric matrices to every square invertible matrix.
Example 5.4 (Chapter 4’s matrix, through its singular values). Take Chapter 4’s nearly singular matrix \(\mathbf{A} = \begin{bmatrix} 1 & 1 \\ 1 & 1.0001 \end{bmatrix}\) and ask one question: how much can solving \(\mathbf{A}\mathbf{x} = \mathbf{b}\) amplify an error in \(\mathbf{b}\)? The answer is \(\kappa(\mathbf{A}) = \sigma_{\max}/\sigma_{\min}\), so we need the two singular values.
Step 1: go through \(\mathbf{A}^\top\mathbf{A}\). The squared singular values are the eigenvalues of \(\mathbf{A}^\top\mathbf{A}\) (see the connection to the spectral theorem above).
Step 2: use their sum and their product. A \(2 \times 2\) matrix \(\mathbf{M}\) with eigenvalues \(\lambda_1\) and \(\lambda_2\) has
\[ \begin{aligned} \det(\mathbf{M} - \lambda\mathbf{I}) &= \lambda^2 - \text{Tr}(\mathbf{M})\lambda + \det(\mathbf{M}) \\ &= (\lambda - \lambda_1)(\lambda - \lambda_2) = \lambda^2 - (\lambda_1 + \lambda_2)\lambda + \lambda_1\lambda_2, \end{aligned} \]so the two eigenvalues add up to the trace and multiply to the determinant. Both are easy to get for \(\mathbf{M} = \mathbf{A}^\top\mathbf{A}\):
\[ \begin{aligned} \sigma_{\max}^2 \sigma_{\min}^2 &= \det(\mathbf{A}^\top\mathbf{A}) = \det(\mathbf{A})^2 = (0.0001)^2 = 10^{-8}, \\ \sigma_{\max}^2 + \sigma_{\min}^2 &= \text{Tr}(\mathbf{A}^\top\mathbf{A}) = 1^2 + 1^2 + 1^2 + 1.0001^2 \approx 4.0002 . \end{aligned} \]Here we used two rules of determinants: the determinant of a product is the product of the determinants, and transposing a matrix does not change its determinant. For \(2 \times 2\) matrices you can check both by multiplying out. The trace of \(\mathbf{A}^\top\mathbf{A}\) is the sum of the squared entries of \(\mathbf{A}\), that is, \(\|\mathbf{A}\|_F^2\).
Step 3: split the sum. The product is tiny while the sum is about \(4\), so one of the two carries almost all of the sum: \(\sigma_{\max}^2 \approx 4.0002\), and then \(\sigma_{\min}^2 = 10^{-8}/\sigma_{\max}^2 \approx 2.5 \times 10^{-9}\). Square roots give \(\sigma_{\max} \approx 2.00005\) (the tangent line of \(\sqrt{x}\) at \(x = 4\) gives \(\sqrt{4 + h} \approx 2 + h/4\)) and \(\sigma_{\min} \approx \sqrt{25 \times 10^{-10}} = 0.00005\).
Step 4: divide. \(\kappa(\mathbf{A}) \approx 2.00005/0.00005 \approx 40{,}000\).
Step 5: compare with Chapter 4. There, the eigenvalues were \(\lambda_1 \approx 2.00005\) and \(\lambda_2 \approx 0.00005\), and \(\kappa(\mathbf{A}) \approx 40{,}000\). These are the same numbers, because \(\mathbf{A}\) is symmetric and so \(\sigma_i = |\lambda_i|\). The SVD route got there without the eigenvalues of \(\mathbf{A}\). Step 1 works for any matrix; the shortcut of Step 2 is special to \(2 \times 2\) matrices.
Step 6: see what \(40{,}000\) means. With \(\mathbf{b} = [2, 2.0001]^\top\) the solution is \(\mathbf{x} = [1, 1]^\top\). Change the last digit of \(\mathbf{b}\): with \(\mathbf{b}' = [2, 2.0002]^\top\), the solution jumps to \(\mathbf{x}' = [0, 2]^\top\). The relative change in \(\mathbf{b}\) is \(0.0001/2.83 \approx 0.0035\%\); the relative change in \(\mathbf{x}\) is \(\|[-1, 1]^\top\|_2/\|[1, 1]^\top\|_2 = 100\%\). The error grew about \(28{,}000\) times. Why not \(40{,}000\)? The change \([0, 0.0001]^\top\) does not point along the worst direction \(\mathbf{u}_2 \approx [1, -1]^\top/\sqrt{2}\): only its part along \(\mathbf{u}_2\), a fraction \(1/\sqrt{2}\) of it, is amplified fully, and \(40{,}000/\sqrt{2} \approx 28{,}000\). Chapter 4 ran a different experiment: it changed an entry of \(\mathbf{A}\), not of \(\mathbf{b}\), and the inverse jumped from \(10001\) to \(5001\). The same tiny \(\sigma_{\min}\) is behind both.
Example 5.5. Take \(\mathbf{N} = \begin{bmatrix} 1 & 10 \\ 0 & 1 \end{bmatrix}\) (N for non-symmetric). Its characteristic equation is \((1 - \lambda)^2 = 0\), so both eigenvalues equal \(1\). The eigenvalue ratio is \(1\), which would call \(\mathbf{N}\) perfectly safe.
The singular values disagree. Follow Steps 1 to 4 of the previous example. The product is \(\det(\mathbf{N}^\top\mathbf{N}) = \det(\mathbf{N})^2 = 1\) and the sum is \(\text{Tr}(\mathbf{N}^\top\mathbf{N}) = 1^2 + 10^2 + 0^2 + 1^2 = 102\). So, as in Step 3, \(\sigma_{\max}^2 \approx 102\) (more precisely \(101.99\)) and \(\sigma_{\min}^2 = 1/\sigma_{\max}^2 \approx 0.0098\). Since \(\sigma_{\max}\sigma_{\min} = 1\),
\[ \begin{aligned} \kappa(\mathbf{N}) = \frac{\sigma_{\max}}{\sigma_{\min}} = \sigma_{\max}^2 \approx 102 . \end{aligned} \]The singular values are right. With \(\mathbf{b} = [10, 1]^\top\), the solution of \(\mathbf{N}\mathbf{x} = \mathbf{b}\) is \(\mathbf{x} = [0, 1]^\top\). Change \(\mathbf{b}\) to \([10, 1.1]^\top\), a relative change of \(0.1/\sqrt{101} \approx 1\%\). The solution becomes \(\mathbf{x}' = [-1, 1.1]^\top\): it moved by \(\|[-1, 0.1]^\top\|_2 \approx 1.005\), a relative change of about \(100\%\). The error grew about \(101\) times, close to \(\kappa(\mathbf{N}) \approx 102\), while the eigenvalues predicted no growth at all.
One more consequence: do not square the danger. The matrix \(\mathbf{A}^\top\mathbf{A}\) is symmetric with eigenvalues \(\sigma_i^2 \geq 0\), so by the connection above its singular values are \(\sigma_i^2\), and \(\kappa(\mathbf{A}^\top\mathbf{A}) = \kappa(\mathbf{A})^2\). Solving least squares through the normal equations \(\mathbf{A}^\top\mathbf{A}\mathbf{x} = \mathbf{A}^\top\mathbf{b}\) squares the condition number: for Chapter 4’s matrix, \(40{,}000\) becomes about \(1.6\) billion. A computer keeps about 16 significant digits of every number. A rule of thumb says that solving loses about \(\log_{10}\kappa\) of them: about 5 through \(\mathbf{A}\) (leaving 11) and about 9 through \(\mathbf{A}^\top\mathbf{A}\) (leaving 7). By hand, with exact numbers as in the examples above, nothing is lost. This is why the route through \(\mathbf{A}^\top\mathbf{A}\) is numerically suboptimal, and why least-squares solvers such as np.linalg.lstsq work with the SVD of \(\mathbf{A}\) itself.
5.1.7 Complexity Note - Interlude
How do libraries compute the SVD, and what changes when the matrix is huge? This course does not develop the algorithms; later courses in numerical linear algebra do. Here are the main families, so that you recognize the names. Take \(\mathbf{A} \in \mathbb{R}^{m \times n}\) with \(m \geq n\).
- Dense matrices: all singular values. Libraries transform the whole matrix with orthogonal steps, which do not change the singular values, until only the diagonal and the entries just above it are non-zero (Golub and Kahan, 1965). A variant of the QR algorithm (Golub and Reinsch, 1970) or a divide-and-conquer method then finds the singular values and vectors of this simpler matrix. The cost is \(O(mn^2)\) operations, or \(O(m^2 n)\) if all \(m\) columns of \(\mathbf{U}\) are built. This is how
np.linalg.svdworks. - Large sparse matrices: Lanczos methods. Often only the top \(k\) singular values and vectors are needed. Like the Power Method later in this chapter (repeat \(\mathbf{x} \leftarrow \mathbf{A}\mathbf{x}/\|\mathbf{A}\mathbf{x}\|_2\)), Lanczos methods use \(\mathbf{A}\) only through products \(\mathbf{A}\mathbf{x}\) and \(\mathbf{A}^\top\mathbf{y}\), and each product costs time proportional to the number of non-zero entries of \(\mathbf{A}\). Unlike the Power Method, they keep many of the vectors produced, not only the last one, and pick the best combination of them. They are a standard tool at large scale:
scipy.sparse.\allowbreak linalg.svdsuses one by default, through ARPACK, a library written at Rice. - Large matrices, approximately: randomized methods. Multiply \(\mathbf{A}\) by a few more than \(k\) random vectors; the results capture the dominant directions of \(\mathbf{A}\). Orthonormalize them, project \(\mathbf{A}\) onto them, and take an ordinary SVD of the small matrix that comes out. This gives good approximations of the top \(k\) singular values and vectors (Halko, Martinsson and Tropp, 2011). The cost is \(O(mnk)\), and the method reads \(\mathbf{A}\) only a small, fixed number of times. scikit-learn’s
TruncatedSVDuses it by default.
The SVD now provides everything Chapter 4 deferred: a decomposition that works for any matrix, a unique definition of the pseudoinverse, and a clean characterization of the condition number. Both EVD and SVD will be central to the optimization-driven view of decompositions we develop in this chapter.
5.2 Optimization for Eigendecomposition
We have now seen what eigendecomposition and SVD compute. For a dense matrix of moderate size, libraries transform the whole matrix, as in the complexity note above; np.linalg.eigh does the same for a symmetric matrix. When only the leading eigenvectors of a huge matrix are needed, as in PCA or in ranking web pages, a different idea takes over: touch the matrix only through matrix-vector products. That idea comes from optimization. We can formulate the problem of finding an eigenvector as a search for a very special direction in space: the direction in which the matrix transformation has the most impact.
By framing eigendecomposition as an optimization problem, we not only demystify the process but also develop an intuitive algorithm –the Power Method– from first principles.
5.2.1 Finding the Best Rank-One Approximation
A fundamental task in AI is to approximate complex data with a simpler one; e.g., sparsity, low-rankness. For a symmetric matrix \(\mathbf{A} \in \mathbb{R}^{p \times p}\), what is the best possible approximation we can build using the simplest possible building block? Within our context, what about a rank-one matrix?
Before we formulate this as an optimization problem, let us recall the Spectral Theorem from the previous chapter: any symmetric matrix is fundamentally a weighted sum of rank-one matrices. Specifically, it can be perfectly reconstructed from its eigenpairs \((\lambda_i, \mathbf{q}_i)\):
\[ \mathbf{A} = \sum_{i=1}^p \lambda_i \mathbf{q}_i\mathbf{q}_i^\top. \]Each term \(\lambda_i \mathbf{q}_i\mathbf{q}_i^\top\) is a rank-one matrix whose “importance” in the sum is determined by the magnitude of the eigenvalue \(\lambda_i\). A matrix \(\mathbf{A}\) is literally built from these orthonormal rank-one components.
Example 5.6 (A 2x2 Matrix as a Sum of Components). Consider the symmetric matrix \(\mathbf{A} = \begin{bmatrix} 9.1 & 2.7 \\ 2.7 & 9.1 \end{bmatrix}\). Its eigendecomposition yields two eigenpairs:
- A large eigenvalue, \(\lambda_1 = 11.8\), with eigenvector \(\mathbf{q}_1 = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 \\ 1 \end{bmatrix}\).
- A small eigenvalue, \(\lambda_2 = 6.4\), with eigenvector \(\mathbf{q}_2 = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 \\ -1 \end{bmatrix}\).
Let’s construct the two rank-one matrices that form \(\mathbf{A}\):
- Component 1 (Dominant): \[ \begin{aligned} \lambda_1\mathbf{q}_1\mathbf{q}_1^\top &= \frac{11.8}{2} \begin{bmatrix} 1 \\ 1 \end{bmatrix}\begin{bmatrix} 1 & 1 \end{bmatrix} \\ &= 5.9 \begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix} = \begin{bmatrix} 5.9 & 5.9 \\ 5.9 & 5.9 \end{bmatrix}. \end{aligned} \]
- Component 2 (Minor): \[ \begin{aligned} \lambda_2\mathbf{q}_2\mathbf{q}_2^\top &= \frac{6.4}{2} \begin{bmatrix} 1 \\ -1 \end{bmatrix}\begin{bmatrix} 1 & -1 \end{bmatrix} \\ &= 3.2 \begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix} = \begin{bmatrix} 3.2 & -3.2 \\ -3.2 & 3.2 \end{bmatrix}. \end{aligned} \]
Summing these components:
\[ \begin{bmatrix} 5.9 & 5.9 \\ 5.9 & 5.9 \end{bmatrix} + \begin{bmatrix} 3.2 & -3.2 \\ -3.2 & 3.2 \end{bmatrix} = \begin{bmatrix} 9.1 & 2.7 \\ 2.7 & 9.1 \end{bmatrix} \]Example 5.7. Consider the matrix \(\mathbf{A} = \begin{bmatrix} 10 & 0 \\ 0 & 1 \end{bmatrix}\). The eigenvectors are \(\mathbf{q}_1 = \left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right]\) and \(\mathbf{q}_2 = \left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right]\) with eigenvalues \(\lambda_1 = 10, \lambda_2 = 1\). The components are: \(\lambda_1 \mathbf{q}_1 \mathbf{q}_1^\top = 10 \left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right] \left[\begin{smallmatrix} 1 & 0 \end{smallmatrix}\right] = \left[\begin{smallmatrix} 10 & 0 \\ 0 & 0 \end{smallmatrix}\right]\). \(\lambda_2 \mathbf{q}_2 \mathbf{q}_2^\top = 1 \left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right] \left[\begin{smallmatrix} 0 & 1 \end{smallmatrix}\right] = \left[\begin{smallmatrix} 0 & 0 \\ 0 & 1 \end{smallmatrix}\right]\). Their sum is indeed \(\mathbf{A}\).
Let’s use these examples to build some intuition behind the low-rank approximation problem. Our goal is to find a single unit vector \(\mathbf{q}\) and a scalar \(\lambda\) that form a rank-one matrix \(\lambda\mathbf{q}\mathbf{q}^\top\) that best approximates \(\mathbf{A}\). At first, we will assume that the solution to this problem is selecting one of the rank-1 matrices in the eigendecomposition of \(\mathbf{A}\) and make the claim that the answer to the above question is the dominant component. We call the two components \(\mathbf{C}_1 = \lambda_1\mathbf{q}_1\mathbf{q}_1^\top\) and \(\mathbf{C}_2 = \lambda_2\mathbf{q}_2\mathbf{q}_2^\top\) (C for component); the name \(\mathbf{A}_k\) is taken, it means the best rank-\(k\) copy of the SVD section. To see why the dominant component is the correct choice, let’s explicitly compute the error for both possible approximations in our examples. The error is the squared Frobenius norm of the residual matrix, \(\|\mathbf{A} - (\text{approximation})\|_F^2\).
Example 5.8 (Error Calculation for the Diagonal Matrix). Consider the matrix \(\mathbf{A} = \begin{bmatrix} 10 & 0 \\ 0 & 1 \end{bmatrix}\). Its two rank-one components are provided in the previous example. Let’s compute the error for each choice.
1. Approximating with the Dominant Component (\(\mathbf{C}_1 = \lambda_1\mathbf{q}_1\mathbf{q}_1^\top\)): The residual matrix is what’s left over after subtracting the approximation:
\[ \mathbf{R}_1 = \mathbf{A} - \mathbf{C}_1 = \begin{bmatrix} 10 & 0 \\ 0 & 1 \end{bmatrix} - \begin{bmatrix} 10 & 0 \\ 0 & 0 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix}. \]The approximation error is the squared Frobenius norm of this residual:
\[ \text{Error}_1 = \|\mathbf{R}_1\|_F^2 = 0^2 + 0^2 + 0^2 + 1^2 = 1. \]2. Approximating with the Minor Component (\(\mathbf{C}_2 = \lambda_2\mathbf{q}_2\mathbf{q}_2^\top\)): The residual matrix in this case is:
\[ \mathbf{R}_2 = \mathbf{A} - \mathbf{C}_2 = \begin{bmatrix} 10 & 0 \\ 0 & 1 \end{bmatrix} - \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} 10 & 0 \\ 0 & 0 \end{bmatrix}. \]The approximation error is:
\[ \text{Error}_2 = \|\mathbf{R}_2\|_F^2 = 10^2 + 0^2 + 0^2 + 0^2 = 100. \]I.e., approximating with the dominant component yields a tiny error of 1, while using the minor component yields a much larger error of 100. Notice that the error in each case is the square of the other component’s eigenvalue (\(\text{Error}_1 = \lambda_2^2\), \(\text{Error}_2 = \lambda_1^2\)).
Example 5.9 (Error Calculation for the Non-Diagonal Matrix). Let’s verify this for our non-diagonal matrix, \(\mathbf{A} = \begin{bmatrix} 9.1 & 2.7 \\ 2.7 & 9.1 \end{bmatrix}\). Its components are computed in Example 5.6.
1. Approximating with the Dominant Component (\(\mathbf{C}_1 = \lambda_1\mathbf{q}_1\mathbf{q}_1^\top\)): The residual is the other component of the matrix:
\[ \mathbf{R}_1 = \mathbf{A} - \mathbf{C}_1 = \begin{bmatrix} 9.1 & 2.7 \\ 2.7 & 9.1 \end{bmatrix} - \begin{bmatrix} 5.9 & 5.9 \\ 5.9 & 5.9 \end{bmatrix} = \begin{bmatrix} 3.2 & -3.2 \\ -3.2 & 3.2 \end{bmatrix}. \]The approximation error is:
\[ \begin{aligned} \text{Error}_1 &= \|\mathbf{R}_1\|_F^2 \\ &= (3.2)^2 + (-3.2)^2 + (-3.2)^2 + (3.2)^2 \\ &= 4 \times 10.24 = 40.96. \end{aligned} \]2. Approximating with the Minor Component (\(\mathbf{C}_2 = \lambda_2\mathbf{q}_2\mathbf{q}_2^\top\)): The residual is now the dominant component:
\[ \mathbf{R}_2 = \mathbf{A} - \mathbf{C}_2 = \begin{bmatrix} 9.1 & 2.7 \\ 2.7 & 9.1 \end{bmatrix} - \begin{bmatrix} 3.2 & -3.2 \\ -3.2 & 3.2 \end{bmatrix} = \begin{bmatrix} 5.9 & 5.9 \\ 5.9 & 5.9 \end{bmatrix}. \]The approximation error is:
\[ \begin{aligned} \text{Error}_2 &= \|\mathbf{R}_2\|_F^2 \\ &= (5.9)^2 + (5.9)^2 + (5.9)^2 + (5.9)^2 \\ &= 4 \times 34.81 = 139.24. \end{aligned} \]Again, the conclusion is the same. Approximating with the component corresponding to the largest eigenvalue (\(\lambda_1=11.8\)) results in a significantly smaller error (40.96) than using the minor component (139.24). And as before, the errors are precisely the squares of the eigenvalues not used in the approximation: \(\text{Error}_1 = \lambda_2^2 = 6.4^2 = 40.96\) and \(\text{Error}_2 = \lambda_1^2 = 11.8^2 = 139.24\).
Now, going into the original question of finding the best rank-1 approximation of a matrix (and having the “hunch” that the answer to this question is the dominant component), we will define the problem properly. Again, our goal is to find a single unit vector \(\mathbf{q}\) and a scalar \(\lambda\) that form a rank-one matrix \(\lambda\mathbf{q}\mathbf{q}^\top\) that best approximates \(\mathbf{A}\). Based on the examples above, we could formalize this as a minimization problem using the Frobenius norm to measure the distance between the matrices:
\[ \min_{\lambda \in \mathbb{R}, \mathbf{x} \in \mathbb{R}^p} \|\mathbf{A} - \lambda \mathbf{x}\mathbf{x}^\top\|_F^2 \quad \text{subject to} \quad \|\mathbf{x}\|_2 = 1. \]The constraint \(\|\mathbf{x}\|_2 = 1\) is essential; without it, we could scale \(\mathbf{x}\) and \(\lambda\) in ways that lead to ambiguous solutions.
To solve this, we expand the objective. A key property we will use is that for a unit vector \(\mathbf{x}\), the matrix \(\mathbf{P} = \mathbf{x}\mathbf{x}^\top\) is a projection matrix, and its squared Frobenius norm is one: \(\|\mathbf{x}\mathbf{x}^\top\|_F^2 = \text{Tr}((\mathbf{x}\mathbf{x}^\top)^\top(\mathbf{x}\mathbf{x}^\top)) = \text{Tr}((\mathbf{x}\mathbf{x}^\top)(\mathbf{x}\mathbf{x}^\top)) = \text{Tr}(\mathbf{x}(\mathbf{x}^\top\mathbf{x})\mathbf{x}^\top) = \text{Tr}(\mathbf{x}\mathbf{x}^\top) = \mathbf{x}^\top\mathbf{x} = 1\).
Example 5.10 (Verifying the Norm of a Rank-One Projection). Let’s verify this essential property with a concrete example.
Let’s pick a simple 2D unit vector, \(\mathbf{x} = \frac{1}{\sqrt{5}}\begin{bmatrix} 1 \\ 2 \end{bmatrix}\). We can confirm its norm is 1: \(\|\mathbf{x}\|_2^2 = (\frac{1}{\sqrt{5}})^2 + (\frac{2}{\sqrt{5}})^2 = \frac{1}{5} + \frac{4}{5} = 1\).
Then, construct the outer product matrix \(\mathbf{P} = \mathbf{x}\mathbf{x}^\top\).
\[ \mathbf{P} = \left(\frac{1}{\sqrt{5}}\begin{bmatrix} 1 \\ 2 \end{bmatrix}\right) \left(\frac{1}{\sqrt{5}}\begin{bmatrix} 1 & 2 \end{bmatrix}\right) = \frac{1}{5} \begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix} = \begin{bmatrix} 0.2 & 0.4 \\ 0.4 & 0.8 \end{bmatrix}. \]Finally, compute the squared Frobenius norm of \(\mathbf{P}\). Using the definition (sum of the squares of all elements):
\[ \begin{aligned} \|\mathbf{P}\|_F^2 &= (0.2)^2 + (0.4)^2 + (0.4)^2 + (0.8)^2 \\ &= 0.04 + 0.16 + 0.16 + 0.64 = 1.00. \end{aligned} \]The property holds exactly. This shows that the “energy” or “magnitude” of a projection matrix formed from a unit vector is precisely 1.
Let’s expand the objective function using the identity \(\|\mathbf{M}-\mathbf{N}\|_F^2 = \|\mathbf{M}\|_F^2 - 2\langle \mathbf{M}, \mathbf{N} \rangle + \|\mathbf{N}\|_F^2\):
\[ \begin{aligned} \|\mathbf{A} - \lambda \mathbf{x}\mathbf{x}^\top\|_F^2 &= \|\mathbf{A}\|_F^2 - 2\langle \mathbf{A}, \lambda \mathbf{x}\mathbf{x}^\top \rangle + \|\lambda \mathbf{x}\mathbf{x}^\top\|_F^2 \\ &= \|\mathbf{A}\|_F^2 - 2\lambda \langle \mathbf{A}, \mathbf{x}\mathbf{x}^\top \rangle + \lambda^2 \|\mathbf{x}\mathbf{x}^\top\|_F^2 \\ &= \|\mathbf{A}\|_F^2 - 2\lambda \text{Tr}(\mathbf{A}^\top \mathbf{x}\mathbf{x}^\top) + \lambda^2(1) \end{aligned} \]Using the cyclic property of the trace, \(\text{Tr}(\mathbf{A}^\top \mathbf{x}\mathbf{x}^\top) = \text{Tr}(\mathbf{x}^\top\mathbf{A}^\top\mathbf{x}) = \mathbf{x}^\top\mathbf{A}\mathbf{x}\) (since \(\mathbf{A}\) is symmetric; check it yourself!). Our objective then becomes:
\[ f(\lambda, \mathbf{x}) = \|\mathbf{A}\|_F^2 - 2\lambda(\mathbf{x}^\top\mathbf{A}\mathbf{x}) + \lambda^2. \]This is a simple quadratic in \(\lambda\). For a fixed \(\mathbf{x}\), we can find the optimal \(\lambda\) by taking the derivative with respect to \(\lambda\) and setting it to zero:
\[ \frac{\partial f}{\partial \lambda} = -2(\mathbf{x}^\top\mathbf{A}\mathbf{x}) + 2\lambda = 0 \quad \implies \quad \lambda = \mathbf{x}^\top\mathbf{A}\mathbf{x}. \]I.e., the optimal scaling factor \(\lambda\) for a given direction \(\mathbf{x}\) is the quadratic form \(\mathbf{x}^\top\mathbf{A}\mathbf{x}\). This quantity is so important it has its own name: the Rayleigh Quotient; more below.
Substituting this optimal \(\lambda\) back into our objective, the problem reduces to one over \(\mathbf{x}\) only:
\[ \begin{aligned} &\min_{\|\mathbf{x}\|_2 = 1} \left( \|\mathbf{A}\|_F^2 - 2(\mathbf{x}^\top\mathbf{A}\mathbf{x})(\mathbf{x}^\top\mathbf{A}\mathbf{x}) + (\mathbf{x}^\top\mathbf{A}\mathbf{x})^2 \right) \\ &= \min_{\|\mathbf{x}\|_2 = 1} \left( \|\mathbf{A}\|_F^2 - (\mathbf{x}^\top\mathbf{A}\mathbf{x})^2 \right). \end{aligned} \]Since \(\|\mathbf{A}\|_F^2\) is a constant, minimizing this expression is equivalent to maximizing its positive part:
\[ \max_{\|\mathbf{x}\|_2 = 1} (\mathbf{x}^\top\mathbf{A}\mathbf{x})^2 \]which is equivalent to
\[ \max_{\|\mathbf{x}\|_2 = 1} |\mathbf{x}^\top\mathbf{A}\mathbf{x}|. \]All in all, the problem of finding the best rank-one approximation is equivalent to finding the unit vector \(\mathbf{x}\) that maximizes the Rayleigh Quotient.
Theorem 5.2 (Rayleigh Quotient). The solution to the optimization problem
\[ \max_{\mathbf{x} \in \mathbb{R}^p} |\mathbf{x}^\top\mathbf{A}\mathbf{x}| \quad \text{subject to} \quad \|\mathbf{x}\|_2 = 1 \]for a symmetric matrix \(\mathbf{A}\) is the eigenvector corresponding to the largest in magnitude eigenvalue of \(\mathbf{A}\). The maximum value of the objective is the absolute value of that largest in magnitude eigenvalue, \(|\lambda_1|\). The solution is unique up to sign when \(|\lambda_1| > |\lambda_2|\); if two eigenvalues tie in magnitude, each of their eigenvectors is a solution.
This transforms our approximation problem into a search for the direction of maximum stretch. The eigenvector associated with the largest in magnitude eigenvalue is the direction in which the transformation \(\mathbf{A}\) has the greatest effect, and the eigenvalue itself is the scaling factor in that direction.
To prove this, we will use the Spectral Theorem. The strategy is to change our coordinate system from the standard basis to the orthonormal basis of eigenvectors of \(\mathbf{A}\). In this new basis, the quadratic form \(\mathbf{x}^\top\mathbf{A}\mathbf{x}\) will simplify into a straightforward weighted sum, which we can then easily maximize.
Step 1: Express \(\mathbf{x}\) in the Eigenbasis of \(\mathbf{A}\). Since \(\mathbf{A}\) is symmetric, the Spectral Theorem guarantees that there exists an orthonormal basis of eigenvectors \(\{\mathbf{q}_1, \mathbf{q}_2, \dots, \mathbf{q}_p\}\) for the space \(\mathbb{R}^p\). Let the corresponding real eigenvalues be \(\{\lambda_1, \lambda_2, \dots, \lambda_p\}\), which we sort in descending order such that \(|\lambda_1| \ge |\lambda_2| \ge \dots \ge |\lambda_p|\).
Any vector \(\mathbf{x}\) can be uniquely expressed as a linear combination of these basis vectors:
\[ \mathbf{x} = \sum_{i=1}^p c_i \mathbf{q}_i, \]where the coefficients \(c_i\) are the coordinates of \(\mathbf{x}\) in this new basis.
Step 2: Simplify the Constraint. Our constraint is \(\|\mathbf{x}\|_2 = 1\), or equivalently, \(\|\mathbf{x}\|_2^2 = \mathbf{x}^\top\mathbf{x} = 1\). Let’s rewrite this using our new representation for \(\mathbf{x}\):
\[ \mathbf{x}^\top\mathbf{x} = \left( \sum_{i=1}^p c_i \mathbf{q}_i^\top \right) \left( \sum_{j=1}^p c_j \mathbf{q}_j \right) = \sum_{i=1}^p \sum_{j=1}^p c_i c_j (\mathbf{q}_i^\top \mathbf{q}_j). \]Because the eigenvectors form an orthonormal set, their inner product \(\mathbf{q}_i^\top \mathbf{q}_j\) is 1 if \(i=j\) and 0 otherwise. This property causes the double summation to collapse, as all the cross-terms where \(i \neq j\) disappear:
\[ \mathbf{x}^\top\mathbf{x} = \sum_{i=1}^p c_i^2 (\mathbf{q}_i^\top \mathbf{q}_i) = \sum_{i=1}^p c_i^2. \]Thus, on the new coordinates, the constraint \(\|\mathbf{x}\|_2 = 1\) is equivalent to: \(\sum_{i=1}^p c_i^2 = 1\).
Step 3: Simplify the Objective Function. Now we transform the objective function, the Rayleigh Quotient, into the new coordinate system:
\[ \mathbf{x}^\top\mathbf{A}\mathbf{x} = \left( \sum_{i=1}^p c_i \mathbf{q}_i^\top \right) \mathbf{A} \left( \sum_{j=1}^p c_j \mathbf{q}_j \right). \]First, let’s apply the matrix \(\mathbf{A}\) to the sum on the right. Since each \(\mathbf{q}_j\) is an eigenvector, we know that \(\mathbf{A}\mathbf{q}_j = \lambda_j \mathbf{q}_j\).
\[ \mathbf{A} \left( \sum_{j=1}^p c_j \mathbf{q}_j \right) = \sum_{j=1}^p c_j (\mathbf{A}\mathbf{q}_j) = \sum_{j=1}^p c_j \lambda_j \mathbf{q}_j. \]Substituting this back into our expression:
\[ \mathbf{x}^\top\mathbf{A}\mathbf{x} = \left( \sum_{i=1}^p c_i \mathbf{q}_i^\top \right) \left( \sum_{j=1}^p c_j \lambda_j \mathbf{q}_j \right) = \sum_{i=1}^p \sum_{j=1}^p c_i c_j \lambda_j (\mathbf{q}_i^\top \mathbf{q}_j). \]Again, due to the orthonormality of the eigenvectors, the inner product \(\mathbf{q}_i^\top \mathbf{q}_j\) is non-zero only when \(i=j\). The expression simplifies to:
\[ \mathbf{x}^\top\mathbf{A}\mathbf{x} = \sum_{i=1}^p c_i^2 \lambda_i. \]Step 4: Solve the Simplified Optimization Problem. This transformation is the heart of the proof. Our original, complex problem has been reduced to the following:
\[ \max_{c_1, \dots, c_p} \left| \sum_{i=1}^p c_i^2 \lambda_i\right| \quad \text{subject to} \quad \sum_{i=1}^p c_i^2 = 1. \]The objective is a weighted average of the eigenvalues, where the weights \(c_i^2\) are non-negative and must sum to one. To make this sum as large as possible in absolute value, we should place all of the weight on the largest in magnitude available term. Since we sorted our eigenvalues such that \(|\lambda_1| \ge |\lambda_2| \ge \dots\), that largest term is \(|\lambda_1|\).
We can show this formally. Since \(|\lambda_i| \le |\lambda_1|\) for all \(i\):
\[ \begin{aligned} \left|\sum_{i=1}^p c_i^2 \lambda_i\right| &\le \sum_{i=1}^p c_i^2 |\lambda_i| \le \sum_{i=1}^p c_i^2 |\lambda_1| \\ &= |\lambda_1| \sum_{i=1}^p c_i^2 = |\lambda_1| (1) = |\lambda_1|. \end{aligned} \]This proves that the maximum possible value of the objective is \(|\lambda_1|\).
Step 5: Find the Maximizer. The final step is to determine which vector \(\mathbf{x}\) achieves this maximum value. The maximum is achieved when we put all the “weight” (“our bet”) on the largest in magnitude eigenvalue. This corresponds to choosing the coefficients such that:
\[ c_1^2 = 1 \quad \text{and} \quad c_i^2 = 0 \text{ for all } i > 1. \]This implies that \(c_1 = \pm 1\) and all other coefficients are zero. What does this mean for our original vector \(\mathbf{x}\)?
\[ \mathbf{x} = \sum_{i=1}^p c_i \mathbf{q}_i = (\pm 1)\mathbf{q}_1 + 0\cdot\mathbf{q}_2 + \dots + 0\cdot\mathbf{q}_p = \pm \mathbf{q}_1. \]The maximum absolute value of the Rayleigh Quotient is achieved when the vector \(\mathbf{x}\) is exactly the eigenvector corresponding to the largest in magnitude eigenvalue, \(\mathbf{q}_1\) (or its negative, which represents the same direction).
This completes the proof. The change to the eigenbasis elegantly reveals that maximizing the quadratic form is equivalent to picking out the largest eigenvalue. But before we move on, an interlude on matrix powers.
5.3 Interlude: The Meaning of Matrix Powers
What does it mean to apply a linear transformation not once, but repeatedly? This concept of repeated application, or matrix powers, is the engine that drives the Power Method next and has implications in fields like graph theory and network analysis. Let’s dive into this, before we discuss the Power Method.
Formally, for any square matrix \(\mathbf{A}\), we define its powers as repeated multiplication:
\[ \mathbf{A}^2 = \mathbf{A}\mathbf{A}, \quad \mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}, \]and in general:
\[ \mathbf{A}^k = \underbrace{\mathbf{A}\mathbf{A}\cdots\mathbf{A}}_{k \text{ times}}. \]By convention, the zeroth power is the identity matrix, \(\mathbf{A}^0 = \mathbf{I}\). These powers follow the familiar rules of exponents, such that \(\mathbf{A}^k\mathbf{A}^l = \mathbf{A}^{k+l}\) and \((\mathbf{A}^k)^l = \mathbf{A}^{kl}\).
5.3.1 Application: Counting Paths in a Network
One of the most elegant applications of matrix powers is in understanding connectivity in networks (or graphs). A network can be represented by an adjacency matrix, \(\mathbf{A}\), where the entry \(A_{ij}\) is 1 if there is a directed connection (an edge) from node \(j\) to node \(i\), and 0 otherwise. Careful: column \(j\) is where an edge starts and row \(i\) is where it ends, the transpose of Chapter 3’s adjacency matrix. With this convention, \(\mathbf{A}\) times a vector moves weight along the edges, which is what PageRank needs at the end of this chapter.
Let’s examine the structure of \(\mathbf{A}^2\). The element at position \((i, j)\) is computed as:
\[ (\mathbf{A}^2)_{ij} = \sum_{k=1}^p A_{ik}A_{kj}. \]The term \(A_{ik}A_{kj}\) is 1 only if there is an edge from \(j\) to \(k\) and an edge from \(k\) to \(i\). This describes a path of length two from node \(j\) to node \(i\) that passes through the intermediate node \(k\). By summing over all possible intermediate nodes \(k\), the value \((\mathbf{A}^2)_{ij}\) counts the total number of distinct paths of length two from node \(j\) to node \(i\) (nodes may repeat along the way; graph theory calls such routes walks).
This remarkable property generalizes. It can be proven by induction that the matrix \(\mathbf{A}^k\) is a census of all paths of length \(k\):
\[ \begin{aligned} (\mathbf{A}^k)_{ij} = \text{\# of distinct paths of length $k$ from node $j$ to node $i$.} \end{aligned} \]Example 5.11 (Counting Paths with Matrix Powers). Consider the simple directed network shown below.
Its adjacency matrix \(\mathbf{A}\) (with \(A_{ij}=1\) for an edge \(j \to i\)) is constructed by listing the connections:
- From node 1: an edge to node 3 (\(A_{31}=1\)).
- From node 2: edges to node 1 (\(A_{12}=1\)), node 2 (\(A_{22}=1\)), and node 3 (\(A_{32}=1\)).
- From node 3: no outgoing edges.
This gives the correct adjacency matrix:
\[ \mathbf{A} = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 1 & 0 \\ 1 & 1 & 0 \end{bmatrix}. \]Let’s compute \(\mathbf{A}^2\) to find all paths of length two:
\[ \mathbf{A}^2 = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 1 & 0 \\ 1 & 1 & 0 \end{bmatrix} \begin{bmatrix} 0 & 1 & 0 \\ 0 & 1 & 0 \\ 1 & 1 & 0 \end{bmatrix} = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 1 & 0 \\ 0 & 2 & 0 \end{bmatrix}. \]Let’s interpret some entries of \(\mathbf{A}^2\) to verify the result:
- \((\mathbf{A}^2)_{32} = 2\): This predicts there are exactly two paths of length two from node 2 to node 3. By inspecting the graph, we can trace these two distinct paths:
- \(\square\)\(2 \to 1 \to 3\)
- \(\square\)\(2 \to 2 \to 3\)
- \(\square\)
- \((\mathbf{A}^2)_{12} = 1\): This predicts there is one path of length two from node 2 to node 1. We can trace this path: \(2 \to 2 \to 1\).
- \((\mathbf{A}^2)_{11} = 0\): This predicts there are zero paths of length two from node 1 to itself. This is correct, as there is no way to leave node 1 and return in exactly two steps.
The matrix power calculation correctly enumerates all paths of the specified length.
Just as repeated multiplication by an adjacency matrix reveals structural properties of a graph, repeated multiplication by any matrix \(\mathbf{A}\) reveals its dominant directional properties. The vector \(\mathbf{A}^k\mathbf{x}\) is the result of applying the transformation \(k\) times. As we are about to see, this repeated application amplifies the components of \(\mathbf{x}\) that are aligned with the dominant eigenvector, forcing any initial vector to converge to this principal direction (almost any: its part along the dominant eigenvector must not be zero, as we will see).
5.4 The Power Method: An Algorithm from Optimization
Going back to our original discussion, we are interested in how to solve
\[ \begin{aligned} \max_{\mathbf{x}} |\mathbf{x}^\top\mathbf{A}\mathbf{x}| \quad \text{s.t.} \quad \|\mathbf{x}\|_2=1. \end{aligned} \]We can use a simple iterative algorithm that “climbs the hill” of this function. This algorithm is the Power Method (or Power Iteration). It is based on a remarkably simple idea: if we repeatedly apply the transformation \(\mathbf{A}\) to an arbitrary vector, the vector will progressively align with the direction of maximum stretch: the dominant eigenvector.
To see this principle in action, let’s trace how the components of a vector evolve with each application of \(\mathbf{A}\).
Example 5.12 (How the Dominant Eigenvector Emerges). Let’s use \(\mathbf{A} = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix}\), with its eigenpairs:
- \(\lambda_1 = 4\), with eigenvector \(\mathbf{q}_1 = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ 1 \end{bmatrix}\).
- \(\lambda_2 = 2\), with eigenvector \(\mathbf{q}_2 = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ -1 \end{bmatrix}\).
Our starting vector will be \(\mathbf{x}_0 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\). This vector is an equal mix of the two eigenvectors:
\[ \mathbf{x}_0 = \frac{1}{\sqrt{2}}\mathbf{q}_1 + \frac{1}{\sqrt{2}}\mathbf{q}_2. \]The initial ratio of the magnitude of the \(\mathbf{q}_2\) component to the \(\mathbf{q}_1\) component is 1:1.
Let us apply \(\mathbf{A}\) once. We compute \(\mathbf{x}_1 = \mathbf{A}\mathbf{x}_0\). (In this example \(\mathbf{x}_t\) stands for \(\mathbf{A}^t\mathbf{x}_0\), with no normalization; in the algorithm below, \(\mathbf{x}_t\) is always a unit vector.) Using the decomposition:
\[ \begin{aligned} \mathbf{x}_1 &= \mathbf{A}\left(\frac{1}{\sqrt{2}}\mathbf{q}_1 + \frac{1}{\sqrt{2}}\mathbf{q}_2\right) = \frac{1}{\sqrt{2}}(\mathbf{A}\mathbf{q}_1) + \frac{1}{\sqrt{2}}(\mathbf{A}\mathbf{q}_2) \\ &= \frac{1}{\sqrt{2}}(\lambda_1\mathbf{q}_1) + \frac{1}{\sqrt{2}}(\lambda_2\mathbf{q}_2). \end{aligned} \]which leads to:
\[ \mathbf{x}_1 = \frac{4}{\sqrt{2}}\mathbf{q}_1 + \frac{2}{\sqrt{2}}\mathbf{q}_2. \]The component in the direction of \(\mathbf{q}_1\) has been magnified by a factor of 4, while the component in the direction of \(\mathbf{q}_2\) has only been magnified by 2. The new ratio of the \(\mathbf{q}_2\) component to the \(\mathbf{q}_1\) component is now 2:4, or 1:2. The dominant component is already becoming more prominent.
Let’s apply \(\mathbf{A}\) again. We compute \(\mathbf{x}_2 = \mathbf{A}\mathbf{x}_1 = \mathbf{A}^2\mathbf{x}_0\), where particularly:
\[ \begin{aligned} \mathbf{x}_2 &= \mathbf{A}\left(\frac{4}{\sqrt{2}}\mathbf{q}_1 + \frac{2}{\sqrt{2}}\mathbf{q}_2\right) = \frac{4}{\sqrt{2}}(\lambda_1\mathbf{q}_1) + \frac{2}{\sqrt{2}}(\lambda_2\mathbf{q}_2) \\ &= \frac{4 \cdot 4}{\sqrt{2}}\mathbf{q}_1 + \frac{2 \cdot 2}{\sqrt{2}}\mathbf{q}_2. \end{aligned} \]which leads to:
\[ \mathbf{x}_2 = \frac{16}{\sqrt{2}}\mathbf{q}_1 + \frac{4}{\sqrt{2}}\mathbf{q}_2. \]This exponential effect is now clear. The \(\mathbf{q}_1\) component is scaled by \(\lambda_1^2=16\), while the \(\mathbf{q}_2\) component is scaled by \(\lambda_2^2=4\). The ratio of the second component to the first has shrunk to 4:16, or 1:4.
Let’s track this evolution in Table 5.2. The ratio of the components is governed by \((\lambda_2/\lambda_1)^t = (2/4)^t = (0.5)^t\).
| \(t\) | \(\mathbf{q}_1\) component | \(\mathbf{q}_2\) component | ratio of components | \(\mathbf{A}^t \mathbf{x}_0\) |
|---|---|---|---|---|
| 0 | \(1/\sqrt{2} \approx 0.707\) | \(1/\sqrt{2} \approx 0.707\) | 1.0 | \([1, 0]^\top\) |
| 1 | \(4/\sqrt{2} \approx 2.828\) | \(2/\sqrt{2} \approx 1.414\) | 0.5 | \([3, 1]^\top\) |
| 2 | \(16/\sqrt{2} \approx 11.31\) | \(4/\sqrt{2} \approx 2.828\) | 0.25 | \([10, 6]^\top\) |
| 3 | \(64/\sqrt{2} \approx 45.25\) | \(8/\sqrt{2} \approx 5.657\) | 0.125 | \([36, 28]^\top\) |
| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
| \(t\) | \(\lambda_1^t/\sqrt{2}\) | \(\lambda_2^t/\sqrt{2}\) | \((0.5)^t \to 0\) | \(\tfrac{1}{2}[4^t + 2^t, 4^t - 2^t]^\top\) |
As the number of iterations increases, the component of the vector in the \(\mathbf{q}_2\) direction becomes negligible. The vector \(\mathbf{A}^t\mathbf{x}_0\) becomes almost perfectly parallel to the dominant eigenvector \(\mathbf{q}_1\); see also Figure 5.1. The Power Method algorithm simply adds a normalization step at each iteration to prevent the vector’s magnitude from growing exponentially, preserving the directional convergence while keeping the numbers manageable.
Based on the above, the Power Iteration algorithm is as follows:
The second test in the stopping check matters when the dominant eigenvalue is negative. Then each step flips the sign of the iterate, \(\mathbf{x}_{t+1} \approx -\mathbf{x}_t\), even after its direction has settled.
Example 5.13 (Power Method by Hand). Let’s find the dominant eigenvector of the matrix we have been analyzing, \(\mathbf{A} = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix}\). We already know its true eigenpairs are \(\lambda_1=4\) with \(\mathbf{q}_1 = \frac{1}{\sqrt{2}}[1, 1]^\top \approx [0.707, 0.707]^\top\), and \(\lambda_2=2\) with its corresponding eigenvector.
We start with a random-like initial vector, say \(\mathbf{x}_0 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\), which is not aligned with either eigenvector.
Iteration 1:
- Transform: Apply the matrix to the current vector. \[ \tilde{\mathbf{x}}_1 = \mathbf{A}\mathbf{x}_0 = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 3 \\ 1 \end{bmatrix}. \]
- Normalize: Compute the norm of the resulting vector. \[ \|\tilde{\mathbf{x}}_1\|_2 = \sqrt{3^2 + 1^2} = \sqrt{10} \approx 3.162. \]
- Update: Divide by the norm to get the new unit vector. \[ \mathbf{x}_1 = \frac{1}{\sqrt{10}}\begin{bmatrix} 3 \\ 1 \end{bmatrix} \approx \begin{bmatrix} 0.949 \\ 0.316 \end{bmatrix}. \]
After one step, our vector has already swung from pointing along the x-axis to a new direction that is closer to the true eigenvector.
Iteration 2:
- Transform: Apply the matrix to our new vector, \(\mathbf{x}_1\). \[ \begin{aligned} \tilde{\mathbf{x}}_2 &= \mathbf{A}\mathbf{x}_1 = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} \left(\frac{1}{\sqrt{10}}\begin{bmatrix} 3 \\ 1 \end{bmatrix}\right) \\ &= \frac{1}{\sqrt{10}}\begin{bmatrix} (3)(3)+(1)(1) \\ (1)(3)+(3)(1) \end{bmatrix} = \frac{1}{\sqrt{10}}\begin{bmatrix} 10 \\ 6 \end{bmatrix}. \end{aligned} \]
- Normalize: \[ \|\tilde{\mathbf{x}}_2\|_2 = \frac{1}{\sqrt{10}}\sqrt{10^2+6^2} = \frac{\sqrt{136}}{\sqrt{10}} \approx 3.688. \]
- Update: \[ \mathbf{x}_2 = \frac{\frac{1}{\sqrt{10}}\left[\begin{smallmatrix} 10 \\ 6 \end{smallmatrix}\right]}{\frac{\sqrt{136}}{\sqrt{10}}} = \frac{1}{\sqrt{136}}\begin{bmatrix} 10 \\ 6 \end{bmatrix} \approx \begin{bmatrix} 0.857 \\ 0.514 \end{bmatrix}. \]
The true dominant eigenvector is \([0.707, 0.707]^\top\). Our first two estimates are:
\[ \mathbf{x}_1 \approx \begin{bmatrix} 0.949 \\ 0.316 \end{bmatrix}, \quad \mathbf{x}_2 \approx \begin{bmatrix} 0.857 \\ 0.514 \end{bmatrix}. \]After just two iterations, our estimate has moved significantly closer to the true eigenvector, and the ratio of its components (\(0.514 / 0.857 \approx 0.6\)) is approaching 1. With each step, the vector “pivots” further towards the direction of maximum stretch.
But, how well does this algorithm perform? To answer this question and before analyzing the convergence rate in detail, it is crucial to address two practical aspects of the algorithm we have just defined: the choice of the starting vector, and what it means for the algorithm to “converge.”
5.4.1 A Note on the Algorithm: The Starting Point
The Power Method, like many iterative algorithms in AI (including gradient descent), is sensitive to its starting point. In our previous example, we chose an arbitrary vector, \(\mathbf{x}_0 = [1, 0]^\top\), and it worked perfectly. But what would happen if we made a very specific, unlucky choice?
Example 5.14 (Starting Orthogonal to the Solution). Using the same example, now our starting vector is \(\mathbf{x}_0 = \mathbf{q}_2 = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ -1 \end{bmatrix}\).
Iteration 1:
- Transform: Apply the matrix. Since \(\mathbf{x}_0\) is an eigenvector, this is simple. \[ \tilde{\mathbf{x}}_1 = \mathbf{A}\mathbf{x}_0 = \mathbf{A}\mathbf{q}_2 = \lambda_2 \mathbf{q}_2 = 2 \left( \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ -1 \end{bmatrix} \right). \]
- Normalize: The norm of the resulting vector is: \[ \|\tilde{\mathbf{x}}_1\|_2 = \|2 \mathbf{q}_2\|_2 = 2 \|\mathbf{q}_2\|_2 = 2(1) = 2. \]
- Update: Divide by the norm. \[ \mathbf{x}_1 = \frac{\tilde{\mathbf{x}}_1}{\|\tilde{\mathbf{x}}_1\|_2} = \frac{2 \mathbf{q}_2}{2} = \mathbf{q}_2. \]
The algorithm is permanently trapped. It started at \(\mathbf{q}_2\), and after one full iteration, its estimate has not changed at all. It will continue to produce \(\mathbf{q}_2\) indefinitely and will never find the true dominant eigenvector, \(\mathbf{q}_1\).
5.4.2 Why Did This Happen? The Role of the Initial Coefficients
This failure is not a coincidence; it is a direct consequence of the mathematics behind the convergence proof later in this chapter. Any starting vector \(\mathbf{x}_0\) can be written as a combination of the eigenvectors:
\[ \mathbf{x}_0 = c_1\mathbf{q}_1 + c_2\mathbf{q}_2 + \dots + c_p\mathbf{q}_p. \]After \(t\) iterations, the un-normalized vector is \(\mathbf{A}^t\mathbf{x}_0 = c_1\lambda_1^t\mathbf{q}_1 + c_2\lambda_2^t\mathbf{q}_2 + \dots\). The algorithm works because the term with the largest eigenvalue, \(c_1\lambda_1^t\mathbf{q}_1\), eventually grows to dominate all others (relative to the others: if every \(|\lambda_i|\) is below \(1\), all terms shrink, but the others shrink faster).
However, in our pathological example, the starting vector \(\mathbf{x}_0 = \mathbf{q}_2\) is perfectly orthogonal to \(\mathbf{q}_1\). This means its representation in the eigenbasis is:
\[ \mathbf{x}_0 = (0)\cdot\mathbf{q}_1 + (1)\cdot\mathbf{q}_2. \]The initial coefficient for the dominant eigenvector, \(c_1\), is exactly zero. Consequently, the dominant term \(c_1\lambda_1^t\mathbf{q}_1\) is zero for all iterations. It never gets a chance to grow, and the algorithm converges to the eigenvector corresponding to the next largest eigenvalue for which the initial coefficient was non-zero (in this case, \(\mathbf{q}_2\)).
5.4.3 Generalization and the Power of Randomness
This illustrates a crucial principle: initialization matters. The set of “bad” starting points for the Power Method is the entire subspace of vectors that are orthogonal to the true dominant eigenvector \(\mathbf{q}_1\).
How do we avoid starting in this failure-prone subspace? This is where randomness becomes a powerful tool. In a 2D space, the “bad” subspace is a single line. In a 3D space, it’s a plane. In a high-dimensional space, it is a hyperplane. While this subspace is infinitely large, it is also infinitesimally “thin” compared to the entire space of possible starting vectors.
If you were to pick a starting vector completely at random (for instance, by generating its components from a standard normal distribution), the probability of it landing exactly on this specific, “thin” hyperplane is virtually zero. A random vector will, with overwhelmingly high probability, have a non-zero component in every possible direction, including the direction of the dominant eigenvector.
Therefore, the standard practice for the Power Method is not just to pick an arbitrary vector, but to pick a random vector. This is not a heuristic; it is a theoretically sound strategy that ensures the condition \(c_1 \neq 0\) is met, allowing the algorithm to find the correct solution. (In other words, pay attention in the Stats class! :) ).
Now, assume we have overcome the issue of the initial point in our algorithm. But for how many iterations would we let the algorithm run? What does it mean “until convergence or stopping criteria are met”? For that, we will start discussing convergence metrics and what practitioners use in practice.
5.5 A Note on the Algorithm: When to Stop?
An iterative algorithm generates a sequence of improving estimates: \(\mathbf{x}_0, \mathbf{x}_1, \mathbf{x}_2, \dots\). The goal is to get this sequence as close as possible to the true solution, which we will call \(\mathbf{x}^\star\).
Ideally, we would stop when the error is small enough. We could measure this error in two ways:
- Error in the solution: The distance between our current estimate and the true solution is small: \(\|\mathbf{x}_t - \mathbf{x}^\star\|_2 < \varepsilon\) (or \(\|\mathbf{x}_t + \mathbf{x}^\star\|_2 < \varepsilon\): for the Power Method, \(-\mathbf{x}^\star\) is as good an answer as \(\mathbf{x}^\star\)).
- Error in the objective value: The value of the Rayleigh Quotient is close to the dominant eigenvalue, \(\lambda^\star\): \(|\lambda^\star - \mathbf{x}_t^\top\mathbf{A}\mathbf{x}_t| < \varepsilon\).
The fundamental caveat is that in any real problem, we do not know the true solution \(\mathbf{x}^\star\) or the true maximum value \(\lambda^\star\). If we did, we would not need to run the algorithm in the first place. Therefore, we must rely on practical, observable criteria that act as proxies for this true error.
5.5.1 Criterion 1: Fixed Number of Iterations
The simplest possible stopping criterion is to run the algorithm for a predetermined number of iterations, \(T\).
- Pros: This method is easy to implement and guarantees a predictable, finite runtime. This can be important in systems with strict time budgets. This is the reason why the per-iteration complexity of an algorithm needs to be analyzed and fleshed out: knowing that, we can extrapolate the final complexity by multiplying that \(O(\cdot)\) complexity with the number of iterations \(T\) to get the final complexity.
- Cons: This approach is highly inefficient and unreliable. The right number of iterations is problem-dependent. A fixed \(T\) might be far too large for an easy problem (wasting computation) or far too small for a hard problem (stopping with a poor solution).
Example 5.15 (The Impact of the Spectral Gap). Let’s run the Power Method for just \(T=2\) iterations on two different problems.
Problem 1 (Large Gap): Our matrix \(\mathbf{A} = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix}\). The true solution is \(\mathbf{q}^\star \approx [0.707, 0.707]^\top\). As we calculated before, starting from \(\mathbf{x}_0 =[1, 0]^\top\), we get:
\[ \mathbf{x}_2 \approx \begin{bmatrix} 0.857 \\ 0.514 \end{bmatrix}. \]This vector is already quite close to the true solution. The angle between our estimate and the truth is \(\arccos(\mathbf{x}_2^\top\mathbf{q}^\star) \approx 14^\circ\). We have made significant progress.
Problem 2 (Small Gap): Consider the matrix \(\mathbf{B} = \begin{bmatrix} 4 & 0 \\ 0 & 3.8 \end{bmatrix}\). The true dominant eigenvector is \(\mathbf{q}^\star =[1, 0]^\top\). Let’s start with a vector that is a mix of both eigenvectors, say \(\mathbf{x}_0 = \frac{1}{\sqrt{2}}[1, 1]^\top \approx [0.707, 0.707]^\top\).
Iteration 1:
\[ \tilde{\mathbf{x}}_1 = \mathbf{B}\mathbf{x}_0 = \left[\begin{smallmatrix} 4 & 0 \\ 0 & 3.8 \end{smallmatrix}\right] \left[\begin{smallmatrix} 0.707 \\ 0.707 \end{smallmatrix}\right] = \left[\begin{smallmatrix} 2.828 \\ 2.687 \end{smallmatrix}\right]. \]Normalizing gives \(\mathbf{x}_1 \approx [0.725, 0.689]^\top\).
Iteration 2:
\[ \tilde{\mathbf{x}}_2 = \mathbf{B}\mathbf{x}_1 = \left[\begin{smallmatrix} 4 & 0 \\ 0 & 3.8 \end{smallmatrix}\right] \left[\begin{smallmatrix} 0.725 \\ 0.689 \end{smallmatrix}\right] = \left[\begin{smallmatrix} 2.900 \\ 2.618 \end{smallmatrix}\right]. \]Normalizing gives \(\mathbf{x}_2 \approx [0.742, 0.670]^\top\). The angle between our final estimate and the truth is \(\arccos(\mathbf{x}_2^\top\mathbf{q}^\star) \approx 42^\circ\). After two iterations, we have made little progress compared to the previous case.
The spectral gap sets the speed
Example 5.15's two matrices, run for 30 steps instead of 2: the angle between the iterate and the dominant eigenvector after every step.
1def angles(M, x, q, T):
2 x, out = x / np.linalg.norm(x), []
3 for t in range(T + 1):
4 side = np.linalg.norm(x - (x @ q) * q) # the part of x off the line of q
5 out.append(np.degrees(np.arctan2(side, abs(x @ q))))
6 x = M @ x
7 x = x / np.linalg.norm(x)
8 return out
9A = np.array([[3.0, 1.0], [1.0, 3.0]]) # lambda2 / lambda1 = 2 / 4 = 0.5
10B = np.array([[4.0, 0.0], [0.0, 3.8]]) # lambda2 / lambda1 = 3.8 / 4 = 0.95
11curves = {"A": angles(A, np.array([1.0, 0.0]), np.array([1.0, 1.0]) / np.sqrt(2), 30),
12 "B": angles(B, np.array([1.0, 1.0]), np.array([1.0, 0.0]), 30)}
13for name, c in curves.items():
14 print(f"{name}: angle {c[0]:.0f} degrees at the start, {c[2]:.1f} after 2 steps, {c[30]:.2g} after 30")
A: angle 45 degrees at the start, 14.0 after 2 steps, 5.3e-08 after 30 B: angle 45 degrees at the start, 42.1 after 2 steps, 12 after 30
The angle against step, on a log scale. For A, with λ2/λ1 = 0.5, the tangent of the angle halves at every step: 14 degrees after 2 steps, as in the example, and under a ten-millionth of a degree after 30. For B, with λ2/λ1 = 0.95, it shrinks by only 5% per step: 42 degrees after 2 steps and still 12 after 30.
Recorded on an Apple M1 Max laptop, macOS 26.6.2, Python 3.13.7, NumPy 2.4.6, 2026-11-30.
5.5.2 Criterion 2: Stop When Progress Stalls
A much more robust and efficient approach is to monitor the algorithm’s progress and stop when the changes between iterations become negligibly small. This adapts to the difficulty of the problem, running for many iterations when needed but stopping early for simple cases.
This idea is formalized by measuring the distance between successive iterates and comparing it to a small, user-defined tolerance, \(\varepsilon\) (epsilon).
Stopping Criterion: Stop at iteration \(t\) if \(\|\mathbf{x}_{t+1} - \mathbf{x}_t\|_2 < \varepsilon\) (or \(\|\mathbf{x}_{t+1} + \mathbf{x}_t\|_2 < \varepsilon\) when the dominant eigenvalue is negative; see Algorithm 1).
Common choices for \(\varepsilon\) in practice are values like \(10^{-6}\) or \(10^{-8}\). This criterion essentially states: “If the algorithm has stopped making meaningful progress, we consider it to have converged.”
A catch: a small step is not a small error. On the slow matrix of Criterion 1, with eigenvalues \(4\) and \(3.8\), the first step is \(\|\mathbf{x}_1 - \mathbf{x}_0\|_2 \approx 0.026\). With the tolerance \(\varepsilon = 0.1\) of the next example, the test stops at \(t = 1\), still about \(44^\circ\) from \(\mathbf{q}_1\). When the ratio \(|\lambda_2|/|\lambda_1|\) is near \(1\) the iterate barely moves, so it looks stalled while it is still far away. Near the end, one step multiplies the angle to \(\mathbf{q}_1\) by about this ratio \(\rho\), so a step of size \(\varepsilon\) means an error of about \(\varepsilon/(1 - \rho)\): twenty times \(\varepsilon\) for \(\rho = 0.95\). In practice, use a tiny \(\varepsilon\) (with \(10^{-6}\) the test takes about \(20\) steps on \(\left[\begin{smallmatrix} 3 & 1 \\ 1 & 3 \end{smallmatrix}\right]\) and about \(210\) on the slow matrix) and keep a cap on the number of iterations.
Example 5.16 (Applying a Practical Stopping Criterion). Let’s revisit our first Power Method example (\(\mathbf{A} = \left[\begin{smallmatrix} 3 & 1 \\ 1 & 3 \end{smallmatrix}\right]\)) and apply this criterion with a tolerance of \(\varepsilon = 0.1\).
- Iteration 1: We found \(\mathbf{x}_1 \approx [0.949, 0.316]^\top\).
- Check: \(\|\mathbf{x}_1 - \mathbf{x}_0\|_2 = \|[-0.051, 0.316]^\top\|_2 \approx 0.320\).
- Decision: \(0.320 > 0.1\). Continue.
- Iteration 2: We found \(\mathbf{x}_2 \approx [0.857, 0.514]^\top\).
- Check: \(\|\mathbf{x}_2 - \mathbf{x}_1\|_2 = \|[-0.092, 0.198]^\top\|_2 \approx 0.218\).
- Decision: \(0.218 > 0.1\). Continue.
- Iteration 3: \(\tilde{\mathbf{x}}_3 = \mathbf{A}\mathbf{x}_2 = \left[\begin{smallmatrix} 3.085 \\ 2.399 \end{smallmatrix}\right]\). Normalizing gives \(\mathbf{x}_3 \approx [0.789, 0.614]^\top\).
- Check: \(\|\mathbf{x}_3 - \mathbf{x}_2\|_2 = \|[-0.068, 0.100]^\top\|_2 \approx 0.121\).
- Decision: \(0.121 > 0.1\). Continue.
- Iteration 4: \(\tilde{\mathbf{x}}_4 = \mathbf{A}\mathbf{x}_3 = \left[\begin{smallmatrix} 2.981 \\ 2.631 \end{smallmatrix}\right]\). Normalizing gives \(\mathbf{x}_4 \approx [0.750, 0.662]^\top\).
- Check: \(\|\mathbf{x}_4 - \mathbf{x}_3\|_2 = \|[-0.039, 0.048]^\top\|_2 \approx 0.062\).
- Decision: \(0.062 < 0.1\). Stop.
The algorithm halts at iteration 4, returning \(\mathbf{x}_4 \approx [0.750, 0.662]^\top\) as our final estimate.
In addition to monitoring the change in the solution vector, another widely used approach is to monitor the change in the objective function value itself. For the Power Method, our objective is to maximize the absolute value of the Rayleigh Quotient, \(f(\mathbf{x}) = \mathbf{x}^\top\mathbf{A}\mathbf{x}\). The logic is the same: if the objective value is no longer improving, we can be confident that we are near a solution.
Stopping Criterion (Objective Value): Stop at iteration \(t\) if \(|f(\mathbf{x}_{t+1}) - f(\mathbf{x}_t)| < \varepsilon\).
This criterion measures how much our “score” in the optimization game is improving. Let’s see how it performs on our running example.
Example 5.17 (Applying the Objective Value Criterion). We use the same setup: \(\mathbf{A} = \left[\begin{smallmatrix} 3 & 1 \\ 1 & 3 \end{smallmatrix}\right]\), \(\mathbf{x}_0 =[1, 0]^\top\), and the sequence of iterates \(\mathbf{x}_1, \mathbf{x}_2, \dots\) we found before. We will use a tolerance of \(\varepsilon = 0.05\).
- Initialize: First, we compute the objective value at the start. \[ f(\mathbf{x}_0) = \mathbf{x}_0^\top\mathbf{A}\mathbf{x}_0 = \begin{bmatrix} 1 & 0 \end{bmatrix} \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix} = 3. \]
- Iteration 1: We found \(\mathbf{x}_1 \approx [0.949, 0.316]^\top\).
- Compute new objective: \(f(\mathbf{x}_1) = \mathbf{x}_1^\top\mathbf{A}\mathbf{x}_1 \approx 3.60\).
- Check: \(|f(\mathbf{x}_1) - f(\mathbf{x}_0)| = |3.60 - 3| = 0.60\).
- Decision: \(0.60 > 0.05\). Continue.
- Iteration 2: We found \(\mathbf{x}_2 \approx [0.857, 0.514]^\top\).
- Compute new objective: \(f(\mathbf{x}_2) = \mathbf{x}_2^\top\mathbf{A}\mathbf{x}_2 \approx 3.88\).
- Check: \(|f(\mathbf{x}_2) - f(\mathbf{x}_1)| = |3.88 - 3.60| = 0.28\).
- Decision: \(0.28 > 0.05\). Continue.
- Iteration 3: We found \(\mathbf{x}_3 \approx [0.789, 0.614]^\top\).
- Compute new objective: \(f(\mathbf{x}_3) = \mathbf{x}_3^\top\mathbf{A}\mathbf{x}_3 \approx 3.97\).
- Check: \(|f(\mathbf{x}_3) - f(\mathbf{x}_2)| = |3.97 - 3.88| = 0.09\).
- Decision: \(0.09 > 0.05\). Continue.
- Iteration 4: We found \(\mathbf{x}_4 \approx [0.750, 0.662]^\top\).
- Compute new objective: \(f(\mathbf{x}_4) = \mathbf{x}_4^\top\mathbf{A}\mathbf{x}_4 \approx 3.99\).
- Check: \(|f(\mathbf{x}_4) - f(\mathbf{x}_3)| = |3.99 - 3.97| = 0.02\).
- Decision: \(0.02 < 0.05\). Stop.
Both criteria successfully detected that the rate of improvement had dropped below a meaningful threshold.
5.5.3 Absolute vs. Relative Change: The Importance of Normalization
While the simple difference \(|f(\mathbf{x}_t) - f(\mathbf{x}_{t-1})| < \varepsilon\) worked well in our example, it has a potential flaw: it is sensitive to the scale of the objective function.
Consider two scenarios:
- Large Scale: An optimization problem where the objective values are very large, say around \(1,000,000\). An improvement of \(100\) might be a negligible step (only \(0.01\%\)), but an absolute tolerance of \(\varepsilon = 0.01\) would never be met, causing the algorithm to run needlessly for many iterations.
- Small Scale: A different problem where the optimal value is very small, say \(10^{-9}\). An improvement of \(5 \times 10^{-10}\) might be significant (half the optimal value), but an absolute tolerance of \(\varepsilon = 10^{-8}\) would cause the algorithm to stop far too early, returning an inaccurate result.
To solve this, practitioners often use a relative stopping criterion, which normalizes the change by the magnitude of the objective value itself.
Stopping Criterion (Relative Objective Value): Stop at iteration \(t\) if \(\frac{|f(\mathbf{x}_t) - f(\mathbf{x}_{t-1})|}{|f(\mathbf{x}_{t-1})|} < \varepsilon\).
This criterion measures the percentage of improvement. A 1% improvement is treated the same whether the objective value is \(1,000,000\) or \(10^{-9}\), making the tolerance \(\varepsilon\) much more robust and interpretable across different problems. (To avoid division by zero when \(f(\mathbf{x}_{t-1})\) is small, practical implementations often use a hybrid like \(\frac{|f(\mathbf{x}_t) - f(\mathbf{x}_{t-1})|}{\max(1, |f(\mathbf{x}_{t-1})|)} < \varepsilon\)).
For the Power Method, the objective value converges to the dominant eigenvalue. Therefore, the scale of the absolute changes will be directly influenced by the magnitude of that eigenvalue. Using a relative tolerance is a sound strategy to ensure the stopping criterion behaves consistently regardless of whether the dominant eigenvalue is large or small.
5.6 Analysis and Complexity of the Power Method
We have seen empirically that the Power Method works, but to use it effectively, we must answer a critical question: how fast does it converge? A formal analysis will not only prove that convergence is guaranteed (under certain conditions) but will also reveal that the rate of convergence is geometric, allowing us to predict the number of iterations required to reach a desired accuracy.
5.6.1 Convergence Proof
The key idea is to track the “error” or “contamination” from the non-dominant eigenvectors and show that it decays exponentially to zero.
As mentioned before, our randomly chosen initial unit vector \(\mathbf{x}_0\) can be uniquely expressed in the eigenbasis:
\[ \mathbf{x}_0 = c_1\mathbf{q}_1 + c_2\mathbf{q}_2 + \dots + c_p\mathbf{q}_p = c_1\mathbf{q}_1 + \sum_{i=2}^p c_i\mathbf{q}_i. \]Since \(\mathbf{x}_0\) is a unit vector, we have \(\|\mathbf{x}_0\|_2^2 = \sum c_i^2 = 1\). Because we chose \(\mathbf{x}_0\) randomly, we can assume that the coefficient of the dominant eigenvector, \(c_1\), is non-zero. We also assume \(|\lambda_1| > |\lambda_2|\), so that \(|\lambda_2/\lambda_1| < 1\).
Applying \(\mathbf{A}^t\) to our decomposition gives:
\[ \tilde{\mathbf{x}}_t = \mathbf{A}^t\left(c_1\mathbf{q}_1 + \sum_{i=2}^p c_i\mathbf{q}_i\right) = c_1\lambda_1^t\mathbf{q}_1 + \sum_{i=2}^p c_i\lambda_i^t\mathbf{q}_i. \]To analyze its direction, we factor out the dominant term \(\lambda_1^t\):
\[ \tilde{\mathbf{x}}_t = \lambda_1^t \left( c_1\mathbf{q}_1 + \sum_{i=2}^p c_i\left(\frac{\lambda_i}{\lambda_1}\right)^t\mathbf{q}_i \right). \]The vector we care about is the normalized one, \(\mathbf{x}_t = \tilde{\mathbf{x}}_t / \|\tilde{\mathbf{x}}_t\|_2\), which is the iterate of the algorithm: normalizing at every step only rescales \(\mathbf{A}^t\mathbf{x}_0\). So \(\mathbf{x}_t\) is plus or minus the unit vector along the vector inside the parentheses above (minus when \(\lambda_1^t < 0\), which is why a negative \(\lambda_1\) flips the sign of \(\mathbf{x}_t\) every step). Let’s call this vector \(\mathbf{s}_t\) (the letter \(\mathbf{v}\) is taken by the singular vectors):
\[ \mathbf{s}_t = c_1\mathbf{q}_1 + \underbrace{\sum_{i=2}^p c_i\left(\frac{\lambda_i}{\lambda_1}\right)^t\mathbf{q}_i}_{\text{Error term, } \mathbf{e}_t}. \]The vector \(\mathbf{s}_t\) is simply the sum of our target signal, \(c_1\mathbf{q}_1\), and an error term, \(\mathbf{e}_t\), which is a combination of all the other eigenvectors. Our iterate \(\mathbf{x}_t\) lies on the line through \(\mathbf{s}_t\).
Let’s find the norm of the error term \(\mathbf{e}_t\). Since the eigenvectors are orthonormal, we can use the Pythagorean theorem:
\[ \|\mathbf{e}_t\|_2^2 = \left\|\sum_{i=2}^p c_i\left(\frac{\lambda_i}{\lambda_1}\right)^t\mathbf{q}_i\right\|_2^2 = \sum_{i=2}^p c_i^2 \left|\frac{\lambda_i}{\lambda_1}\right|^{2t}. \]Because of the spectral gap, we know that \(|\lambda_i| \le |\lambda_2|\) for all \(i \ge 2\). We can therefore bound this sum:
\[ \|\mathbf{e}_t\|_2^2 \le \sum_{i=2}^p c_i^2 \left|\frac{\lambda_2}{\lambda_1}\right|^{2t} = \left|\frac{\lambda_2}{\lambda_1}\right|^{2t} \sum_{i=2}^p c_i^2. \]Let’s define the constant \(C^2 = \sum_{i=2}^p c_i^2\). This constant depends only on our initial vector. Taking the square root gives us the final bound on the error term’s magnitude:
\[ \|\mathbf{e}_t\|_2 \le C \left|\frac{\lambda_2}{\lambda_1}\right|^t. \]The error term \(\mathbf{e}_t\) shrinks exponentially with each iteration. This means that the vector \(\mathbf{s}_t = c_1\mathbf{q}_1 + \mathbf{e}_t\) becomes more and more aligned with the line through the target eigenvector \(\mathbf{q}_1\). We quantify this with the angle \(\theta_t\) between the line through our iterate \(\mathbf{x}_t\) (the line through \(\mathbf{s}_t\)) and the line through \(\mathbf{q}_1\). Signs do not matter here: \(-\mathbf{q}_1\) is as good an answer as \(\mathbf{q}_1\), and a random start heads to \(-\mathbf{q}_1\) half of the time (when \(c_1 < 0\)). Since \(\mathbf{e}_t\) is perpendicular to \(\mathbf{q}_1\), the angle sits in a right triangle:
\[ \tan(\theta_t) = \frac{\|\mathbf{e}_t\|_2}{\|c_1\mathbf{q}_1\|_2} = \frac{\|\mathbf{e}_t\|_2}{|c_1|}. \]Substituting our bound for the error term:
\[ \tan(\theta_t) \le \frac{C}{|c_1|} \left|\frac{\lambda_2}{\lambda_1}\right|^t. \]This proves that the tangent of the angle between our estimate and the true eigenvector converges to zero at a geometric (or linear in log-scale) rate. The convergence rate is dictated by the spectral gap ratio, \(\rho = |\lambda_2|/|\lambda_1|\).
5.6.2 From Convergence Rate to Practical Guarantees
The formal analysis gives us a powerful tool to connect our desired accuracy, \(\varepsilon\), to the number of iterations, \(T\), that the algorithm must run.
Our convergence metric, such as the distance between iterates \(\|\mathbf{x}_t - \mathbf{x}_{t-1}\|_2\), is directly related to the angle \(\theta_t\). If we want our final error to be less than some tolerance \(\varepsilon\), we need to run the algorithm for enough iterations \(T\) such that:
\[ \frac{C}{|c_1|} \left|\frac{\lambda_2}{\lambda_1}\right|^T \approx \varepsilon. \]Solving for \(T\), we take the logarithm of both sides:
\[ T \log\left|\frac{\lambda_2}{\lambda_1}\right| + \log\left(\frac{C}{|c_1|}\right) \approx \log(\varepsilon). \]Since \(|\lambda_2/\lambda_1| < 1\), its logarithm is negative. Rearranging gives:
\[ \begin{aligned} T &\approx \frac{\log(\varepsilon) - \log(C/|c_1|)}{\log(|\lambda_2/\lambda_1|)} = \frac{\log(|c_1|/C) - \log(1/\varepsilon)}{\log(|\lambda_2/\lambda_1|)} \\ &= \frac{\log(1/\varepsilon) - \log(|c_1|/C)}{\log(|\lambda_1/\lambda_2|)}. \end{aligned} \]In Big-O notation, this simplifies to:
\[ T = O\left(\frac{\log(1/\varepsilon)}{\log(|\lambda_1/\lambda_2|)}\right). \]This shows that to get one additional digit of accuracy (i.e., to make \(\varepsilon\) ten times smaller), we only need to run a fixed number of additional iterations. This is the hallmark of a fast convergence rate.
Example 5.18 (Estimating Required Iterations). Let’s consider our matrix \(\mathbf{A} = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix}\), where the spectral gap ratio is \(\rho = 2/4 = 0.5\). Suppose we start with \(\mathbf{x}_0 =[1, 0]^\top\), for which we found \(c_1=1/\sqrt{2}\) and \(C^2 = c_2^2=0.5 \implies C=1/\sqrt{2}\). The constant term is \(\log(|c_1|/C) = \log(1) = 0\).
If we want to achieve an accuracy of \(\varepsilon = 10^{-3}\), how many iterations do we need?
\[ T \approx \frac{\log(1/10^{-3})}{\log(1/0.5)} = \frac{\log(1000)}{\log(2)} \approx \frac{3 \times \ln(10)}{\ln(2)} \approx \frac{3 \times 2.3}{0.693} \approx 9.96. \]The analysis predicts that we would need approximately 10 iterations to reach an error tolerance of \(10^{-3}\). If we wanted an error of \(10^{-6}\), we would need about 20 iterations.
Now consider the slow-converging matrix \(\mathbf{B}\) from before, with a spectral gap ratio of \(\rho = 3.8/4 = 0.95\).
\[ T \approx \frac{\log(1000)}{\log(1/0.95)} = \frac{\log(1000)}{-\log(0.95)} \approx \frac{6.907}{0.051} \approx 135. \]For the ill-conditioned problem (in terms of spectral gap), we would need around 135 iterations to reach the same accuracy; a direct, quantifiable consequence of the smaller spectral gap.
5.6.3 Complexity and Final Analysis
The cost per iteration is dominated by the matrix-vector product, which is \(O(p^2)\) for a dense matrix. The total complexity to reach an accuracy \(\varepsilon\) is therefore:
\[ \text{Total Cost} = O\left(p^2 \cdot \frac{\log(1/\varepsilon)}{\log(|\lambda_1/\lambda_2|)}\right). \]The Power Method is simple to implement and requires very little memory (it only needs to store the matrix \(\mathbf{A}\) and a single vector). It is particularly effective when the matrix is sparse, as the cost of the matrix-vector product drops from \(O(p^2)\) to \(O(\text{nnz}(\mathbf{A}))\), where \(\text{nnz}(\mathbf{A})\) is the number of non-zero entries. This makes it the method of choice for finding the dominant eigenvector of extremely large, sparse matrices, such as the web graph for Google’s PageRank algorithm (later in the text).
The method’s performance is critically dependent on the spectral gap. If the dominant eigenvalue is not well-separated from the next one (\(|\lambda_1| \approx |\lambda_2|\)), convergence can be painfully slow, as shown in our example. Furthermore, it can only find the single, dominant eigenvector.
5.7 Finding Other Eigenvectors: The Deflation Method
The Power Method provides an elegant and efficient way to find the single dominant eigenvector of a matrix. But what if we need more? In applications like Principal Component Analysis (PCA), we are often interested in the top \(k\) eigenvectors that capture the most significant dimensions of our data. How do we find the rest?
The most conceptually straightforward approach is deflation. The idea is brilliantly simple: once we have found the dominant eigenpair, we can alter the matrix to “remove” or “deflate” that component, transforming the problem into one where the second-largest eigenvalue is now the dominant one. We can then re-apply the Power Method to this new, deflated matrix to find the next eigenpair, and repeat the process.
5.7.1 The Deflation Procedure
Suppose we have successfully run the Power Method and found the dominant eigenpair, \((\lambda_1, \mathbf{q}_1)\). We can now construct a new matrix, \(\mathbf{A}'\), by subtracting the dominant rank-one component from the original matrix:
\[ \mathbf{A}' = \mathbf{A} - \lambda_1 \mathbf{q}_1\mathbf{q}_1^\top. \](We write \(\mathbf{A}'\) rather than \(\mathbf{A}_2\), because \(\mathbf{A}_2\) already means the best rank-2 copy in the SVD section. Since \(\lambda_1\mathbf{q}_1\mathbf{q}_1^\top\) is the best rank-one copy \(\mathbf{A}_1\), the deflated matrix is \(\mathbf{A}' = \mathbf{A} - \mathbf{A}_1\): what the best rank-one approximation leaves over.) This new matrix has a remarkable property: its eigensystem is intimately related to that of \(\mathbf{A}\).
- The vector \(\mathbf{q}_1\) is still an eigenvector of \(\mathbf{A}'\), but its corresponding eigenvalue has been “deflated” to zero.
- All other eigenvectors of \(\mathbf{A}\), \(\{\mathbf{q}_2, \dots, \mathbf{q}_p\}\), are also eigenvectors of \(\mathbf{A}'\), and their corresponding eigenvalues are unchanged.
Let’s quickly show this. First, let’s see how \(\mathbf{A}'\) acts on \(\mathbf{q}_1\):
\[ \mathbf{A}'\mathbf{q}_1 = (\mathbf{A} - \lambda_1 \mathbf{q}_1\mathbf{q}_1^\top)\mathbf{q}_1 = \mathbf{A}\mathbf{q}_1 - \lambda_1 \mathbf{q}_1(\mathbf{q}_1^\top\mathbf{q}_1). \]Since \(\mathbf{q}_1\) is a unit vector, \(\mathbf{q}_1^\top\mathbf{q}_1=1\). And since it’s an eigenvector of \(\mathbf{A}\), \(\mathbf{A}\mathbf{q}_1 = \lambda_1\mathbf{q}_1\). This gives:
\[ \mathbf{A}'\mathbf{q}_1 = \lambda_1\mathbf{q}_1 - \lambda_1\mathbf{q}_1(1) = \mathbf{0} = 0 \cdot \mathbf{q}_1. \]Now, for any other eigenvector \(\mathbf{q}_i\) (where \(i \neq 1\)), we use the fact that it is orthogonal to \(\mathbf{q}_1\), meaning \(\mathbf{q}_i^\top\mathbf{q}_1 = 0\):
\[ \begin{aligned} \mathbf{A}'\mathbf{q}_i &= (\mathbf{A} - \lambda_1 \mathbf{q}_1\mathbf{q}_1^\top)\mathbf{q}_i \\ &= \mathbf{A}\mathbf{q}_i - \lambda_1 \mathbf{q}_1(\mathbf{q}_1^\top\mathbf{q}_i) = \lambda_i\mathbf{q}_i - \lambda_1\mathbf{q}_1(0) = \lambda_i\mathbf{q}_i. \end{aligned} \]The other eigenpairs remain completely intact! The new set of eigenvalues for \(\mathbf{A}'\) is \(\{0, \lambda_2, \lambda_3, \dots, \lambda_p\}\). The dominant eigenvalue of this new matrix is now \(\lambda_2\). We can simply apply the Power Method to \(\mathbf{A}'\) to find \((\lambda_2, \mathbf{q}_2)\), and repeat the process as needed.
Example 5.19 (Deflation in Action). Let’s find the second eigenpair of our trusted matrix, \(\mathbf{A} = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix}\).
From our previous work, we know \(\lambda_1 = 4\) and \(\mathbf{q}_1 = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ 1 \end{bmatrix}\).
Next, we construct the deflated matrix \(\mathbf{A}'\).
\[ \begin{aligned} \mathbf{A}' &= \mathbf{A} - \lambda_1 \mathbf{q}_1\mathbf{q}_1^\top = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} - 4 \left(\frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ 1 \end{bmatrix}\right)\left(\frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \end{bmatrix}\right) \\ &= \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} - 4 \left(\frac{1}{2}\begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix}\right) = \begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} - \begin{bmatrix} 2 & 2 \\ 2 & 2 \end{bmatrix} \\ &= \begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix}. \end{aligned} \]This is our new matrix. Its dominant eigenvalue should be \(\lambda_2=2\).
To see this, we apply the Power Method to the deflated matrix \(\mathbf{A}'\). Let’s start with the same initial vector as before, \(\mathbf{x}_0 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\).
- \(\tilde{\mathbf{x}}_1 = \mathbf{A}'\mathbf{x}_0 = \begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 1 \\ -1 \end{bmatrix}\).
- \(\|\tilde{\mathbf{x}}_1\|_2 = \sqrt{1^2+(-1)^2} = \sqrt{2}\).
- \(\mathbf{x}_1 = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 \\ -1 \end{bmatrix}\).
Amazingly, the algorithm converged in a single step! Our estimate \(\mathbf{x}_1\) is the exact second eigenvector, \(\mathbf{q}_2\). Let’s estimate its eigenvalue: \(\mathbf{x}_1^\top\mathbf{A}\mathbf{x}_1 = 2\). This example demonstrates that applying the Power Method to the deflated matrix successfully finds the next eigenvector in the sequence.
5.7.2 Complexity and Practical Considerations
The deflation method provides a complete algorithm for finding the top \(k\) eigenvectors.
Let’s analyze the total cost. Each of the \(k\) main steps involves one full run of the Power Method followed by one deflation step.
Power method. Let’s say it takes \(T_j\) iterations to find the \(j\)-th eigenvector. The cost is \(O(T_j \cdot p^2)\).
Deflation. The deflation update \(\mathbf{A}_{\text{current}} \gets \mathbf{A}_{\text{current}} - \hat{\lambda}_j \mathbf{q}_j\mathbf{q}_j^\top\) requires: \(i)\) An outer product \(\mathbf{q}_j\mathbf{q}_j^\top\): \(O(p^2)\); \(ii)\) A scalar-matrix multiplication: \(O(p^2)\); \(iii)\) A matrix subtraction: \(O(p^2)\). The total cost of one deflation step is \(O(p^2)\).
Total. The total complexity to find \(k\) eigenvectors is the sum of these costs:
\[ \text{Total Cost} = \sum_{j=1}^k O(T_j \cdot p^2 + p^2) = O(k \cdot \bar{T} \cdot p^2), \]where \(\bar{T}\) is the average number of iterations per eigenvector.
5.7.3 The Hidden Dangers: A Word of Caution
While conceptually simple, deflation has serious practical drawbacks that make it less common in high-precision numerical software.
The biggest issue is the accumulation of numerical errors. The Power Method finds an approximation of \(\mathbf{q}_1\), not the exact vector. This small error in \(\mathbf{q}_1\) gets “baked into” the deflated matrix \(\mathbf{A}'\). The subsequent Power Method run on this slightly incorrect matrix will find a slightly incorrect \(\mathbf{q}_2\). This error is then baked into \(\mathbf{A}''\), and so on. The errors compound, and the accuracy of the eigenvectors found later in the sequence can be very poor. A particularly damaging effect is the loss of orthogonality between the computed eigenvectors.
The Power Method’s greatest strength is its efficiency on large, sparse matrices. However, the deflation step is catastrophic for sparsity. The outer product \(\mathbf{q}_j\mathbf{q}_j^\top\) is almost always a completely dense matrix. When you subtract this dense matrix from a sparse matrix, the result is dense. If the deflated matrix is formed explicitly, all subsequent matrix-vector products will be slow \(O(p^2)\) operations, completely negating the initial advantage of sparsity. The fix is not to form it: \(\mathbf{A}'\mathbf{x} = \mathbf{A}\mathbf{x} - \lambda_1\mathbf{q}_1(\mathbf{q}_1^\top\mathbf{x})\) costs one sparse product plus \(O(p)\).
Because of these limitations, while deflation is a brilliant theoretical tool, more numerically stable methods like Orthogonal Iteration or the Lanczos algorithm are typically used in practice for finding multiple eigenvectors of large matrices.
5.7.4 The Power Method Computes the SVD Too
The SVD section promised that the Power Method also computes singular values and singular vectors. The symmetric matrix \(\mathbf{A}^\top\mathbf{A}\) has eigenvectors \(\mathbf{v}_i\) (the right singular vectors of \(\mathbf{A}\)) and eigenvalues \(\sigma_i^2\). So:
- run Algorithm 1 on \(\mathbf{A}^\top\mathbf{A}\); it returns \(\mathbf{v}_1\), and its Rayleigh quotient returns \(\sigma_1^2\);
- set \(\sigma_1 = \sqrt{\sigma_1^2}\) and \(\mathbf{u}_1 = \mathbf{A}\mathbf{v}_1/\sigma_1\);
- deflate, \(\mathbf{A}^\top\mathbf{A} - \sigma_1^2\mathbf{v}_1\mathbf{v}_1^\top\), and repeat to get \((\sigma_2, \mathbf{u}_2, \mathbf{v}_2)\), and so on.
We never need to form \(\mathbf{A}^\top\mathbf{A}\): each step multiplies a vector by \(\mathbf{A}\) and then by \(\mathbf{A}^\top\), since \(\mathbf{A}^\top\mathbf{A}\mathbf{x} = \mathbf{A}^\top(\mathbf{A}\mathbf{x})\), at a cost of \(O(mn)\). Deflation keeps this: \((\mathbf{A}^\top\mathbf{A} - \sigma_1^2\mathbf{v}_1\mathbf{v}_1^\top)\mathbf{x} = \mathbf{A}^\top(\mathbf{A}\mathbf{x}) - \sigma_1^2\mathbf{v}_1(\mathbf{v}_1^\top\mathbf{x})\) adds only \(O(n)\). The speed depends on the ratio \(\sigma_2^2/\sigma_1^2\) of the top two eigenvalues of \(\mathbf{A}^\top\mathbf{A}\). For the \(2 \times 3\) matrix of Example 5.1 the ratio is \(10/12 \approx 0.83\), so each step shrinks the error by only about \(17\%\). One caution: going through \(\mathbf{A}^\top\mathbf{A}\) squares the condition number (SVD section), so the top \(\sigma_i\) come out accurately while the small ones lose digits. Libraries work with \(\mathbf{A}\) itself.
5.8 The Trillion-Dollar Eigenvector
While the theory is elegant, one might wonder about its real-world impact. Does finding the direction of “maximum stretch” solve problems outside of data science and physics?
The answer is a yes. This section explores how the concepts we have studied became the foundation for Google’s original PageRank algorithm, an innovation that helped organize the World Wide Web and launch a multi-trillion-dollar company.
5.8.1 The Problem: Ranking the Chaos of the Web
In the late 1990s, early search engines in the internet ranked pages primarily by content, counting how many times a search term appeared. This was easily manipulated and often produced irrelevant results. The founders of Google, Sergey Brin and Larry Page, proposed the following: the importance of a webpage is not just determined by its own content, but by the other pages that link to it. A link from a high-quality, authoritative page to another is a strong “vote” of confidence.
This simple idea reframes the web as a massive, directed graph where pages are nodes and hyperlinks are edges. The question then becomes: how do you mathematically define “importance” or “rank” in a network of billions of nodes and trillions of links?
5.8.2 The Model
The conceptual breakthrough was to model the behavior of a hypothetical “random surfer.” This surfer starts on a random webpage and endlessly clicks on links. The pages that this surfer visits most often are, by definition, the most important ones. The PageRank of a webpage is simply the long-term probability of finding our random surfer on that page.
Let’s formalize this for a small internet with \(p\) pages.
- The Adjacency Matrix (\(\mathbf{L}\)): We first build a \(p \times p\) adjacency matrix where \(L_{ij} = 1\) if there is a link from page \(j\) to page \(i\), and 0 otherwise.
- The Probability Matrix (\(\mathbf{A}\)): A surfer on page \(j\) with \(d_j\) outgoing links will click on any one of them with probability \(1/d_j\). We can create a column-stochastic matrix \(\mathbf{A}\) (every column sums to 1) by dividing each column of \(\mathbf{L}\) by its sum. The entry \(A_{ij}\) now represents the probability that a surfer on page \(j\) will click a link to page \(i\). (Again, pay attention to the Stats class!)
Let a vector \(\mathbf{z}_t \in \mathbb{R}^p\) represent the probability distribution of the surfer’s location at time step \(t\). The sum of its entries is 1. If the surfer is at location \(\mathbf{z}_t\), their location at the next time step, \(\mathbf{z}_{t+1}\), is found by applying the transformation matrix \(\mathbf{A}\):
\[ \mathbf{z}_{t+1} = \mathbf{A}\mathbf{z}_t. \]After many clicks, this probability distribution should stabilize, meaning it no longer changes. This final, stable distribution is the PageRank vector, \(\mathbf{z}\). At this stationary state, we must have:
\[ \mathbf{z} = \mathbf{A}\mathbf{z}. \]5.8.3 The Eigen-Connection and the Power Method
Rewriting the equation as \(\mathbf{A}\mathbf{z} = 1 \cdot \mathbf{z}\) reveals its true identity: the PageRank vector \(\mathbf{z}\) is the eigenvector of the web’s probability matrix \(\mathbf{A}\) corresponding to the eigenvalue \(\lambda=1\).
How can we find this eigenvector for a matrix representing billions of webpages? We cannot invert it or compute its characteristic polynomial. However, the update rule \(\mathbf{z}_{t+1} = \mathbf{A}\mathbf{z}_t\) is precisely the core operation of the Power Method. Starting with an initial guess (e.g., a uniform distribution \(\mathbf{z}_0 = [1/p, \dots, 1/p]^\top\)), we can find the PageRank by simply iterating:
\[ \mathbf{z}_t = \mathbf{A}^t \mathbf{z}_0. \]This sequence will converge to the dominant eigenvector. But for this to work, we need a guarantee that \(\lambda=1\) is the largest eigenvalue.
Half of the guarantee is easy. Take \(\mathbf{A}\mathbf{z} = \lambda\mathbf{z}\) and add up the sizes of the entries:
\[ \begin{aligned} |\lambda|\sum_i |z_i| = \sum_i \Big|\sum_j A_{ij}z_j\Big| &\leq \sum_i\sum_j A_{ij}|z_j| \\ &= \sum_j |z_j|\sum_i A_{ij} = \sum_j |z_j|, \end{aligned} \]because the entries of \(\mathbf{A}\) are non-negative and each column sums to \(1\). So \(|\lambda| \leq 1\): no eigenvalue is larger than \(1\) in size. The other half, that no other eigenvalue ties with \(1\) in size, is what the refinement below buys. One more caution: this \(\mathbf{A}\) is not symmetric, so the Rayleigh quotient story and the convergence proof of this chapter do not apply to it as they stand; the Perron–Frobenius theorem below plays their role.
Example 5.20 (A Three-Page Internet). Consider the simple network below.
The probability matrix \(\mathbf{A}\) is:
\[ \mathbf{A} = \begin{bmatrix} 0 & 0 & 1 \\ 1/2 & 0 & 0 \\ 1/2 & 1 & 0 \end{bmatrix}. \]Let’s start with a uniform distribution \(\mathbf{z}_0 = [1/3, 1/3, 1/3]^\top \approx [0.333, 0.333, 0.333]^\top\).
- Iteration 1: \(\mathbf{z}_1 = \mathbf{A}\mathbf{z}_0 = [0.333, 0.167, 0.500]^\top\). Page 3 is already the most likely.
- Iteration 2: \(\mathbf{z}_2 = \mathbf{A}\mathbf{z}_1 = [0.500, 0.167, 0.333]^\top\). Page 1 is now most likely.
- Iteration 3: \(\mathbf{z}_3 = \mathbf{A}\mathbf{z}_2 = [0.333, 0.250, 0.417]^\top\).
- …
- After many iterations: The vector converges to the stationary distribution (the true PageRank): \[ \mathbf{z}^\star \approx \begin{bmatrix} 0.40 \\ 0.20 \\ 0.40 \end{bmatrix}. \]
Pages 1 and 3 are the most important, each twice as likely to be visited as Page 2. By hand: \(\mathbf{A}\mathbf{z} = \mathbf{z}\) gives \(z_1 = z_3\) (row 1) and \(z_2 = z_1/2\) (row 2); with the entries summing to \(1\), \(\mathbf{z}^\star = [0.4, 0.2, 0.4]^\top\) exactly. The iteration does settle here because the other two eigenvalues of \(\mathbf{A}\) have size about \(0.71\), below \(1\); the next subsection shows a web where it never settles.
5.8.4 The Trillion-Dollar Refinement
The real web has problems like “dangling nodes” (pages with no outgoing links) and cycles, which can trap the random surfer and break the simple model. Two pages that link only to each other give \(\mathbf{A} = \left[\begin{smallmatrix} 0 & 1 \\ 1 & 0 \end{smallmatrix}\right]\), with eigenvalues \(1\) and \(-1\) of the same size: from \([1, 0]^\top\) the surfer bounces forever, \([1, 0]^\top \to [0, 1]^\top \to [1, 0]^\top \to \cdots\), and nothing settles. A dangling page has a column of zeros in \(\mathbf{L}\), so the division above is impossible. The fix is to let a surfer on a dangling page jump to any page, which makes its column of \(\mathbf{A}\) all \(1/p\). The full PageRank algorithm then introduces a “teleportation” factor: with a small probability (say, 15%), the surfer gets bored, ignores the links, and jumps to any page on the web with uniform probability. This is captured in the modified Google matrix:
\[ \mathbf{M} = (1-\beta)\mathbf{A} + \beta\mathbf{J}, \]where \(\beta = 0.15\) is the probability of a random jump and \(\mathbf{J}\) is a matrix with every entry equal to \(1/p\) (J for jump; the letter \(\mathbf{B}\) is taken by the slow matrix of the stopping criteria). A powerful result from the Perron-Frobenius theorem guarantees that this new matrix \(\mathbf{M}\) has a unique, positive eigenvector with eigenvalue \(\lambda=1\), and all other eigenvalues are smaller in magnitude.
This refinement ensures that a unique PageRank vector exists and, critically, that the spectral gap is guaranteed. This makes the Power Method a robust and reliable algorithm for finding this trillion-dollar eigenvector.
The final piece of the puzzle is computational efficiency. The adjacency matrix of the web is astronomically large, but it is also incredibly sparse; most pages do not link to most other pages. As we’ve seen, the Power Method’s complexity per iteration on a sparse matrix is proportional to the number of non-zero entries (the number of links), not the total number of pages squared. This still holds for \(\mathbf{M}\), as long as the dangling columns and the jump are applied without forming them: every entry of \(\mathbf{J}\mathbf{z}\) equals \(1/p\) because \(\mathbf{z}\) sums to \(1\), and a dangling column adds the same number to every entry. One iteration then costs about the number of links plus \(p\). This efficiency is what made it possible to calculate the ranks of the entire web, turning a piece of linear algebra into the foundation of modern search.
Exercises
Below is a set of exercises related to the content of Chapter 5. The exercises are partitioned by difficulty. Programming questions should be completed in Python using the NumPy library, assuming knowledge from an introductory algorithms course.
EASY EXERCISES
- E1.Rayleigh Quotient Calculation. For the symmetric matrix \(\mathbf{A} = \begin{bmatrix} 5 & 2 \\ 2 & 2 \end{bmatrix}\) and the unit vector \(\mathbf{q} = \frac{1}{\sqrt{5}}\begin{bmatrix} 2 \\ 1 \end{bmatrix}\), compute the Rayleigh Quotient \(\mathbf{q}^\top\mathbf{A}\mathbf{q}\).
- E2.One Step of Power Method. Given the matrix \(\mathbf{A} = \begin{bmatrix} 6 & 2 \\ 2 & 3 \end{bmatrix}\) and the starting vector \(\mathbf{x}_0 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\), perform one full iteration of the Power Method to find the next estimate, \(\mathbf{x}_1\).
- E3.Matrix Powers for Path Counting. Given the adjacency matrix for a 3-node graph: \[ \mathbf{A} = \begin{bmatrix} 0 & 1 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix}. \]
Compute \(\mathbf{A}^2\) and state the number of paths of length two from node 2 to node 1.
- E4.Stopping Criteria Concept. What is the main practical problem with using an “ideal” stopping criterion like \(\|\mathbf{x}_t - \mathbf{x}^\star\|_2 < \varepsilon\) in a real-world application?
- E5.Spectral Gap and Convergence. Matrix \(\mathbf{A}\) has eigenvalues \(\{10, 9, 5, 2\}\). Matrix \(\mathbf{B}\) has eigenvalues \(\{10, 5, 4, 1\}\). For which matrix will the Power Method converge to the dominant eigenvector faster? Explain your reasoning.
- E6.Deflation Formula. After finding the dominant eigenpair \((\lambda_1, \mathbf{q}_1)\) of a matrix \(\mathbf{A}\), what is the formula for the deflated matrix \(\mathbf{A}'\) that you would use to find the second eigenpair?
- E7.PageRank’s Core Equation. What is the fundamental eigenvector equation that the final PageRank vector \(\mathbf{z}\) must satisfy with respect to the web’s probability matrix \(\mathbf{A}\)?
MEDIUM EXERCISES
- M1.Power Method with Stopping Criterion. Using the matrix \(\mathbf{A} = \begin{bmatrix} 5 & 2 \\ 2 & 2 \end{bmatrix}\) and starting vector \(\mathbf{x}_0 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\), perform iterations of the Power Method until the stopping criterion \(\|\mathbf{x}_t - \mathbf{x}_{t-1}\|_2 < 0.1\) is met. Show the result of each iteration.
- M2.Best Rank-One Approximation. The dominant eigenpair of the matrix \(\mathbf{A} = \begin{bmatrix} 6 & 2 \\ 2 & 3 \end{bmatrix}\) is \(\lambda_1 = 7\) and \(\mathbf{q}_1 = \frac{1}{\sqrt{5}}\begin{bmatrix} 2 \\ 1 \end{bmatrix}\). What is the best rank-one approximation of \(\mathbf{A}\)? Compute this matrix explicitly.
- M3.Initialization Failure. You are running the Power Method on the matrix \(\mathbf{A} = \begin{bmatrix} 10 & 0 \\ 0 & 1 \end{bmatrix}\). If you start with the vector \(\mathbf{x}_0 = \begin{bmatrix} 0 \\ 1 \end{bmatrix}\), what will the sequence of iterates \(\mathbf{x}_t\) be? Explain why the algorithm fails to find the dominant eigenvector in this case, using the concept of the initial vector’s decomposition in the eigenbasis.
- M4.Full Deflation Procedure. For the matrix \(\mathbf{A} = \begin{bmatrix} 6 & 2 \\ 2 & 3 \end{bmatrix}\) (whose dominant eigenpair is given in M2):
- a)Compute the deflated matrix \(\mathbf{A}'\).
- b)Show by direct multiplication that the second eigenvector of \(\mathbf{A}\), which is \(\mathbf{q}_2 = \frac{1}{\sqrt{5}}\begin{bmatrix} 1 \\ -2 \end{bmatrix}\), is also an eigenvector of \(\mathbf{A}'\). What is its eigenvalue for \(\mathbf{A}'\)?
- a)
- M5.Complexity on Sparse vs. Dense Matrices. A \(1000 \times 1000\) matrix \(\mathbf{A}\) is extremely sparse and has only 5000 non-zero entries. A second matrix \(\mathbf{B}\) of the same size is dense. Compare the approximate number of FLOPs required for one iteration of the Power Method on \(\mathbf{A}\) versus on \(\mathbf{B}\).
- M6.PageRank Matrix Construction. For the web graph shown below, construct the column-stochastic probability matrix \(\mathbf{A}\). Then, starting with a uniform probability distribution \(\mathbf{z}_0\), compute the distribution after one step, \(\mathbf{z}_1\).
- M7.Python: Power Method Implementation. Write a Python function
power_method(A, num_iter=100)that implements the Power Method. It should take a matrixAand a number of iterations, initialize with a random vector, and return the estimated dominant eigenvector. Test it on the matrix from M1. - M8.Rayleigh Quotient of an Eigenvector. Prove that if \(\mathbf{q}\) is a normalized eigenvector of a symmetric matrix \(\mathbf{A}\) with corresponding eigenvalue \(\lambda\), its Rayleigh Quotient \(\mathbf{q}^\top\mathbf{A}\mathbf{q}\) is exactly equal to \(\lambda\).
HARD EXERCISES
- H1.Convergence Rate Proof. For a symmetric matrix \(\mathbf{A}\) with eigenpairs \((\lambda_i, \mathbf{q}_i)\) and a starting vector \(\mathbf{x}_0 = c_1\mathbf{q}_1 + c_2\mathbf{q}_2\), show that the “contamination” from the second eigenvector, measured by the ratio of the coefficients of \(\mathbf{q}_2\) to \(\mathbf{q}_1\) in the vector \(\mathbf{A}^t\mathbf{x}_0\), decreases by a factor of exactly \(|\lambda_2/\lambda_1|\) at each iteration.
- H2.Deflation Drawbacks. The deflation method replaces the matrix \(\mathbf{A}\) with \(\mathbf{A}' = \mathbf{A} - \lambda_1\mathbf{q}_1\mathbf{q}_1^\top\).
- a)Explain why this method is poorly suited for large, sparse matrices.
- b)Create a simple \(3 \times 3\) symmetric matrix \(\mathbf{A}\) with some zero entries (for example, tridiagonal), compute its dominant eigenpair \((\lambda_1, \mathbf{q}_1)\), and show by direct computation that the deflated matrix \(\mathbf{A}'\) is dense.
- a)
- H3.Inverse Power Method. The Power Method finds the eigenvalue with the largest magnitude. Propose an algorithm to find the eigenvalue with the smallest magnitude, assuming the matrix \(\mathbf{A}\) is invertible. (Hint: What are the eigenvalues of \(\mathbf{A}^{-1}\) in relation to the eigenvalues of \(\mathbf{A}\)?). Explain where this “Inverse Power Method” pays more than the standard Power Method: once, up front, or in every iteration?
- H4.Python: Power Method with Deflation. Write a Python function
deflation_power_method(A, k)that finds the topkeigenpairs of a matrixA. The function should have an outer loop that runsktimes. Inside the loop, it should:- a)Call a
power_methodfunction (like the one from M7, extended to also return the eigenvalue \(\mathbf{x}^\top\mathbf{A}\mathbf{x}\)) on the current matrix to get an eigenpair. - b)Store the found eigenpair.
- c)Compute the next deflated matrix.
Return the list of
kfound eigenpairs. Test your function on a simple 3x3 symmetric matrix. - a)
- H5.PageRank Theory. The full PageRank matrix is \(\mathbf{M} = (1-\beta)\mathbf{A} + \beta\mathbf{J}\), where \(0 \le \beta \le 1\), \(\mathbf{A}\) is column-stochastic and \(\mathbf{J}\) is a matrix with all entries equal to \(1/p\). Prove that \(\mathbf{M}\) is column-stochastic, that is, its entries are non-negative and \(\mathbf{1}^\top\mathbf{M} = \mathbf{1}^\top\). Then explain why an eigenvector \(\mathbf{z}\) with \(\mathbf{M}\mathbf{z} = \mathbf{z}\) and non-negative entries can be scaled so that its entries sum to 1, making it a valid probability distribution.