Derivation of the conjugate gradient method explained

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

\boldsymbol{Ax}=\boldsymbol{b}

where

\boldsymbol{A}

is symmetric positive-definite, without computing

\boldsymbol{A}-1

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(\boldsymbol{x})=\boldsymbol{x}T\boldsymbol{A}\boldsymbol{x}-2\boldsymbol{b}T\boldsymbol{x}.

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 \boldsymbol^\mathrm\boldsymbol\boldsymbol-2\boldsymbol^\mathrm\boldsymbol = C for 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

\boldsymbol{A}-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

\boldsymbol{x}0

, pick a direction

\boldsymbol{p}0

somehow, then minimize

f(\boldsymbol{x}0+\boldsymbol{p}0\alpha0)

. This has a simple closed-form solution that does not involve matrix inversion:\alpha_0 = \frac Geometrically, we start at some point

\boldsymbol{x}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

\boldsymbol{x}1=\boldsymbol{x}0+\alpha0\boldsymbol{p}0

, pick a new direction

\boldsymbol{p}1

, compute

\alpha1

, etc.

We can summarize this as the following algorithm:

Start by picking an initial guess

\boldsymbol{x}0

, and compute the initial residual

\boldsymbol{r}0=\boldsymbol{b}-\boldsymbol{Ax}0

, then iterate:
T\boldsymbol{r}
\begin{align} \alpha
i}{\boldsymbol{p}
T\boldsymbol{Ap}
i},\\ \boldsymbol{x}

i+1&=\boldsymbol{x}i+\alphai\boldsymbol{p}i,\\ \boldsymbol{r}i+1&=\boldsymbol{r}i-\alphai\boldsymbol{Ap}i \end{align}

where

\boldsymbol{p}0,\boldsymbol{p}1,\boldsymbol{p}2,\ldots

are to be picked. Notice in particular how the residual is calculated iteratively step-by-step, instead of anew every time:\boldsymbol_ = \boldsymbol - \boldsymbol_ = \boldsymbol - \boldsymbol (\boldsymbol_i+\alpha_i\boldsymbol_i) = \boldsymbol_i -\alpha_i \boldsymbol \boldsymbol_i It is possibly true that

\alphai=0

prematurely, which would bring numerical problems. However, for particular choices of

\boldsymbol{p}0,\boldsymbol{p}1,\boldsymbol{p}2,\ldots

, this will not occur before convergence, as we will prove below.

Conjugate directions

If the directions

\boldsymbol{p}0,\boldsymbol{p}1,\boldsymbol{p}2,\ldots

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 center 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\boldsymbol{p}0,...,tn-1\boldsymbol{p}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

\boldsymbol{c}+ti\boldsymbol{p}i

is a hyperplane spanned by the vectors

\{\boldsymbol{p}j:ji\}

, where

\boldsymbol{c}

is the center of the ellipsoid.

Note that we need to scale each directional vector

\boldsymbol{p}i

by a scalar

ti

, so that

\boldsymbol{c}+ti\boldsymbol{p}i

falls exactly on the ellipsoid.

Given an ellipsoid with equation \boldsymbol^\mathrm\boldsymbol\boldsymbol-2\boldsymbol^\mathrm\boldsymbol = C for some constant

C

, we can translate it so that its center is at origin. This changes the equation to \boldsymbol^\mathrm\boldsymbol\boldsymbol = C' for some other constant

C'

. The condition of tangency is then:(t_i\boldsymbol_i + \boldsymbol_j dt_j)^\mathrm\boldsymbol (t_i\boldsymbol_i + \boldsymbol_j dt_j) = C' + O(dt_j^2), \quad \forall i \neq j that is,
T\boldsymbol{Ap}
\boldsymbol{p}
j=0
for any

ij

.

The conjugate direction method is imprecise in the sense that no formulae are given for selection of the directions

\boldsymbol{p}0,\boldsymbol{p}1,\boldsymbol{p}2,\ldots

. 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
123

