Course contents 16 / 16

16 / 16 · Numerical Computation

Iterative methods: power iteration and conjugate gradient

When a matrix is too large to factorize, multiply by it instead: the power method for the top eigenvector, conjugate gradient for a positive definite system, Krylov subspaces, the square-root rate and preconditioning.

On this page 9

Take a linear system with a million unknowns: the values of a field on a 1000×10001000 \times 1000 grid, the weights of a large regression, the coefficients of a kernel model. Every method in the course so far would factorize the matrix. For n=106n = 10^6 that is out of reach:

QuantityDense LUOne sparse product AxAx
storagen2n^2 doubles, 8 TB5 nonzeros per row, 64 MB
arithmetic23n3=6.7⋅1017\tfrac23 n^3 = 6.7 \cdot 10^{17} flops2⋅5n=1072 \cdot 5n = 10^7 flops

The LU count is derived in the linear systems note: step kk updates an (n−k)×(n−k)(n - k) \times (n - k) block, and the sum of squares gives 13n3\tfrac13 n^3 multiply–adds (Boyd and Vandenberghe, 2004, Appendix C.3). At 101310^{13} flops per second the factorization would take most of a day, on a machine with 8 TB of memory. The product with a sparse matrix takes milliseconds. Many matrices of machine learning are not even stored: a Hessian is available only through Hessian–vector products, a kernel matrix through a routine that multiplies it by a vector.

What can be computed from products v↦Avv \mapsto Av alone? More than one might expect: the largest eigenvalue, by the power method, and the solution of Ax=bAx = b for a symmetric positive definite AA, by conjugate gradient. Both build their answers from the same vectors b,Ab,A2b,…b, Ab, A^2b, \dots, and both are slowed down by the same thing, a spectrum that is hard to separate.

The power method#

Multiply any vector by AA again and again, and its direction turns towards the eigenvector of the largest eigenvalue, as the eigenvalue note showed for matrix powers. The power method turns this into an algorithm. Start from a random x0x_0 and repeat

xk+1=Axk∥Axk∥,μk=R(xk)=xk⊤Axkxk⊤xk.\begin{aligned} x_{k+1} &= \frac{Ax_k}{\lVert Ax_k\rVert} , \\ \mu_k &= R(x_k) = \frac{x_k^\top Ax_k}{x_k^\top x_k} . \end{aligned}

The normalization only keeps the numbers from overflowing; μk\mu_k is the Rayleigh quotient, the estimate of the eigenvalue.

Why it works: let AA be symmetric with orthonormal eigenvectors qiq_i and eigenvalues ordered by size, ∣λ1∣>∣λ2∣≥⋯≥∣λn∣\lvert\lambda_1\rvert \gt \lvert\lambda_2\rvert \ge \dots \ge \lvert\lambda_n\rvert. Expand the start as x0=∑iciqix_0 = \sum_i c_i q_i with c1≠0c_1 \ne 0. Each multiplication scales the ii-th component by λi\lambda_i:

Akx0=∑i=1nciλikqi=c1λ1k(q1+∑i≥2cic1(λiλ1)kqi).\begin{aligned} A^k x_0 &= \sum_{i=1}^n c_i \lambda_i^k q_i \\ &= c_1 \lambda_1^k \Big(q_1 + \sum_{i \ge 2} \frac{c_i}{c_1} \Big(\frac{\lambda_i}{\lambda_1}\Big)^k q_i\Big) . \end{aligned}

Every term of the sum shrinks at least as fast as ∣λ2/λ1∣k\lvert\lambda_2/\lambda_1\rvert^k. The normalized xkx_k is Akx0A^k x_0 divided by its length, so it has the same angle θk\theta_k to q1q_1. The qiq_i are orthonormal, so the tangent of that angle is the length of the part orthogonal to q1q_1 over the part along it:

tan⁡θk=(∑i≥2ci2λi2k)1/2∣c1λ1k∣≤∣λ2λ1∣k(∑i≥2ci2)1/2∣c1∣=∣λ2λ1∣ktan⁡θ0.\begin{aligned} \tan\theta_k &= \frac{\big(\sum_{i \ge 2} c_i^2\lambda_i^{2k}\big)^{1/2}}{\lvert c_1\lambda_1^k\rvert} \\ &\le \Big\lvert\frac{\lambda_2}{\lambda_1}\Big\rvert^k \frac{\big(\sum_{i \ge 2} c_i^2\big)^{1/2}}{\lvert c_1\rvert} \\ &= \Big\lvert\frac{\lambda_2}{\lambda_1}\Big\rvert^k \tan\theta_0 . \end{aligned}

The distance from ±q1\pm q_1 falls by the factor ∣λ2/λ1∣\lvert\lambda_2/\lambda_1\rvert per step: the convergence rate of the power method.

The eigenvalue estimate converges twice as fast. Write a unit vector as x=(q1+εv)/1+ε2x = (q_1 + \varepsilon v)/\sqrt{1 + \varepsilon^2}, with vv a unit vector orthogonal to q1q_1. Then q1⊤Av=λ1q1⊤v=0q_1^\top A v = \lambda_1 q_1^\top v = 0, and

R(x)=λ1+ε2 v⊤Av1+ε2=λ1−ε2 (λ1−v⊤Av)1+ε2.\begin{aligned} R(x) &= \frac{\lambda_1 + \varepsilon^2\, v^\top Av}{1 + \varepsilon^2} \\ &= \lambda_1 - \frac{\varepsilon^2\,(\lambda_1 - v^\top Av)}{1 + \varepsilon^2} . \end{aligned}

Here ε=tan⁡θ\varepsilon = \tan\theta. An error ε\varepsilon in the direction costs only ε2\varepsilon^2 in the eigenvalue, because the Rayleigh quotient is stationary at an eigenvector, and ∣λ1−v⊤Av∣\lvert\lambda_1 - v^\top Av\rvert is at most 2∣λ1∣2\lvert\lambda_1\rvert. With tan⁡θk≤∣λ2/λ1∣ktan⁡θ0\tan\theta_k \le \lvert\lambda_2/\lambda_1\rvert^k\tan\theta_0 from above, the error of μk\mu_k for a symmetric matrix falls like (λ2/λ1)2k(\lambda_2/\lambda_1)^{2k}.

Example. For A=(5222)A = \begin{pmatrix} 5 & 2 \\ 2 & 2 \end{pmatrix}, with eigenvalues 6 and 1, start from x0=(1,0)x_0 = (1, 0):

Step kk0123
μk\mu_k55.965525.999045.99997
6−μk6 - \mu_k13.4⋅10−23.4 \cdot 10^{-2}9.6⋅10−49.6 \cdot 10^{-4}2.7⋅10−52.7 \cdot 10^{-5}

