next up previous contents
Next: Debugging Up: No Title Previous: Gathering data

Conjugate gradients

 

The method of conjugate-gradients (Numerical Recipes, Sec. 10.6) can make dramatic improvements in the convergence.

While the theory behind conjugate-gradients is subtle, the implementation is straight-forward. The theory states that at step n, rather than choosing the search direction ( tex2html_wrap_inline399 ) to be along the down-hill gradient

displaymath401

one should search along a direction which is a linear combination of the previous search direction ( tex2html_wrap_inline403 ) and the down-hill gradient,

displaymath405

The ``magic'' linear-combination coefficient tex2html_wrap_inline407 is

displaymath409

Because conjugate-gradients depends upon being relatively near a minimum, it pays to first do a few (say ten) standard steps of line-minimization first. Thus, you should replace the statement

    dir=(-1.)*grad;
in your code with the following code fragment
    if (i<=10) 
      dir=(-1.)*grad;
    else {
      beta= ...
      dir=beta*dir+(-1.)*grad;
    }
where beta is defined as above.

Hint: Don't forget to compute dot products by taking the real part of the corresponding ``dagger product''.





Tomas Arias
Sun Apr 15 22:02:59 EDT 2001