Browse code

round the losses to 12 digits to make them equal

Then equal losses will be sorted on x-coordinates.

Bas Nijholt authored on 22/11/2018 18:58:19
Showing 1 changed files
... ...
@@ -563,8 +563,13 @@ class Learner1D(BaseLearner):
563 563
         def finite_loss(loss, xs):
564 564
             # If the loss is infinite we return the
565 565
             # distance between the two points.
566
-            return (loss if not math.isinf(loss)
567
-                    else (xs[1] - xs[0]) / self._scale[0])
566
+            if math.isinf(loss):
567
+                loss = (xs[1] - xs[0]) / self._scale[0]
568
+
569
+            # We round the loss to 12 digits such that losses
570
+            # are equal up to numerical precision will be considered
571
+            # equal.
572
+            return round(loss, ndigits=12)
568 573
 
569 574
         quals = [(-finite_loss(loss, x), x, 1)
570 575
                  for x, loss in self.losses_combined.items()]