The error falls by about 1/36=(λ2/λ1)21/36 = (\lambda_2/\lambda_1)^2 per step.

Each step costs one product with AA and two vectors of memory, which is why the method and its relatives run wherever a matrix is too large to decompose. Spectral normalization of a GAN estimates the largest singular value of each weight matrix with one power step per training step, warm-started from the previous step’s vector. PageRank is the dominant eigenvector of a transition matrix with one row per web page. The step size 1/L1/L of gradient descent needs LL, the largest eigenvalue of a Hessian, which the power method estimates from Hessian–vector products.

Where it breaks: a small gap#

The rate ∣λ2/λ1∣\lvert\lambda_2/\lambda_1\rvert is close to 1 when the top two eigenvalues are close, and then the method crawls. A matrix met everywhere in numerical work shows it. The grid Laplacian on an N×NN \times N grid has the row

(Lx)ij=4xij−xi−1,j−xi+1,j−xi,j−1−xi,j+1,(Lx)_{ij} = 4x_{ij} - x_{i-1,j} - x_{i+1,j} - x_{i,j-1} - x_{i,j+1} ,

with neighbours outside the grid set to zero. It has n=N2n = N^2 unknowns, at most five nonzeros per row, and eigenvalues known in closed form,

λjk=4−2cos⁡jπN+1−2cos⁡kπN+1,1≤j,k≤N,\lambda_{jk} = 4 - 2\cos\frac{j\pi}{N + 1} - 2\cos\frac{k\pi}{N + 1} , \quad 1 \le j, k \le N ,

between 4−4cos⁡πN+1≈2π2/N24 - 4\cos\frac{\pi}{N+1} \approx 2\pi^2/N^2 and 4+4cos⁡πN+1<84 + 4\cos\frac{\pi}{N+1} \lt 8. Divided by h2h^2, with grid spacing hh, each row is the five-point difference approximation of −Δ-\Delta, the operator behind diffusion and smoothing on images and meshes.

Derivation: the eigenvalues of the grid Laplacian

Start with one dimension: the N×NN \times N matrix TT with 2 on the diagonal and −1-1 beside it. Try the vector (uj)i=sin⁡(iθj)(u_j)_i = \sin(i\theta_j) with θj=jπ/(N+1)\theta_j = j\pi/(N + 1). The identity sin⁡(a−b)+sin⁡(a+b)=2sin⁡acos⁡b\sin(a - b) + \sin(a + b) = 2\sin a\cos b gives, for each row ii,

(Tuj)i=2sin⁡(iθj)−sin⁡((i−1)θj)−sin⁡((i+1)θj)=(2−2cos⁡θj)sin⁡(iθj).\begin{aligned} (Tu_j)_i &= 2\sin(i\theta_j) - \sin((i - 1)\theta_j) - \sin((i + 1)\theta_j) \\ &= (2 - 2\cos\theta_j)\sin(i\theta_j) . \end{aligned}

The first and last rows lack a neighbour, but the missing terms are sin⁡(0)=0\sin(0) = 0 and sin⁡((N+1)θj)=sin⁡(jπ)=0\sin((N + 1)\theta_j) = \sin(j\pi) = 0, so the formula holds there too. The grid Laplacian is L=I⊗T+T⊗IL = I \otimes T + T \otimes I, one TT along each grid direction, and L(uj⊗uk)=(μj+μk)(uj⊗uk)L(u_j \otimes u_k) = (\mu_j + \mu_k)(u_j \otimes u_k) with μj=2−2cos⁡θj\mu_j = 2 - 2\cos\theta_j. The N2N^2 products uj⊗uku_j \otimes u_k give all eigenvalues. Finally 1−cos⁡θ≈θ2/21 - \cos\theta \approx \theta^2/2 gives the smallest one.

For N=100N = 100 the ratio λ2/λ1\lambda_2/\lambda_1 is 0.999640.99964. Each step removes 0.036% of the unwanted components, and the power method needs 17,142 steps to get λ1\lambda_1 to six digits. SciPy’s eigsh, which wraps the implicitly restarted Lanczos method of the ARPACK library, gets it to full precision with 511 products. The difference is in how the products are used. The power method keeps only the latest vector Akx0A^k x_0, while Lanczos finds the best estimate in the span of all of them, the Krylov subspace of the section below.

Two other remedies change the matrix instead. Inverse iteration with a shift applies the power method to (A−σI)−1(A - \sigma I)^{-1}. Its eigenvalues are 1/(λi−σ)1/(\lambda_i - \sigma), so the largest belongs to the eigenvalue of AA nearest to σ\sigma, and the rate of the power method becomes ∣(λ1−σ)/(λ2−σ)∣\lvert(\lambda_1 - \sigma)/(\lambda_2 - \sigma)\rvert, where here λ1\lambda_1 is the eigenvalue nearest to σ\sigma and λ2\lambda_2 the next-nearest. A shift close to λ1\lambda_1 makes it tiny, at the price of a linear solve per step. Rayleigh quotient iteration updates the shift to the current μk\mu_k at every step and converges cubically for symmetric matrices (Rakhuba, 2025, lecture 17). For several eigenvectors at once, subspace iteration multiplies a block of pp vectors and re-orthonormalizes it by QR after each step; its rate is ∣λp+1/λp∣\lvert\lambda_{p+1}/\lambda_p\rvert.

Solving Ax = b by minimizing a quadratic#

For a symmetric positive definite AA, the system Ax=bAx = b is an optimization problem in disguise. Define

f(x)=12x⊤Ax−b⊤x.f(x) = \tfrac12 x^\top Ax - b^\top x .

Its gradient is ∇f(x)=Ax−b\nabla f(x) = Ax - b, so its only stationary point, and its minimum, is the solution x∗x^*. The negative gradient is the residual r=b−Axr = b - Ax. The distance to the minimum is measured best in the energy norm ∥v∥A=v⊤Av\lVert v\rVert_A = \sqrt{v^\top Av}, because the excess of ff is exactly half its square:

f(x)−f(x∗)=12x⊤Ax−x∗⊤Ax+12x∗⊤Ax∗=12(x−x∗)⊤A(x−x∗)=12∥x−x∗∥A2,\begin{aligned} f(x) - f(x^*) &= \tfrac12 x^\top Ax - x^{*\top}Ax + \tfrac12 x^{*\top}Ax^* \\ &= \tfrac12 (x - x^*)^\top A (x - x^*) \\ &= \tfrac12 \lVert x - x^*\rVert_A^2 , \end{aligned}

where the first line substitutes b=Ax∗b = Ax^*.

The unconstrained optimization note has a method for this: gradient descent. On a quadratic the best step along the residual can be computed exactly. Setting the derivative of f(x+αr)f(x + \alpha r) to zero,

