You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2020/09/09 22:21:51 UTC

[incubator-datasketches-java] branch RelativeErrorQuantiles updated: Reversed changes to min, max in KLL. My Mistake.

This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch RelativeErrorQuantiles
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-java.git


The following commit(s) were added to refs/heads/RelativeErrorQuantiles by this push:
     new c0c87ea  Reversed changes to min, max in KLL. My Mistake.
c0c87ea is described below

commit c0c87eab0bcfd7bb79470d85edf6ae282c1e1025
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Wed Sep 9 15:21:23 2020 -0700

    Reversed changes to min, max in KLL. My Mistake.
---
 .../apache/datasketches/kll/KllFloatsSketch.java   | 27 +++++++++++++---------
 .../apache/datasketches/quantiles/ItemsSketch.java |  2 +-
 .../datasketches/kll/KllFloatsSketchTest.java      | 14 +++++------
 .../quantiles/HeapUpdateDoublesSketchTest.java     |  1 -
 4 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java b/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java
index 275a9c5..8459105 100644
--- a/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java
+++ b/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java
@@ -246,8 +246,8 @@ public class KllFloatsSketch {
 
   // Specific to the floats sketch
   private float[] items_; // the continuous array of float items
-  private float minValue_ = Float.MAX_VALUE;
-  private float maxValue_ = Float.MIN_VALUE;
+  private float minValue_;
+  private float maxValue_;
 
   /**
    * Heap constructor with the default <em>k = 200</em>, which has a rank error of about 1.65%.
@@ -279,8 +279,8 @@ public class KllFloatsSketch {
     numLevels_ = 1;
     levels_ = new int[] {k, k};
     items_ = new float[k];
-    minValue_ = Float.MAX_VALUE;
-    maxValue_ = Float.MIN_VALUE;
+    minValue_ = Float.NaN;
+    maxValue_ = Float.NaN;
     isLevelZeroSorted_ = false;
 
   }
@@ -301,8 +301,8 @@ public class KllFloatsSketch {
       isLevelZeroSorted_ = false;
       minK_ = k_;
       items_ = new float[k_];
-      minValue_ = Float.MAX_VALUE;
-      maxValue_ = Float.MIN_VALUE;
+      minValue_ = Float.NaN;
+      maxValue_ = Float.NaN;
     } else {
       if (isSingleItem) {
         n_ = 1;
@@ -765,8 +765,8 @@ public class KllFloatsSketch {
       mergeHigherLevels(other, finalN);
     }
     //update min, max values, n
-    if (!Float.isFinite(minValue_) || (other.minValue_ < minValue_)) { minValue_ = other.minValue_; }
-    if (!Float.isFinite(maxValue_) || (other.maxValue_ > maxValue_)) { maxValue_ = other.maxValue_; }
+    if (Float.isNaN(minValue_) || (other.minValue_ < minValue_)) { minValue_ = other.minValue_; }
+    if (Float.isNaN(maxValue_) || (other.maxValue_ > maxValue_)) { maxValue_ = other.maxValue_; }
     n_ = finalN;
 
     assertCorrectTotalWeight();
@@ -887,9 +887,14 @@ public class KllFloatsSketch {
    * @param value an item from a stream of items. NaNs are ignored.
    */
   public void update(final float value) {
-    if (!Float.isFinite(value)) { return; }
-    minValue_ = (value < minValue_) ? value : minValue_;
-    maxValue_ = (value > maxValue_) ? value : maxValue_;
+    if (Float.isNaN(value)) { return; }
+    if (isEmpty()) {
+      minValue_ = value;
+      maxValue_ = value;
+    } else {
+      if (value < minValue_) { minValue_ = value; }
+      if (value > maxValue_) { maxValue_ = value; }
+    }
     if (levels_[0] == 0) {
       compressWhileUpdating();
     }
diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java b/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java
index 3121673..db4ffc7 100644
--- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java
+++ b/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java
@@ -349,7 +349,7 @@ public final class ItemsSketch<T> {
    * specify the number of evenly spaced fractional ranks.
    *
    * @param evenlySpaced an integer that specifies the number of evenly spaced fractional ranks.
-   * This must be a positive integer greater than 0. A value of 1 will return the min value.
+   * This must be a positive integer greater than 1.
    * A value of 2 will return the min and the max value. A value of 3 will return the min,
    * the median and the max value, etc.
    *
diff --git a/src/test/java/org/apache/datasketches/kll/KllFloatsSketchTest.java b/src/test/java/org/apache/datasketches/kll/KllFloatsSketchTest.java
index 30e7e50..d439757 100644
--- a/src/test/java/org/apache/datasketches/kll/KllFloatsSketchTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllFloatsSketchTest.java
@@ -41,16 +41,14 @@ public class KllFloatsSketchTest {
   @Test
   public void empty() {
     final KllFloatsSketch sketch = new KllFloatsSketch();
-    sketch.update(Float.NaN); // these must not change anything
-    sketch.update(Float.POSITIVE_INFINITY);
-    sketch.update(Float.NEGATIVE_INFINITY);
+    sketch.update(Float.NaN); // this must not change anything
     assertTrue(sketch.isEmpty());
     assertEquals(sketch.getN(), 0);
     assertEquals(sketch.getNumRetained(), 0);
     assertTrue(Double.isNaN(sketch.getRank(0)));
-    assertEquals(sketch.getMinValue(), Float.MAX_VALUE);
-    assertEquals(sketch.getMaxValue(), Float.MIN_VALUE);
-    assertTrue(Double.isNaN(sketch.getQuantile(0.5)));
+    assertTrue(Float.isNaN(sketch.getMinValue()));
+    assertTrue(Float.isNaN(sketch.getMaxValue()));
+    assertTrue(Float.isNaN(sketch.getQuantile(0.5)));
     assertNull(sketch.getQuantiles(new double[] {0}));
     assertNull(sketch.getPMF(new float[] {0}));
     assertNotNull(sketch.toString(true, true));
@@ -318,8 +316,8 @@ public class KllFloatsSketchTest {
     assertEquals(sketch2.getNumRetained(), sketch1.getNumRetained());
     assertEquals(sketch2.getN(), sketch1.getN());
     assertEquals(sketch2.getNormalizedRankError(false), sketch1.getNormalizedRankError(false));
-    assertEquals(sketch2.getMinValue(), Float.MAX_VALUE);
-    assertEquals(sketch2.getMaxValue(), Float.MIN_VALUE);
+    assertTrue(Float.isNaN(sketch2.getMinValue()));
+    assertTrue(Float.isNaN(sketch2.getMaxValue()));
     assertEquals(sketch2.getSerializedSizeBytes(), sketch1.getSerializedSizeBytes());
   }
 
diff --git a/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java
index 2a51f33..8d7b903 100644
--- a/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketchTest.java
@@ -899,7 +899,6 @@ public class HeapUpdateDoublesSketchTest {
   public void checkEvenlySpaced() {
     int n = 11;
     double[] es = org.apache.datasketches.Util.evenlySpaced(0.0, 1.0, n);
-        //QuantilesHelper.getEvenlySpacedRanks(n);
     int len = es.length;
     for (int j=0; j<len; j++) {
       double f = es[j];


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org