0
T\boldsymbol{Ap}
\boldsymbol{p}
1
T\boldsymbol{Ap}
\boldsymbol{p}
2
T\boldsymbol{Ap}
\boldsymbol{p}
3

1
T\boldsymbol{Ap}
\boldsymbol{p}
2
T\boldsymbol{Ap}
\boldsymbol{p}
3

2
T\boldsymbol{Ap}
\boldsymbol{p}
3

\vdots

\ddots

This resembles the problem of orthogonalization, which requires

T\boldsymbol{p}
\boldsymbol{p}
j=0
for any

ij

, and
T\boldsymbol{p}
\boldsymbol{p}
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:

\boldsymbol{p}0

.

\boldsymbol{p}10

, then modify it to

\boldsymbol{p}1=\boldsymbol{p}10-

\boldsymbol{p
0
T\boldsymbol{Ap}
10
}\boldsymbol_.

\boldsymbol{p}20

, then modify it to

\boldsymbol{p}2=\boldsymbol{p}20-

1 \boldsymbol{p
i
\sum
i=0
T\boldsymbol{Ap}
20
}\boldsymbol_.

\boldsymbol{p}n-1,0

, then modify it to

\boldsymbol{p}n-1=\boldsymbol{p}n-1,0-

n-2
\sum
i=0
\boldsymbol{p
i
T\boldsymbol{Ap}
n-1,0
}\boldsymbol_ .The most natural choice of

\boldsymbol{p}k,0

is the gradient. That is,

\boldsymbol{p}k,0=\nablaf(\boldsymbol{x}k)

. Since conjugate directions can be scaled by a nonzero value, we scale it by

-1/2

for notational cleanness, obtaining \boldsymbol_ = \mathbf_k = \mathbf - \mathbf_kThus, we have

\boldsymbol{p}k=\boldsymbol{r}k-

k-1
\sum
i=0
\boldsymbol{p
i
T\boldsymbol{Ar}
k
}\boldsymbol_. Plugging it in, we have the conjugate gradient algorithm:\begin& \mathbf_0 := \mathbf - \mathbf_0 \\& \mathbf_0 := \mathbf_0 \\& k := 0 \\& \textk < n \\& \qquad \alpha_k := \frac \\ & \qquad \mathbf_ := \mathbf_k + \alpha_k \mathbf_k \\& \qquad \text |\alpha_k| \text\\& \qquad \mathbf_ := \mathbf_k - \alpha_k \mathbf_k \\& \qquad \mathbf_ := \boldsymbol_ - \sum_^\frac\boldsymbol_\\& \qquad k := k + 1 \\& \text \mathbf_ \text \endProposition. If at some point,

\alphak=0

, then the algorithm has converged, that is,

\nablaf(xk+1)=0

.

Proof. By construction, it would mean that

xk+1=xk

, 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.

T
p
i

rj=0,\foralli<j

and
T
r
i

rj=0,\foralli<j

.

Proof. By the geometric construction, the tangent plane to the ellipsoid at

xj

contains each of the previous conjugate direction vectors

p0,p1,...,pj-1

. Further,

rj

is perpendicular to the tangent, thus
T
p
i

rj=0,\foralli<j

. The second equation is true since by construction,

r0,r1,...,rj-1

is a linear transform of

p0,p1,...,pj-1

.

Lemma 2.

T
p
k

rk=

Tr
r
k
.

Proof. By construction,

pk:=\boldsymbol{r}k-

k-1
\sum
i=0
\boldsymbol{p
i
T\boldsymbol{Ar}
k-1
}\boldsymbol_, now apply lemma 1.

Lemma 3.

T\boldsymbol{Ar}
\boldsymbol{p}
k+1

=\begin{cases} 0,i<k

T
\\ -\boldsymbol{r}
k+1

\boldsymbol{r}k+1/\alphak,i=k \end{cases}

.

Proof. By construction, we have

ri+1=ri-\alphakApi

, thus\boldsymbol r_^T \boldsymbol A \boldsymbol p_i = \boldsymbol r_^T \fracNow apply lemma 1.

