Derivation of the conjugate gradient method

From HandWiki

In numerical linear algebra, the conjugate gradient method is an iterative method for numerically solving the linear system

Ax=b

where A is symmetric positive-definite, without computing A1 explicitly. The conjugate gradient method can be derived from several different perspectives, including specialization of the conjugate direction method[1] 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(x)=xTAx2bTx.

which allows us to apply geometric intuition.

thumb 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 xTAx2bTx=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 A1 explicitly, but this is precisely what we are trying to avoid.

The simplest method is greedy line search, where we start at some point x0, pick a direction p0 somehow, then minimize f(x0+p0α0). This has a simple closed-form solution that does not involve matrix inversion:α0=p0T(bAx0)p0TAp0Geometrically, we start at some point x0 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 x1=x0+α0p0, pick a new direction p1, compute α1, etc.

We can summarize this as the following algorithm:

Start by picking an initial guess x0, and compute the initial residual r0=bAx0, then iterate:

αi=piTripiTApi,xi+1=xi+αipi,ri+1=riαiApi

where p0,p1,p2, are to be picked. Notice in particular how the residual is calculated iteratively step-by-step, instead of anew every time:ri+1=bAxi+1=bA(xi+αipi)=riαiApiIt is possibly true that αi=0 prematurely, which would bring numerical problems. However, for particular choices of p0,p1,p2,, this will not occur before convergence, as we will prove below.

Conjugate directions

If the directions p0,p1,p2, 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.

Two conjugate diameters of an ellipse. Each edge of the bounding parallelogram is parallel to one of the diameters.

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 t0p0,,tn1pn1 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 c+tipi is a hyperplane spanned by the vectors {pj:ji}, where c is the center of the ellipsoid.

Note that we need to scale each directional vector pi by a scalar ti, so that c+tipi falls exactly on the ellipsoid.

Given an ellipsoid with equation xTAx2bTx=Cfor some constant C, we can translate it so that its center is at origin. This changes the equation to xTAx=Cfor some other constant C. The condition of tangency is then:(tipi+pjdtj)TA(tipi+pjdtj)=C+O(dtj2),ijthat is, piTApj=0 for any ij.

The conjugate direction method is imprecise in the sense that no formulae are given for selection of the directions p0,p1,p2,. 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:

0 1 2 3
0 p0TAp1 p0TAp2 p0TAp3
1 p1TAp2 p1TAp3
2 p2TAp3

This resembles the problem of orthogonalization, which requires piTpj=0 for any ij, and piTpj=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 p0.
  • Arbitrarily set p10, then modify it to p1=p10p0TAp10p0TAp0p0.
  • Arbitrarily set p20, then modify it to p2=p20i=01piTAp20piTApipi.
  • ...
  • Arbitrarily set pn1,0, then modify it to pn1=pn1,0i=0n2piTApn1,0piTApipi.

The most natural choice of pk,0 is the gradient. That is, pk,0=f(xk). Since conjugate directions can be scaled by a nonzero value, we scale it by 1/2 for notational cleanness, obtaining pk,0=𝐫k=𝐛𝐀𝐱kThus, we have pk=rki=0k1piTArkpiTApipi. Plugging it in, we have the conjugate gradient algorithm:𝐫0:=𝐛𝐀𝐱0𝐩0:=𝐫0k:=0do while k<nαk:=𝐩kT𝐫k𝐩kT𝐀𝐩k𝐱k+1:=𝐱k+αk𝐩kif |αk| is sufficiently small, then exit loop𝐫k+1:=𝐫kαk𝐀𝐩k𝐩k+1:=rk+1i=0kpiTArk+1piTApipik:=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.

Simplification

This algorithm can be significantly simplified by some lemmas, resulting in the conjugate gradient algorithm.

Lemma 1. 𝐩iT𝐫j=0,i<j and 𝐫iT𝐫j=0,i<j.

Proof. By the geometric construction, the tangent plane to the ellipsoid at 𝐱j contains each of the previous conjugate direction vectors 𝐩0,𝐩1,,𝐩j1. Further, 𝐫j is perpendicular to the tangent, thus 𝐩iT𝐫j=0,i<j. The second equation is true since by construction, 𝐫0,𝐫1,,𝐫j1 is a linear transform of 𝐩0,𝐩1,,𝐩j1.

Lemma 2. 𝐩kT𝐫k=𝐫kT𝐫k.

Proof. By construction, 𝐩k:=rki=0k1piTArk1piTApipi, now apply lemma 1.