ddαf(x+αr)=r⊤(A(x+αr)−b)=−r⊤r+α r⊤Ar=0,\begin{aligned} \tfrac{d}{d\alpha} f(x + \alpha r) &= r^\top\big(A(x + \alpha r) - b\big) \\ &= -r^\top r + \alpha\, r^\top Ar = 0 , \end{aligned}

gives α=r⊤r/r⊤Ar\alpha = r^\top r / r^\top Ar and steepest descent. The same equation says that the new residual is orthogonal to the old one. With the condition number κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min} of AA, the error of steepest descent in the energy norm shrinks per step by at least the factor

κ−1κ+1,\frac{\kappa - 1}{\kappa + 1} ,

derived below as the one-step case of the CG bound (Shewchuk, 1994, §6.2). Reducing the error by a factor ε\varepsilon takes about κ2ln⁡(1/ε)\tfrac\kappa2 \ln(1/\varepsilon) steps, because ln⁡1+y1−y≈2y\ln\frac{1 + y}{1 - y} \approx 2y for small yy, here y=1/κy = 1/\kappa. Because each new gradient is perpendicular to the old one, on an elongated bowl the iterates zigzag across the valley, undoing part of the progress they made along it.

Even on a 2×22 \times 2 system the method never finishes. For the matrix of the example above and b=(1,1)b = (1, 1), with solution x∗=(0,0.5)x^* = (0, 0.5), the relative error in the energy norm after steps 1 to 6 is

0.522, 0.273, 0.142, 0.074, 0.039, 0.020,0.522, \ 0.273, \ 0.142, \ 0.074, \ 0.039, \ 0.020 ,

roughly halving at every step, forever.

Conjugate directions#

In a round bowl, A=IA = I, the zigzag disappears. Minimizing along each coordinate axis in turn finds the minimum in nn steps, because a step along one axis does not spoil the minimum already found along the others. An elongated bowl is a round one in stretched coordinates: with y=A1/2xy = A^{1/2}x the quadratic becomes 12y⊤y−(A−1/2b)⊤y\tfrac12 y^\top y - (A^{-1/2}b)^\top y (Merkulov, 2024, lecture 12). A direction dd in xx is A1/2dA^{1/2}d in yy, and (A1/2di)⊤(A1/2dj)=di⊤Adj(A^{1/2}d_i)^\top(A^{1/2}d_j) = d_i^\top A d_j. So directions that are orthogonal in yy are, back in xx, conjugate or AA-orthogonal:

di⊤Adj=0for i≠j.d_i^\top A d_j = 0 \quad \text{for } i \ne j .

Exact line searches along nn conjugate directions d0,…,dn−1d_0, \dots, d_{n-1} reach x∗x^* in nn steps. To see why, expand the initial error in the directions, x∗−x0=∑iαidix^* - x_0 = \sum_i \alpha_i d_i. This is possible because nonzero conjugate directions are linearly independent: multiplying ∑icidi=0\sum_i c_i d_i = 0 by dk⊤Ad_k^\top A leaves ck dk⊤Adk=0c_k\, d_k^\top Ad_k = 0, and dk⊤Adk>0d_k^\top Ad_k \gt 0, so every ck=0c_k = 0. Multiplying the expansion by dk⊤Ad_k^\top A kills every term but one, and A(x∗−x0)=b−Ax0=r0A(x^* - x_0) = b - Ax_0 = r_0:

dk⊤A(x∗−x0)=αk dk⊤Adk,αk=dk⊤r0dk⊤Adk.\begin{aligned} d_k^\top A (x^* - x_0) &= \alpha_k\, d_k^\top A d_k , \\ \alpha_k &= \frac{d_k^\top r_0}{d_k^\top A d_k} . \end{aligned}

The line search along dkd_k from xkx_k chooses α=dk⊤rk/dk⊤Adk\alpha = d_k^\top r_k / d_k^\top A d_k, by the same derivative as for steepest descent with dkd_k in place of rr. The residual rk=r0−∑i<kαiAdir_k = r_0 - \sum_{i \lt k} \alpha_i A d_i differs from r0r_0 only by vectors AdiA d_i that are orthogonal to dkd_k, so dk⊤rk=dk⊤r0d_k^\top r_k = d_k^\top r_0. Each line search therefore removes exactly one component of the error and leaves the others alone. After nn steps none are left (Shewchuk, 1994, section 7).

The difficulty is to find conjugate directions cheaply. The eigenvectors of AA are conjugate, but computing them is harder than solving the system. Gram–Schmidt in the inner product u⊤Avu^\top A v makes any basis conjugate, but each new direction must be orthogonalized against all previous ones, at a cost that grows with every step.

Conjugate gradient#

The conjugate gradient method (CG) of Hestenes and Stiefel (1952) makes conjugate directions out of the residuals, and, as shown below, the residuals need almost no orthogonalization. Start with x0=0x_0 = 0, r0=br_0 = b, d0=r0d_0 = r_0, and repeat

αk=rk⊤rkdk⊤Adk,xk+1=xk+αkdk,rk+1=rk−αkAdk,βk=rk+1⊤rk+1rk⊤rk,dk+1=rk+1+βkdk.\begin{aligned} \alpha_k &= \frac{r_k^\top r_k}{d_k^\top A d_k} , \\ x_{k+1} &= x_k + \alpha_k d_k , \\ r_{k+1} &= r_k - \alpha_k A d_k , \\ \beta_k &= \frac{r_{k+1}^\top r_{k+1}}{r_k^\top r_k} , \\ d_{k+1} &= r_{k+1} + \beta_k d_k . \end{aligned}

The first line is the exact line search along dkd_k; the derivation below shows why its numerator can be rk⊤rkr_k^\top r_k. The next two move the point and update the residual with the product AdkAd_k, the only product with AA in the step. The last two make the new direction from the new residual, with βk\beta_k chosen so that dk+1d_{k+1} is conjugate to dkd_k.

A step costs one product with AA, two inner products and three vector updates, and the method stores four vectors. Conjugacy to dkd_k is all that the formula enforces, yet the new direction comes out conjugate to every earlier one as well. As long as no residual is zero, three facts hold at every step kk (Shewchuk, 1994, section 8; Rakhuba, 2025, lecture 15):

  1. The residuals are mutually orthogonal, and rkr_k is orthogonal to d0,…,dk−1d_0, \dots, d_{k-1}.
  2. The residuals r0,…,rk−1r_0, \dots, r_{k-1} and the directions d0,…,dk−1d_0, \dots, d_{k-1} both span the space of b,Ab,…,Ak−1bb, Ab, \dots, A^{k-1}b.
  3. The directions are conjugate: dk⊤Adi=0d_k^\top A d_i = 0 for i<ki \lt k.

