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 2024/02/14 02:29:27 UTC

(datasketches-java) branch improve_partition_boundaries created (now d0ae2b39)

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

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


      at d0ae2b39 Merge branch 'master' into improve_partition_boundaries

This branch includes the following new commits:

     new cc77ef08 Primary changes (so far) are to ItemsSketchSortedView::getPartitionBoundaries(..).
     new 2a71af49 Merge branch 'minor_changes_to_boundsRule' into improve_partition_boundaries
     new 4b652d58 Turned printing off.
     new 1bd6adb2 Improve ItemsSketch.toString(summary) printout.
     new 3a9402a9 This fixes a bug discovered in recent Druid testing.
     new d0ae2b39 Merge branch 'master' into improve_partition_boundaries

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


(datasketches-java) 01/06: Primary changes (so far) are to ItemsSketchSortedView::getPartitionBoundaries(..).

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cc77ef0815af8c18632c82893dfa2c1120307545
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sat Feb 10 11:54:33 2024 -0800

    Primary changes (so far) are to
    ItemsSketchSortedView::getPartitionBoundaries(..).
    
    This change dramatically improved the handling of the end points and
    isolates this adjustment from the SortedView class members.
    
    The changes to SortedViewIterator and GenericSortedViewIterator are to
    add some functionality of getting the key iteration variables without
    having to specify the sorting criteria.
    
    Added a specific test to check the upper and lower boundary adjustments
    of a partition.
---
 .../quantiles/ItemsSketchSortedView.java           | 73 +++++++++++++-----
 .../quantilescommon/GenericSortedViewIterator.java | 25 ++++++-
 .../quantilescommon/SortedViewIterator.java        | 35 +++++++--
 .../ItemsSketchPartitionBoundariesTest.java        | 87 ++++++++++++++++++++++
 4 files changed, 191 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java b/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java
index 9638a9a9..fa6d9541 100644
--- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java
+++ b/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java
@@ -156,26 +156,58 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T>, Partition
     if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
     final long totalN = this.totalN;
     final int svLen = cumWeights.length;