Lemma 3. piTArk+1={0,i<krk+1Trk+1/αk,i=k.

Proof. By construction, we have 𝐫i+1=𝐫iαi𝐀𝐩i, thusrk+1TApi=rk+1Triri+1αiNow apply lemma 1.


Plugging lemmas 1-3 in, we have αk=𝐫k𝐫k𝐩k𝐀𝐩k and 𝐩k+1:=rk+1+𝐫k+1𝐫k+1𝐫k𝐫k𝐩k, which is the proper conjugate gradient algorithm.

Arnoldi/Lanczos iteration

The conjugate gradient method can also be seen as a variant of the Arnoldi/Lanczos iteration applied to solving linear systems.

The general Arnoldi method

In the Arnoldi iteration, one starts with a vector r0 and gradually builds an orthonormal basis {v1,v2,v3,} of the Krylov subspace

𝒦(A,r0)=span{r0,Ar0,A2r0,}

by defining vi=wi/wi2 where

vi={r0if i=1,Avi1j=1i1(vjTAvi1)vjif i>1.

In other words, for i>1, vi is found by Gram-Schmidt orthogonalizing Avi1 against {v1,v2,,vi1} followed by normalization.

Put in matrix form, the iteration is captured by the equation

AVi=Vi+1H~i

where

Vi=[v1v2vi],H~i=[h11h12h13h1,ih21h22h23h2,ih32h33h3,ihi,i1hi,ihi+1,i]=[Hihi+1,ieiT]

with

hji={vjTAviif ji,wi+12if j=i+1,0if j>i+1.

When applying the Arnoldi iteration to solving linear systems, one starts with r0=bAx0, the residual corresponding to an initial guess x0. After each step of iteration, one computes yi=Hi1(r02e1) and the new iterate xi=x0+Viyi.

The direct Lanczos method

For the rest of discussion, we assume that A is symmetric positive-definite. With symmetry of A, the upper Hessenberg matrix Hi=ViTAVi becomes symmetric and thus tridiagonal. It then can be more clearly denoted by

Hi=[a1b2b2a2b3bi1ai1bibiai].

This enables a short three-term recurrence for vi in the iteration, and the Arnoldi iteration is reduced to the Lanczos iteration.

Since A is symmetric positive-definite, so is Hi. Hence, Hi can be LU factorized without partial pivoting into

Hi=LiUi=[1c21ci11ci1][d1b2d2b3di1bidi]

with convenient recurrences for ci and di:

ci=bi/di1,di={a1if i=1,aicibiif i>1.

Rewrite xi=x0+Viyi as

xi=x0+ViHi1(r02e1)=x0+ViUi1Li1(r02e1)=x0+Pizi

with

Pi=ViUi1,zi=Li1(r02e1).

It is now important to observe that

Pi=[Pi1pi],zi=[zi1ζi].

In fact, there are short recurrences for pi and ζi as well:

pi=1di(vibipi1),ζi=ciζi1.

With this formulation, we arrive at a simple recurrence for xi:

xi=x0+Pizi=x0+Pi1zi1+ζipi=xi1+ζipi.

The relations above straightforwardly lead to the direct Lanczos method, which turns out to be slightly more complex.

The conjugate gradient method from imposing orthogonality and conjugacy

If we allow pi to scale and compensate for the scaling in the constant factor, we potentially can have simpler recurrences of the form:

xi=xi1+αi1pi1,ri=ri1αi1Api1,pi=ri+βi1pi1.

As premises for the simplification, we now derive the orthogonality of ri and conjugacy of pi, i.e., for ij,

riTrj=0,piTApj=0.

The residuals are mutually orthogonal because ri is essentially a multiple of vi+1 since for i=0, r0=r02v1, for i>0,

ri=bAxi=bA(x0+Viyi)=r0AViyi=r0Vi+1H~iyi=r0ViHiyihi+1,i(eiTyi)vi+1=r02v1Vi(r02e1)hi+1,i(eiTyi)vi+1=hi+1,i(eiTyi)vi+1.

To see the conjugacy of pi, it suffices to show that PiTAPi is diagonal:

PiTAPi=UiTViTAViUi1=UiTHiUi1=UiTLiUiUi1=UiTLi

is symmetric and lower triangular simultaneously and thus must be diagonal.

Now we can derive the constant factors αi and βi with respect to the scaled pi by solely imposing the orthogonality of ri and conjugacy of pi.

Due to the orthogonality of ri, it is necessary that ri+1Tri=(riαiApi)Tri=0. As a result,

αi=riTririTApi=riTri(piβi1pi1)TApi=riTripiTApi.

Similarly, due to the conjugacy of pi, it is necessary that pi+1TApi=(ri+1+βipi)TApi=0. As a result,

βi=ri+1TApipiTApi=ri+1T(riri+1)αipiTApi=ri+1Tri+1riTri.

This completes the derivation.

References

  1. Hestenes, M. R.; Stiefel, E. (December 1952). "Methods of conjugate gradients for solving linear systems". Journal of Research of the National Bureau of Standards 49 (6): 409. doi:10.6028/jres.049.044. http://nvlpubs.nist.gov/nistpubs/jres/049/6/V49.N06.A08.pdf. 
  2. Shewchuk, Jonathan Richard. "An introduction to the conjugate gradient method without the agonizing pain." (1994)
  3. Saad, Y. (2003). "Chapter 6: Krylov Subspace Methods, Part I". Iterative methods for sparse linear systems (2nd ed.). SIAM. ISBN 978-0-89871-534-7. https://archive.org/details/iterativemethods0000saad.