shewchuk94in

shewchuk94in - An Introduction to the Conjugate Gradient...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: An Introduction to the Conjugate Gradient Method Without the Agonizing Pain Edition 1 1 4 Jonathan Richard Shewchuk August 4, 1994 School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213 Abstract The Conjugate Gradient Method is the most prominent iterative method for solving sparse systems of linear equations. Unfortunately, many textbook treatments of the topic are written with neither illustrations nor intuition, and their victims can be found to this day babbling senselessly in the corners of dusty libraries. For this reason, a deep, geometric understanding of the method has been reserved for the elite brilliant few who have painstakingly decoded the mumblings of their forebears. Nevertheless, the Conjugate Gradient Method is a composite of simple, elegant ideas that almost anyone can understand. Of course, a reader as intelligent as yourself will learn them almost effortlessly. The idea of quadratic forms is introduced and used to derive the methods of Steepest Descent, Conjugate Directions, and Conjugate Gradients. Eigenvectors are explained and used to examine the convergence of the Jacobi Method, Steepest Descent, and Conjugate Gradients. Other topics include preconditioning and the nonlinear Conjugate Gradient Method. I have taken pains to make this article easy to read. Sixty-six illustrations are provided. Dense prose is avoided. Concepts are explained in several different ways. Most equations are coupled with an intuitive interpretation. Supported in part by the Natural Sciences and Engineering Research Council of Canada under a 1967 Science and Engineering Scholarship and by the National Science Foundation under Grant ASC-9318163. The views and conclusions contained in this document are those of the author and should not be interpreted as representing the official policies, either express or implied, of NSERC, NSF, or the U.S. Government. Keywords: conjugate gradient method, preconditioning, convergence analysis, agonizing pain 5. Thinking with Eigenvectors and Eigenvalues 5.1. Eigen do it if I try 5.2. Jacobi iterations 5.3. A Concrete Example 4. The Method of Steepest Descent 3. The Quadratic Form 2. Notation 1. Introduction Contents 6. Convergence Analysis of Steepest Descent 6.1. Instant Results 6.2. General Convergence 7. The Method of Conjugate Directions 7.1. Conjugacy 7.2. Gram-Schmidt Conjugation 7.3. Optimality of the Error Term 9. Convergence Analysis of Conjugate Gradients 9.1. Picking Perfect Polynomials 9.2. Chebyshev Polynomials 11. Starting and Stopping 11.1. Starting 11.2. Stopping 13. Conjugate Gradients on the Normal Equations 12. Preconditioning 10. Complexity 8. The Method of Conjugate Gradients 14. The Nonlinear Conjugate Gradient Method 14.1. Outline of the Nonlinear Conjugate Gradient Method 14.2. General Line Search 14.3. Preconditioning B Canned Algorithms B1. Steepest Descent B2. Conjugate Gradients B3. Preconditioned Conjugate Gradients A Notes i 49 49 50 51 42 42 43 47 38 38 38 32 33 35 21 21 25 26 13 13 17 9 9 11 12 41 30 39 37 6 2 1 1 48 D Homework ii C Ugly Proofs C1. The Solution to Minimizes the Quadratic Form C2. A Symmetric Matrix Has Orthogonal Eigenvectors. C3. Optimality of Chebyshev Polynomials B4. Nonlinear Conjugate Gradients with Newton-Raphson and Fletcher-Reeves B5. Preconditioned Nonlinear Conjugate Gradients with Secant and Polak-Ribi` re e 52 53 54 54 54 55 56 About this Article An electronic copy of this article is available by anonymous FTP to WARP.CS.CMU.EDU (IP address 128.2.209.103) under the filename quake-papers/painless-conjugate-gradient.ps. A PostScript file containing full-page copies of the figures herein, suitable for transparencies, is available as quake-papers/painless-conjugate-gradient-pics.ps. Most of the illustrations were created using Mathematica. c 1994 by Jonathan Richard Shewchuk. This article may be freely duplicated and distributed so long as no consideration is received in return, and this copyright notice remains intact. This guide was created to help students learn Conjugate Gradient Methods as easily as possible. Please mail me (jrs@cs.cmu.edu) comments, corrections, and any intuitions I might have missed; some of these will be incorporated into a second edition. I am particularly interested in hearing about use of this guide for classroom teaching. For those who wish to learn more about iterative methods, I recommend William L. Briggs' "A Multigrid Tutorial" [2], one of the best-written mathematical books I have read. Special thanks to Omar Ghattas, who taught me much of what I know about numerical methods, and provided me with extensive comments on the first draft of this article. Thanks also to James Epperson, David O'Hallaron, James Stichnoth, Nick Trefethen, and Daniel Tunkelang for their comments. To help you skip chapters, here's a dependence graph of the sections: 1 Introduction 10 Complexity This article is dedicated to every mathematician who uses figures as abundantly as I have herein. iii 2 Notation 13 Normal Equations 3 Quadratic Form 4 Steepest Descent 5 Eigenvectors 7 Conjugate Directions 6 SD Convergence 8 Conjugate Gradients 9 CG Convergence 11 Stop & Start 12 Preconditioning 14 Nonlinear CG iv 1. Introduction When I decided to learn the Conjugate Gradient Method (henceforth, CG), I read four different descriptions, which I shall politely not identify. I understood none of them. Most of them simply wrote down the method, then proved its properties without any intuitive explanation or hint of how anybody might have invented CG in the first place. This article was born of my frustration, with the wish that future students of CG will learn a rich and elegant algorithm, rather than a confusing mass of equations. CG is the most popular iterative method for solving large systems of linear equations. CG is effective for systems of the form (1) where is an unknown vector, is a known vector, and is a known, square, symmetric, positive-definite (or positive-indefinite) matrix. (Don't worry if you've forgotten what "positive-definite" means; we shall review it.) These systems arise in many important settings, such as finite difference and finite element methods for solving partial differential equations, structural analysis, circuit analysis, and math homework. Iterative methods like CG are suited for use with sparse matrices. If is dense, your best course of action is probably to factor and solve the equation by backsubstitution. The time spent factoring a dense is roughly equivalent to the time spent solving the system iteratively; and once is factored, the system can be backsolved quickly for multiple values of . Compare this dense matrix with a sparse matrix of larger size that fills the same amount of memory. The triangular factors of a sparse usually have many more nonzero elements than itself. Factoring may be impossible due to limited memory, and will be time-consuming as well; even the backsolving step may be slower than iterative solution. On the other hand, most iterative methods are memory-efficient and run quickly with sparse matrices. I assume that you have taken a first course in linear algebra, and that you have a solid understanding of matrix multiplication and linear independence, although you probably don't remember what those eigenthingies were all about. From this foundation, I shall build the edifice of CG as clearly as I can. 2. Notation Let us begin with a few definitions and notes on notation. With a few exceptions, I shall use capital letters to denote matrices, lower case letters to denote vectors, matrix, and and are vectors -- that is, 1 matrices. and Greek letters to denote scalars. is an Written out fully, Equation 1 is 21 1 The inner product of two vectors is written , and represents the scalar sum . Note that 1 . If and are orthogonal, then 0. In general, expressions that reduce to 1 1 matrices, such as and , are treated as scalar values. 4 1 4 65#4 3 1) 20 1) 20 # . . . 11 12 22 1 2 1 2 1 2 .. . . . . . . . . . . 2 # # # $# "" ( ! ( ! ( # && && && # '&&% '&&% '&&% "" # ! @9 ) 1 120 ) )1 1) 28720 4 2 -4 -2 2 4 6 1 -4 -6 Figure 1: Sample two-dimensional linear system. The solution lies at the intersection of the lines. A matrix is positive-definite if, for every nonzero vector , This may mean little to you, but don't feel bad; it's not a very intuitive idea, and it's hard to imagine how a matrix that is positive-definite might look differently from one that isn't. We will get a feeling for what positive-definiteness is about when we see how it affects the shape of quadratic forms. Finally, don't forget the important basic identities and 3. The Quadratic Form A quadratic form is simply a scalar, quadratic function of a vector with the form where is a matrix, and are vectors, and is a scalar constant. I shall show shortly that if and positive-definite, is minimized by the solution to . Throughout this paper, I will demonstrate ideas with the simple sample problem The system is illustrated in Figure 1. In general, the solution lies at the intersection point of hyperplanes, each having dimension 1. For this problem, the solution is 2 2 . The corresponding quadratic form appears in Figure 2. A contour plot of is illustrated in Figure 3. i ) v B u7 t I ` F Y d i qh B gp f B i h 3 2 2 6 2 8 0 d eA ) cb ) B 1 2 V V G VI G XR WUH F ) ) G )I G T2SRQPH F 0 A -2 2 6 B C 2 1 A 3 2 D E ) 2 Jonathan Richard Shewchuk 2 2 2 1 8 I a` F Y d f gR I w F Y I ` F Y sr (2) 1 1 1. (3) is symmetric (4) The Quadratic Form 3 150 4 2 0 50 0 6 -2 2 0 -2 -6 -4 4 2 2 4 2 -4 -2 2 4 6 1 -2 -4 -6 y 6`x Figure 3: Contours of the quadratic form. Each ellipsoidal curve has constant . y `x Figure 2: Graph of a quadratic form . The minimum point of this surface is the solution to -4 1 I ` F Y . 100 6 4 2 -4 -2 -2 2 4 6 -4 -6 -8 Because is positive-definite, the surface defined by to say about this in a moment.) The gradient of a quadratic form is defined to be . The gradient is a vector field that, for a given point , points in the direction of greatest increase of Figure 4 illustrates the gradient vectors for Equation 3 with the constants given in Equation 4. At the bottom by setting equal to zero. of the paraboloid bowl, the gradient is zero. One can minimize With a little bit of tedious math, one can apply Equation 5 to Equation 3, and derive If is symmetric, this equation reduces to Setting the gradient to zero, we obtain Equation 1, the linear system we wish to solve. Therefore, the solution to is a critical point of . If is positive-definite as well as symmetric, then this cX B cdRw F Y B I A ) 1 2 1 2 I ` F Y I w F Y I ` F Y I F ( w Y ! I F & ` F Y " aw Y I && %& ` F Y " I I w F Y I w F Y I w F Y e7 y 6`x increase of 1 2 . . . 6yx Figure 4: Gradient of the quadratic form. For every , the gradient points in the direction of steepest , and is orthogonal to the contour lines. is shaped like a paraboloid bowl. (I'll have more 4 Jonathan Richard Shewchuk 2 1 (5) (6) (7) The Quadratic Form (a) (b) 5 1 (c) (d) 1 Figure 5: (a) Quadratic form for a positive-definite matrix. (b) For a negative-definite matrix. (c) For a singular (and positive-indefinite) matrix. A line that runs through the bottom of the valley is the set of solutions. (d) For an indefinite matrix. Because the solution is a saddle point, Steepest Descent and CG will not work. In three dimensions or higher, a singular matrix can also have a saddle. solution is a minimum of , so can be solved by finding an that minimizes 1 symmetric, then Equation 6 hints that CG will find a solution to the system 2 1 is symmetric.) 2 . (If is not . Note that Why do symmetric positive-definite matrices have this nice property? Consider the relationship between 1 . From Equation 3 one can show (Appendix C1) at some arbitrary point and at the solution point that if is symmetric (be it positive-definite or not), The fact that is a paraboloid is our best intuition of what it means for a matrix to be positive-definite. If is not positive-definite, there are several other possibilities. could be negative-definite -- the result of negating a positive-definite matrix (see Figure 2, but hold it upside-down). might be singular, in which case no solution is unique; the set of solutions is a line or hyperplane having a uniform value for . If is none of the above, then is a saddle point, and techniques like Steepest Descent and CG will likely fail. Figure 5 demonstrates the possibilities. The values of and determine where the minimum point of the paraboloid lies, but do not affect the paraboloid's shape. Why go to the trouble of converting the linear system into a tougher-looking problem? The methods under study -- Steepest Descent and CG -- were developed and are intuitively understood in terms of minimization problems like Figure 2, not in terms of intersecting hyperplanes such as Figure 1. Y d Y If is positive-definite as well, then by Inequality 2, the latter term is positive for all is a global minimum of . l Ri wkB jiF ) `B jiF I I 1 2 . It follows that F I hgq I ` Y A ) T F V A F I w Y aI jiF Y 2 2 1 I ` F Y I ` F Y rf 2 2 1 I ` F Y (8) I ` F Y I w F Y i I w F Y I q A ) T F Y 6 Jonathan Richard Shewchuk 4. The Method of Steepest Descent In the method of Steepest Descent, we start at an arbitrary point 0 and slide down to the bottom of the paraboloid. We take a series of steps 1 until we are satisfied that we are close enough to the 2 solution . When we take a step, we choose the direction in which decreases most quickly, which is the direction . According to Equation 7, this direction is . opposite Allow me to introduce a few definitions, which you should memorize. The error is a vector that indicates how far we are from the solution. The residual indicates how far we are from the correct value of . It is easy to see that , and you should think of the residual as being the error transformed by into the same space as . More importantly, , and you should also think of the residual as the direction of steepest descent. For nonlinear problems, discussed in Section 14, only the latter definition applies. So remember, whenever you read "residual", think "direction of steepest descent." Suppose we start at 0 2 2 . Our first step, along the direction of steepest descent, will fall somewhere on the solid line in Figure 6(a). In other words, we will choose a point 1 The question is, how big a step should we take? A line search is a procedure that chooses to minimize along a line. Figure 6(b) illustrates this task: we are restricted to choosing a point on the intersection of the vertical plane and the paraboloid. Figure 6(c) is the parabola defined by the intersection of these surfaces. What is the value of at the base of the parabola? 1 0 and There is an intuitive reason why we should expect these vectors to be orthogonal at the minimum. Figure 7 shows the gradient vectors at various points along the search line. The slope of the parabola (Figure 6(c)) at any point is equal to the magnitude of the projection of the gradient onto the line (Figure 7, dotted arrows). These projections represent the rate of increase of as one traverses the search line. is minimized where the projection is zero -- where the gradient is orthogonal to the search line. To determine , note that 1 1 , and we have 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 n r n mr n m r n m ) r ) n r mF n r y m n Irm n r )F y m )I m 0 0 0 0 0 0 0 0 0 0 0 0 y Y Y n rn r m n m r )n B F n m r ) I n m r ys n F n m r ) I n m r eA n B y m I n m r ) }nI m B m I m s F n rn) r m m) n n { |z In 2 |z Y n m r n m {F n n m r ) I m F Y m z ) I m F Y y TI m F Y z From basic calculus, chain rule, 1 should be chosen so that minimizes when the directional derivative 1 is equal to zero. By the 1 1 0 . Setting this expression to zero, we find that are orthogonal (see Figure 6(d)). 1 n n I 4 m F Y v 4 m r B n p n r B n n r 4 m u 4 m B n n 4 m ts 4 m eB 4 m q 4 m p 0 y n4 n m oI 4 m F Y B B 0 { |z n I 2 F Y z m n m 2 y n m r eA n m R n m Y Y y m m "" i n 2 i n 2 y n r n m CaI @ F Y B m )v B n m r ) I m s F B F o F B Y i n xBw 2 t m y n I 4m F Y (9) The Method of Steepest Descent 7 (b) 0 -2.5 0 (c) -4 -2 -2 -4 2 1 4 6 0.2 0.4 0.6 -6 2 2 , take a step in the direction of steepest descent of . (b) Find the point on the intersection of these two surfaces that minimizes . (c) This parabola is the intersection of surfaces. The bottommost point is our target. (d) The gradient at the bottommost point is orthogonal to the gradient of the previous step. 2 2 1 -2 -1 1 2 3 1 -1 -2 -3 is shown at several locations along the search line (solid arrows). Each gradient's projection onto the line is also shown (dotted arrows). The gradient vectors represent the direction of steepest increase of , and the projections represent the rate of increase as one traverses the search line. On the search line, is minimized where the gradient is orthogonal to the search line. x Figure 7: The gradient x j~ Figure 6: The method of Steepest Descent. (a) Starting at n m 140 120 100 80 60 40 20 -6 2 4 2 1 -4 0 -2 y n p m n eA n 4 F y I 4m r m Y n m -4 -2 2 4 6 1 2.5 2 0 -2.5 -5 2.5 1 5 (d) I w F Y x x x 2 (a) 4 2 150 100 50 0 4 2 -4 -2 2 4 6 0 -2 -4 -6 Putting it all together, the method of Steepest Descent is: 1 The example is run until it converges in Figure 8. Note the zigzag path, which appears because each gradient is orthogonal to the previous gradient. The algorithm, as written above, requires two matrix-vector multiplications per iteration. The computational cost of Steepest Descent is dominated by matrix-vector products; fortunately, one can be eliminated. By premultiplying both sides of Equation 12 by and adding , we have 1 Although Equation 10 is still needed to compute 0 , Equation 13 can be used for every iteration thereafter. The product , which occurs in both Equations 11 and 13, need only be computed once. The disadvantage of using this recurrence is that the sequence defined by Equation 13 is generated without any feedback from the value of , so that accumulation of floating point roundoff error may cause to converge to some point near . This effect can be avoided by periodically using Equation 10 to recompute the correct residual. Before analyzing the convergence of Steepest Descent, I must digress to ensure that you have a solid understanding of eigenvectors. W ~ n4 m j~ Figure 8: Here, the method of Steepest Descent starts at 2 2 and converges at 2 n r m n 4 m r n 4 m y B n 4 m r n 64 m r n4m y r n 4 m eA n 4 @7 n m i n 4 m r n 4 m) r n n n 4m m4 r 4 m) r n m B @c 4 m in 4 B y r 8 Jonathan Richard Shewchuk 2 1 64 @ m n m n 4m r 2 . (10) (11) (12) (13) Thinking with Eigenvectors and Eigenvalues 5. Thinking with Eigenvectors and Eigenvalues 9 After my one course in linear algebra, I knew eigenvectors and eigenvalues like the back of my head. If your instructor was anything like mine, you recall solving problems involving eigendoohickeys, but you never really understood them. Unfortunately, without an intuitive grasp of them, CG won't make sense either. If you're already eigentalented, feel free to skip this section. Eigenvectors are used primarily as an analysis tool; Steepest Descent and CG do not calculate the value of any eigenvectors as part of the algorithm1 . 5.1. Eigen do it if I try An eigenvector of a matrix is a nonzero vector that does not rotate when is applied to it (except perhaps to point in precisely the opposite direction). may change length or reverse its direction, but it won't turn sideways. In other words, there is some scalar constant such that . The value is an eigenvalue of . For any constant , the vector is also an eigenvector with eigenvalue , because . In other words, if you scale an eigenvector, it's still an eigenvector. Why should you care? Iterative methods often depend on applying to a vector over and over again. When is repeatedly applied to an eigenvector , one of two things can happen. If 1, then will vanish as approaches infinity (Figure 9). If 1, then will grow to infinity (Figure 10). Each time is applied, the vector grows or shrinks according to the value of . B2 v v Bv B3 v to zero. v Bv B2 v B3 v 1 However, there are practical applications for eigenvectors. The eigenvectors of the stiffness matrix associated with a discretized structure of uniform density represent the natural modes of vibration of the structure being studied. For instance, the eigenvectors of the stiffness matrix associated with a one-dimensional uniformly-spaced mesh are sine waves, and to express vibrations as a linear combination of these eigenvectors is equivalent to performing a discrete Fourier transform. Figure 10: Here, has a corresponding eigenvalue of 2. As increases, diverges to infinity. Figure 9: is an eigenvector of with a corresponding eigenvalue of 0 5. As increases, G 4 converges 4 0 G G G G 4 y D y G y G y I y F G G G G Jonathan Richard Shewchuk If is symmetric (and often if it is not), then there exists a set of linearly independent eigenvectors of , denoted 1 2 . This set is not unique, because each eigenvector can be scaled by an arbitrary nonzero constant. Each eigenvector has a corresponding eigenvalue, denoted 1 2 . These are uniquely defined for a given matrix. The eigenvalues may or may not be equal to each other; for instance, the eigenvalues of the identity matrix are all one, and every nonzero vector is an eigenvector of . What if is applied to a vector that is not an eigenvector? A very important skill in understanding linear algebra -- the skill this section is written to teach -- is to think of a vector as a sum of other vectors forms a basis for (because a whose behavior is understood. Consider that the set of eigenvectors symmetric has eigenvectors that are linearly independent). Any -dimensional vector can be expressed as a linear combination of these eigenvectors, and because matrix-vector multiplication is distributive, one can examine the effect of on each eigenvector separately. In Figure 11, a vector is illustrated as a sum of two eigenvectors 1 and 2 . Applying to is equivalent to applying to the eigenvectors, and summing the result. On repeated application, we have will 1 2 1 1 2 2 . If the magnitudes of all the eigenvalues are smaller than one, converge to zero, because the eigenvectors that compose converge to zero when is repeatedly applied. If one of the eigenvalues has magnitude greater than one, will diverge to infinity. This is why numerical analysts attach importance to the spectral radius of a matrix: max is an eigenvalue of . If we want to converge to zero quickly, should be less than one, and preferably as small as possible. B3 x v 1 v2 x Bx B2 x (solid arrow) can be expressed as a linear combination of eigenvectors (dashed arrows), whose associated eigenvalues are 1 0 7 and 2 2. The effect of repeatedly applying to is best understood by examining the effect of on each eigenvector. When is repeatedly applied, one eigenvector converges to zero while the other diverges; hence, also diverges. It's important to mention that there is a family of nonsymmetric matrices that do not have a full set of independent eigenvectors. These matrices are known as defective, a name that betrays the well-deserved hostility they have earned from frustrated linear algebraists. The details are too complicated to describe in this article, but the behavior of defective matrices can be analyzed in terms of generalized eigenvectors and generalized eigenvalues. The rule that converges to zero if and only if all the generalized eigenvalues have magnitude smaller than one still holds, but is harder to prove. Here's a useful fact: the eigenvalues of a positive-definite matrix are all positive. This fact can be proven from the definition of eigenvalue: By the definition of positive-definite, the is positive (for nonzero ). Hence, must be positive also. e ) @) G G ) G 4 G Figure 11: The vector 4 G G # # i "" i i G G 4 4 I G F i 4 I aG F A G A R G 4 4 G 4 4 # i "" i i G 4 G G G G 10 G Thinking with Eigenvectors and Eigenvalues 5.2. Jacobi iterations 11 Of course, a procedure that always converges to zero isn't going to help you attract friends. Consider a more useful procedure: the Jacobi Method for solving . The matrix is split into two parts: , whose diagonal elements are identical to those of , and whose off-diagonal elements are zero; and , whose . diagonal elements are zero, and whose off-diagonal elements are identical to those of . Thus, We derive the Jacobi Method: 1 1 where 1 1 Because is diagonal, it is easy to invert. This identity can be converted into an iterative method by forming the recurrence (15) 1 Given a starting vector 0 , this formula generates a sequence of vectors. Our hope is that each successive vector will be closer to the solution than the last. is called a stationary point of Equation 15, because if , then 1 will also equal . Now, this derivation may seem quite arbitrary to you, and you're right. We could have formed any number of identities for instead of Equation 14. In fact, simply by splitting differently -- that is, by choosing a different and -- we could have derived the Gauss-Seidel method, or the method of Successive Over-Relaxation (SOR). Our hope is that we have chosen a splitting for which has a small spectral radius. Here, I chose the Jacobi splitting arbitrarily for simplicity. 0 Again, apply the principle of thinking of a vector as a sum of other, well-understood vectors. Express each iterate as the sum of the exact solution and the error term . Then, Equation 15 becomes 1 1 Each iteration does not affect the "correct part" of (because is a stationary point); but each iteration does affect the error term. It is apparent from Equation 16 that if 1, then the error term will converge to zero as approaches infinity. Hence, the initial vector 0 has no effect on the inevitable outcome! Of course, the choice of 0 does affect the number of iterations required to converge to within a given tolerance. However, its effect is less important than that of the spectral radius , which determines the speed of convergence. Suppose that is the eigenvector of with the largest eigenvalue (so that ). If the initial error 0 , expressed as a linear combination of eigenvectors, includes a component in the direction of , this component will be the slowest to converge. n4 p m I G F i (by Equation 14) G n m2 G F I n4 p m n4 m2 n4 p n4 p m A G n 4 p eG A Am m A G n 4 p A F G I m eA n 4 G m G n Suppose we start with some arbitrary vector to the result. What does each iteration do? . For each iteration, we apply to this vector, then add A G V G i V C G B A n 4 @S n 4 2 m G m uQ m i eA G A V A V B B n p m n 4 m n 4 p m n m @ " n m n 4 m 2 I G F n4 m n m 7 4 2 (14) (16) 4 2 -4 -2 2 7 -2 2 4 6 -4 -6 are directed along the axes of the paraboloid defined by the quadratic form . Each eigenvector is labeled with its associated eigenvalue. Each eigenvalue is proportional to the steepness of the corresponding slope. is not generally symmetric (even if is), and may even be defective. However, the rate of convergence , which depends on . Unfortunately, Jacobi does not converge of the Jacobi Method depends largely on for every , or even for every positive-definite . 5.3. A Concrete Example To demonstrate these ideas, I shall solve the system specified by Equation 4. First, we need a method of finding eigenvalues and eigenvectors. By definition, for any eigenvector with eigenvalue , 0 Eigenvectors are nonzero, so must be singular. Then, 2 and the eigenvalues are 7 and 2. To find the eigenvector associated with 1 2 1 2 4 2 4 2 B h h f B B g qB 0F f I B det 2 6 9 14 2 1 i I B F I B F h A B 3 2 7 2 7, 0 0 The determinant of is called the characteristic polynomial. It is a degree polynomial in whose roots are the set of eigenvalues. The characteristic polynomial of (from Equation 4) is det 0 qB 9F I 9 0 I qcB 9F I UG F B B 0 Figure 12: The eigenvectors of 12 Jonathan Richard Shewchuk 2 1 B B f B 0 y `x G Convergence Analysis of Steepest Descent 13 Any solution to this equation is an eigenvector; say, 1 2 . By the same method, we find that 2 1 is an eigenvector corresponding to the eigenvalue 2. In Figure 12, we see that these eigenvectors coincide with the axes of the familiar ellipsoid, and that a larger eigenvalue corresponds to a steeper slope. (Negative eigenvalues indicate that decreases along the axis, as in Figures 5(b) and 5(d).) Now, let's see the Jacobi Method in action. Using the constants specified by Equation 4, we have 1 1 6 1 6 The eigenvectors of are 2 1 with eigenvalue 2 3, and 2 1 with eigenvalue 2 3. These are graphed in Figure 13(a); note that they do not coincide with the eigenvectors of , and are not related to the axes of the paraboloid. Figure 13(b) shows the convergence of the Jacobi method. The mysterious path the algorithm takes can be understood by watching the eigenvector components of each successive error term (Figures 13(c), (d), and (e)). Figure 13(f) plots the eigenvector components as arrowheads. These are converging normally at the rate defined by their eigenvalues, as in Figure 11. I hope that this section has convinced you that eigenvectors are useful tools, and not just bizarre torture devices inflicted on you by your professors for the pleasure of watching you suffer (although the latter is a nice fringe benefit). 6. Convergence Analysis of Steepest Descent 6.1. Instant Results is an eigenvector To understand the convergence of Steepest Descent, let's first consider the case where with eigenvalue . Then, the residual is also an eigenvector. Equation 12 gives 1 0 Figure 14 demonstrates why it takes only one step to converge to the exact solution. The point lies on one of the axes of the ellipsoid, and so the residual points directly to the center of the ellipsoid. Choosing 1 gives us instant convergence. For a more general analysis, we must express as a linear combination of eigenvectors, and we shall furthermore require these eigenvectors to be orthonormal. It is proven in Appendix C2 that if is n4 m n4 p m )v i xBt n 4n r 4 m r A n 4 p n p I 4 m 9 B F nm 4 r n ) 4 m r m m ) n r n4 r 4n m r 4 n m r n 4 m) r A n 4 m p n 64 m p 4 m m) n 4 9 n n m p C 4 m p u 4 m r B B h 1 3 0 B n4 p m A n4 h m 0 2 3 2 3 4 3 h h 0 0 B f h f B f A n4 h m f 1 3 0 0 2 2 0 1 3 0 2 8 )v i xBt )v i t B )v f B B f i jt n 64 m G 0 n y V 4m Y 14 Jonathan Richard Shewchuk 2 (a) 4 4 2 2 -4 -2 2 4 6 1 -4 -2 2 4 6 -2 0 -4 -6 -6 2 (c) 4 4 2 2 -4 -2 2 4 6 1 -4 -2 2 1 4 6 -2 0 -4 -4 -6 -6 2 (e) 2 (f) 4 4 2 2 -4 -2 2 4 6 1 -4 -2 2 4 6 -2 2 -2 -4 -4 -6 -6 Figure 13: Convergence of the Jacobi Method. (a) The eigenvectors of are shown with their corresponding eigenvalues. Unlike the eigenvectors of , these eigenvectors are not the axes of the paraboloid. (b) The Jacobi Method starts at 2 2 and converges at 2 2 . (c, d, e) The error vectors 0 , 1 , 2 (solid arrows) and their eigenvector components (dashed arrows). (f) Arrowheads represent the eigenvector components of the first four error vectors. Each eigenvector component of the error is converging to zero at the expected rate based on its eigenvalue. n p m n 0 47 0 47 -2 -4 2 (d) m ~ B W '~ n p m 2 (b) 1 1 n p m 1 Convergence Analysis of Steepest Descent 4 15 2 -4 -2 2 4 6 -2 -4 -6 Figure 14: Steepest Descent converges to the exact solution on the first iteration if the error term is an eigenvector. symmetric, there exists a set of orthogonal eigenvectors of . As we can scale eigenvectors arbitrarily, let us choose so that each eigenvector is of unit length. This choice gives us the useful property that Express the error term as a linear combination of eigenvectors 2 2 2 2 2 2 2 3 i I $ where is the length of each component of n 4 m r n 4 m) r i n rn r n r 4 m 4 m) 4 m i F " F n 4 m p n 4 m ) p I ) i n pn p n p 4 m 4 m) 4 m n p n r BC 4 m B 4 m n4 p m i " 5 n 4 m p # . From Equations 17 and 18 we have the following identities: (19) (20) i i 1 0 1 i l ) 2 1 (17) (18) (21) (22) (23) 6 4 2 -4 -2 2 4 6 -2 -4 Figure 15: Steepest Descent converges to the exact solution on the first iteration if the eigenvalues are all equal. too can be expressed as a sum of eigenvector components, and the length of Equation 19 shows that these components are . Equations 20 and 22 are just Pythagoras' Law. Now we can proceed with the analysis. Equation 12 gives 1 2 2 2 3 has only one eigenvector component, then convergence is We saw in the last example that, if 1 . Now let's examine the case where achieved in one step by choosing is arbitrary, but all the eigenvectors have a common eigenvalue . Equation 24 becomes 2 3 2 2 1 0 Figure 15 demonstrates why, once again, there is instant convergence. Because all the eigenvalues are equal, the ellipsoid is spherical; hence, no matter what point we start at, the residual must point to the center 1. of the sphere. As before, choose n4 p m 3 A n n p n I 4 m 9 B F 3 4 m p 64 m p n y n 4 Vp 4m m n4 r 3 A n4 p m 3 m n r n4 r 4n m r 4 n m r n 4 m) r A n 4 m p 4 m m) 16 Jonathan Richard Shewchuk 2 1 n 64 p m n y V 4m 8 n4 r B m (24) Convergence Analysis of Steepest Descent 8 17 6 4 2 -6 -4 -2 2 -2 Figure 16: The energy norm of these two vectors is equal. However, if there are several unequal, nonzero eigenvalues, then no choice of will eliminate all the eigenvector components, and our choice becomes a sort of compromise. In fact, the fraction in Equation 24 is best thought of as a weighted average of the values of 1 . The weights 2 ensure that longer components are given precedence. As a result, on any given iteration, some of the shorter components of of might actually increase in length (though never for long). For this reason, the methods of Steepest Descent and Conjugate Gradients are called roughers. By contrast, the Jacobi Method is a smoother, because every eigenvector component is reduced on every iteration. Steepest Descent and Conjugate Gradients are not smoothers, although they are often erroneously identified as such in the mathematical literature. 6.2. General Convergence To bound the convergence of Steepest Descent in the general case, we shall define the energy norm 1 2 (see Figure 16). This norm is easier to work with than the Euclidean norm, and is in some sense a more natural norm; examination of Equation 8 shows that minimizing is equivalent to n4 p m n W 4 m p n4 y m 2 1 V I p ) F W p p n4 p m 1 2 2 2 (by symmetry of ) 2 2 2 2 2 2 1 1 2 2 2 2 2 3 2 (by Identities 21, 22, 23) (25) 2 2 2 2 3 2 The analysis depends on finding an upper bound for . To demonstrate how the weights and eigenvalues affect convergence, I shall derive a result for 2. Assume that 1 2 . The spectral condition number of is defined to be 1. The slope of (relative to the coordinate system defined by the 1 2 eigenvectors), which depends on the starting point, is denoted 2 1 . We have 2 1 1 2 2 1 1 2 2 1 1 2 2 2 2 2 2 3 2 2 2 1 2 2 2 3 1 2 3 2 2 2 The value of , which determines the rate of convergence of Steepest Descent, is graphed as a function of and in Figure 17. The graph confirms my two examples. If 0 is an eigenvector, then the slope is zero (or infinite); we see from the graph that is zero, so convergence is instant. If the eigenvalues are equal, then the condition number is one; again, we see that is zero. Figure 18 illustrates examples from near each of the four corners of Figure 17. These quadratic forms are graphed in the coordinate system defined by their eigenvectors. Figures 18(a) and 18(b) are examples with a large condition number. Steepest Descent can converge quickly if a fortunate starting point is chosen (Figure 18(a)), but is usually at its worst when is large (Figure 18(b)). The latter figure gives us our best intuition for why a large condition number can be bad: forms a trough, and Steepest Descent bounces back and forth between the sides of the trough while making little progress along its length. In Figures 18(c) and 18(d), the condition number is small, so the quadratic form is nearly spherical, and convergence is quick regardless of the starting point. Holding constant (because is fixed), a little basic calculus reveals that Equation 26 is maximized when . In Figure 17, one can see a faint ridge defined by this line. Figure 19 plots worst-case starting points for our sample matrix . These starting points fall on the lines defined by 2 1 . An ȧ I 2 2 2 1 n4 r n4 r m m) 2 A A I F IA F F B A I F A F I IA F B I n m4 p 3F i 3F n @ 4 m p I 3F B I 3F n I 3 F I B 4m p 3F I n n p n n r I 4 m p 4 m n) F I n 4 m r 4 m) F B n 4 m p I 4 m r 4 m) rF n 4n m r 4 m) r n n n r B 4m p I 4 m r n 4 m) F " n 4n r 4 m r wA gn n n 4 r 4 m r A n 4 p m n m 4 r n 4 m ) r m4 r 4 m) r B n m 4 r n 4 m ) r m ) m ) n 4 r n 4 r n 4 eA n 4 p n 4 r n 4 y A n 4 p n 4 p y m m) m m m m m m n n yeA n 4 )p F n 4 r n 4 tA n 4 )F y mp m I m) m I 4m r 4m ) n 64 p n 64 p m m) 1 1 n p m I ` F Y n 64 m p n I 4m F Y 18 minimizing Jonathan Richard Shewchuk . With this norm, we have (by Equation 12) v (26) Convergence Analysis of Steepest Descent 19 0.8 0.6 100 80 60 0.4 0.2 0 20 40 15 5 10 10 2 (a) 6 4 2 -4 -2 -2 -4 6 4 2 -4 -2 -2 -4 2 4 2 4 6 4 2 1 -4 -2 -2 -4 2 4 2 (c) 2 (d) 6 4 2 1 -4 -2 -2 -4 2 4 Figure 18: These four examples represent points near the corresponding four corners of the graph in Figure 17. (a) Large , small . (b) An example of poor convergence. and are both large. (c) Small and . (d) Small , large . number of . 2 (b) 1 1 Figure 17: Convergence of Steepest Descent as a function of (the slope of ) and (the condition ). Convergence is fast when or are small. For a fixed matrix, convergence is worst when 20 c 4 0 2 -4 -2 2 4 6 -2 -4 -6 Figure 19: Solid lines represent the starting points that give the worst convergence for Steepest Descent. Dashed lines represent steps toward convergence. If the first iteration starts from a worst-case point, so do all succeeding iterations. Each step taken intersects the paraboloid axes (gray arrows) at precisely a 45 angle. Here, 3 5. upper bound for (corresponding to the worst-case starting points) is found by setting 2 2 2: 1 5 5 5 2 2 1 1 1 1 Inequality 27 is plotted in Figure 20. The more ill-conditioned the matrix (that is, the larger its condition number ), the slower the convergence of Steepest Descent. In Section 9.2, it is proven that Equation 27 is also valid for 2, if the condition number of a symmetric, positive-definite matrix is defined to be the ratio of the largest to smallest eigenvalue. The convergence results for Steepest Descent are A i n n v W 4 m p W m p 4 B 1 1 A I A A A 4 2 4 4 3 4 4 3 3 2 2 (27) 0 and (28) i # o0 4 A AB I żF BA F B B 20 Jonathan Richard Shewchuk 2 n 1 m S D The Method of Conjugate Directions 21 1 0.8 0.6 0.4 0.2 0 20 40 60 80 100 Figure 20: Convergence of Steepest Descent (per iteration) worsens as the condition number of the matrix increases. 0 1 2 1 2 (by Equation 8) 0 0 1 1 2 7. The Method of Conjugate Directions 7.1. Conjugacy Steepest Descent often finds itself taking steps in the same direction as earlier steps (see Figure 8). Wouldn't it be better if, every time we took a step, we got it right the first time? Here's an idea: let's pick a set of orthogonal search directions 0 1 1 . In each search direction, we'll take exactly one step, and that step will be just the right length to line up evenly with . After steps, we'll be done. Figure 21 illustrates this idea, using the coordinate axes as search directions. The first (horizontal) step leads to the correct 1 -coordinate; the second (vertical) step will hit home. Notice that 1 is orthogonal to 0 . In general, for each step we choose a point 1 To find the value of , use the fact that 1 should be orthogonal to , so that we need never step in n p m n4 m n y n 4 m n 4 m eA n 4 2R n m A B n4 p n m p n4m p n4 ) p m m) n V # i "" i n i n m m m 4 m p 64 2 m n I F B m F w F Y Y I I n 4 @ F YY I w m B n4 y m n m (29) 4 2 -4 -2 2 4 6 -2 1 0 0 1 -4 -6 Figure 21: The Method of Orthogonal Directions. Unfortunately, this method only works if you already know the answer. the direction of again. Using this condition, we have 1 0 0 (by Equation 29) Unfortunately, we haven't accomplished anything, because we can't compute and if we knew , the problem would already be solved. without knowing The solution is to make the search directions -orthogonal instead of orthogonal. Two vectors are -orthogonal, or conjugate, if 0 Figure 22(a) shows what -orthogonal vectors look like. Imagine if this article were printed on bubble gum, and you grabbed Figure 22(a) by the ends and stretched it until the ellipses appeared circular. The vectors would then appear orthogonal, as in Figure 22(b). Our new requirement is that (see Figure 23(a)). Not coincidentally, this 1 be -orthogonal to orthogonality condition is equivalent to finding the minimum point along the search direction , as in n4 p m n4 m n4 m n4 y m n 4 n4m n4 n m) B m p 4 m) n4 m n m n n m 4 m) n p m I n n y 4m n 4 n 4 A n 4 F n 4 y m m m p m) 64 m p n 4 m ) 22 Jonathan Richard Shewchuk 2 1 n m n 64 p m n m @ n4 m n4 p m n m (30) ; and 2 4 4 2 2 -4 -2 2 4 1 -4 -2 2 4 -2 -2 -4 -4 (a) (b) because these pairs of vectors are orthogonal. Steepest Descent. To see this, set the directional derivative to zero: 1 Following the derivation of Equation 30, here is the expression for -orthogonal: Unlike Equation 30, we can calculate this expression. Note that if the search vector were the residual, this formula would be identical to the formula used by Steepest Descent. n4 y m n n 4 4m n m 4 r n 4 m ) m ) n4 n4m n4m p n4 ) B m m) n n 64 n m p 4 m ) n 4 m 64 y m) r B n n 64 m ) I 64 m F Y y n I 64 2 F Y m 1 1 W Figure 22: These pairs of vectors are -orthogonal 1 0 0 0 0 1 when the search directions are The Method of Conjugate Directions 23 2 n y 4m 1 (31) (32) 2 4 4 2 2 -4 -2 2 4 6 1 -4 -2 2 4 6 0 -4 -6 (a) Figure 23: The method of Conjugate Directions converges in steps. (a) The first step is taken along some direction 0 . The minimum point 1 is chosen by the constraint that 1 must be -orthogonal to 0 . (b) The initial error 0 can be expressed as a sum of -orthogonal components (gray arrows). Each step of Conjugate Directions eliminates one of these components. 0 0 The values of can be found by a mathematical trick. Because the search directions are -orthogonal, it is possible to eliminate all the values but one from Expression 33 by premultiplying the expression by : 0 0 0 (By Equation 29). By Equations 31 and 34, we find that . This fact gives us a new way to look at the error term. As the following equation shows, the process of building up component by component can also be 0 (by -orthogonality of 1 0 (by -orthogonality of vectors) vectors) (34) n m 1 To prove that this procedure really does compute combination of search directions; namely, in steps, express the error term as a linear n p m -2 5 n mp V # n n m n m p n ) m m) n n m n n y m A) n p n I 4 m 4 m V 654 3 m F m ) n n m n m p n ) m n mn n ) m m ) m n n n m m) m n4 n y m ڧ 4 m B 9 1 0 1 -2 0 -4 -6 (b) n m n n m p m) n p n m m) n p m n m n n m m 24 Jonathan Richard Shewchuk 2 1 (33) n m) The Method of Conjugate Directions viewed as a process of cutting down the error term component by component (see Figure 23(b)). 0 25 1 0 1 7.2. Gram-Schmidt Conjugation All that is needed now is a set of -orthogonal search directions to generate them, called a conjugate Gram-Schmidt process. Suppose we have a set of linearly independent vectors 0 1 1 . The coordinate axes will , take and subtract out do in a pinch, although more intelligent choices are possible. To construct any components that are not -orthogonal to the previous vectors (see Figure 24). In other words, set 0, set 0 , and for 0 0 The difficulty with using Gram-Schmidt conjugation in the method of Conjugate Directions is that all 3 operations the old search vectors must be kept in memory to construct each new one, and furthermore u0 u+ u1 u* 0 k k 1 . Set 0 to 0 , and . 1 Figure 24: Gram-Schmidt conjugation of two vectors. Begin with two linearly independent vectors 0 and . The vector 1 is composed of two components: , which is -orthogonal (or conjugate) 0 , which is parallel to 0 . After conjugation, only the -orthogonal portion remains, and d(0) d(0) d(1) F I 0 (by -orthogonality of 0 i n D m n n m m) 1 where the are defined for . To find their values, use the same trick used to find i n ر 4 m 5 A n 4 4m 1 4 4n m # i i i V "" n 4 m V4 n n m m ) n m 4) B n A n 4 m ) ԯ 4 m ) ر 4 5 A n m 4 ) V 4 D D n n m 4 m) 4 4 After iterations, every component is cut away, and n m n m n n 5 n n m m B m m V4 n n y 5 A m m V4 1 0 1 0 n # mp 5 4 V # 5 V # n p m n 4m p n m (35) 0; the proof is complete. . Fortunately, there is a simple way (36) : vectors) (37) 4 2 -4 -2 2 4 6 -2 -4 -6 Figure 25: The method of Conjugate Directions using the axial unit vectors, also known as Gaussian elimination. are required to generate the full set. In fact, if the search vectors are constructed by conjugation of the axial unit vectors, Conjugate Directions becomes equivalent to performing Gaussian elimination (see Figure 25). As a result, the method of Conjugate Directions enjoyed little use until the discovery of CG -- which is a method of Conjugate Directions -- cured these disadvantages. An important key to understanding the method of Conjugate Directions (and also CG) is to notice that Figure 25 is just a stretched copy of Figure 21! Remember that when one is performing the method of Conjugate Directions (including CG), one is simultaneously performing the method of Orthogonal Directions in a stretched (scaled) space. 7.3. Optimality of the Error Term Conjugate Directions has an interesting property: it finds at every step the best solution within the bounds be the -dimensional of where it's been allowed to explore. Where has it been allowed to explore? Let subspace span 0 ; the value is chosen from 0 . What do I mean by "best 1 1 solution"? I mean that Conjugate Directions chooses the value from 0 that minimizes (see Figure 26). In fact, some authors derive CG by trying to minimize within 0 . In the same way that the error term can be expressed as a linear combination of search directions n W 4 m p 4 An mp 4 n W 4 m p 4 An mp 4 A n mp n4 p m 26 Jonathan Richard Shewchuk 2 1 i i i n V 4 m "" n m n m The Method of Conjugate Directions 27 (Equation 35), its energy norm can be expressed as a summation. 1 1 (by Equation 35) 1 Each term in this summation is associated with a search direction that has not yet been traversed. Any other vector chosen from 0 must have these same terms in its expansion, which proves that must have the minimum energy norm. Having proven the optimality with equations, let's turn to the intuition. Perhaps the best way to visualize the workings of Conjugate Directions is by comparing the space we are working in with a "stretched" space, as in Figure 22. Figures 27(a) and 27(c) demonstrate the behavior of Conjugate Directions in 2 and 3 ; lines that appear perpendicular in these illustrations are orthogonal. On the other hand, Figures 27(b) and 27(d) show the same drawings in spaces that are stretched (along the eigenvector axes) so that the ellipsoidal contour lines become spherical. Lines that appear perpendicular in these illustrations are -orthogonal. In Figure 27(a), the Method of Conjugate Directions begins at 0 , takes a step in the direction of 0 , and stops at the point 1 , where the error vector 1 is -orthogonal to 0 . Why should we expect this to be the minimum point on 0 1 ? The answer is found in Figure 27(b): in this stretched space, 1 appears perpendicular to 0 because they are -orthogonal. The error vector 1 is a radius of the concentric circles that represent contours on which is constant, so 0 1 must be tangent at 1 to the circle that 1 lies on. Hence, 1 is the point on 0 that minimizes 1 . 1 This is not surprising; we have already seen in Section 7.1 that -conjugacy of the search direction and the error term is equivalent to minimizing (and therefore ) along the search direction. However, after Conjugate Directions takes a second step, minimizing along a second search direction 1 , why should we expect that will still be minimized in the direction of 0 ? After taking steps, why will be minimized over all of 0 ? n n m m n m n4 p m n W m p A n m n p m n m 2 (by -orthogonality of vectors). g n m n m W p W p An k X8 Figure 26: In this figure, the shaded area is span 0 2 0 0 1 . The ellipsoid is a contour on which the energy norm is constant. After two steps, Conjugate Directions finds 2 , the point on 0 2 that minimizes . e (0) n n n m m) m 4 n n n 5 n m m ) m m # V m@ W p n p m d(0) d(1) Y 4 An m An n m @ 45 V # 45 V # m n m 4 An mp n W p m @ n W 4 m p n }| m 2 p n I 4m F Y n p m 0 e e (1) (2) 28 Jonathan Richard Shewchuk 0 0 1 1 1 1 (a) 0 0 1 0 1 0 0 2 0 (c) Figure 27: Optimality of the Method of Conjugate Directions. (a) A two-dimensional problem. Lines that appear perpendicular are orthogonal. (b) The same problem in a "stretched" space. Lines that appear perpendicular are -orthogonal. (c) A three-dimensional problem. Two concentric ellipsoids are shown; is at the center of both. The line 0 1 is tangent to the outer ellipsoid at 2 is 1 . The plane 0 tangent to the inner ellipsoid at 2 . (d) Stretched view of the three-dimensional problem. f 9 0 n m 1 1 2 0 (d) An 1 0 2 1 m @ 1 1 n m @ n m @ n m n n mr m 2 An m n m 0 1 0 (b) n p m n r m n m n m 2 1 An 0 1 1 1 1 n 2 0 m m A n @ m 0 f 9 n m n n n p m m n r m n m 2 m2 n m n n mr m An m An m n m @ n m n m The Method of Conjugate Directions 29 In Figure 27(b), 0 and 1 appear perpendicular because they are -orthogonal. It is clear that 1 must point to the solution , because 0 is tangent at 1 to a circle whose center is . However, a three-dimensional example is more revealing. Figures 27(c) and 27(d) each show two concentric ellipsoids. The point 1 lies on the outer ellipsoid, and 2 lies on the inner ellipsoid. Look carefully at these figures: the plane 0 2 slices through the larger ellipsoid, and is tangent to the smaller ellipsoid at 2 . The point is at the center of the ellipsoids, underneath the plane. Looking at Figure 27(c), we can rephrase our question. Suppose you and I are standing at 1 , and on 0 want to walk to the point that minimizes 2 ; but we are constrained to walk along the search direction 1 . If 1 points to the minimum point, we will succeed. Is there any reason to expect that 1 will point the right way? Figure 27(d) supplies an answer. Because 1 is -orthogonal to 0 , they are perpendicular in this diagram. Now, suppose you were staring down at the plane 0 2 as if it were a sheet of paper; the sight you'd see would be identical to Figure 27(b). The point 2 would be at the center of the paper, and the point would lie underneath the paper, directly under the point 2 . Because 0 and 1 are perpendicular, 1 points directly to 2 , which is the point in 0 2 closest to . The plane 2 0 is tangent to the sphere on which 2 lies. If you took a third step, it would be straight down from 2 to , in a direction -orthogonal to 2 . Another way to understand what is happening in Figure 27(d) is to imagine yourself standing at the . Each time the solution point , pulling a string connected to a bead that is constrained to lie in 0 expanding subspace is enlarged by a dimension, the bead becomes free to move a little closer to you. Now if you stretch the space so it looks like Figure 27(c), you have the Method of Conjugate Directions. Another important property of Conjugate Directions is visible in these illustrations. We have seen that, at each step, the hyperplane 0 is tangent to the ellipsoid on which lies. Recall from Section 4 that the residual at any point is orthogonal to the ellipsoidal surface at that point. It follows that is orthogonal to as well. To show this fact mathematically, premultiply Equation 35 by : 1 (38) (39) We could have derived this identity by another tack. Recall that once we take a step in a search direction, we need never step in that direction again; the error term is evermore -orthogonal to all the old search directions. Because , the residual is evermore orthogonal to all the old search directions. Because the search directions are constructed from the vectors, the subspace spanned by 0 1 is , and the residual is orthogonal to these previous vectors as well (see Figure 28). This is proven by taking the inner product of Equation 36 and : 1 0 There is one more identity we will use later. From Equation 40 (and Figure 28), 0 (by Equation 39) i i V 4 "" 0 (by -orthogonality of -vectors). (40) (41) (42) n m n m n m A n m n 2 m n4 r m n n m @ m n 4 m) B n m 4 An m n4 n m m n m A n 2 m n A m n m n 4 m r 4) n 4 m r n 4 m ) n in 5 m n n An m r m ) 4 m V4 n r m m o i 4 n n n 5 m 4 m ) m # B V A n 2 m n m n m p n m n r 4) r 4) n m m 2 4 An m n4 p n B m u 4 m r n ԥ m n n m r 4 m) n p n4 m m) B n rn4 m m) n4 r m n m n m n m An n m m 4 n m 4 30 Jonathan Richard Shewchuk r(2) Figure 28: Because the search directions 0 1 are constructed from the vectors 0 1 , they span the same subspace 2 (the gray-colored plane). The error term 2 is -orthogonal to 2 , the residual 2 is orthogonal to 2 , and a new search direction 2 is constructed (from 2 ) to be -orthogonal to 2 . The endpoints of 2 and 2 lie on a plane parallel to 2 , because 2 is constructed from 2 by Gram-Schmidt conjugation. To conclude this section, I note that as with the method of Steepest Descent, the number of matrix-vector products per iteration can be reduced to one by using a recurrence to find the residual: 1 1 8. The Method of Conjugate Gradients It may seem odd that an article about CG doesn't describe CG until page 30, but all the machinery is now in place. In fact, CG is simply the method of Conjugate Directions where the search directions are constructed by conjugation of the residuals (that is, by setting ). This choice makes sense for many reasons. First, the residuals worked for Steepest Descent, so why not for Conjugate Directions? Second, the residual has the nice property that it's orthogonal to the previous search directions (Equation 39), so it's guaranteed always to produce a new, linearly independent search direction unless the residual is zero, in which case the problem is already solved. As we shall see, there is an even better reason to choose the residual. Let's consider the implications of this choice. Because the search vectors are built from the residuals, the is equal to . As each residual is orthogonal to the previous search subspace span 0 1 1 directions, it is also orthogonal to the previous residuals (see Figure 29); Equation 41 becomes Interestingly, Equation 43 shows that each new residual is just a linear combination of the previous residual and . Recalling that , this fact implies that each new subspace 1 is formed 1 1 and the subspace . Hence, from the union of the previous subspace span span 0 0 2 2 0 1 1 0 0 0 0 0 4 n m r n m V4 V4 in i n m r m i 0 P n4 n4 y n4 r n n m yA m n 4 Bp F m I 4m 4m n 6m 4 p B m B i in i "" i n m r "" m 4 n4 r m l n4 r 4 m g 4 n n m r 4 m) r i n r in m m 4 4 4 pn V 4 m n 64 r m i i i r n V 4 m r "" n m r n m u 2 d (2) e (2) d(1) d(0) u1 u0 n V4 m (43) (44) The Method of Conjugate Gradients 31 d(0) Figure 29: In the method of Conjugate Gradients, each new residual is orthogonal to all the previous residuals and search directions; and each new search direction is constructed (from the residual) to be -orthogonal to all the previous residuals and search directions. The endpoints of 2 and 2 lie on a plane parallel to 2 (the shaded subspace). In CG, 2 is a linear combination of 2 and 1 . This subspace is called a Krylov subspace, a subspace created by repeatedly applying a matrix to a vector. It has a pleasing property: because is included in 1 , the fact that the next residual 1 (Equation 39) implies that is orthogonal to is -orthogonal to . Gram-Schmidt conjugation 1 1 ! becomes easy, because 1 is already -orthogonal to all of the previous search directions except Recall from Equation 37 that the Gram-Schmidt constants are and Equation 43, simplify this expression. Taking the inner product of 1 ; let us 1 1 1 1 0 1 otherwise (By Equation 44.) 1 1 1 1 1 1 (By Equation 37.) 0 terms have disappeared. It is no longer necessary to store old search vectors As if by magic, most of the to ensure the -orthogonality of new search vectors. This major advance is what makes CG as important an algorithm as it is, because both the space complexity and time complexity per iteration are reduced from 2 to , where is the number of nonzero entries of . Henceforth, I shall use the abbreviation 1 . Simplifying further: (by Equation 32) 1 1 1 1 (by Equation 42) n4 m n 64 r m n n $ n n 4 r m m ) m m) 4 B 4 A D i A i A i 64 n4 r m n m46 r 4 i i 6"z } 6 z 6{ x x i i n 4 r n 4 r { m i n 4m) r n 4 m r x{ B m ) n rn4 r n rn4 r m m B m m n n4 rn ) y n rn4) r m m) m B m m ) n V4 r n V4m r n4m r n4 r ) m m) n V4 r n V4m n4m r n4 r ) m m) d(1) r(1) r(0) r(2) d (2) e (2) n4 m 4 n 64 r m n n m 4 m) r n n n y m 4m r m n r n 4) r m m) 4 64 n V F 4 4 F4 m I I 4 2 -4 -2 2 4 6 0 -2 -4 -6 Figure 30: The method of Conjugate Gradients. Let's put it all together into one piece now. The method of Conjugate Gradients is: 0 0 0 1 1 1 1 1 1 1 1 The performance of CG on our sample problem is demonstrated in Figure 30. The name "Conjugate Gradients" is a bit of a misnomer, because the gradients are not conjugate, and the conjugate directions are not all gradients. "Conjugated Gradients" would be more accurate. 9. Convergence Analysis of Conjugate Gradients CG is complete after iterations, so why should we care about convergence analysis? In practice, accumulated floating point roundoff error causes the residual to gradually lose accuracy, and cancellation i (by Equations 32 and 42) 4n m n 64 m A n 64 m r n 64 m i n4 r n4m r n n 64 m r n ) 64 r 64 m i n n m y m) n r n r i n 4 m n 4 m eA Bn 4 m n 64 m 4 m 4 m y 4 m R 64 m n4 n4m n y n m 4 r n 4 m ) r 4 m m ) n n m B @c m r m in 32 Jonathan Richard Shewchuk 2 1 n m (45) (46) (47) (48) (49) Convergence Analysis of Conjugate Gradients 33 error causes the search vectors to lose -orthogonality. The former problem could be dealt with as it was for Steepest Descent, but the latter problem is not easily curable. Because of this loss of conjugacy, the mathematical community discarded CG during the 1960s, and interest only resurged when evidence for its effectiveness as an iterative procedure was published in the seventies. Times have changed, and so has our outlook. Today, convergence analysis is important because CG is commonly used for problems so large it is not feasible to run even iterations. Convergence analysis is seen less as a ward against floating point error, and more as a proof that CG is useful for problems that are out of the reach of any exact algorithm. The first iteration of CG is identical to the first iteration of Steepest Descent, so without changes, Section 6.1 describes the conditions under which CG converges on the first iteration. 9.1. Picking Perfect Polynomials We have seen that at each step of CG, the value span span Krylov subspaces such as this have another pleasing property. For a fixed , the error term has the form The coefficients are related to the values and , but the precise relationship is not important here. What is important is the proof in Section 7.3 that CG chooses the coefficients that minimize . The expression in parentheses above can be expressed as a polynomial. Let be a polynomial of degree . can take either a scalar or a matrix as its argument, and will evaluate to the same; for instance, 2 2 1, then 2 2 2 . This flexible notation comes in handy for eigenvectors, for if 2 2 , and so on.) which you should convince yourself that . (Note that , 2 Now we can express the error term as 0 if we require that 0 1. CG chooses this polynomial when it chooses the coefficients. Let's examine the effect of applying this polynomial to 0 . As in the analysis of Steepest Descent, express 0 as a linear combination of orthogonal unit eigenvectors 0 1 and we find that 2 2 2 n p m n W 4 m p I F 4 n4 n4 y m m 5 A n n m p 4m p 4 i in in in n m p 4 ""i m i p m i p i m p r n m r V 4 "" n m r n m r n m n4 p 4 An mp m is chosen from 2 0 3 0 0 0 2 0 0 0 1 8 v I 8F 4 t "8 I 8F 4 I 8F 4 in p F m q 4 I i "" 5 n m p # I F 4 n p m I F 4 A n 4m p n 4m p n4 p m n 4m p 0 , where I F 4 1 0 0 XI F 4 A 4 I F 34 0 Jonathan Richard Shewchuk (a) 1 1 0.75 0.5 0.25 -0.25 -0.5 -0.75 -1 2 7 1 0.75 0.5 0.25 -0.25 -0.5 -0.75 -1 2 7 2 (c) 2 (d) 1 0.75 0.5 0.25 -0.25 -0.5 -0.75 -1 2 7 1 0.75 0.5 0.25 -0.25 -0.5 -0.75 -1 2 7 CG finds the polynomial that minimizes this expression, but convergence is only as good as the convergence be the set of eigenvalues of , we have of the worst eigenvector. Letting min max min max Figure 31 illustrates, for several values of , the that minimizes this expression for our sample problem with eigenvalues 2 and 7. There is only one polynomial of degree zero that satisfies 0 0 1, and that is 0 1, graphed in Figure 31(a). The optimal polynomial of degree one is 1 1 2 9, graphed in Figure 31(b). Note that 1 2 5 9 and 1 7 5 9, and so the energy norm of the error term after one iteration of CG is no greater than 5 9 its initial value. Figure 31(c) shows that, after two iterations, Equation 50 evaluates to zero. This is because a polynomial of degree two can be fit to three points ( 2 0 1, 2 2 0, and 2 7 0). In general, a polynomial of degree can fit 1 points, and thereby accommodate separate eigenvalues. The foregoing discussing reinforces our understanding that CG yields the exact result after iterations; and furthermore proves that CG is quicker if there are duplicated eigenvalues. Given infinite floating point precision, the number of iterations required to compute an exact solution is at most the number of distinct eigenvalues. (There is one other possibility for early termination: 0 may already be -orthogonal to some of the eigenvectors of . If eigenvectors are missing from the expansion of 0 , their eigenvalues may be omitted from consideration in Equation 50. Be forewarned, however, that these eigenvectors may be reintroduced by floating point roundoff error.) B A I F I F n m n m 2 BpI F 4 2 n m p vI 8 v I 2 2 2 y be to zero on each eigenvalue, given the constraint that 0 1. 2 0 2 Figure 31: The convergence of CG after iterations depends on how close a polynomial F 4 t n m F 4 t n m I F I F TI F I F n 4m p I F I F I F I F sI F dI F (b) of degree can (50) Convergence Analysis of Conjugate Gradients 2 5 35 10 49 -1 -0.5 -0.5 -1 -1.5 -2 0.5 1 -1 -0.5 -0.5 -1 -1.5 -2 0.5 1 Figure 32: Chebyshev polynomials of degree 2, 5, 10, and 49. We also find that CG converges more quickly when eigenvalues are clustered together (Figure 31(d)) and , because it is easier for CG to choose a than when they are irregularly distributed between polynomial that makes Equation 50 small. If we know something about the characteristics of the eigenvalues of , it is sometimes possible to suggest a polynomial that leads to a proof of a fast convergence. For the remainder of this analysis, however, I shall assume the most general case: the eigenvalues are evenly distributed between and , the number of distinct eigenvalues is large, and floating point roundoff occurs. 9.2. Chebyshev Polynomials A useful approach is to minimize Equation 50 over the range rather than at a finite number of points. The polynomials that accomplish this are based on Chebyshev polynomials. The Chebyshev polynomial of degree is 1 (If this expression doesn't look like a polynomial to you, try working it out for equal to 1 or 2.) Several Chebyshev polynomials are illustrated in Figure 32. The Chebyshev polynomials have the property that 1 (in fact, they oscillate between 1 and 1) on the domain 1 1 , and furthermore that is maximum on the domain 1 1 among all such polynomials. Loosely speaking, increases as quickly as possible outside the boxes in the illustration. I F 4 v i xBt B v i xBt l A F 1 2 2 2 1 s # 4 0 I B 4 v o0 i # 4 t o0 A B F 4I B # 4 0 2 1.5 1 0.5 2 1.5 1 0.5 I F I F -1 -0.5 -0.5 -1 -1.5 -2 0.5 1 -1 -0.5 -0.5 -1 -1.5 -2 0.5 1 2 1.5 1 0.5 2 1.5 1 0.5 I F I F I F 4 I F4 I F4 36 2 Jonathan Richard Shewchuk 0.75 0.5 0.25 1 -0.25 -0.5 -0.75 -1 2 3 4 5 6 7 8 that minimizes Equation 50 for 2 and 7 in the general case. This curve is a scaled version of the Chebyshev polynomial of degree 2. The energy norm of the error term after two iterations is no greater than 0.183 times its initial value. Compare with Figure 31(c), where it is known that there are only two eigenvalues. 2 It is shown in Appendix C3 that Equation 50 is minimized by choosing 2 This polynomial has the oscillating properties of Chebyshev polynomials on the domain (see Figure 33). The denominator enforces our requirement that 0 1. The numerator has a maximum value of one on the interval between and , so from Equation 50 we have 2 The second addend inside the square brackets converges to zero as grows, so it is more common to express the convergence of CG with the weaker inequality 2 1 1 0 W n m p A n W m p 4 B 1 1 1 1 ( V %4 1 1 1 0 n mp 1 0 1 0 o0 # 4 0 o0 I F 4 ' V &0 ' 11 )) ' &0 ' 4 V ' V ' &1 0&1) ('0) (' 4 A B wA BA ! 4 n BA 4 W m p # 4 V B o0 # A 4 V 4 o0 # 4 0 I F 4 W n 4 m p y Figure 33: The polynomial &%$ # "! n 4m p I F 1 (51) (52) Complexity 37 1 0.8 0.6 0.4 0.2 0 20 40 60 80 100 Figure 34: Convergence of Conjugate Gradients (per iteration) as a function of condition number. Compare with Figure 20. 1 in Equation 51, we obtain The first step of CG is identical to a step of Steepest Descent. Setting Equation 28, the convergence result for Steepest Descent. This is just the linear polynomial case illustrated in Figure 31(b). Figure 34 charts the convergence per iteration of CG, ignoring the lost factor of 2. In practice, CG usually converges faster than Equation 52 would suggest, because of good eigenvalue distributions or good starting points. Comparing Equations 52 and 28, it is clear that the convergence of CG is much quicker than that of Steepest Descent (see Figure 35). However, it is not necessarily true that every iteration of CG enjoys faster convergence; for example, the first iteration of CG is an iteration of Steepest Descent. The factor of 2 in Equation 52 allows CG a little slack for these poor iterations. 10. Complexity The dominating operations during an iteration of either Steepest Descent or CG are matrix-vector products. operations, where is the number of non-zero In general, matrix-vector multiplication requires is sparse and entries in the matrix. For many problems, including those listed in the introduction, . Suppose we wish to perform enough iterations to reduce the norm of the error by a factor of ; that is, 0 . Equation 28 can be used to show that the maximum number of iterations required to achieve this bound using Steepest Descent is whereas Equation 52 suggests that the maximum number of iterations CG requires is 6 $ 1 2 ln 2 i 6 $ 1 1 ln 2 2 5 5 F I 3 4 3 7 n mp 2 F I n4m p 40 35 30 25 20 15 10 5 0 200 400 600 800 1000 Figure 35: Number of iterations of Steepest Descent required to match one iteration of CG. I conclude that Steepest Descent has a time complexity of . Both algorithms have a space complexity of , whereas CG has a time complexity of . Finite difference and finite element approximations of second-order elliptic boundary value problems 2 posed on -dimensional domains often have . Thus, Steepest Descent has a time complexity of 2 for two-dimensional problems, versus 3 2 for CG; and Steepest Descent has a time complexity 5 3 for three-dimensional problems, versus 4 3 for CG. of 11. Starting and Stopping In the preceding presentation of the Steepest Descent and Conjugate Gradient algorithms, several details have been omitted; particularly, how to choose a starting point, and when to stop. 11.1. Starting There's not much to say about starting. If you have a rough estimate of the value of , use it as the starting value 0 . If not, set 0 0; either Steepest Descent or CG will eventually converge when used to solve linear systems. Nonlinear minimization (coming up in Section 14) is trickier, though, because there may be several local minima, and the choice of starting point will determine which minimum the procedure converges to, or whether it will converge at all. 11.2. Stopping When Steepest Descent or CG reaches the minimum point, the residual becomes zero, and if Equation 11 or 48 is evaluated an iteration later, a division by zero will result. It seems, then, that one must stop F FI I f F I F I F I z 38 Jonathan Richard Shewchuk n m F I F I n m F I Preconditioning 39 immediately when the residual is zero. To complicate things, though, accumulated roundoff error in the recursive formulation of the residual (Equation 47) may yield a false zero residual; this problem could be resolved by restarting with Equation 45. Usually, however, one wishes to stop before convergence is complete. Because the error term is not available, it is customary to stop when the norm of the residual falls below a specified value; often, this value is some small fraction of the initial residual ( 0 ). See Appendix B for sample code. 12. Preconditioning Preconditioning is a technique for improving the condition number of a matrix. Suppose that symmetric, positive-definite matrix that approximates , but is easier to invert. We can solve indirectly by solving 1 1 are better clustered than those of , we can iteratively If , or if the eigenvalues of 1 is not generally solve Equation 53 more quickly than the original problem. The catch is that symmetric nor definite, even if and are. We can circumvent this difficulty, because for every symmetric, positive-definite there is a (not necessarily unique) matrix that has the property that . (Such an can be obtained, for 1 and 1 have the same eigenvalues. This instance, by Cholesky factorization.) The matrices 1 with eigenvalue , then 1 is true because if is an eigenvector of is an eigenvector of with eigenvalue : 1 1 1 The system can be transformed into the problem 1 1 1 which we solve first for , then for . Because is symmetric and positive-definite, can be found by Steepest Descent or CG. The process of using CG to solve this system is called the Transformed Preconditioned Conjugate Gradient Method: 0 0 0 1 1 1 1 1 C C C C C 1 1 1 1 C 1 in 1 1 ) V V C 9 V ) 9 V 9 ) ) V V V u) i ) n An n n m4 64 m m46 r 64 m i n4 r n4m r n n 64 m r n ) 64 m r 4 m ) m i 4n m V V n 4 m y B n 4 m r n 64 m r )i n 4 n 4 eA n 4 n y m m m 2 64 2 m i n 4 m V V n 4 m ) n y ) n4 rn4 r 4m m m) n n m ) 2 V V s V m r m B 9) C $ 9 V I V ) F I ) F I V V F ) ) C C C ) V V i V V V ) C C 9 1 1 R 9 n mr V 2 8 n 4 m r is a V V 9 C C C 9 C $ C V 9 (53) C C C 9 C C 9 C I F @ AI F Bq V @9@ -4 -2 2 4 6 -2 -4 -6 -8 Figure 36: Contour lines of the quadratic form of the diagonally preconditioned sample problem. must be computed. However, a few careful This method has the undesirable characteristic that 1 and , and using the identities variable substitutions can eliminate . Setting 1 1 , we derive the Untransformed Preconditioned Conjugate Gradient and Method: 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 is needed. By the same means, it is possible The matrix does not appear in these equations; only to derive a Preconditioned Steepest Descent Method that does not use . 1 , and occais determined by the condition number of The effectiveness of a preconditioner sionally by its clustering of eigenvalues. The problem remains of finding a preconditioner that approximates 1 well enough to improve convergence enough to make up for the cost of computing the product 1 ; it is only necessary to be able to once per iteration. (It is not necessary to explicitly compute or 1 to a vector.) Within this constraint, there is a surprisingly rich supply compute the effect of applying of possibilities, and I can only scratch the surface here. n4 r m V 9 V 9 V 9 9 9 9 1 1 n4 n4 m ) m V 4n m n 64 m A n 64 m r V n 64 m n4 r i n4 r n m n 64 m r V n ) 64 r 4 m i n m n V y n m) r n r i 4 m 4 m B 4 m n 4 m n 4 n 4 eA n 4 y m m m R 64 m i n4 n4m n y n 4 r m )n 4 r 4 m i m V m) n n r m V m n m B 2o m r C 4n m r V n 4 m r in 9 9 9 C 40 Jonathan Richard Shewchuk 2 1 9 9 V V 9 9 V V ) n4 n m 2) 4 m C Conjugate Gradients on the Normal Equations 41 Intuitively, preconditioning is an attempt to stretch the quadratic form to make it appear more spherical, so that the eigenvalues are close to each other. A perfect preconditioner is ; for this preconditioner, 1 has a condition number of one, and the quadratic form is perfectly spherical, so solution takes only one iteration. Unfortunately, the preconditioning step is solving the system , so this isn't a useful preconditioner at all. The simplest preconditioner is a diagonal matrix whose diagonal entries are identical to those of . The process of applying this preconditioner, known as diagonal preconditioning or Jacobi preconditioning, is equivalent to scaling the quadratic form along the coordinate axes. (By comparison, the perfect precondiscales the quadratic form along its eigenvector axes.) A diagonal matrix is trivial to invert, tioner but is often only a mediocre preconditioner. The contour lines of our sample problem are shown, after diagonal preconditioning, in Figure 36. Comparing with Figure 3, it is clear that some improvement has occurred. The condition number has improved from 3 5 to roughly 2 8. Of course, this improvement is much more beneficial for systems where 2. A more elaborate preconditioner is incomplete Cholesky preconditioning. Cholesky factorization is a , where is a lower triangular matrix. Incomplete technique for factoring a matrix into the form Cholesky factorization is a variant in which little or no fill is allowed; is approximated by the product , where might be restricted to have the same pattern of nonzero elements as ; other elements of are thrown away. To use as a preconditioner, the solution to is computed by backsubstitution is never explicitly computed). Unfortunately, incomplete Cholesky preconditioning is (the inverse of not always stable. Many preconditioners, some quite sophisticated, have been developed. Whatever your choice, it is generally accepted that for large-scale applications, CG should nearly always be used with a preconditioner. 13. Conjugate Gradients on the Normal Equations CG can be used to solve systems where solution to the least squares problem is not symmetric, not positive-definite, and even not square. A min 2 can be found by setting the derivative of Expression 54 to zero: If is square and nonsingular, the solution to Equation 55 is the solution to . If is not square, and is overconstrained -- that is, has more linearly independent equations than variables -- then there may or may not be a solution to , but it is always possible to find a value of that minimizes Expression 54, the sum of the squares of the errors of each linear equation. 2 is symmetric and positive (for any , 0). If is not underconstrained, is nonsingular, and methods like Steepest Descent and CG can be used to solve Equation 55. The then only nuisance in doing so is that the condition number of is the square of that of , so convergence is significantly slower. An important technical point is that the matrix is never formed explicitly, because it is less sparse than . Instead, is multiplied by by first finding the product , and then . Also, numerical F ) Q R 9 9 HI) C F C F ) ) @@0 F ) @T ) R ) B cb ) @T ) F GF Ȩ D E ) F F ) CF CF C C CF ) ȧ q ) ) @ 9 V ) CF CF 9 (54) (55) 14. The Nonlinear Conjugate Gradient Method CG can be used not only to find the minimum point of a quadratic form, but to minimize any continuous function for which the gradient can be computed. Applications include a variety of optimization problems, such as engineering design, neural net training, and nonlinear regression. 14.1. Outline of the Nonlinear Conjugate Gradient Method To derive nonlinear CG, there are three changes to the linear algorithm: the recursive formula for the residual cannot be used, it becomes more complicated to compute the step size , and there are several different choices for . In nonlinear CG, the residual is always set to the negation of the gradient; . The search directions are computed by Gram-Schmidt conjugation of the residuals as with linear CG. Performing a line search along this search direction is much more difficult than in the linear case, and a variety of procedures that minimizes is found by ensuring can be used. As with the linear CG, a value of that the gradient is orthogonal to the search direction. We can use any algorithm that finds the zeros of the . expression In linear CG, there are several equivalent expressions for the value of . In nonlinear CG, these different expressions are no longer equivalent; researchers are still investigating the best choice. Two choices are the Fletcher-Reeves formula, which we used in linear CG for its ease of computation, and the Polak-Ribi` re e formula: 1 1 1 1 The Fletcher-Reeves method converges if the starting point is sufficiently close to the desired minimum, whereas the Polak-Ribi` re method can, in rare cases, cycle infinitely without converging. However, Polake Ribi` re often converges much more quickly. e Fortunately, convergence of the Polak-Ribi` re method can be guaranteed by choosing max 0 . e 0. To restart CG is to forget the past search Using this value is equivalent to restarting CG if directions, and start CG anew in the direction of steepest descent. Here is an outline of the nonlinear CG method: 0 0 0 Find that minimizes 1 1 1 i 1 or 1 max 0 S 1 1 1 1 i R i 4n m n n I 4m r B r n 4 m) r n n 64 m m46 rF 64 m) r i n n r F B i n I n 64 m eA nY C n 64 m y 4 m R 64 m i n n tA 4 m n 4 m y I 4 m 4 m i 4 @ F Y m n n n I m F Y C m r m B R 1 1 n n I 4 m F Y C 4 m r B n n A n 4 F y m Y I 4m 4m n n 4n m r 4 m) r n n n 64 m I 4 m r B 64 m rF 64 m) r y R n4 y m i n4 r n4m r n n 64 m r n ) 4 r 64 m m) m ) ) n4 y m Y 42 stability is improved if the value with itself. Jonathan Richard Shewchuk (in Equation 46) is computed by taking the inner product of n4 rn4m r n n 4 m r n ) 64 m r 64 m ) m n 4 v n 4 n 4 eA n 4 F y m )I m m m 2 tY RP IQ I w F Y The Nonlinear Conjugate Gradient Method 1 1 43 Nonlinear CG comes with few of the convergence guarantees of linear CG. The less similar is to a quadratic function, the more quickly the search directions lose conjugacy. (It will become clear shortly that the term "conjugacy" still has some meaning in nonlinear CG.) Another problem is that a general function may have many local minima. CG is not guaranteed to converge to the global minimum, and may not even find a local minimum if has no lower bound. Figure 37 illustrates nonlinear CG. Figure 37(a) is a function with many local minima. Figure 37(b) demonstrates the convergence of nonlinear CG with the Fletcher-Reeves formula. In this example, CG is not nearly as effective as in the linear case; this function is deceptively difficult to minimize. Figure 37(c) shows a cross-section of the surface, corresponding to the first line search in Figure 37(b). Notice that there are several minima; the line search finds a value of corresponding to a nearby minimum. Figure 37(d) shows the superior convergence of Polak-Ribi` re CG. e Because CG can only generate conjugate vectors in an -dimensional space, it makes sense to restart CG every iterations, especially if is small. Figure 38 shows the effect when nonlinear CG is restarted every second iteration. (For this particular example, both the Fletcher-Reeves method and the Polak-Ribi` re e method appear the same.) 14.2. General Line Search Depending on the value of , it might be possible to use a fast algorithm to find the zeros of . For instance, if is polynomial in , then an efficient algorithm for polynomial zero-finding can be used. However, we will only consider general-purpose algorithms. Two iterative methods for zero-finding are the Newton-Raphson method and the Secant method. Both methods require that be twice continuously differentiable. Newton-Raphson also requires that it be possible to compute the second derivative of with respect to . The Newton-Raphson method relies on the Taylor series approximation 2 2 where is the Hessian matrix 2 2 1 2 2 1 1 1 2 2 2 2 2 2 2 1 2 ` " ` ` . . . I ` F Y ) { { 5 h eA F y y A 5 I I Y f y 2 2 0 2 2 0 2 1 2 2 .. . . . . ) Y Y "$" "" ( & " " && "" '&&% " " y ` ` n 4 m n 64 m 1 y YX tA y ` F Y ) eA I y A ) v w F tY I y F Y " " " " ` ` y eA F I Y A n 64 r n 64 m m y "" ! I F " " w Y " " ` ` Vy I T y WeA w F Y UI eA ) v ` F tY I y eA F I w Y y T y UI eA Y Y Y F Y y F Y Y I ` F Y Y (56) (57) 44 Jonathan Richard Shewchuk (a) 6 4 500 0 2 2 4 0 -2 -4 -2 6 -4 -2 2 4 6 (c) 600 6 400 4 200 0 -0.04 -0.02 0.02 0.04 -4 -2 2 4 6 -200 -2 Figure 37: Convergence of the nonlinear Conjugate Gradient Method. (a) A complicated function with many local minima and maxima. (b) Convergence path of Fletcher-Reeves CG. Unlike linear CG, convergence does not occur in two steps. (c) Cross-section of the surface corresponding to the first line search. (d) Convergence path of Polak-Ribi` CG. ere n m @ 2 y 0 2 1 -2 2 (d) 4 -250 n 6 0 m I ` F Y 250 2 2 (b) n eA n 4 F y m Y I 4m 1 1 The Nonlinear Conjugate Gradient Method 45 6 4 0 -4 -2 2 4 6 -2 Figure 38: Nonlinear CG can be more effective with periodic restarts. 1 0.75 0.5 0.25 -1 -0.5 -0.25 -0.5 -0.75 -1 0.5 1 1.5 2 Figure 39: The Newton-Raphson method for minimizing a one-dimensional function (solid curve). Starting from the point , calculate the first and second derivatives, and use them to construct a quadratic approximation to the function (dashed curve). A new point is chosen at the base of the parabola. This procedure is iterated until convergence is reached. y n 2 m @ a 2 1 The function The truncated Taylor series approximates with a parabola; we step to the bottom of the parabola (see Figure 39). In fact, if is a quadratic form, then this parabolic approximation is exact, because is just the familiar matrix . In general, the search directions are conjugate if they are -orthogonal. The varies with . The more quickly varies meaning of "conjugate" keeps changing, though, because with , the more quickly the search directions lose conjugacy. On the other hand, the closer is to the solution, the less varies from iteration to iteration. The closer the starting point is to the solution, the more similar the convergence of nonlinear CG is to that of linear CG. To perform an exact line search of a non-quadratic function, repeated steps must be taken along the line is zero; hence, one CG iteration may include many Newton-Raphson iterations. The values of until and must be evaluated at each step. These evaluations may be inexpensive if can be analytically simplified, but if the full matrix must be evaluated repeatedly, the algorithm is prohibitively slow. For some applications, it is possible to circumvent this problem by performing an approximate line search that uses only the diagonal elements of . Of course, there are functions for which it is not possible to evaluate at all. To perform an exact line search without computing , the Secant method approximates the second by evaluating the first derivative at the distinct points 0 and , where is derivative of an arbitrary small nonzero number: 0 2 which becomes a better approximation to the second derivative as and approach zero. If we substitute Expression 58 for the third term of the Taylor expansion (Equation 56), we have Minimize by setting its derivative to zero: Like Newton-Raphson, the Secant method also approximates with a parabola, but instead of choosing the parabola by finding the first and second derivative at a point, it finds the first derivative at two different points (see Figure 40). Typically, we will choose an arbitrary on the first Secant method iteration; on subsequent iterations we will choose to be the value of from the previous Secant method iteration. In other words, if we let denote the value of calculated during Secant iteration , then . 1 Both the Newton-Raphson and Secant methods should be terminated when is reasonably close to the exact solution. Demanding too little precision could cause a failure of convergence, but demanding too fine precision makes the computation unnecessarily slow and gains nothing, because conjugacy will break l ) v w F Y 7B ) v I I t i p b y 7A I b F Y ) v I` F Y t v B) v w ) F I tY I y b A F tY b g hby A b A A v F y eA F y I t Y ) ` Y q I F tY r "t4 sy bB qu T B y y F Y 2 0 (58) (59) b Y ) Y Y n 4 @ m b c y Y b y y i I t ) v w F Y B { |z { y 5 v I eA F Y z B 5 t y A F I Y y )Y ) Y C B Y Y b v b )I b e y f { v I eA Y Y A F tY { |z F Y z t T y dI A Y y eA F I Y Y 46 Jonathan Richard Shewchuk is approximately minimized by setting Expression 57 to zero, giving y A F I Y y eA F I Y ut4 r y C t 64 r b B Y) ) Y ) Y Y The Nonlinear Conjugate Gradient Method 1 47 0.5 -1 1 2 3 4 -0.5 -1 -1.5 Figure 40: The Secant method for minimizing a one-dimensional function (solid curve). Starting from the point , calculate the first derivatives at two different points (here, 0 and 2), and use them to construct a quadratic approximation to the function (dashed curve). Notice that both curves have the same 0, and also at 2. As in the Newton-Raphson method, a new point is chosen at the base slope at of the parabola, and the procedure is iterated until convergence. down quickly anyway if varies much with . Therefore, a quick but inexact line search is often the better policy (for instance, use only a fixed number of Newton-Raphson or Secant method iterations). Unfortunately, inexact line search may lead to the construction of a search direction that is not a descent nonpositive?), and restart CG if necessary direction. A common solution is to test for this eventuality (is by setting . A bigger problem with both methods is that they cannot distinguish minima from maxima. The result of nonlinear CG generally depends strongly on the starting point, and if CG with the Newton-Raphson or Secant method starts near a local maximum, it is likely to converge to that point. Each method has its own advantages. The Newton-Raphson method has a better convergence rate, and is to be preferred if can be calculated (or well approximated) quickly (i.e., in time). The Secant method only requires first derivatives of , but its success may depend on a good choice of the parameter . It is easy to derive a variety of other methods as well. For instance, by sampling at three different points, it is possible to generate a parabola that approximates without the need to calculate even a first derivative of . 14.3. Preconditioning Nonlinear CG can be preconditioned by choosing a preconditioner that approximates and has the 1 is easy to compute. In linear CG, the preconditioner attempts to transform the quadratic property that form so that it is similar to a sphere; a nonlinear CG preconditioner performs this transformation for a region near . Even when it is too expensive to compute the full Hessian , it is often reasonable to compute its diagonal b Y F I a v Y y 9 v y A F I Y )r Y Y I ` F Y b v Y ) r V r 9 Y b v n4 m 6 4 0 -4 -2 2 4 6 -2 Figure 41: The preconditioned nonlinear Conjugate Gradient Method, using the Polak-Ribi` formula and ere a diagonal preconditioner. The space has been "stretched" to show the improvement in circularity of the contour lines around the minimum. for use as a preconditioner. However, be forewarned that if is sufficiently far from a local minimum, the diagonal elements of the Hessian may not all be positive. A preconditioner should be positive-definite, so ) nonpositive diagonal elements cannot be allowed. A conservative solution is to not precondition (set when the Hessian cannot be guaranteed to be positive-definite. Figure 41 demonstrates the convergence of diagonally preconditioned nonlinear CG, with the Polak-Ribi` re formula, on the same function illustrated e at the solution point to precondition every in Figure 37. Here, I have cheated by using the diagonal of iteration. A Notes Conjugate Direction methods were probably first presented by Schmidt [14] in 1908, and were independently reinvented by Fox, Huskey, and Wilkinson [7] in 1948. In the early fifties, the method of Conjugate Gradients was discovered independently by Hestenes [10] and Stiefel [15]; shortly thereafter, they jointly published what is considered the seminal reference on CG [11]. Convergence bounds for CG in terms of Chebyshev polynomials were developed by Kaniel [12]. A more thorough analysis of CG convergence is provided by van der Sluis and van der Vorst [16]. CG was popularized as an iterative method for large, sparse matrices by Reid [13] in 1971. CG was generalized to nonlinear problems in 1964 by Fletcher and Reeves [6], based on work by Davidon [4] and Fletcher and Powell [5]. Convergence of nonlinear CG with inexact line searches was analyzed by Daniel [3]. The choice of for nonlinear CG is discussed by Gilbert and Nocedal [8]. A history and extensive annotated bibliography of CG to the mid-seventies is provided by Golub and O'Leary [9]. Most research since that time has focused on nonsymmetric systems. A survey of iterative methods for the solution of linear systems is offered by Barrett et al. [1]. 9 Y n m 2 48 Jonathan Richard Shewchuk 2 1 Canned Algorithms B Canned Algorithms 49 The code given in this section represents efficient implementations of the algorithms discussed in this article. B1. Steepest Descent Given the inputs 1: , , a starting value , a maximum number of iterations If is divisible by 50 1 This algorithm terminates when the maximum number of iterations 0 . The fast recursive formula for the residual is usually used, but once every 50 iterations, the exact residual is recalculated to remove accumulated floating point error. Of course, the number 50 is arbitrary; for large , might be appropriate. If the tolerance is large, the residual need not be corrected at all (in practice, this correction is rarely used). If the tolerance is close to the limits of the floating point precision of the 2 , and if this test holds true, the exact machine, a test should be added after is evaluated to check if 0 residual should also be recomputed and reevaluated. This prevents the procedure from terminating early due to floating point roundoff error. o 2 else w w w w w ww While and 2 D 0 A r g r y g) r B r kBs r r yeA y r s r )r B c 0 2 0 do o w w wwy xr , and an error tolerance n mr 2 n4m r S 2 has been exceeded, or when 50 B2. Conjugate Gradients Given the inputs 1: Jonathan Richard Shewchuk , , a starting value , a maximum number of iterations While If is divisible by 50 else 1 See the comments at the end of Section B1. Au A r r g z # r ) # y r r B cB r yeA z y # oP# D r)u # r r g B o r 0 0 and 2 0 do o w wx h Ygfe i @d w w Y ww y w y w @ w w 2 Y ww ww w x , and an error tolerance S 2 Canned Algorithms B3. Preconditioned Conjugate Gradients Given the inputs , , a starting value , a (perhaps implicitly defined) preconditioner number of iterations , and an error tolerance 1: 51 While If is divisible by 50 else 1 1 The statement " be in the form of a matrix. 1 " implies that one should apply the preconditioner, which may not actually See also the comments at the end of Section B1. Au A r g z # ) # r y r V r B cB r yeA z y # oP# D u # r r) V B o r 1 0 0 and 2 0 do 9 w wx h Yg e k i @d w w k Y 9w w jw y k w y w @ w w 2 Y w 9j w ww w x 2 r V 9 lw k oϧ , a maximum 52 Jonathan Richard Shewchuk B4. Nonlinear Conjugate Gradients with Newton-Raphson and Fletcher-Reeves Given a function , a starting value , a maximum number of CG iterations , a CG error tolerance 1, a maximum number of Newton-Raphson iterations , and a Newton-Raphson error tolerance 1: 0 0 0 While and 2 0 do 0 Do 1 while and 2 2 If 1 or 0 0 1 This algorithm terminates when the maximum number of iterations 0 . has been exceeded, or when Each Newton-Raphson iteration adds to ; the iterations are terminated when each update falls below a given tolerance ( ), or when the number of iterations exceeds . A fast inexact line and/or by approximating the Hessian with its search can be accomplished by using a small diagonal. Nonlinear CG is restarted (by setting ) whenever a search direction is computed that is not a descent direction. It is also restarted once every iterations, to improve convergence for small . The calculation of may result in a divide-by-zero error. This may occur because the starting point 0 is not sufficiently close to the desired minimum, or because is not twice continuously differentiable. In the former case, the solution is to choose a better starting point or a more sophisticated line search. In the latter case, CG might not be the most appropriate minimization algorithm. n m 2 y I ` F Y s oP o w w ux r w gi ) r A d w r w h YgA e w iٶ r @d w # w r ) #gYz w r z y I F ` Y B sA w 5D ytA z n m `m z w y z t m n m m` r B w ) uw z 2 D Y # oPϨ w # w w # r ) ru w rg Iw F Y B wr ww x Y o r A o w h y 5 y y Y n mr 2 n4m r 52 Canned Algorithms B5. Preconditioned Nonlinear Conjugate Gradients with Secant and Polak-Ribi` re e 53 Given a function , a starting value , a maximum number of CG iterations , a CG error tolerance 1, a Secant method step parameter 0 , a maximum number of Secant method iterations , and a Secant method error tolerance 1: 0 0 Calculate a preconditioner 1 0 While and 2 0 do 0 0 0 Do 1 while and 2 2 Calculate a preconditioner 1 If 1 or 0 0 else 1 This algorithm terminates when the maximum number of iterations 0 . has been exceeded, or when Each Secant method iteration adds to ; the iterations are terminated when each update falls below a given tolerance ( ), or when the number of iterations exceeds . A fast inexact line search can be accomplished by using a small . The parameter 0 determines the value of in Equation 59 for the first step of each Secant method minimization. Unfortunately, it may be necessary to adjust this parameter o y oP b o o I ` F A w A k z w x ww k z A d w h h Yg e w w 9 k' r V) gr @ o # V jw k Y T 9 k Y ) # r w w z 4z w w yr z I F y w Y B oA 5D w w p ts rqp u V @yu twvxy uA y w w y ) v I` F tY w p ) v I b A F tY tY rp ws q b ) w y q B w z 2 D # oϧY# w w w # ) r oY i k w r V 9nw k I` F Y T 9 I ` F Y B wyr ww x b b y o 5 5 y Y n mr 2 n4m r 2 54 to achieve convergence. The Polak-Ribi` re e parameter is Jonathan Richard Shewchuk be taken that the preconditioner form of a matrix. is always positive-definite. The preconditioner is not necessarily in the parameter is negative. It is Nonlinear CG presents several choices: Preconditioned or not, Newton-Raphson method or Secant method or another method, Fletcher-Reeves or Polak-Ribi` re. It should be possible to construct any of the e variations from the versions presented above. (Polak-Ribi` re is almost always to be preferred.) e C Ugly Proofs C1. The Solution to Minimizes the Quadratic Form Suppose is symmetric. Let be a point that satisfies (Equation 3), and let be an error term. Then and minimizes the quadratic form (by symmetry of ) 1 2 1 2 If is positive-definite, then the latter term is positive for all 0; therefore minimizes . Any symmetric matrix has a full complement of orthogonal eigenvectors. To prove this, I will demonstrate for the case of a 4 4 matrix and let you make the obvious generalization to matrices of arbitrary size. It has already been proven that has at least one eigenvector with eigenvalue . Let , which has unit length. Choose three arbitrary vectors 2 3 4 so that the are mutually 1 orthogonal and all of unit length (such vectors can be found by Gram-Schmidt orthogonalization). Let 1 . Note also that for are orthonormal, , and so 1 2 3 4 . Because the Any matrix has at least one eigenvector. To see this, note that det therefore has at least one zero (possibly complex); call it . The matrix and is therefore singular, so there must be a nonzero vector for which an eigenvector, because . 4 I R F B B I 9 u F B V c) i i ) 4 C2. A Symmetric Matrix Has Orthogonal Eigenvectors. is a polynomial in , and has determinant zero 0. The vector is Y 1 2 p ) cB p ) p A deA p B ) td ) cB p d eA p A F I l p p ) p A ` F Y I A d tA )p ) cd ) B A A )p ) p ) A A B ) cI p F ) I p F 1 2 1 2 1 2 (by Equation 3) ) whenever the Polak-Ribi` re e Nonlinear CG is restarted (by setting also restarted once every iterations, to improve convergence for small . j j } }j j n j V j V V m 1 1 1 1 1 "{ ~ ~ "{ }| u{ | u{ }| u{ r w 9 h ' h Yg e 1 1 . Care must A I p F Y p v t 1 2 3 4 1 2 3 4 1 2 3 4 0 0 0 0 0 0 where is a 3 3 symmetric matrix. must have some eigenvalue with eigenvalue . Let be a vector of length 4 whose first element is zero, and whose remaining elements are the elements of . Clearly, 0 0 0 0 0 0 1 1 and The more general statement that a symmetric matrix has orthogonal eigenvectors is proven by induction. For the example above, assume any 3 3 matrix (such as ) has 3 orthogonal eigenvectors; call them 1 , , and they are orthogonal because 2 , and 3 . Then 1, 2 , and 3 are eigenvectors of has orthonormal columns, and therefore maps orthogonal vectors to orthogonal vectors. Thus, has 4 orthogonal eigenvectors. C3. Optimality of Chebyshev Polynomials Chebyshev polynomials are optimal for minimization of expressions like Expression 50 because they increase in magnitude more quickly outside the range 1 1 than any other polynomial that is restricted to have magnitude no greater than one inside the range 1 1 . The Chebyshev polynomial of degree , 1 2 2 1 2 1 can also be expressed on the region 1 1 as cos cos 1 1 1 From this expression (and from Figure 32), one can deduce that the Chebyshev polynomials have the property 1 1 1 and oscillate rapidly between 1 and 1: cos 1 0 1 } } o} " }& " " w W In other words, 1 0 0 0 0, so , and thus is an eigenvector of . Furthermore, 1 are orthogonal. Thus, has at least two orthogonal eigenvectors! 0 1 2 3 4 0 Q q 1, 1 1 1 Ugly Proofs 0. Thus, 55 B Q }& Similarly, the function 2 oscillates in the range that 0 1. 1 on the domain . also satisfies the requirement of degree such that 0 1 and The proof relies on a cute trick. There is no polynomial is better than on the range . To prove this, suppose that there is such a polynomial; then, 1 on the range . It follows that the polynomial has a zero at 0, and also has zeros on the range . Hence, is a polynomial of degree with at least 1 zeros, which is impossible. By contradiction, I conclude that the Chebyshev polynomial of degree optimizes Expression 50. D Homework For the following questions, assume (unless otherwise stated) that you are using exact arithmetic; there is no floating point roundoff error. 1. (Easy.) Prove that the preconditioned Conjugate Gradient method is not affected if the preconditioning matrix is scaled. In other words, for any nonzero constant , show that the sequence of steps taken using the preconditioner is identical to the steps taken using the preconditioner 0 1 . 2. (Hard, but interesting.) Suppose you wish to solve for a symmetric, positive-definite matrix . Unfortunately, the trauma of your linear algebra course has caused you Estimates for Some Computational Techniques in Linear Algebra, Mathematics of Computation 20 (1966), 369378. [13] John K. Reid, On the Method of Conjugate Gradients for the Solution of Large Sparse Systems of Linear Equations, Large Sparse Sets of Linear Equations (London and New York) (John K. Reid, ed.), Academic Press, London and New York, 1971, pp. 231254. [14] E. Schmidt, Title unknown, Rendiconti del Circolo Matematico di Palermo 25 (1908), 5377. [15] Eduard Stiefel, Uber einige Methoden der Relaxationsrechnung, Zeitschrift f r Angewandte Matheu matik und Physik 3 (1952), no. 1, 133. [16] A. van der Sluis and H. A. van der Vorst, The Rate of Convergence of Conjugate Gradients, Numerische Mathematik 48 (1986), no. 5, 543560. ...
View Full Document

Ask a homework question - tutors are online