Plugging lemmas 1-3 in, we have

\alpha
k=
\top
rrk
k
\top
pApk
k
and

pk+1:=\boldsymbol{r}k+1+

\top
rrk+1
k+1
\top
rrk
k

pk

, which is the proper conjugate gradient algorithm.

Arnoldi/Lanczos iteration

See also: Arnoldi iteration and 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

\boldsymbol{r}0

and gradually builds an orthonormal basis

\{\boldsymbol{v}1,\boldsymbol{v}2,\boldsymbol{v}3,\ldots\}

of the Krylov subspace

l{K}(\boldsymbol{A},\boldsymbol{r}0)=span\{\boldsymbol{r}0,\boldsymbol{Ar}

2\boldsymbol{r}
0,\ldots\}

by defining

\boldsymbol{v}i=\boldsymbol{w}i/\lVert\boldsymbol{w}i\rVert2

where

\boldsymbol{v}i=\begin{cases} \boldsymbol{r}0&ifi=1,\\ \boldsymbol{Av}i-1

i-1
-\sum
j=1
T\boldsymbol{Av}
(\boldsymbol{v}
i-1

)\boldsymbol{v}j&ifi>1. \end{cases}

In other words, for

i>1

,

\boldsymbol{v}i

is found by Gram-Schmidt orthogonalizing

\boldsymbol{Av}i-1

against

\{\boldsymbol{v}1,\boldsymbol{v}2,\ldots,\boldsymbol{v}i-1\}

followed by normalization.

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

\boldsymbol{AV}i=\boldsymbol{V}i+1\boldsymbol{\tilde{H}}i

where

\begin{align} \boldsymbol{V}i&=\begin{bmatrix} \boldsymbol{v}1&\boldsymbol{v}2&&\boldsymbol{v}i \end{bmatrix},\\ \boldsymbol{\tilde{H}}i&=\begin{bmatrix} h11&h12&h13&&h1,i\\ h21&h22&h23&&h2,i\\ &h32&h33&&h3,i\\ &&\ddots&\ddots&\vdots\\ &&&hi,i-1&hi,i\\ &&&&hi+1,i\end{bmatrix}=\begin{bmatrix} \boldsymbol{H}i\\ hi+1,i

T \end{bmatrix} \end{align}
\boldsymbol{e}
i

with

hji

T\boldsymbol{Av}
=\begin{cases} \boldsymbol{v}
i

&ifj\leqi,\\ \lVert\boldsymbol{w}i+1\rVert2&ifj=i+1,\\ 0&ifj>i+1. \end{cases}

When applying the Arnoldi iteration to solving linear systems, one starts with

\boldsymbol{r}0=\boldsymbol{b}-\boldsymbol{Ax}0

, the residual corresponding to an initial guess

\boldsymbol{x}0

. After each step of iteration, one computes

\boldsymbol{y}i=\boldsymbol{H}

-1
i

(\lVert\boldsymbol{r}0\rVert2\boldsymbol{e}1)

and the new iterate

\boldsymbol{x}i=\boldsymbol{x}0+\boldsymbol{V}i\boldsymbol{y}i

.

The direct Lanczos method

For the rest of discussion, we assume that

\boldsymbol{A}

is symmetric positive-definite. With symmetry of

\boldsymbol{A}

, the upper Hessenberg matrix

\boldsymbol{H}i=\boldsymbol{V}

T\boldsymbol{AV}
i
becomes symmetric and thus tridiagonal. It then can be more clearly denoted by

\boldsymbol{H}i=\begin{bmatrix} a1&b2\\ b2&a2&b3\\ &\ddots&\ddots&\ddots\\ &&bi-1&ai-1&bi\\ &&&bi&ai \end{bmatrix}.

This enables a short three-term recurrence for

\boldsymbol{v}i

in the iteration, and the Arnoldi iteration is reduced to the Lanczos iteration.

Since

\boldsymbol{A}

is symmetric positive-definite, so is

\boldsymbol{H}i

. Hence,

\boldsymbol{H}i

