In numerical linear algebra, the conjugate gradient method is an iterative method for numerically solving the linear system
𝑨𝒙=𝒃 where 𝑨 is symmetric positive-definite, without computing 𝑨−1 explicitly. The conjugate gradient method can be derived from several different perspectives, including specialization of the conjugate direction method for optimization, and variation of the Arnoldi/Lanczos iteration for eigenvalue problems. The intent of this article is to document the important steps in these derivations.
Conjugate direction The conjugate gradient method can be seen as a special case of the conjugate direction method applied to minimization of the quadratic function
f(𝒙)=𝒙T𝑨𝒙−2𝒃T𝒙. which allows us to apply geometric intuition.
Line search
Geometrically, the quadratic function can be equivalently presented by writing down its value at every point in space. The points of equal value make up its contour surfaces, which are concentric ellipsoids with the equation 𝒙T𝑨𝒙−2𝒃T𝒙=Cfor varying C. As C decreases, the ellipsoids become smaller and smaller, until at its minimal value, the ellipsoid shrinks to their shared center. Minimizing the quadratic function is then a problem of moving around the plane, searching for that shared center of all those ellipsoids. The center can be found by computing 𝑨−1 explicitly, but this is precisely what we are trying to avoid. The simplest method is greedy line search, where we start at some point 𝒙0, pick a direction 𝒑0 somehow, then minimize f(𝒙0+𝒑0α0). This has a simple closed-form solution that does not involve matrix inversion:α0=𝒑0T(𝒃−𝑨𝒙0)𝒑0T𝑨𝒑0Geometrically, we start at some point 𝒙0 on some ellipsoid, then choose a direction and travel along that direction, until we hit the point where the ellipsoid is minimized in that direction. This is not necessarily the minimum, but it is progress towards it. Visually, it is moving along a line, and stopping as soon as we reach a point tangent to the contour ellipsoid. We can now repeat this procedure, starting at our new point 𝒙1=𝒙0+α0𝒑0, pick a new direction 𝒑1, compute α1, etc. We can summarize this as the following algorithm: Start by picking an initial guess 𝒙0, and compute the initial residual 𝒓0=𝒃−𝑨𝒙0, then iterate:
αi=𝒑iT𝒓i𝒑iT𝑨𝒑i,𝒙i+1=𝒙i+αi𝒑i,𝒓i+1=𝒓i−αi𝑨𝒑i where 𝒑0,𝒑1,𝒑2,… are to be picked. Notice in particular how the residual is calculated iteratively step-by-step, instead of anew every time:𝒓i+1=𝒃−𝑨𝒙i+1=𝒃−𝑨(𝒙i+αi𝒑i)=𝒓i−αi𝑨𝒑iIt is possibly true that αi=0 prematurely, which would bring numerical problems. However, for particular choices of 𝒑0,𝒑1,𝒑2,…, this will not occur before convergence, as we will prove below.
Conjugate directions If the directions 𝒑0,𝒑1,𝒑2,… are not picked well, then progress will be slow. In particular, the gradient descent method would be slow. This can be seen in the diagram, where the green line is the result of always picking the local gradient direction. It zig-zags towards the minimum, but repeatedly overshoots. In contrast, if we pick the directions to be a set of mutually conjugate directions, then there will be no overshoot, and we would obtain the global minimum after n steps, where n is the number of dimensions.
The concept of conjugate directions came from classical geometry of ellipse. For an ellipse, two semi-axes are mutually conjugate with respect to the ellipse iff the lines are parallel to the tangent bounding parallelogram, as pictured. The concept generalizes to n-dimensional ellipsoids, where n semi-axes t0𝒑0,…,tn−1𝒑n−1 are mutually conjugate with respect to the ellipsoid iff each axis is parallel to the tangent bounding parallelepiped. In other words, for any i, the tangent plane to the ellipsoid at 𝒄+ti𝒑i is a hyperplane spanned by the vectors {𝒑j:j≠i}, where 𝒄 is the center of the ellipsoid. Note that we need to scale each directional vector 𝒑i by a scalar ti, so that 𝒄+ti𝒑i falls exactly on the ellipsoid. Given an ellipsoid with equation 𝒙T𝑨𝒙−2𝒃T𝒙=Cfor some constant C, we can translate it so that its center is at origin. This changes the equation to 𝒙T𝑨𝒙=C′for some other constant C′. The condition of tangency is then:(ti𝒑i+𝒑jdtj)T𝑨(ti𝒑i+𝒑jdtj)=C′+O(dtj2),∀i≠jthat is, 𝒑iT𝑨𝒑j=0 for any i≠j. The conjugate direction method is imprecise in the sense that no formulae are given for selection of the directions 𝒑0,𝒑1,𝒑2,…. Specific choices lead to various methods including the conjugate gradient method and Gaussian elimination.
Gram–Schmidt process We can tabulate the equations that we need to set to zero:
This resembles the problem of orthogonalization, which requires 𝒑iT𝒑j=0 for any i≠j, and 𝒑iT𝒑j=1 for any i=j. Thus the problem of finding conjugate axes is less constrained than the problem of orthogonalization, so the Gram–Schmidt process works, with additional degrees of freedom that we can later use to pick the ones that would simplify the computation:
Arbitrarily set 𝒑0. Arbitrarily set 𝒑10, then modify it to 𝒑1=𝒑10−𝒑0T𝑨𝒑10𝒑0T𝑨𝒑0𝒑0. Arbitrarily set 𝒑20, then modify it to 𝒑2=𝒑20−∑i=01𝒑iT𝑨𝒑20𝒑iT𝑨𝒑i𝒑i. ... Arbitrarily set 𝒑n−1,0, then modify it to 𝒑n−1=𝒑n−1,0−∑i=0n−2𝒑iT𝑨𝒑n−1,0𝒑iT𝑨𝒑i𝒑i. The most natural choice of 𝒑k,0 is the gradient. That is, 𝒑k,0=∇f(𝒙k). Since conjugate directions can be scaled by a nonzero value, we scale it by −1/2 for notational cleanness, obtaining 𝒑k,0=𝐫k=𝐛−𝐀𝐱kThus, we have 𝒑k=𝒓k−∑i=0k−1𝒑iT𝑨𝒓k𝒑iT𝑨𝒑i𝒑i. Plugging it in, we have the conjugate gradient algorithm:𝐫0:=𝐛−𝐀𝐱0𝐩0:=𝐫0k:=0do while k<nαk:=𝐩k𝖳𝐫k𝐩k𝖳𝐀𝐩k𝐱k+1:=𝐱k+αk𝐩kif |αk| is sufficiently small, then exit loop𝐫k+1:=𝐫k−αk𝐀𝐩k𝐩k+1:=𝒓k+1−∑i=0k𝒑iT𝑨𝒓k+1𝒑iT𝑨𝒑i𝒑ik:=k+1return 𝐱k+1 as the resultProposition. If at some point, αk=0, then the algorithm has converged, that is, ∇f(xk+1)=0. Proof. By construction, it would mean that 𝐱k+1=𝐱k, that is, taking a conjugate gradient step gets us exactly back to where we were. This is only possible if the local gradient is already zero.
… excerpt ends here. Continue reading the full article.