The heart of the induction is one line. For i<ki \lt k, the update ri+1=ri−αiAdir_{i+1} = r_i - \alpha_i Ad_i gives Adi=(ri−ri+1)/αiAd_i = (r_i - r_{i+1})/\alpha_i, a vector in the span of r0,…,rkr_0, \dots, r_k, to which rk+1r_{k+1} is orthogonal by fact 1. So rk+1⊤Adi=0r_{k+1}^\top Ad_i = 0, and Gram–Schmidt of rk+1r_{k+1} against d0,…,dk−1d_0, \dots, d_{k-1} has nothing to subtract: only the last direction needs a correction. The name is a misnomer: it is the directions that are conjugate, and they are built from gradients.

Derivation: the induction behind CG

Assume the three facts up to step kk; at k=0k = 0 they say only that d0=r0=bd_0 = r_0 = b spans the space of bb. Write the line-search step as αk=dk⊤rk/dk⊤Adk\alpha_k = d_k^\top r_k/d_k^\top Ad_k.

Residual against directions. From rk+1=rk−αkAdkr_{k+1} = r_k - \alpha_k Ad_k, the choice of αk\alpha_k gives dk⊤rk+1=dk⊤rk−αkdk⊤Adk=0d_k^\top r_{k+1} = d_k^\top r_k - \alpha_k d_k^\top Ad_k = 0. For i<ki \lt k, di⊤rk+1=di⊤rk−αkdi⊤Adk=0−0d_i^\top r_{k+1} = d_i^\top r_k - \alpha_k d_i^\top Ad_k = 0 - 0 by facts 1 and 3.

Residuals against residuals. Each rir_i with i≤ki \le k lies in the span of d0,…,did_0, \dots, d_i by fact 2, so rk+1⊤ri=0r_{k+1}^\top r_i = 0.

The two formulas of the algorithm. Since dk=rk+βk−1dk−1d_k = r_k + \beta_{k-1}d_{k-1} and dk−1⊤rk=0d_{k-1}^\top r_k = 0, we have dk⊤rk=rk⊤rkd_k^\top r_k = r_k^\top r_k, so αk=rk⊤rk/dk⊤Adk>0\alpha_k = r_k^\top r_k/d_k^\top Ad_k \gt 0. Gram–Schmidt in the AA-inner product sets βk=−rk+1⊤Adk/dk⊤Adk\beta_k = -r_{k+1}^\top Ad_k/d_k^\top Ad_k. Substitute Adk=(rk−rk+1)/αkAd_k = (r_k - r_{k+1})/\alpha_k and dk⊤Adk=rk⊤rk/αkd_k^\top Ad_k = r_k^\top r_k/\alpha_k, and use rk+1⊤rk=0r_{k+1}^\top r_k = 0:

βk=−rk+1⊤rk−rk+1⊤rk+1rk⊤rk=rk+1⊤rk+1rk⊤rk.\begin{aligned} \beta_k &= -\frac{r_{k+1}^\top r_k - r_{k+1}^\top r_{k+1}}{r_k^\top r_k} \\ &= \frac{r_{k+1}^\top r_{k+1}}{r_k^\top r_k} . \end{aligned}

Conjugacy. dk+1⊤Adk=0d_{k+1}^\top Ad_k = 0 by the choice of βk\beta_k. For i<ki \lt k, dk+1⊤Adi=rk+1⊤Adi+βkdk⊤Adid_{k+1}^\top Ad_i = r_{k+1}^\top Ad_i + \beta_k d_k^\top Ad_i; the first term is zero by the one-line argument above and the second by fact 3.

Spans. rk+1r_{k+1} and dk+1d_{k+1} lie in the space of b,…,Ak+1bb, \dots, A^{k+1}b, because AdkAd_k does. The k+2k + 2 residuals are nonzero and mutually orthogonal, hence independent, so they span that space, whose dimension is at most k+2k + 2. The directions are nonzero, since dk+1⊤rk+1=rk+1⊤rk+1>0d_{k+1}^\top r_{k+1} = r_{k+1}^\top r_{k+1} \gt 0, and conjugate, hence independent as well.

Example. The same system, A=(5222)A = \begin{pmatrix} 5 & 2 \\ 2 & 2 \end{pmatrix} and b=(1,1)b = (1, 1), by hand:

Stepα\alphanew xxnew rrβ\betanew dd
0211\tfrac{2}{11}(211,211)(\tfrac{2}{11}, \tfrac{2}{11})(−311,311)(-\tfrac{3}{11}, \tfrac{3}{11})9121\tfrac{9}{121}1121(−24,42)\tfrac{1}{121}(-24, 42)
11112\tfrac{11}{12}(0,12)(0, \tfrac12)(0,0)(0, 0)

The first step is a step of steepest descent, with Ad0=(7,4)Ad_0 = (7, 4). The second direction differs from the residual r1r_1, and it is conjugate to the first: (−24,42)⋅(7,4)=0(-24, 42) \cdot (7, 4) = 0. Two steps give the exact solution, where steepest descent was still 2% away after six.

Krylov subspaces#

Every vector CG computes is a combination of b,Ab,A2b,…b, Ab, A^2b, \dots. The span of the first kk of them is the Krylov subspace

Kk(A,b)=span⁡{b,Ab,…,Ak−1b}.\mathcal K_k(A, b) = \operatorname{span}\{b, Ab, \dots, A^{k-1}b\} .

Its vectors are cheap, one product with AA each. CG picks the best point of the growing space: xkx_k minimizes the energy-norm error ∥x−x∗∥A\lVert x - x^*\rVert_A over all of Kk\mathcal K_k, equivalently minimizes ff there (Rakhuba, 2025, lecture 15). The power method computes the same vectors and keeps only the last one.

Derivation: CG is optimal over the Krylov space

The proof is Pythagoras in the energy norm. The iterate xk=∑i<kαidix_k = \sum_{i \lt k}\alpha_i d_i lies in Kk\mathcal K_k, and its error ek=x∗−xke_k = x^* - x_k has Aek=b−Axk=rkAe_k = b - Ax_k = r_k, which is orthogonal to r0,…,rk−1r_0, \dots, r_{k-1} and hence to all of Kk\mathcal K_k. For any x∈Kkx \in \mathcal K_k put z=x−xk∈Kkz = x - x_k \in \mathcal K_k:

∥x−x∗∥A2=∥z−ek∥A2=∥z∥A2−2 z⊤rk+∥ek∥A2=∥z∥A2+∥ek∥A2,\begin{aligned} \lVert x - x^*\rVert_A^2 &= \lVert z - e_k\rVert_A^2 \\ &= \lVert z\rVert_A^2 - 2\, z^\top r_k + \lVert e_k\rVert_A^2 \\ &= \lVert z\rVert_A^2 + \lVert e_k\rVert_A^2 , \end{aligned}

