From 6f41343492ca9a6100443f535625012abdfd77d0 Mon Sep 17 00:00:00 2001
From: Michael Chappell <chappell@fmrib.ox.ac.uk>
Date: Thu, 19 Aug 2010 15:51:55 +0000
Subject: [PATCH] Bug fixes to Variable Metric Convergence detection

---
 nonlin.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/nonlin.cpp b/nonlin.cpp
index cfe4d9f..084045d 100644
--- a/nonlin.cpp
+++ b/nonlin.cpp
@@ -622,6 +622,7 @@ NonlinOut varmet(const NonlinParam& p, const NonlinCF& cfo)
     else if (status == LM_LAMBDA_NILL) { // This means we might be heading uphill and should restart
       if (p.NextRestart()) { // If we have spare restarts
         p.SetCF(p.CF());      // Another copy of old value
+        p.SetPar(p.Par());    // Another copy of old values
         iH.reset();           // Back to being unity matrix
         pdir = -grad;
         continue;
@@ -634,7 +635,10 @@ NonlinOut varmet(const NonlinParam& p, const NonlinCF& cfo)
     ColumnVector dpar = newpar - p.Par();
     p.SetPar(newpar);
     p.SetCF(newcf);
-    if (zero_par_step_conv(dpar,p.Par(),p.FractionalParameterTolerance())) {p.SetStatus(NL_PARCONV); return(p.Status());}
+    // cout << "p.FractionalParameterTolerance() = " << p.FractionalParameterTolerance() << endl;
+    // cout << "P.Par() = " << p.Par() << endl;
+    // cout << "dpar = " << dpar << endl;
+    if (zero_par_step_conv(p.Par(),dpar,p.FractionalParameterTolerance())) {p.SetStatus(NL_PARCONV); return(p.Status());}
     // Get gradient at new point
     ColumnVector newgrad = sf*cfo.grad(p.Par());
     // Test for convergence based on "zero" gradient
-- 
GitLab