can be LU factorized without partial pivoting into

\boldsymbol{H}i=\boldsymbol{L}i\boldsymbol{U}i=\begin{bmatrix} 1\\ c2&1\\ &\ddots&\ddots\\ &&ci-1&1\\ &&&ci&1 \end{bmatrix}\begin{bmatrix} d1&b2\\ &d2&b3\\ &&\ddots&\ddots\\ &&&di-1&bi\\ &&&&di \end{bmatrix}

with convenient recurrences for

ci

and

di

:

\begin{align} ci&=bi/di-1,\\ di&=\begin{cases} a1&ifi=1,\\ ai-cibi&ifi>1. \end{cases} \end{align}

Rewrite

\boldsymbol{x}i=\boldsymbol{x}0+\boldsymbol{V}i\boldsymbol{y}i

as

\begin{align} \boldsymbol{x}i&=\boldsymbol{x}0+\boldsymbol{V}i\boldsymbol{H}

-1
i

(\lVert\boldsymbol{r}0\rVert2\boldsymbol{e}1)\\ &=\boldsymbol{x}0+\boldsymbol{V}i\boldsymbol{U}

-1
i
-1
\boldsymbol{L}
i

(\lVert\boldsymbol{r}0\rVert2\boldsymbol{e}1)\\ &=\boldsymbol{x}0+\boldsymbol{P}i\boldsymbol{z}i \end{align}

with

\begin{align} \boldsymbol{P}i&=\boldsymbol{V}i

-1
\boldsymbol{U}
i

,\\ \boldsymbol{z}i&=\boldsymbol{L}

-1
i

(\lVert\boldsymbol{r}0\rVert2\boldsymbol{e}1). \end{align}

It is now important to observe that

\begin{align} \boldsymbol{P}i&=\begin{bmatrix} \boldsymbol{P}i-1&\boldsymbol{p}i \end{bmatrix},\\ \boldsymbol{z}i&=\begin{bmatrix} \boldsymbol{z}i-1\\ \zetai \end{bmatrix}. \end{align}

In fact, there are short recurrences for

\boldsymbol{p}i

and

\zetai

as well:
\begin{align} \boldsymbol{p}
i&=1
di

(\boldsymbol{v}i-bi\boldsymbol{p}i-1),\\ \zetai&=-ci\zetai-1. \end{align}

With this formulation, we arrive at a simple recurrence for

\boldsymbol{x}i

:

\begin{align} \boldsymbol{x}i&=\boldsymbol{x}0+\boldsymbol{P}i\boldsymbol{z}i\\ &=\boldsymbol{x}0+\boldsymbol{P}i-1\boldsymbol{z}i-1+\zetai\boldsymbol{p}i\\ &=\boldsymbol{x}i-1+\zetai\boldsymbol{p}i. \end{align}

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

\boldsymbol{p}i

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

\begin{align} \boldsymbol{x}i&=\boldsymbol{x}i-1+\alphai-1\boldsymbol{p}i-1,\\ \boldsymbol{r}i&=\boldsymbol{r}i-1-\alphai-1\boldsymbol{Ap}i-1,\\ \boldsymbol{p}i&=\boldsymbol{r}i+\betai-1\boldsymbol{p}i-1. \end{align}

As premises for the simplification, we now derive the orthogonality of

\boldsymbol{r}i

and conjugacy of

\boldsymbol{p}i

, i.e., for

ij

,
T\boldsymbol{r}
\begin{align} \boldsymbol{r}
j&=0,\\ \boldsymbol{p}
T\boldsymbol{Ap}
j&=0. \end{align}

The residuals are mutually orthogonal because

\boldsymbol{r}i

is essentially a multiple of

\boldsymbol{v}i+1

since for

i=0

,

\boldsymbol{r}0=\lVert\boldsymbol{r}0\rVert2\boldsymbol{v}1

, for

i>0

,

