]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
regress: speed up range expansion in robust regression
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 27 Jun 2017 08:03:05 +0000 (10:03 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 27 Jun 2017 13:29:01 +0000 (15:29 +0200)
Instead of repeatedly expanding the range of b with the same increment,
double the range on each iteration to speed up the expansion. Also, add
a sanity check for the interval.

regress.c

index c4f8dd581189fc8fd7e31410d128ab919e61e193..ea8cbecc5489f38513219f91bb8c7c7b4ea7b557 100644 (file)
--- a/regress.c
+++ b/regress.c
@@ -566,24 +566,18 @@ RGR_FindBestRobustRegression
        Estimate standard deviation of b and expand range about b based
        on that. */
     sb = sqrt(s2 * W/V);
-    if (sb > tol) {
-      incr = 3.0 * sb;
-    } else {
-      incr = 3.0 * tol;
-    }
+    incr = MAX(sb, tol);
   
-    blo = b;
-    bhi = b;
-
     do {
-      /* Make sure incr is significant to blo and bhi */
-      while (bhi + incr == bhi || blo - incr == blo) {
-        incr *= 2;
-      }
+      incr *= 2.0;
+
+      /* Give up if the interval is too large */
+      if (incr > 100.0)
+        return 0;
+
+      blo = b - incr;
+      bhi = b + incr;
 
-      blo -= incr;
-      bhi += incr;
-      
       /* We don't want 'a' yet */
       eval_robust_residual(x + start, y + start, n_points, blo, &a, &rlo);
       eval_robust_residual(x + start, y + start, n_points, bhi, &a, &rhi);