<s>
In	O
mathematics	O
,	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
is	O
an	O
algorithm	O
for	O
the	O
numerical	B-General_Concept
solution	I-General_Concept
of	O
particular	O
systems	O
of	O
linear	O
equations	O
,	O
namely	O
those	O
whose	O
matrix	O
is	O
positive-definite	B-Algorithm
.	O
</s>
<s>
The	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
is	O
often	O
implemented	O
as	O
an	O
iterative	B-Algorithm
algorithm	I-Algorithm
,	O
applicable	O
to	O
sparse	B-Algorithm
systems	I-Algorithm
that	O
are	O
too	O
large	O
to	O
be	O
handled	O
by	O
a	O
direct	O
implementation	O
or	O
other	O
direct	B-Algorithm
methods	I-Algorithm
such	O
as	O
the	O
Cholesky	O
decomposition	O
.	O
</s>
<s>
Large	O
sparse	B-Algorithm
systems	I-Algorithm
often	O
arise	O
when	O
numerically	B-General_Concept
solving	O
partial	O
differential	O
equations	O
or	O
optimization	O
problems	O
.	O
</s>
<s>
The	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
can	O
also	O
be	O
used	O
to	O
solve	O
unconstrained	O
optimization	O
problems	O
such	O
as	O
energy	O
minimization	O
.	O
</s>
<s>
It	O
is	O
commonly	O
attributed	O
to	O
Magnus	O
Hestenes	O
and	O
Eduard	O
Stiefel	O
,	O
who	O
programmed	O
it	O
on	O
the	O
Z4	B-Device
,	O
and	O
extensively	O
researched	O
it	O
.	O
</s>
<s>
The	O
biconjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
provides	O
a	O
generalization	O
to	O
non-symmetric	O
matrices	O
.	O
</s>
<s>
Various	O
nonlinear	B-Algorithm
conjugate	I-Algorithm
gradient	I-Algorithm
methods	I-Algorithm
seek	O
minima	O
of	O
nonlinear	O
optimization	O
problems	O
.	O
</s>
<s>
for	O
the	O
vector	O
,	O
where	O
the	O
known	O
matrix	O
is	O
symmetric	B-Algorithm
(	O
i.e.	O
,	O
AT	O
=	O
A	O
)	O
,	O
positive-definite	B-Algorithm
(	O
i.e.	O
</s>
<s>
The	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
can	O
be	O
derived	O
from	O
several	O
different	O
perspectives	O
,	O
including	O
specialization	O
of	O
the	O
conjugate	O
direction	O
method	O
for	O
optimization	O
,	O
and	O
variation	O
of	O
the	O
Arnoldi/Lanczos	O
iteration	O
for	O
eigenvalue	O
problems	O
.	O
</s>
<s>
Despite	O
differences	O
in	O
their	O
approaches	O
,	O
these	O
derivations	O
share	O
a	O
common	O
topic	O
—	O
proving	O
the	O
orthogonality	O
of	O
the	O
residuals	B-Algorithm
and	O
conjugacy	O
of	O
the	O
search	O
directions	O
.	O
</s>
<s>
Being	O
conjugate	O
is	O
a	O
symmetric	B-Algorithm
relation	O
:	O
if	O
is	O
conjugate	O
to	O
,	O
then	O
is	O
conjugate	O
to	O
.	O
</s>
<s>
So	O
,	O
we	O
want	O
to	O
regard	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
as	O
an	O
iterative	B-Algorithm
method	I-Algorithm
.	O
</s>
<s>
This	O
also	O
allows	O
us	O
to	O
approximately	O
solve	O
systems	O
where	O
n	O
is	O
so	O
large	O
that	O
the	O
direct	B-Algorithm
method	I-Algorithm
would	O
take	O
too	O
much	O
time	O
.	O
</s>
<s>
The	O
other	O
vectors	O
in	O
the	O
basis	O
will	O
be	O
conjugate	O
to	O
the	O
gradient	O
,	O
hence	O
the	O
name	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
.	O
</s>
<s>
Note	O
that	O
p0	O
is	O
also	O
the	O
residual	B-Algorithm
provided	O
by	O
this	O
initial	O
step	O
of	O
the	O
algorithm	O
.	O
</s>
<s>
Let	O
rk	O
be	O
the	O
residual	B-Algorithm
at	O
the	O
kth	O
step	O
:	O
</s>
<s>
As	O
observed	O
above	O
,	O
is	O
the	O
negative	O
gradient	O
of	O
at	O
,	O
so	O
the	O
gradient	B-Algorithm
descent	I-Algorithm
method	I-Algorithm
would	O
require	O
to	O
move	O
in	O
the	O
direction	O
rk	O
.	O
</s>
<s>
A	O
practical	O
way	O
to	O
enforce	O
this	O
is	O
by	O
requiring	O
that	O
the	O
next	O
search	O
direction	O
be	O
built	O
out	O
of	O
the	O
current	O
residual	B-Algorithm
and	O
all	O
previous	O
search	O
directions	O
.	O
</s>
<s>
The	O
conjugation	O
constraint	O
is	O
an	O
orthonormal-type	O
constraint	O
and	O
hence	O
the	O
algorithm	O
can	O
be	O
viewed	O
as	O
an	O
example	O
of	O
Gram-Schmidt	B-Algorithm
orthonormalization	I-Algorithm
.	O
</s>
<s>
The	O
above	O
algorithm	O
gives	O
the	O
most	O
straightforward	O
explanation	O
of	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
.	O
</s>
<s>
The	O
algorithm	O
is	O
detailed	O
below	O
for	O
solving	O
Ax	O
=	O
b	O
where	O
is	O
a	O
real	O
,	O
symmetric	B-Algorithm
,	O
positive-definite	B-Algorithm
matrix	I-Algorithm
.	O
</s>
<s>
The	O
same	O
formula	O
for	O
is	O
also	O
used	O
in	O
the	O
Fletcher	B-Algorithm
–	I-Algorithm
Reeves	I-Algorithm
nonlinear	B-Algorithm
conjugate	I-Algorithm
gradient	I-Algorithm
method	I-Algorithm
.	O
</s>
<s>
We	O
note	O
that	O
is	O
computed	O
by	O
the	O
gradient	B-Algorithm
descent	I-Algorithm
method	I-Algorithm
applied	O
to	O
.	O
</s>
<s>
Setting	O
would	O
similarly	O
make	O
computed	O
by	O
the	O
gradient	B-Algorithm
descent	I-Algorithm
method	I-Algorithm
from	O
,	O
i.e.	O
,	O
can	O
be	O
used	O
as	O
a	O
simple	O
implementation	O
of	O
a	O
restart	O
of	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
iterations	O
.	O
</s>
<s>
Restarts	O
could	O
slow	O
down	O
convergence	O
,	O
but	O
may	O
improve	O
stability	O
if	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
misbehaves	O
,	O
e.g.	O
,	O
due	O
to	O
round-off	B-Algorithm
error	I-Algorithm
.	O
</s>
<s>
The	O
latter	O
may	O
be	O
more	O
accurate	O
,	O
substituting	O
the	O
explicit	O
calculation	O
for	O
the	O
implicit	O
one	O
by	O
the	O
recursion	O
subject	O
to	O
round-off	B-Algorithm
error	I-Algorithm
accumulation	O
,	O
and	O
is	O
thus	O
recommended	O
for	O
an	O
occasional	O
evaluation	O
.	O
</s>
<s>
A	O
norm	O
of	O
the	O
residual	B-Algorithm
is	O
typically	O
used	O
for	O
stopping	O
criteria	O
.	O
</s>
<s>
The	O
norm	O
of	O
the	O
explicit	O
residual	B-Algorithm
provides	O
a	O
guaranteed	O
level	O
of	O
accuracy	O
both	O
in	O
exact	O
arithmetic	O
and	O
in	O
the	O
presence	O
of	O
the	O
rounding	B-Algorithm
errors	I-Algorithm
,	O
where	O
convergence	O
naturally	O
stagnates	O
.	O
</s>
<s>
In	O
contrast	O
,	O
the	O
implicit	O
residual	B-Algorithm
is	O
known	O
to	O
keep	O
getting	O
smaller	O
in	O
amplitude	O
well	O
below	O
the	O
level	O
of	O
rounding	B-Algorithm
errors	I-Algorithm
and	O
thus	O
cannot	O
be	O
used	O
to	O
determine	O
the	O
stagnation	O
of	O
convergence	O
.	O
</s>
<s>
using	O
that	O
the	O
search	O
directions	O
pk	O
are	O
conjugated	O
and	O
again	O
that	O
the	O
residuals	B-Algorithm
are	O
orthogonal	O
.	O
</s>
<s>
Our	O
first	O
step	O
is	O
to	O
calculate	O
the	O
residual	B-Algorithm
vector	O
r0	O
associated	O
with	O
x0	O
.	O
</s>
<s>
Since	O
this	O
is	O
the	O
first	O
iteration	O
,	O
we	O
will	O
use	O
the	O
residual	B-Algorithm
vector	O
r0	O
as	O
our	O
initial	O
search	O
direction	O
p0	O
;	O
the	O
method	O
of	O
selecting	O
pk	O
will	O
change	O
in	O
further	O
iterations	O
.	O
</s>
<s>
The	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
can	O
theoretically	O
be	O
viewed	O
as	O
a	O
direct	B-Algorithm
method	I-Algorithm
,	O
as	O
in	O
the	O
absence	O
of	O
round-off	B-Algorithm
error	I-Algorithm
it	O
produces	O
the	O
exact	O
solution	O
after	O
a	O
finite	O
number	O
of	O
iterations	O
,	O
which	O
is	O
not	O
larger	O
than	O
the	O
size	O
of	O
the	O
matrix	O
.	O
</s>
<s>
In	O
practice	O
,	O
the	O
exact	O
solution	O
is	O
never	O
obtained	O
since	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
is	O
unstable	O
with	O
respect	O
to	O
even	O
small	O
perturbations	O
,	O
e.g.	O
,	O
most	O
directions	O
are	O
not	O
in	O
practice	O
conjugate	O
,	O
due	O
to	O
a	O
degenerative	O
nature	O
of	O
generating	O
the	O
Krylov	O
subspaces	O
.	O
</s>
<s>
As	O
an	O
iterative	B-Algorithm
method	I-Algorithm
,	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
monotonically	O
(	O
in	O
the	O
energy	O
norm	O
)	O
improves	O
approximations	O
to	O
the	O
exact	O
solution	O
and	O
may	O
reach	O
the	O
required	O
tolerance	O
after	O
a	O
relatively	O
small	O
(	O
compared	O
to	O
the	O
problem	O
size	O
)	O
number	O
of	O
iterations	O
.	O
</s>
<s>
The	O
improvement	O
is	O
typically	O
linear	O
and	O
its	O
speed	O
is	O
determined	O
by	O
the	O
condition	B-Algorithm
number	I-Algorithm
of	O
the	O
system	O
matrix	O
:	O
the	O
larger	O
is	O
,	O
the	O
slower	O
the	O
improvement	O
.	O
</s>
<s>
Let	O
be	O
the	O
iterative	B-Algorithm
approximations	I-Algorithm
of	O
the	O
exact	O
solution	O
,	O
and	O
define	O
the	O
errors	O
as	O
.	O
</s>
<s>
where	O
denotes	O
the	O
spectrum	O
,	O
and	O
denotes	O
the	O
condition	B-Algorithm
number	I-Algorithm
.	O
</s>
<s>
This	O
limit	O
shows	O
a	O
faster	O
convergence	O
rate	O
compared	O
to	O
the	O
iterative	B-Algorithm
methods	I-Algorithm
of	O
Jacobi	B-Algorithm
or	O
Gauss	B-Algorithm
–	I-Algorithm
Seidel	I-Algorithm
which	O
scale	O
as	O
.	O
</s>
<s>
No	O
round-off	B-Algorithm
error	I-Algorithm
is	O
assumed	O
in	O
the	O
convergence	O
theorem	O
,	O
but	O
the	O
convergence	O
bound	O
is	O
commonly	O
valid	O
in	O
practice	O
as	O
theoretically	O
explained	O
by	O
Anne	O
Greenbaum	O
.	O
</s>
<s>
If	O
initialized	O
randomly	O
,	O
the	O
first	O
stage	O
of	O
iterations	O
is	O
often	O
the	O
fastest	O
,	O
as	O
the	O
error	O
is	O
eliminated	O
within	O
the	O
Krylov	O
subspace	O
that	O
initially	O
reflects	O
a	O
smaller	O
effective	O
condition	B-Algorithm
number	I-Algorithm
.	O
</s>
<s>
In	O
typical	O
scientific	O
computing	O
applications	O
in	O
double-precision	O
floating-point	O
format	O
for	O
matrices	O
of	O
large	O
sizes	O
,	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
uses	O
a	O
stopping	O
criteria	O
with	O
a	O
tolerance	O
that	O
terminates	O
the	O
iterations	O
during	O
the	O
first	O
or	O
second	O
stage	O
.	O
</s>
<s>
In	O
most	O
cases	O
,	O
preconditioning	O
is	O
necessary	O
to	O
ensure	O
fast	O
convergence	O
of	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
.	O
</s>
<s>
If	O
is	O
symmetric	B-Algorithm
positive-definite	B-Algorithm
and	O
has	O
a	O
better	O
condition	B-Algorithm
number	I-Algorithm
than	O
,	O
a	O
preconditioned	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
can	O
be	O
used	O
.	O
</s>
<s>
The	O
preconditioner	O
matrix	O
M	O
has	O
to	O
be	O
symmetric	B-Algorithm
positive-definite	B-Algorithm
and	O
fixed	O
,	O
i.e.	O
,	O
cannot	O
change	O
from	O
iteration	O
to	O
iteration	O
.	O
</s>
<s>
If	O
any	O
of	O
these	O
assumptions	O
on	O
the	O
preconditioner	O
is	O
violated	O
,	O
the	O
behavior	O
of	O
the	O
preconditioned	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
may	O
become	O
unpredictable	O
.	O
</s>
<s>
In	O
numerically	B-General_Concept
challenging	O
applications	O
,	O
sophisticated	O
preconditioners	O
are	O
used	O
,	O
which	O
may	O
lead	O
to	O
variable	O
preconditioning	O
,	O
changing	O
between	O
iterations	O
.	O
</s>
<s>
Even	O
if	O
the	O
preconditioner	O
is	O
symmetric	B-Algorithm
positive-definite	B-Algorithm
on	O
every	O
iteration	O
,	O
the	O
fact	O
that	O
it	O
may	O
change	O
makes	O
the	O
arguments	O
above	O
invalid	O
,	O
and	O
in	O
practical	O
tests	O
leads	O
to	O
a	O
significant	O
slow	O
down	O
of	O
the	O
convergence	O
of	O
the	O
algorithm	O
presented	O
above	O
.	O
</s>
<s>
This	O
version	O
of	O
the	O
preconditioned	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
can	O
be	O
called	O
flexible	O
,	O
as	O
it	O
allows	O
for	O
variable	O
preconditioning	O
.	O
</s>
<s>
The	O
flexible	O
version	O
is	O
also	O
shown	O
to	O
be	O
robust	O
even	O
if	O
the	O
preconditioner	O
is	O
not	O
symmetric	B-Algorithm
positive	I-Algorithm
definite	I-Algorithm
(	O
SPD	O
)	O
.	O
</s>
<s>
For	O
a	O
fixed	O
SPD	O
preconditioner	O
,	O
so	O
both	O
formulas	O
for	O
are	O
equivalent	O
in	O
exact	O
arithmetic	O
,	O
i.e.	O
,	O
without	O
the	O
round-off	B-Algorithm
error	I-Algorithm
.	O
</s>
<s>
The	O
mathematical	O
explanation	O
of	O
the	O
better	O
convergence	O
behavior	O
of	O
the	O
method	O
with	O
the	O
Polak	B-Algorithm
–	I-Algorithm
Ribière	I-Algorithm
formula	O
is	O
that	O
the	O
method	O
is	O
locally	O
optimal	O
in	O
this	O
case	O
,	O
in	O
particular	O
,	O
it	O
does	O
not	O
converge	O
slower	O
than	O
the	O
locally	O
optimal	O
steepest	B-Algorithm
descent	I-Algorithm
method	O
.	O
</s>
<s>
In	O
both	O
the	O
original	O
and	O
the	O
preconditioned	O
conjugate	B-Algorithm
gradient	I-Algorithm
methods	I-Algorithm
one	O
only	O
needs	O
to	O
set	O
in	O
order	O
to	O
make	O
them	O
locally	O
optimal	O
,	O
using	O
the	O
line	B-Algorithm
search	I-Algorithm
,	O
steepest	B-Algorithm
descent	I-Algorithm
methods	O
.	O
</s>
<s>
Thus	O
,	O
every	O
iteration	O
of	O
these	O
steepest	B-Algorithm
descent	I-Algorithm
methods	O
is	O
a	O
bit	O
cheaper	O
compared	O
to	O
that	O
for	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
methods	I-Algorithm
.	O
</s>
<s>
The	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
can	O
also	O
be	O
derived	O
using	O
optimal	O
control	O
theory	O
.	O
</s>
<s>
In	O
this	O
approach	O
,	O
the	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
falls	O
out	O
as	O
an	O
optimal	O
feedback	O
controller	O
,	O
for	O
the	O
double	O
integrator	O
system	O
,	O
The	O
quantities	O
and	O
are	O
variable	O
feedback	O
gains	O
.	O
</s>
<s>
The	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
can	O
be	O
applied	O
to	O
an	O
arbitrary	O
n-by-m	O
matrix	O
by	O
applying	O
it	O
to	O
normal	B-Algorithm
equations	I-Algorithm
ATA	O
and	O
right-hand	O
side	O
vector	O
ATb	O
,	O
since	O
ATA	O
is	O
a	O
symmetric	B-Algorithm
positive-semidefinite	B-Algorithm
matrix	I-Algorithm
for	O
any	O
A	O
.	O
</s>
<s>
The	O
result	O
is	O
conjugate	B-Algorithm
gradient	I-Algorithm
on	O
the	O
normal	B-Algorithm
equations	I-Algorithm
(	O
CGNR	O
)	O
.	O
</s>
<s>
As	O
an	O
iterative	B-Algorithm
method	I-Algorithm
,	O
it	O
is	O
not	O
necessary	O
to	O
form	O
ATA	O
explicitly	O
in	O
memory	O
but	O
only	O
to	O
perform	O
the	O
matrix	O
–	O
vector	O
and	O
transpose	O
matrix	O
–	O
vector	O
multiplications	O
.	O
</s>
<s>
Therefore	O
,	O
CGNR	O
is	O
particularly	O
useful	O
when	O
A	O
is	O
a	O
sparse	B-Algorithm
matrix	I-Algorithm
since	O
these	O
operations	O
are	O
usually	O
extremely	O
efficient	O
.	O
</s>
<s>
However	O
the	O
downside	O
of	O
forming	O
the	O
normal	B-Algorithm
equations	I-Algorithm
is	O
that	O
the	O
condition	B-Algorithm
number	I-Algorithm
κ(ATA )	O
is	O
equal	O
to	O
κ2(A )	O
and	O
so	O
the	O
rate	O
of	O
convergence	O
of	O
CGNR	O
may	O
be	O
slow	O
and	O
the	O
quality	O
of	O
the	O
approximate	O
solution	O
may	O
be	O
sensitive	O
to	O
roundoff	B-Algorithm
errors	I-Algorithm
.	O
</s>
<s>
The	O
algorithm	O
purportedly	O
has	O
the	O
best	O
numerical	O
stability	O
when	O
A	O
is	O
ill-conditioned	B-Algorithm
,	O
i.e.	O
,	O
A	O
has	O
a	O
large	O
condition	B-Algorithm
number	I-Algorithm
.	O
</s>
<s>
The	O
conjugate	B-Algorithm
gradient	I-Algorithm
method	I-Algorithm
with	O
a	O
trivial	O
modification	O
is	O
extendable	O
to	O
solving	O
,	O
given	O
complex-valued	O
matrix	O
A	O
and	O
vector	O
b	O
,	O
the	O
system	O
of	O
linear	O
equations	O
for	O
the	O
complex-valued	O
vector	O
x	O
,	O
where	O
A	O
is	O
Hermitian	O
(	O
i.e.	O
,	O
A	O
 '	O
=	O
A	O
)	O
and	O
positive-definite	B-Algorithm
matrix	I-Algorithm
,	O
and	O
the	O
symbol	O
'	O
denotes	O
the	O
conjugate	B-Algorithm
transpose	I-Algorithm
using	O
the	O
MATLAB/GNU	O
Octave	O
style	O
.	O
</s>
<s>
The	O
trivial	O
modification	O
is	O
simply	O
substituting	O
the	O
conjugate	B-Algorithm
transpose	I-Algorithm
for	O
the	O
real	O
transpose	O
everywhere	O
.	O
</s>
<s>
This	O
substitution	O
is	O
backward	O
compatible	O
,	O
since	O
conjugate	B-Algorithm
transpose	I-Algorithm
turns	O
into	O
real	O
transpose	O
on	O
real-valued	O
vectors	O
and	O
matrices	O
.	O
</s>
<s>
The	O
provided	O
above	O
Example	O
code	O
in	O
MATLAB/GNU	O
Octave	O
thus	O
already	O
works	O
for	O
complex	O
Hermitian	O
matrices	O
needed	O
no	O
modification	O
.	O
</s>