which is smallest at z=0z = 0, that is at x=xkx = x_k.

The best point can be described by polynomials. A point of Kk\mathcal K_k is ϕ(A)b\phi(A)b for a polynomial ϕ\phi of degree below kk, so its error is x∗−ϕ(A)Ax∗=p(A)x∗x^* - \phi(A)Ax^* = p(A)x^* with p(λ)=1−λϕ(λ)p(\lambda) = 1 - \lambda \phi(\lambda): a polynomial of degree kk with p(0)=1p(0) = 1. Expanding x∗=∑iciqix^* = \sum_i c_i q_i in orthonormal eigenvectors of AA, as for the power method, gives p(A)x∗=∑ici p(λi) qip(A)x^* = \sum_i c_i\,p(\lambda_i)\,q_i and

∥p(A)x∗∥A2=∑iλici2 p(λi)2≤max⁡ip(λi)2∑iλici2=max⁡ip(λi)2 ∥x∗∥A2.\begin{aligned} \lVert p(A)x^*\rVert_A^2 &= \textstyle\sum_i \lambda_i c_i^2\, p(\lambda_i)^2 \\ &\le \max_i p(\lambda_i)^2 \textstyle\sum_i \lambda_i c_i^2 \\ &= \max_i p(\lambda_i)^2\, \lVert x^*\rVert_A^2 . \end{aligned}

This turns the minimization into a bound on the spectrum, with ∥x∗∥A=∥x0−x∗∥A\lVert x^*\rVert_A = \lVert x_0 - x^*\rVert_A for the start x0=0x_0 = 0:

∥xk−x∗∥A=min⁡p(0)=1∥p(A) x∗∥A≤min⁡p(0)=1 max⁡i∣p(λi)∣⋅∥x∗∥A.\begin{aligned} \lVert x_k - x^*\rVert_A &= \min_{p(0) = 1} \lVert p(A)\, x^*\rVert_A \\ &\le \min_{p(0) = 1}\ \max_i \lvert p(\lambda_i)\rvert \cdot \lVert x^*\rVert_A . \end{aligned}

CG converges as fast as a polynomial with p(0)=1p(0) = 1 can be made small at all the eigenvalues at once. The spread of the eigenvalues matters as much as their range:

  1. With mm distinct eigenvalues, the polynomial ∏j(1−λ/λj)\prod_j (1 - \lambda/\lambda_j) of degree mm vanishes at all of them, so CG is exact after mm steps, in exact arithmetic.
  2. Eigenvalues in a tight cluster are almost one eigenvalue. On a cluster of width δ\delta around cc, the single factor (1−λ/c)(1 - \lambda/c) is at most δ/(2c)\delta/(2c).
  3. An isolated outlier λj\lambda_j costs about one step. The factor (1−λ/λj)(1 - \lambda/\lambda_j) vanishes at it and stays below 1 in absolute value on (0,λj](0, \lambda_j], so multiplying it into a polynomial that is small on the other eigenvalues keeps that polynomial small there.

Two spectra with the same condition number show the difference. A diagonal matrix with 1,000 eigenvalues spread evenly over [1,1000][1, 1000] needs 176 CG steps to bring the relative residual to 10−810^{-8}. One with 995 eigenvalues in [1,2][1, 2] and five outliers up to 1,000 needs 24.

In floating point the vectors b,Ab,A2b,…b, Ab, A^2b, \dots make a terrible basis. They all turn towards the top eigenvector, as in the power method, so their matrix is badly conditioned; Strang (2006) works out a 4×44 \times 4 example in which it already has condition number about 1,000. Krylov methods therefore orthogonalize as they go. For symmetric AA the orthogonalization needs only the two previous vectors, a three-term recurrence called the Lanczos process, and CG is one way of organizing it. The reason: with the orthonormal basis QQ built so far, the matrix H=Q⊤AQH = Q^\top AQ of coefficients has zeros below its first subdiagonal, because AA times the jj-th basis vector lies in the span of the first j+1j + 1; for symmetric AA it is also symmetric, hence tridiagonal (Strang, 2006). The restriction of AA to the orthonormal basis is a small tridiagonal matrix whose eigenvalues approximate the extreme eigenvalues of AA (Rakhuba, 2025, lectures 17–18), which is how eigsh found the top eigenvalue above.

For a nonsymmetric AA, Arnoldi’s process orthogonalizes against all previous vectors, and GMRES picks the point of Kk\mathcal K_k with the smallest residual; for a symmetric indefinite AA the short-recurrence version is MINRES (Rakhuba, 2025, lecture 16).

The square root of the condition number#

Without knowing the eigenvalues, only their range [λmin⁡,λmax⁡][\lambda_{\min}, \lambda_{\max}], we can put a specific polynomial into the bound: any pp with p(0)=1p(0) = 1 gives an upper bound. The right choice is a shifted and scaled Chebyshev polynomial, which is in fact the polynomial of degree kk that stays smallest on the interval among the polynomials equal to 1 at zero (Shewchuk, 1994, appendix C3). Its size on the interval gives (Shewchuk, section 9.2; Merkulov, 2024, lecture 12, Theorem 2)

∥xk−x∗∥A≤2(κ−1κ+1)k∥x0−x∗∥A.\lVert x_k - x^*\rVert_A \le 2\Big(\frac{\sqrt\kappa - 1}{\sqrt\kappa + 1}\Big)^k \lVert x_0 - x^*\rVert_A .
Derivation: the square-root bound

The Chebyshev polynomials are T0=1T_0 = 1, T1(x)=xT_1(x) = x and Tk+1(x)=2xTk(x)−Tk−1(x)T_{k+1}(x) = 2xT_k(x) - T_{k-1}(x), so TkT_k has degree kk. Two facts follow from the recurrence. On [−1,1][-1, 1], write x=cos⁡θx = \cos\theta: then Tk(x)=cos⁡kθT_k(x) = \cos k\theta, because cos⁡(k+1)θ+cos⁡(k−1)θ=2cos⁡θcos⁡kθ\cos(k + 1)\theta + \cos(k - 1)\theta = 2\cos\theta\cos k\theta is the same recurrence with the same first two values, so ∣Tk∣≤1\lvert T_k\rvert \le 1 there. For x≥1x \ge 1, write x=(z+z−1)/2x = (z + z^{-1})/2 with z=x+x2−1≥1z = x + \sqrt{x^2 - 1} \ge 1: then Tk(x)=(zk+z−k)/2T_k(x) = (z^k + z^{-k})/2, by the same recurrence for zk+z−kz^k + z^{-k}, which also starts from 11 and xx, so Tk(x)≥zk/2T_k(x) \ge z^k/2.