\begin{align} \boldsymbol{r}i&=\boldsymbol{b}-\boldsymbol{Ax}i\\ &=\boldsymbol{b}-\boldsymbol{A}(\boldsymbol{x}0+\boldsymbol{V}i\boldsymbol{y}i)\\ &=\boldsymbol{r}0-\boldsymbol{AV}i\boldsymbol{y}i\\ &=\boldsymbol{r}0-\boldsymbol{V}i+1\boldsymbol{\tilde{H}}i\boldsymbol{y}i\\ &=\boldsymbol{r}0-\boldsymbol{V}i\boldsymbol{H}i\boldsymbol{y}i-hi+1,i

T\boldsymbol{y}
(\boldsymbol{e}
i)\boldsymbol{v}

i+1\\ &=\lVert\boldsymbol{r}0\rVert2\boldsymbol{v}1-\boldsymbol{V}i(\lVert\boldsymbol{r}0\rVert2\boldsymbol{e}1)-hi+1,i

T\boldsymbol{y}
(\boldsymbol{e}
i)\boldsymbol{v}

i+1\\ &=-hi+1,i

T\boldsymbol{y}
(\boldsymbol{e}
i)\boldsymbol{v}

i+1.\end{align}

To see the conjugacy of

\boldsymbol{p}i

, it suffices to show that
T\boldsymbol{AP}
\boldsymbol{P}
i
is diagonal:
T\boldsymbol{AP}
\begin{align} \boldsymbol{P}
i&=\boldsymbol{U}
-T
i
T\boldsymbol{AV}
\boldsymbol{V}
i\boldsymbol{U}
-1
i
-T
\\ &=\boldsymbol{U}
i

\boldsymbol{H}i\boldsymbol{U}

-1
i
-T
\\ &=\boldsymbol{U}
i

\boldsymbol{L}i\boldsymbol{U}i\boldsymbol{U}

-1
i
-T
\\ &=\boldsymbol{U}
i

\boldsymbol{L}i \end{align}

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

Now we can derive the constant factors

\alphai

and

\betai

with respect to the scaled

\boldsymbol{p}i

by solely imposing the orthogonality of

\boldsymbol{r}i

and conjugacy of

\boldsymbol{p}i

.

Due to the orthogonality of

\boldsymbol{r}i

, it is necessary that
T\boldsymbol{r}
\boldsymbol{r}
i=(\boldsymbol{r}

i-\alphai\boldsymbol{Ap}

T\boldsymbol{r}
i=0
. As a result,
T\boldsymbol{r}
\begin{align} \alpha
i}{\boldsymbol{r}
T\boldsymbol{r}
i}{(\boldsymbol{p}

i-\betai-1\boldsymbol{p}i-1

T\boldsymbol{r}
)
i}{\boldsymbol{p}
T\boldsymbol{Ap}
i}. \end{align}

Similarly, due to the conjugacy of

\boldsymbol{p}i

, it is necessary that
T\boldsymbol{Ap}
\boldsymbol{p}
i=(\boldsymbol{r}

i+1+\betai\boldsymbol{p}

T\boldsymbol{Ap}
i=0
. As a result,
T\boldsymbol{Ap}
\begin{align} \beta
i}{\boldsymbol{p}
T(\boldsymbol{r}
i-\boldsymbol{r}

i+1)}{\alphai\boldsymbol{p}

T\boldsymbol{r}
i+1
}\text\end

This completes the derivation.

References

  1. Hestenes. M. R.. David Hestenes. Stiefel. E.. Eduard Stiefel. Methods of conjugate gradients for solving linear systems. Journal of Research of the National Bureau of Standards. 49. 6. December 1952. 409. 10.6028/jres.049.044.
  2. Shewchuk, Jonathan Richard. "An introduction to the conjugate gradient method without the agonizing pain." (1994)
  3. Book: Saad, Y.. Iterative methods for sparse linear systems. registration. 2nd. Chapter 6: Krylov Subspace Methods, Part I. SIAM. 2003. 978-0-89871-534-7.

Notes and References

  1. Conjugate Direction Methods http://user.it.uu.se/~matsh/opt/f8/node5.html