Kaynağa Gözat

Make bgfs not fail when the cauchy function can't be initialized properly

Simon Ding 4 yıl önce
ebeveyn
işleme
d649b646e1

+ 4 - 1
jplag/src/main/java/de/jplag/clustering/algorithm/BFGS.java

@@ -197,6 +197,7 @@ public class BFGS {
 
         double alam2 = 0.0, f2 = 0.0;
         double a, b, disc, rhs1, rhs2, tmpalam;
+        int runs = 50;
         while (true) {
             // Evaluate the function and gradient at stp
             // and compute the directional derivative.
@@ -213,6 +214,8 @@ public class BFGS {
             } else if (f <= fold + ftol * alam * slope) {
                 // Sufficient function decrease.
                 return f;
+            } else if (runs-- < 0) {
+                return f;
             } else {
                 // Backtrack
                 if (alam == 1.0) {
@@ -490,7 +493,7 @@ public class BFGS {
             if (t[index[i]] >= 0) break;
         }
 
-        double dt = t[i];
+        double dt = i < n ? t[i] : 0;
         for (; dt_min >= dt && i < n; i++) {
             int b = index[i];
             double tb = t[i];