Map the interval onto [−1,1][-1, 1] by ℓ(λ)=(λmax⁡+λmin⁡−2λ)/(λmax⁡−λmin⁡)\ell(\lambda) = (\lambda_{\max} + \lambda_{\min} - 2\lambda)/(\lambda_{\max} - \lambda_{\min}) and take p(λ)=Tk(ℓ(λ))/Tk(ℓ(0))p(\lambda) = T_k(\ell(\lambda))/T_k(\ell(0)), so that p(0)=1p(0) = 1. On the interval ∣p∣≤1/Tk(σ)\lvert p\rvert \le 1/T_k(\sigma), with σ=ℓ(0)=(κ+1)/(κ−1)\sigma = \ell(0) = (\kappa + 1)/(\kappa - 1). Since σ2−1=4κ/(κ−1)2\sigma^2 - 1 = 4\kappa/(\kappa - 1)^2,

z=σ+σ2−1=κ+1+2κκ−1=(κ+1)2(κ−1)(κ+1)=κ+1κ−1,\begin{aligned} z &= \sigma + \sqrt{\sigma^2 - 1} = \frac{\kappa + 1 + 2\sqrt\kappa}{\kappa - 1} \\ &= \frac{(\sqrt\kappa + 1)^2}{(\sqrt\kappa - 1)(\sqrt\kappa + 1)} = \frac{\sqrt\kappa + 1}{\sqrt\kappa - 1} , \end{aligned}

and max⁡i∣p(λi)∣≤2/zk\max_i\lvert p(\lambda_i)\rvert \le 2/z^k, the bound above. For k=1k = 1 the value is exact, T1(σ)=σT_1(\sigma) = \sigma, so one step from any starting point reduces the energy-norm error by at least 1/σ=(κ−1)/(κ+1)1/\sigma = (\kappa - 1)/(\kappa + 1). A step of steepest descent is such a step: it minimizes ff along the current residual, the one-dimensional Krylov space at the current point. This proves the steepest-descent factor quoted earlier.

Compare the steepest-descent factor (κ−1)/(κ+1)(\kappa - 1)/(\kappa + 1): CG has the same expression with κ\sqrt\kappa in place of κ\kappa. To reduce the error by a factor ε\varepsilon, using ln⁡1+y1−y≈2y\ln\frac{1 + y}{1 - y} \approx 2y with y=1/κy = 1/\kappa and y=1/κy = 1/\sqrt\kappa:

kSD≈κ2ln⁡1ε,kCG≈κ2ln⁡2ε.\begin{aligned} k_{\text{SD}} &\approx \frac{\kappa}{2} \ln\frac1\varepsilon , \\ k_{\text{CG}} &\approx \frac{\sqrt\kappa}{2} \ln\frac2\varepsilon . \end{aligned}

For κ=104\kappa = 10^4 and six digits that is the difference between about 69,000 and 725 steps.

The grid Laplacian with N=100N = 100 has κ=4,134\kappa = 4{,}134. With bb all ones, reducing the energy-norm error a millionfold takes:

MethodBoundSteps taken
steepest descent28,55428,369
conjugate gradient466144

Steepest descent follows its bound almost exactly. CG beats its own bound threefold. The bound replaced each p(λi)2p(\lambda_i)^2 in ∑iλici2 p(λi)2\sum_i \lambda_i c_i^2\, p(\lambda_i)^2 by the worst one, and here many cic_i are zero. The eigenvectors are products of the sine vectors sin⁡(iθj)\sin(i\theta_j), and for even jj such a vector is antisymmetric about the middle of the grid, so its sum, the component of bb along it, is zero. Only the quarter of the eigenvectors with jj and kk both odd take part.

Momentum gives gradient descent the same κ\sqrt\kappa rate on a quadratic, but only with step and momentum tuned from λmin⁡\lambda_{\min} and λmax⁡\lambda_{\max}. CG needs neither. Started from 0, gradient descent with or without momentum adds at each step multiples of the current residual and of the previous step, so its kk-th iterate lies in Kk\mathcal K_k; CG’s minimization over that space makes it at least as good in the energy norm.

The κ\sqrt\kappa makes CG practical at the size of the opening example. The Laplacian with N=1000N = 1000 has n=106n = 10^6 unknowns and κ≈4⋅105\kappa \approx 4 \cdot 10^5. CG brings the relative residual to 10−810^{-8} in 1,853 steps, about 4⋅10104 \cdot 10^{10} flops and seconds of time, with 64 MB for the matrix and 32 MB for the four vectors.

Where it breaks: rounding and ill-conditioning#

Finite termination is a property of exact arithmetic. In floating point the residuals slowly lose their orthogonality and the directions their conjugacy, so information that CG had already used comes back. Ridge regression with 200 features whose scales range from 1 to 1,000 leads to the system (X⊤X+I)w=X⊤y(X^\top X + I)w = X^\top y with κ=1.1⋅106\kappa = 1.1 \cdot 10^6. CG needs 2,904 steps on this 200×200200 \times 200 system, almost fifteen times the dimension. The method still converges. This behaviour made numerical analysts set CG aside in the 1960s, and it returned in the 1970s as an iterative method, judged by how fast its residual falls (Shewchuk, 1994, section 9).

The stopping test has the same subtlety. CG never sees the error, only the residual, and the usual test is ∥rk∥≤tol⋅∥b∥\lVert r_k\rVert \le \text{tol} \cdot \lVert b\rVert. A small residual guarantees a small error only up to the factor κ\kappa: the relative error is at most κ\kappa times the relative residual, by the bound of the conditioning note. The recursively updated rkr_k also drifts from the true b−Axkb - Ax_k, since rounding errors in the update rk−αkAdkr_k - \alpha_k Ad_k are never corrected against bb, and long runs recompute it from time to time (Shewchuk, sections 4 and 9).

Preconditioning#

If κ\kappa sets the speed, change the system so that κ\kappa becomes small. A preconditioner is a symmetric positive definite M≈AM \approx A whose systems Mz=rMz = r are cheap to solve. CG is then applied to M−1Ax=M−1bM^{-1}Ax = M^{-1}b, written symmetrically through a factor M=C⊤CM = C^\top C as C−⊤AC−1y=C−⊤bC^{-\top}AC^{-1}y = C^{-\top}b with y=Cxy = Cx. The factor never appears in the algorithm: each step needs one solve with MM (Shewchuk, 1994, section 12; Rakhuba, 2025, lecture 17). The rate is set by the eigenvalues of M−1AM^{-1}A, because C−⊤AC−1C^{-\top}AC^{-1} has the same ones: C−1(C−⊤AC−1)C=M−1AC^{-1}(C^{-\top}AC^{-1})C = M^{-1}A is a similar matrix.

