Exercise: The Conjugate Gradient Method
Contents
11. Exercise: The Conjugate Gradient Method#
In the conjugate gradient method, the solution at iteration \(n+1\) is:
where
and
It can be shown that the residual can be computed as
and thus avoiding computation of \(\mathbf{Ax}_n\). However, using (11.5) leads to the accumulation of rounding errors. Thus, it is recommended that (11.2) is used every 50 iterations.
Unlike the Jacobi method, it is not intuitively obvious why the conjugate gradient method works. Following is an attempt to explain why the method works.
In the conjugate gradient method, the value of \(\bo{x}\) that minimizes
is obtained by line minimizations in \(n\) linearly independent directions, where \(n\) is the order of the symmetric positive definite matrix \(\bo{A}\). Note that after minimization of \(f(\bo{x})\) in any direction \(\bo{d}_i\), the gradient \(\bo{r}_{i+1}\) will be orthogonal to \(\bo{d}_i\).
In the conjugate gradient method, each direction \(\bo{d}_i\) is is chosen such that the gradient \(\bo{r}_{i+1}\) will also be orthogonal to all the directions \(\bo{d}_j\), for \(j<i\), that have already been used for line minimization. If the directions are also linearly independent, after \(n\) line minimizations, the function will be at its minimum in \(n\) linearly independent directions. Further, at this point, the gradient
is orthogonal to the \(n\) direction vectors. Thus, it must be the zero vector.
Following is a description of how the direction vectors are computed. Suppose the search is initiated at \(\bo{x}_0 = \bo{0}\). At this point, the gradient of the \(f(\bo{x})\) is
Let \(\bo{d}_0 = \bo{r}_0\) be the first direction for line minimization. After minimization of \(f(\bo{x})\) in the direction \(\bo{d}_0\), the value of \(\bo{x}\) is
At \(\bo{x}_1\), the gradient of the function is
and \(\bo{r}_1\) is orthogonal to \(\bo{d}_0\). Writing the product \(\bo{d}_0\bo{r}_1=0\) as
shows that
and in general,
At this point, line minimization proceeds in the direction \(\bo{d}_1\), and the value of \(\bo{x}\) at the minimum is
The gradient of the function at \(\bo{x}_2\) is
and \(\bo{r}_2\) is orthogonal to \(\bo{d}_1\). In the conjugate gradient method, the direction \(\bo{d}_1\) is chosen such that \(\bo{r}_2\) will also be orthogonal to the direction \(\bo{d}_0\). Thus the product
So, the direction, \(\bo{d}_1\) must satisfy the condition
in order for \(\bo{r}_2\) to be orthogonal to \(\bo{d}_0\). To accomplish this, following the Grahm-Schmidt procedure, \(\bo{d}_1\) is written as
Writing \(\bo{d}_0'\bo{Ad}_1=0\) as
shows that
In general,
and by induction, \(\bo{r}_{i+1}'\bo{d}_j=0\) provided \(\bo{d}_i'\bo{Ad}_j=0\) for \(j<i\). This can be achieved by using Grahm-Schmidt as
where
Note that using the result \(\bo{r}_i\bo{d}_j=0\) for \(j<i\) in \eqref{eq:24} implies:
Using (11.22) in (11.19), shows that \(\bo{r}_i'\bo{Ad}_j=0\) for \(j<i-1\). Thus, in (11.21), \(\beta_{ij}=0\) for \(j<i-1\), and the general expression for \(\bo{d}_i\) simplifies to
where
Writing \(\bo{r}_i\) as
and pre-multiplying by \(\bo{r}_i'\) gives
Pre-multiplying (11.25) by \(\bo{d}_{i-1}\) gives
Further, from (11.23), we can see that
Using this is (11.27) gives
Using (11.26) and (11.29) in (11.24) gives
Finally, using (11.28) in (11.12) gives
12. Preconditioned conjugate gradient method#
In the PCCG method, the conjugate gradient method is applied to a transformed system of equations. The transformation of the system is based on a matrix \(\mathbf{M}\) that is approximately equal to \(\mathbf{A}\) and is easy to invert. A detailed explanation of PCCG is given in An Introduction to the Conjugate Gradient Method Without the Agonizing Pain by Jonathan Richard Shewchuk.
In PCCG, the solution at iteration \(n+1\) is:
where
As in the conjugate gradient method, the residual can be computed more efficiently as
However, it is recommended that (12.3) is used to every 50 iterations to avoid the accumulation of errors.
12.1. Exercise#
Write a PCG function for the Conjugate Gradient Method algorithm described above.