-    //adjust ends of sortedView arrays
-    cumWeights[0] = 1L;
-    cumWeights[svLen - 1] = totalN;
-    quantiles[0] = this.getMinItem();
-    quantiles[svLen - 1] = this.getMaxItem();
-
-    final double[] evSpNormRanks = evenlySpacedDoubles(0, 1.0, numEquallySized + 1);
-    final int len = evSpNormRanks.length;
-    final T[] evSpQuantiles = (T[]) Array.newInstance(clazz, len);
-    final long[] evSpNatRanks = new long[len];
-    for (int i = 0; i < len; i++) {
-      final int index = getQuantileIndex(evSpNormRanks[i], searchCrit);
-      evSpQuantiles[i] = quantiles[index];
-      evSpNatRanks[i] = cumWeights[index];
+    if (numEquallySized > svLen / 2) {
+      throw new IllegalArgumentException(QuantilesAPI.UNSUPPORTED_MSG
+          + " Number of requested partitions is too large for this sized sketch. "
+          + "Requested Partitions: " + numEquallySized + " > "
+          + "Retained Items: " + svLen + " / 2.");
+    }
+
+    final double[] searchNormRanks = evenlySpacedDoubles(0, 1.0, numEquallySized + 1);
+    final int partArrLen = searchNormRanks.length;
+    final T[] partQuantiles = (T[]) Array.newInstance(clazz, partArrLen);
+    final long[] partNatRanks = new long[partArrLen];
+    final double[] partNormRanks = new double[partArrLen];
+    //adjust ends
+    int adjLen = svLen;
+    final boolean adjLow = quantiles[0] != minItem;
+    final boolean adjHigh = quantiles[svLen - 1] != maxItem;
+    adjLen += adjLow ? 1 : 0;
+    adjLen += adjHigh ? 1 : 0;
+
+    final T[] adjQuantiles;
+    final long[] adjCumWeights;
+    if (adjLen > svLen) {
+      adjQuantiles = (T[]) new Object[adjLen];
+      adjCumWeights = new long[adjLen];
+      final int offset = adjLow ? 1 : 0;
+      System.arraycopy(quantiles, 0, adjQuantiles, offset, svLen);
+      System.arraycopy(cumWeights,0, adjCumWeights, offset, svLen);
+      if (adjLow) {
+        adjQuantiles[0] = minItem;
+        adjCumWeights[0] = 1;
+      }
+      if (adjHigh) {
+        adjQuantiles[adjLen - 1] = maxItem;
+        adjCumWeights[adjLen - 1] = cumWeights[svLen - 1];
+        adjCumWeights[adjLen - 2] = cumWeights[svLen - 1] - 1;
+      }
+    } else {
+      adjQuantiles = quantiles;
+      adjCumWeights = cumWeights;
+    }
+    for (int i = 0; i < partArrLen; i++) {
+      final int index = getQuantileIndex(searchNormRanks[i], adjCumWeights, searchCrit);
+      partQuantiles[i] = adjQuantiles[index];
+      final long cumWt = adjCumWeights[index];
+      partNatRanks[i] = cumWt;
+      partNormRanks[i] = (double)cumWt / totalN;
     }
     final GenericPartitionBoundaries<T> gpb = new GenericPartitionBoundaries<>(
         this.totalN,
-        evSpQuantiles,
-        evSpNatRanks,
-        evSpNormRanks,
+        partQuantiles,
+        partNatRanks,
+        partNormRanks,
         getMaxItem(),
         getMinItem(),
         searchCrit);
@@ -198,13 +230,14 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T>, Partition
   public T getQuantile(final double rank, final QuantileSearchCriteria searchCrit) {
     if (isEmpty()) { throw new IllegalArgumentException(EMPTY_MSG); }
     QuantilesUtil.checkNormalizedRankBounds(rank);
-    final int index = getQuantileIndex(rank, searchCrit);
+    final int index = getQuantileIndex(rank, cumWeights, searchCrit);
     return quantiles[index];
   }
 
-  private int getQuantileIndex(final double rank, final QuantileSearchCriteria searchCrit) {
+  private int getQuantileIndex(final double normRank, final long[] cumWeights,
+      final QuantileSearchCriteria searchCrit) {
     final int len = cumWeights.length;
-    final double naturalRank = getNaturalRank(rank, totalN, searchCrit);
+    final double naturalRank = getNaturalRank(normRank, totalN, searchCrit);
     final InequalitySearch crit = (searchCrit == INCLUSIVE) ? InequalitySearch.GE : InequalitySearch.GT;
     final int index = InequalitySearch.find(cumWeights, 0, len - 1, naturalRank, crit);
     if (index == -1) { return len - 1; }
diff --git a/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java
index 5a5c00e2..fcfefa12 100644
--- a/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java
+++ b/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java
@@ -19,6 +19,8 @@
 
 package org.apache.datasketches.quantilescommon;
 
+import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
+
 /**
  * Iterator over quantile sketches of generic type.
  * @param <T> The generic quantile type
@@ -32,10 +34,10 @@ public class GenericSortedViewIterator<T> extends SortedViewIterator {
   }
 
   /**
-   * Gets the quantile at the current index.
+   * Gets the quantile at the current index
+   * This is equivalent to <i>getQuantile(INCLUSIVE)</i>.
    *
-   * <p>Don't call this before calling next() for the first time
-   * or after getting false from next().</p>
+   * <p>Don't call this before calling next() for the first time or after getting false from next().</p>
    *
    * @return the quantile at the current index.
    */
@@ -43,4 +45,21 @@ public class GenericSortedViewIterator<T> extends SortedViewIterator {
     return quantiles[index];
   }
 
+  /**
+   * Gets the quantile at the current index (or previous index)
+   * based on the chosen search criterion.
+   *
+   * <p>Don't call this before calling next() for the first time or after getting false from next().</p>
+   *
+   * @param searchCrit if INCLUSIVE, includes the quantile at the current index.
+   * Otherwise, returns the quantile of the previous index.
+   *
+   * @return the quantile at the current index (or previous index)
+   * based on the chosen search criterion. If the chosen search criterion is <i>EXCLUSIVE</i> and
+   * the current index is at zero, this will return <i>null</i>.
+   */
+  public T getQuantile(final QuantileSearchCriteria searchCrit) {
+    if (searchCrit == INCLUSIVE) { return quantiles[index]; }
+    return (index == 0) ? null : quantiles[index - 1];
+  }
 }
diff --git a/src/main/java/org/apache/datasketches/quantilescommon/SortedViewIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/SortedViewIterator.java
index 06c298d4..01af51ea 100644
--- a/src/main/java/org/apache/datasketches/quantilescommon/SortedViewIterator.java
+++ b/src/main/java/org/apache/datasketches/quantilescommon/SortedViewIterator.java
@@ -48,17 +48,29 @@ public class SortedViewIterator {
     index = -1;
   }
 
+  /**
+   * Gets the natural rank at the current index.
+   * This is equivalent to <i>getNaturalRank(INCLUSIVE)</i>.
+   *
+   * <p>Don't call this before calling next() for the first time or after getting false from next().</p>
+   *
+   * @return the natural rank at the current index.
+   */
+  public long getNaturalRank() {
+    return cumWeights[index];
+  }
+
   /**
    * Gets the natural rank at the current index (or previous index) based on the chosen search criterion.
    * This is also referred to as the "cumulative weight". The natural rank is a number in the range <i>[1, N]</i>,
    * where <i>N</i> ({@link #getN()}) is the total number of items fed to the sketch.
    *
-   * <p>Don't call this before calling next() for the first time
-   * or after getting false from next().</p>
+   * <p>Don't call this before calling next() for the first time or after getting false from next().</p>
    *
    * @param searchCrit if INCLUSIVE, includes the weight of the item at the current index in the computation of
    * the natural rank.
    * Otherwise, it will return the natural rank of the previous index.
+   *
    * @return the natural rank at the current index (or previous index) based on the chosen search criterion.
    */
   public long getNaturalRank(final QuantileSearchCriteria searchCrit) {
@@ -74,16 +86,28 @@ public class SortedViewIterator {
     return totalN;
   }
 
+  /**
+   * Gets the normalized rank at the current index.
+   * This is equivalent to <i>getNormalizedRank(INCLUSIVE)</i>.
+   *
+   * <p>Don't call this before calling next() for the first time or after getting false from next().</p>
+   *
+   * @return the normalized rank at the current index
+   */
+  public double getNormalizedRank() {
+    return (double) getNaturalRank() / totalN;
+  }
+
   /**
    * Gets the normalized rank at the current index (or previous index)
    * based on the chosen search criterion. Where <i>normalized rank = natural rank / N</i> ({@link #getN()})
    * and is a fraction in the range (0,1.0].
    *
-   * <p>Don't call this before calling next() for the first time
-   * or after getting false from next().</p>
+   * <p>Don't call this before calling next() for the first time or after getting false from next().</p>
    *
    * @param searchCrit if INCLUSIVE, includes the normalized rank at the current index.
    * Otherwise, returns the normalized rank of the previous index.
+   *
    * @return the normalized rank at the current index (or previous index)
    * based on the chosen search criterion.
    */
@@ -94,8 +118,7 @@ public class SortedViewIterator {
   /**
    * Gets the weight contribution of the item at the current index.
    *
-   * <p>Don't call this before calling next() for the first time
-   * or after getting false from next().</p>
+   * <p>Don't call this before calling next() for the first time or after getting false from next().</p>
    *
    * @return the weight contribution of the item at the current index.
    */
diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
new file mode 100644
index 00000000..a980c01b
--- /dev/null
+++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.quantiles;
+
+import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Comparator;
+
+import org.apache.datasketches.quantilescommon.GenericPartitionBoundaries;
+import org.apache.datasketches.quantilescommon.GenericSortedViewIterator;
+import org.testng.annotations.Test;
+
+public class ItemsSketchPartitionBoundariesTest {
+
+  @Test
+  public void checkSimpleEndsAdjustment() {
+    final String[] quantiles = {"2","4","6","7"};
+    final long[] cumWeights = {2, 4, 6, 8};
+    final long totalN = 8;
+    final Comparator<String> comparator = Comparator.naturalOrder();
+    final String maxItem = "8";
+    final String minItem = "1";
+    ItemsSketchSortedViewString sv = new ItemsSketchSortedViewString(
+        quantiles, cumWeights, totalN, comparator, maxItem, minItem);
+
+    GenericSortedViewIterator<String> itr = sv.iterator();
+    while (itr.next()) {
+      println(itr.getNaturalRank(INCLUSIVE) + ", " + itr.getQuantile(INCLUSIVE));
+    }
+    GenericPartitionBoundaries<String> gpb = sv.getPartitionBoundaries(2);
+    String[] boundaries = gpb.getBoundaries();
+    long[] natRanks = gpb.getNaturalRanks();
+    double[] normRanks = gpb.getNormalizedRanks();
+    long[] deltaItems = gpb.getNumDeltaItems();
+    int numParts = gpb.getNumPartitions();
+    String maxItm = gpb.getMaxItem();
+    String minItm = gpb.getMinItem();
+    assertEquals(boundaries, new String[] {"1","4","8"});
+    assertEquals(natRanks, new long[] {1,4,8});
+    assertEquals(normRanks, new double[] {.125,.5,1.0});
+    assertEquals(deltaItems, new long[] {0,4,4});
+    assertEquals(numParts, 2);
+    assertEquals(maxItm, "8");
+    assertEquals(minItm, "1");
+  }
+
+  @Test
+  public void printlnTest() {
+    println("PRINTING: "+this.getClass().getName());
+  }
+
+  private final static boolean enablePrinting = true;
+
+  /**
+   * @param format the format
+   * @param args the args
+   */
+  static final void printf(final String format, final Object ...args) {
+    if (enablePrinting) { System.out.printf(format, args); }
+  }
+
+  /**
+   * @param o the Object to println
+   */
+  static final void println(final Object o) {
+    if (enablePrinting) { System.out.println(o.toString()); }
+  }
+
+}


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


(datasketches-java) 02/06: Merge branch 'minor_changes_to_boundsRule' into improve_partition_boundaries

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2a71af49ca4c28102929619e4f9fbef7b527f201
Merge: cc77ef08 bae6ab5b
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sat Feb 10 12:15:50 2024 -0800

    Merge branch 'minor_changes_to_boundsRule' into improve_partition_boundaries

 .../apache/datasketches/partitions/BoundsRule.java |  7 ++++++-
 .../datasketches/partitions/Partitioner.java       | 22 ++++++++++++++--------
 2 files changed, 20 insertions(+), 9 deletions(-)


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


(datasketches-java) 05/06: This fixes a bug discovered in recent Druid testing.

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3a9402a9637e469a25d09c3173c9730307ab28d0
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Tue Feb 13 18:26:37 2024 -0800

    This fixes a bug discovered in recent Druid testing.
    
    Makes other improvements to the getPartionBoundaries code.
---
 .../quantiles/ItemsSketchSortedView.java           | 28 ++++++++++++++++------
 .../ItemsSketchPartitionBoundariesTest.java        |  3 ++-
 .../quantiles/ItemsSketchSortedViewString.java     |  5 ++--
 .../datasketches/quantiles/ItemsSketchTest.java    |  3 ++-
 .../quantilescommon/CrossCheckQuantilesTest.java   |  2 +-
 5 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java b/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java
index fa6d9541..862f54d7 100644
--- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java
+++ b/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java
@@ -19,6 +19,7 @@
 
 package org.apache.datasketches.quantiles;
 
+import static org.apache.datasketches.quantiles.ClassicUtil.getNormalizedRankError;
 import static org.apache.datasketches.quantilescommon.GenericInequalitySearch.find;
 import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
 import static org.apache.datasketches.quantilescommon.QuantilesAPI.EMPTY_MSG;
@@ -55,6 +56,7 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T>, Partition
   private final T maxItem;
   private final T minItem;
   private final Class<T> clazz;
+  private final int k;
 
   /**
    * Construct from elements for testing.
@@ -70,7 +72,8 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T>, Partition
       final long totalN,
       final Comparator<T> comparator,
       final T maxItem,
-      final T minItem) {
+      final T minItem,
+      final int k) {
     this.quantiles = quantiles;
     this.cumWeights = cumWeights;
     this.totalN = totalN;
@@ -78,6 +81,7 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T>, Partition
     this.maxItem = maxItem;
     this.minItem = minItem;
     this.clazz = (Class<T>)quantiles[0].getClass();
+    this.k = k;
   }
 
   /**
@@ -93,9 +97,10 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T>, Partition
     this.quantiles = (T[]) Array.newInstance(sketch.clazz, numQuantiles);
     this.minItem = sketch.minItem_;
     this.maxItem = sketch.maxItem_;
-    cumWeights = new long[numQuantiles];
-    comparator = sketch.getComparator();
-    clazz = sketch.clazz;
+    this.cumWeights = new long[numQuantiles];
+    this.comparator = sketch.getComparator();
+    this.clazz = sketch.clazz;
+    this.k = sketch.getK();
 
     final Object[] combinedBuffer = sketch.getCombinedBuffer();
     final int baseBufferCount = sketch.getBaseBufferCount();
@@ -155,12 +160,21 @@ public class ItemsSketchSortedView<T> implements GenericSortedView<T>, Partition
       final QuantileSearchCriteria searchCrit) {
     if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
     final long totalN = this.totalN;
+    final double delta = getNormalizedRankError(k, true) * totalN;
+    final int maxParts = (int) (totalN / Math.ceil(delta * 2) );
     final int svLen = cumWeights.length;
+    if (numEquallySized > maxParts) {
+      throw new SketchesArgumentException(QuantilesAPI.UNSUPPORTED_MSG
+          + "Requested number of partitions is too large for this sized sketch. "
+          + "It exceeds maximum number of partitions allowed by the error threshold for this size sketch."
+          + "Requested Partitions: " + numEquallySized + " > " + maxParts);
+    }
     if (numEquallySized > svLen / 2) {
-      throw new IllegalArgumentException(QuantilesAPI.UNSUPPORTED_MSG
-          + " Number of requested partitions is too large for this sized sketch. "
+      throw new SketchesArgumentException(QuantilesAPI.UNSUPPORTED_MSG
+          + "Requested number of partitions is too large for this sized sketch. "
+          + "It exceeds maximum number of retained items divided by 2."
           + "Requested Partitions: " + numEquallySized + " > "
-          + "Retained Items: " + svLen + " / 2.");
+          + "Retained Items / 2: " + (svLen / 2));
     }
 
     final double[] searchNormRanks = evenlySpacedDoubles(0, 1.0, numEquallySized + 1);
diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
index 7cafbc39..03c41776 100644
--- a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
@@ -29,6 +29,7 @@ import org.apache.datasketches.quantilescommon.GenericSortedViewIterator;
 import org.testng.annotations.Test;
 
 public class ItemsSketchPartitionBoundariesTest {
+  private static final int k = 128;
 
   @Test
   public void checkSimpleEndsAdjustment() {
@@ -39,7 +40,7 @@ public class ItemsSketchPartitionBoundariesTest {
     final String maxItem = "8";
     final String minItem = "1";
     ItemsSketchSortedViewString sv = new ItemsSketchSortedViewString(
-        quantiles, cumWeights, totalN, comparator, maxItem, minItem);
+        quantiles, cumWeights, totalN, comparator, maxItem, minItem, k);
 
     GenericSortedViewIterator<String> itr = sv.iterator();
     while (itr.next()) {
diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java
index 0dbf5bde..09a8accd 100644
--- a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java
+++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java
@@ -32,7 +32,8 @@ public class ItemsSketchSortedViewString extends ItemsSketchSortedView<String> {
       final long totalN,
       final Comparator<String> comparator,
       final String maxItem,
-      final String minItem) {
-    super(quantiles, cumWeights, totalN, comparator, maxItem, minItem);
+      final String minItem,
+      final int k) {
+    super(quantiles, cumWeights, totalN, comparator, maxItem, minItem, k);
   }
 }
diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java
index 6d1b0d0c..3b458a56 100644
--- a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.datasketches.quantiles;
 
+import static org.apache.datasketches.quantiles.PreambleUtil.DEFAULT_K;
 import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.EXCLUSIVE;
 import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
 import static org.testng.Assert.assertEquals;
@@ -618,7 +619,7 @@ public class ItemsSketchTest {
     Double[] qArr = {8.0, 10.0, 10.0, 20.0};
     long[] cwArr =  {1,  3,  4,  5};
     Comparator<Double> comp = Comparator.naturalOrder();
-    ItemsSketchSortedView<Double> sv = new ItemsSketchSortedView<>(qArr, cwArr, 5L, comp, 20.0, 8.0);
+    ItemsSketchSortedView<Double> sv = new ItemsSketchSortedView<>(qArr, cwArr, 5L, comp, 20.0, 8.0, DEFAULT_K);
     double[] ranks = {0, .1, .2, .3, .6, .7, .8, .9, 1.0};
     Double[] qOut = new Double[9];
     for (int i = 0; i < ranks.length; i++) {
diff --git a/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java b/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java
index 2cbc006b..d66bf5f3 100644
--- a/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java
+++ b/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java
@@ -349,7 +349,7 @@ public class CrossCheckQuantilesTest {
     kllItemsSV = new KllItemsSketchSortedViewString(svIValues[set], svCumWeights[set], totalN[set],
         comparator, svImax, svImin);
     itemsSV = new ItemsSketchSortedViewString(svIValues[set], svCumWeights[set], totalN[set],
-        comparator, svImax, svImin);
+        comparator, svImax, svImin, k);
   }
 
   private final static ReqSketchSortedView getRawReqSV(


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


(datasketches-java) 04/06: Improve ItemsSketch.toString(summary) printout.

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1bd6adb2d9e283b9980045aebf6b279baa8335fd
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Mon Feb 12 20:39:36 2024 -0800

    Improve ItemsSketch.toString(summary) printout.
---
 .../apache/datasketches/quantiles/ItemsUtil.java   | 54 +++++++++++-----------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java b/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java
index bf42dd18..8138464c 100644
--- a/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java
+++ b/src/main/java/org/apache/datasketches/quantiles/ItemsUtil.java
@@ -20,6 +20,9 @@
 package org.apache.datasketches.quantiles;
 
 import static org.apache.datasketches.common.Util.LS;
+import static org.apache.datasketches.quantiles.ClassicUtil.computeNumLevelsNeeded;
+import static org.apache.datasketches.quantiles.ClassicUtil.computeValidLevels;
+import static org.apache.datasketches.quantiles.ClassicUtil.getNormalizedRankError;
 
 import java.util.Arrays;
 
@@ -85,7 +88,7 @@ final class ItemsUtil {
     final long bitPattern = sketch.getBitPattern();
 
     if (dataDetail) {
-      sb.append(ClassicUtil.LS).append("### ").append(thisSimpleName).append(" DATA DETAIL: ").append(ClassicUtil.LS);
+      sb.append(LS).append("### ").append(thisSimpleName).append(" DATA DETAIL: ").append(LS);
       final Object[] items  = sketch.getCombinedBuffer();
 
       //output the base buffer
@@ -95,7 +98,7 @@ final class ItemsUtil {
           sb.append(' ').append(items[i]);
         }
       }
-      sb.append(ClassicUtil.LS);
+      sb.append(LS);
       //output all the levels
       final int numItems = combAllocCount;
       if (numItems > (2 * k)) {
@@ -105,46 +108,45 @@ final class ItemsUtil {
             final int levelNum = j > (2 * k) ? (j - (2 * k)) / k : 0;
             final String validLvl = ((1L << levelNum) & bitPattern) > 0 ? "    T  " : "    F  ";
             final String lvl = String.format("%5d", levelNum);
-            sb.append(ClassicUtil.LS).append("   ").append(validLvl).append(" ").append(lvl).append(":");
+            sb.append(LS).append("   ").append(validLvl).append(" ").append(lvl).append(":");
           }
           sb.append(' ').append(items[j]);
         }
-        sb.append(ClassicUtil.LS);
+        sb.append(LS);
       }
-      sb.append("### END DATA DETAIL").append(ClassicUtil.LS);
+      sb.append("### END DATA DETAIL").append(LS);
     }
 
     if (sketchSummary) {
       final long n = sketch.getN();
       final String nStr = String.format("%,d", n);
-      final int numLevels = ClassicUtil.computeNumLevelsNeeded(k, n);
-      final String bufCntStr = String.format("%,d", combAllocCount);
+      final String baseBufCntStr = String.format("%,d", bbCount);
+      final String cBufCntStr = String.format("%,d", combAllocCount);
+      final int totNumLevels = computeNumLevelsNeeded(k, n);
+      final int numValidSamples = sketch.getNumRetained();
+      final String numValidSampStr = String.format("%,d", numValidSamples);
       final int preBytes = sketch.isEmpty() ? Long.BYTES : 2 * Long.BYTES;
-      final double epsPmf = ClassicUtil.getNormalizedRankError(k, true);
+      final double epsPmf = getNormalizedRankError(k, true);
       final String epsPmfPctStr = String.format("%.3f%%", epsPmf * 100.0);
-      final double eps =  ClassicUtil.getNormalizedRankError(k, false);
+      final double eps =  getNormalizedRankError(k, false);
       final String epsPctStr = String.format("%.3f%%", eps * 100.0);
-      final int numSamples = sketch.getNumRetained();
-      final String numSampStr = String.format("%,d", numSamples);
       final T minItem = sketch.isEmpty() ? null : sketch.getMinItem();
       final T maxItem = sketch.isEmpty() ? null : sketch.getMaxItem();
-      sb.append(ClassicUtil.LS).append("### ").append(thisSimpleName).append(" SUMMARY: ").append(ClassicUtil.LS);
-      sb.append("   K                            : ").append(k).append(ClassicUtil.LS);
-      sb.append("   N                            : ").append(nStr).append(ClassicUtil.LS);
-      sb.append("   BaseBufferCount              : ").append(bbCount).append(ClassicUtil.LS);
-      sb.append("   CombinedBufferAllocatedCount : ").append(bufCntStr).append(ClassicUtil.LS);
-      sb.append("   Total Levels                 : ").append(numLevels).append(ClassicUtil.LS);
-      sb.append("   Valid Levels                 : ").append(ClassicUtil.computeValidLevels(bitPattern))
-        .append(ClassicUtil.LS);
-      sb.append("   Level Bit Pattern            : ").append(Long.toBinaryString(bitPattern))
-        .append(ClassicUtil.LS);
-      sb.append("   Valid Samples                : ").append(numSampStr).append(ClassicUtil.LS);
-      sb.append("   Preamble Bytes               : ").append(preBytes).append(ClassicUtil.LS);
+      sb.append(LS).append("### ").append(thisSimpleName).append(" SUMMARY: ").append(LS);
+      sb.append("   K                            : ").append(k).append(LS);
+      sb.append("   N                            : ").append(nStr).append(LS);
+      sb.append("   BaseBufferCount              : ").append(baseBufCntStr).append(LS);
+      sb.append("   CombinedBufferAllocatedCount : ").append(cBufCntStr).append(LS);
+      sb.append("   Total Levels                 : ").append(totNumLevels).append(LS);
+      sb.append("   Valid Levels                 : ").append(computeValidLevels(bitPattern)).append(LS);
+      sb.append("   Level Bit Pattern            : ").append(Long.toBinaryString(bitPattern)).append(LS);
+      sb.append("   Valid Samples                : ").append(numValidSampStr).append(LS);
+      sb.append("   Preamble Bytes               : ").append(preBytes).append(LS);
       sb.append("   Normalized Rank Error        : ").append(epsPctStr).append(LS);
       sb.append("   Normalized Rank Error (PMF)  : ").append(epsPmfPctStr).append(LS);
-      sb.append("   Min Quantile                 : ").append(minItem).append(ClassicUtil.LS);
-      sb.append("   Max Quantile                 : ").append(maxItem).append(ClassicUtil.LS);
-      sb.append("### END SKETCH SUMMARY").append(ClassicUtil.LS);
+      sb.append("   Min Quantile                 : ").append(minItem).append(LS);
+      sb.append("   Max Quantile                 : ").append(maxItem).append(LS);
+      sb.append("### END SKETCH SUMMARY").append(LS);
     }
     return sb.toString();
   }


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


(datasketches-java) 06/06: Merge branch 'master' into improve_partition_boundaries

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d0ae2b39b5ea0802ae416fa5772526a65f651293
Merge: 3a9402a9 5e7174f4
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Tue Feb 13 18:27:10 2024 -0800

    Merge branch 'master' into improve_partition_boundaries

 .../org/apache/datasketches/common/Family.java     |   7 +-
 .../datasketches/sampling/EbppsItemsSample.java    | 309 ++++++++++++
 .../datasketches/sampling/EbppsItemsSketch.java    | 518 +++++++++++++++++++++
 .../apache/datasketches/sampling/PreambleUtil.java | 135 ++++--
 .../sampling/ReservoirItemsSketch.java             |   8 +-
 .../datasketches/sampling/ReservoirItemsUnion.java |   8 +-
 .../sampling/ReservoirLongsSketch.java             |   8 +-
 .../datasketches/sampling/ReservoirLongsUnion.java |   8 +-
 .../datasketches/sampling/VarOptItemsSketch.java   |   8 +-
 .../datasketches/sampling/VarOptItemsUnion.java    |   8 +-
 .../datasketches/sampling/EbppsSampleTest.java     | 148 ++++++
 .../datasketches/sampling/EbppsSketchTest.java     | 310 ++++++++++++
 12 files changed, 1421 insertions(+), 54 deletions(-)


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


(datasketches-java) 03/06: Turned printing off.

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4b652d581fc360526afdd933116e66b3ebdf9cf7
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sat Feb 10 12:26:23 2024 -0800

    Turned printing off.
---
 .../datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
index a980c01b..7cafbc39 100644
--- a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchPartitionBoundariesTest.java
@@ -67,7 +67,7 @@ public class ItemsSketchPartitionBoundariesTest {
     println("PRINTING: "+this.getClass().getName());
   }
 
-  private final static boolean enablePrinting = true;
+  private final static boolean enablePrinting = false;
 
   /**
    * @param format the format


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