The simplest choice, M=diag⁡(A)M = \operatorname{diag}(A) or Jacobi, rescales the variables; for the ridge system above it lowers κ\kappa from 1.1⋅1061.1 \cdot 10^6 to 3.55 and the step count from 2,904 to 20. It is the matrix version of scaling the features before gradient descent. Incomplete Cholesky factors, which drop the fill-in of the exact factorization, are a stronger choice (Shewchuk, section 12).

CG also runs inside other methods. Newton’s method needs the step Hp=−gH p = -g, and for a network with millions of weights the Hessian HH cannot be stored. Hessian-free optimization solves that system approximately by a few CG steps that need only products of a vector with HH or with its Gauss–Newton approximation, which automatic differentiation computes at the cost of a few gradients (Martens, 2010). SciPy’s Newton-CG method implements the same idea.

Code#

The costs of the opening, the power method on the 2×22 \times 2 example and on the grid Laplacian against eigsh, CG written out on the 2×22 \times 2 system, steepest descent against CG with their bounds, two spectra with the same κ\kappa, Jacobi preconditioning of a ridge system, and CG with a million unknowns. It runs in about 15 seconds, most of them in the last part; exact digits can differ across platforms and library versions, and the step count of eigsh with the ARPACK version.

import numpy as np
import scipy.sparse as sp
from scipy.sparse.linalg import eigsh, spsolve, LinearOperator

# the 5-point Laplacian on an N x N grid: n = N^2 unknowns, at most 5 nonzeros per row
def laplacian_2d(N):
    T = sp.diags([-1.0, 2.0, -1.0], [-1, 0, 1], shape=(N, N))
    I = sp.identity(N)
    return (sp.kron(I, T) + sp.kron(T, I)).tocsr()

# 1. what n = 10^6 costs: dense LU against one sparse matrix-vector product
n = 10**6
print(f'{2 / 3 * n**3:.1e} flops, {8 * n**2 / 1e12:.0f} TB dense; {2 * 5 * n:.0e} flops per sparse product')
# 6.7e+17 flops, 8 TB dense; 1e+07 flops per sparse product

# 2. the power method on a 2 x 2 matrix with eigenvalues 6 and 1
A = np.array([[5.0, 2.0], [2.0, 2.0]])
x = np.array([1.0, 0.0])
quotients = []
for k in range(4):
    quotients.append(x @ A @ x / (x @ x))                # Rayleigh quotient of the current vector
    x = A @ x / np.linalg.norm(A @ x)
print(np.round(quotients, 5), [f'{6 - q:.1e}' for q in quotients])
# [5.      5.96552 5.99904 5.99997] ['1.0e+00', '3.4e-02', '9.6e-04', '2.7e-05']

# 3. the power method where the gap is small: the Laplacian with N = 100 (n = 10,000)
N = 100
L = laplacian_2d(N)
lam1 = 4 + 4 * np.cos(np.pi / (N + 1))                    # the eigenvalues are known in closed form
lam2 = 4 + 2 * np.cos(np.pi / (N + 1)) + 2 * np.cos(2 * np.pi / (N + 1))
rng = np.random.default_rng(0)
x = rng.normal(size=N * N)
for k in range(1, 100_001):
    y = L @ x
    q = x @ y / (x @ x)
    x = y / np.linalg.norm(y)
    if (lam1 - q) / lam1 < 1e-6:
        break
count = [0]
def matvec(v):
    count[0] += 1
    return L @ v
top = eigsh(LinearOperator(L.shape, matvec=matvec, dtype=float), k=1, which='LA', tol=1e-10,
            v0=np.random.default_rng(0).normal(size=N * N))[0][0]
print(round(lam2 / lam1, 5), k, count[0], abs(top - lam1) < 1e-12)
# 0.99964 17142 511 True

# 4. conjugate gradient, written out; keep=True also returns the iterates
def conjugate_gradient(A, b, tol=1e-10, maxiter=100_000, Minv=None, keep=False):
    x = np.zeros_like(b)
    r = b.copy()
    z = r if Minv is None else Minv * r                   # Minv: a diagonal preconditioner, or none
    d = z.copy()
    rz = r @ z
    xs = [x.copy()] if keep else None
    for k in range(1, maxiter + 1):
        Ad = A @ d                                         # the only product with A in the step
        alpha = rz / (d @ Ad)
        x = x + alpha * d
        r = r - alpha * Ad
        if keep:
            xs.append(x.copy())
        if np.linalg.norm(r) <= tol * np.linalg.norm(b):
            break
        z = r if Minv is None else Minv * r
        rz, rz_old = r @ z, rz
        d = z + (rz / rz_old) * d
    return x, k, xs

def steepest_descent(A, b, x_star, tol, maxiter):
    x, r = np.zeros_like(b), b.copy()
    e0 = np.sqrt(x_star @ (A @ x_star))
    errors = []
    for k in range(1, maxiter + 1):
        Ar = A @ r
        x = x + (r @ r) / (r @ Ar) * r                    # exact line search along the residual
        r = r - (r @ r) / (r @ Ar) * Ar
        e = x - x_star
        errors.append(np.sqrt(e @ (A @ e)) / e0)
        if errors[-1] <= tol:
            break
    return k, errors

b = np.array([1.0, 1.0])
x, k, xs = conjugate_gradient(A, b, keep=True)
print(k, np.round(xs[1], 4), np.round(xs[2], 4))
print(np.round(steepest_descent(A, b, np.linalg.solve(A, b), 0, 6)[1], 3))
# 2 [0.1818 0.1818] [0.  0.5]
# [0.522 0.273 0.142 0.074 0.039 0.02 ]

# 5. steepest descent against CG on the Laplacian, b = all ones, error in the A-norm reduced 10^6-fold
b = np.ones(N * N)
x_star = spsolve(L.tocsc(), b)
kappa = lam1 / (4 - 4 * np.cos(np.pi / (N + 1)))
k_sd, _ = steepest_descent(L, b, x_star, 1e-6, 100_000)
_, _, xs = conjugate_gradient(L, b, tol=1e-12, keep=True)
e0 = np.sqrt(x_star @ (L @ x_star))
k_cg = next(k for k, x in enumerate(xs) if np.sqrt((x - x_star) @ (L @ (x - x_star))) <= 1e-6 * e0)
bound_sd = np.log(1e-6) / np.log((kappa - 1) / (kappa + 1))
bound_cg = np.log(1e-6 / 2) / np.log((np.sqrt(kappa) - 1) / (np.sqrt(kappa) + 1))
print(round(kappa), k_sd, round(bound_sd), k_cg, round(bound_cg))
print([round(c * np.log(f / 1e-6)) for c, f in ((1e4 / 2, 1), (1e2 / 2, 2))])   # kappa = 10^4: SD and CG estimates
# 4134 28369 28554 144 466
# [69078, 725]

# 6. the same condition number, two spectra: 1,000 eigenvalues spread over [1, 1000],
#    or 995 of them in [1, 2] and five outliers up to 1000
spread = np.linspace(1, 1000, 1000)
clustered = np.concatenate([np.linspace(1, 2, 995), [100, 200, 400, 700, 1000]])
for lam in (spread, clustered):
    print(lam.max() / lam.min(), conjugate_gradient(sp.diags(lam).tocsr(), np.ones(1000), tol=1e-8)[1])
# 1000.0 176
# 1000.0 24

# 7. preconditioning: ridge regression with features on scales from 1 to 1000
rng = np.random.default_rng(0)
X = rng.normal(size=(2000, 200)) * np.logspace(0, 3, 200)
y = X @ (rng.normal(size=200) / np.logspace(0, 3, 200)) + 0.1 * rng.normal(size=2000)
H, g = X.T @ X + np.eye(200), X.T @ y                     # (X^T X + I) w = X^T y
Minv = 1 / np.diag(H)                                      # Jacobi: divide by the diagonal
ev = np.linalg.eigvalsh(H)
evp = np.linalg.eigvalsh(np.sqrt(Minv)[:, None] * H * np.sqrt(Minv)[None, :])
w_plain, k_plain, _ = conjugate_gradient(H, g)
w_jac, k_jac, _ = conjugate_gradient(H, g, Minv=Minv)
print(f'{ev[-1] / ev[0]:.1e} {evp[-1] / evp[0]:.2f}', k_plain, k_jac, np.allclose(w_jac, np.linalg.solve(H, g)))
# 1.1e+06 3.55 2904 20 True

# 8. n = 10^6: the Laplacian with N = 1000, stored in about 64 MB, solved by CG to a relative residual of 1e-8
L = laplacian_2d(1000)
b = np.ones(L.shape[0])
x, k, _ = conjugate_gradient(L, b, tol=1e-8, maxiter=10_000)
mem = (L.data.nbytes + L.indices.nbytes + L.indptr.nbytes) / 1e6
kappa = (4 + 4 * np.cos(np.pi / 1001)) / (4 - 4 * np.cos(np.pi / 1001))
flops = k * (2 * L.nnz + 10 * L.shape[0])                  # per step: one product, two inner products, three updates
print(L.shape[0], L.nnz, round(mem), f'{kappa:.1e}', k, f'{flops:.1e}', f'{np.linalg.norm(b - L @ x) / np.linalg.norm(b):.1e}')
# 1000000 4996000 64 4.1e+05 1853 3.7e+10 9.9e-09

The course in one paragraph#

Machine learning is written in linear algebra, differentiated with calculus, trained by optimization and run in floating point; the course built each layer on the one before.

In linear algebra, data are vectors and models are linear maps between them (vectors and linear maps). Solving a system is elimination, the factorization A=LUA = LU (linear systems), and least squares is a projection (orthogonality). Eigenvalues describe repeated application (eigenvalues), symmetric matrices give the axes of quadratic forms, covariances and Hessians (symmetric matrices), and the SVD gives rank, low-rank approximation and PCA for every matrix (SVD).

In calculus, derivatives are best linear approximations (derivatives). In many variables they become gradients, Jacobians and Hessians chained by matrix products (gradients), written compactly for vector and matrix expressions (matrix calculus); the Jacobian determinant changes variables in integrals (multiple integrals).

In optimization, convexity turns a zero gradient into a certificate of a global minimum (convexity). Gradient descent needs about κ\kappa steps, and Newton’s method removes κ\kappa near the minimum (unconstrained optimization). Constraints are balanced by multipliers in the KKT conditions (KKT), whose dual gives lower bounds and the SVM’s form (duality).

In numerical computation, the condition number that set the speed of gradient descent also sets how many digits a computer can trust (conditioning). When a matrix is too large to factorize, products with it are enough: the power method finds its top eigenvector, and conjugate gradient solves a positive definite system in about κ\sqrt\kappa steps.

Next#

The course ends here. The Probability course supplies the other half of the language of machine learning: random variables, expectations and the Gaussian, whose covariance matrices are the symmetric positive definite matrices of this course. The Machine Learning course builds on both, starting from data, losses and least squares. The Bayesian Methods course uses the linear algebra most heavily: its Gaussian processes solve kernel systems whose O(n3)O(n^3) factorization is the wall this note started from.

References#

  • M. R. Hestenes, E. Stiefel. Methods of conjugate gradients for solving linear systems. Journal of Research of the National Bureau of Standards, 49(6), 409–436, 1952.
  • J. R. Shewchuk. An Introduction to the Conjugate Gradient Method Without the Agonizing Pain. Technical report CMU-CS-94-125, Carnegie Mellon University, 1994. Sections 4–6 (steepest descent and its convergence), 7 (conjugate directions), 8 (CG), 9 (convergence, Chebyshev polynomials, loss of conjugacy), 12 (preconditioning), 13 (CG on the normal equations).
  • M. Rakhuba. Основы матричных вычислений (Foundations of matrix computations), lecture course, HSE University, Faculty of Computer Science, 2025/26. Course page; lecture 15 (Krylov subspaces, CG as minimization over them), lecture 16 (convergence of CG and its square-root bound, GMRES, MINRES), lecture 17 (preconditioning, the power method, inverse iteration with a shift, Rayleigh quotient iteration and its cubic rate for symmetric matrices, subspace iteration, the Rayleigh–Ritz method), lecture 18 (Arnoldi and Lanczos).
  • D. Merkulov. Optimization for ML, HSE University, 2024. Course site; lecture 12 (the conjugate gradient method: conjugate directions, convergence, Theorems 1 and 2, non-linear CG).
  • G. Strang. Matrix Methods in Data Analysis, Signal Processing, and Machine Learning (MIT 18.065), lecture 12 (computing eigenvalues; Krylov spaces), MIT OpenCourseWare, 2018; and Krylov subspaces and conjugate gradients, notes for MIT 18.086, 2006 (the conditioning of the Krylov basis; Arnoldi becomes Lanczos for symmetric A).
  • S. Boyd, L. Vandenberghe. Convex Optimization. Cambridge University Press, 2004. Appendix C (numerical linear algebra: flop counts, C.3 LU and Cholesky factorization, sparse matrices).
  • J. Martens. Deep learning via Hessian-free optimization. ICML, 2010.