diff --git a/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java b/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java index 121f1f92a..7e536bfe2 100644 --- a/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java +++ b/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java @@ -4,6 +4,8 @@ */ package com.yahoo.sketches.tuple; +import com.yahoo.sketches.BinomialBoundsN; + /** * This is a base class for a specialized version of a tuple sketch, where an array of double values is associated with each key. * A primitive array is used here, as opposed to a generic Summary object, for performance reasons. @@ -54,7 +56,7 @@ public double getEstimate() { */ public double getUpperBound(final int numStdDev) { if (!isEstimationMode()) return getRetainedEntries(); - return Util.upperBound(getEstimate(), getTheta(), numStdDev); + return BinomialBoundsN.getUpperBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_); } /** @@ -66,7 +68,7 @@ public double getUpperBound(final int numStdDev) { */ public double getLowerBound(final int numStdDev) { if (!isEstimationMode()) return getRetainedEntries(); - return Util.lowerBound(getEstimate(), getTheta(), numStdDev); + return BinomialBoundsN.getLowerBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_); } /** diff --git a/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUpdatableSketch.java b/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUpdatableSketch.java index 4d87f2496..478ce577e 100644 --- a/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUpdatableSketch.java +++ b/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUpdatableSketch.java @@ -28,7 +28,7 @@ public abstract class ArrayOfDoublesUpdatableSketch extends ArrayOfDoublesSketch * @param values The given values */ public void update(final long key, final double[] values) { - update(Util.longToLongArray(key), values); + update(new long[] {key}, values); } /** diff --git a/src/main/java/com/yahoo/sketches/tuple/Sketch.java b/src/main/java/com/yahoo/sketches/tuple/Sketch.java index a1d8c345f..55142e030 100644 --- a/src/main/java/com/yahoo/sketches/tuple/Sketch.java +++ b/src/main/java/com/yahoo/sketches/tuple/Sketch.java @@ -4,6 +4,8 @@ */ package com.yahoo.sketches.tuple; +import com.yahoo.sketches.BinomialBoundsN; + /** * This is an equivalent to com.yahoo.sketches.theta.Sketch with * addition of a user-defined Summary object associated with every unique entry @@ -37,7 +39,7 @@ public double getEstimate() { */ public double getUpperBound(final int numStdDev) { if (!isEstimationMode()) return getRetainedEntries(); - return Util.upperBound(getEstimate(), getTheta(), numStdDev); + return BinomialBoundsN.getUpperBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_); } /** @@ -49,7 +51,7 @@ public double getUpperBound(final int numStdDev) { */ public double getLowerBound(final int numStdDev) { if (!isEstimationMode()) return getRetainedEntries(); - return Util.lowerBound(getEstimate(), getTheta(), numStdDev); + return BinomialBoundsN.getLowerBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_); } /** diff --git a/src/main/java/com/yahoo/sketches/tuple/UpdatableSketch.java b/src/main/java/com/yahoo/sketches/tuple/UpdatableSketch.java index 4b7c6abbd..9653120df 100644 --- a/src/main/java/com/yahoo/sketches/tuple/UpdatableSketch.java +++ b/src/main/java/com/yahoo/sketches/tuple/UpdatableSketch.java @@ -56,7 +56,7 @@ public class UpdatableSketch> extends QuickSele * @param value The given U value */ public void update(final long key, final U value) { - update(Util.longToLongArray(key), value); + update(new long[] {key}, value); } /** diff --git a/src/main/java/com/yahoo/sketches/tuple/Util.java b/src/main/java/com/yahoo/sketches/tuple/Util.java index 1557632cf..a447e2508 100644 --- a/src/main/java/com/yahoo/sketches/tuple/Util.java +++ b/src/main/java/com/yahoo/sketches/tuple/Util.java @@ -27,21 +27,6 @@ static final int startingSubMultiple(final int lgTarget, final int lgResizeRatio return lgStart; } - static final double upperBound(final double estimate, final double theta, final double numStdDev) { - double dsq = numStdDev * numStdDev * ((1.0 / theta) - 1.0); - return estimate + (dsq / 2.0) + ((Math.sqrt(dsq) / 2.0) * Math.sqrt((4.0 * estimate) + dsq)); - } - - static final double lowerBound(final double estimate, final double theta, final double numStdDev) { - double dsq = numStdDev * numStdDev * ((1.0 / theta) - 1.0); - return estimate + (dsq / 2.0) - ((Math.sqrt(dsq) / 2.0) * Math.sqrt((4.0 * estimate) + dsq)); - } - - static final long[] longToLongArray(final long value) { - final long[] array = { value }; - return array; - } - static final long[] doubleToLongArray(final double value) { final double d = (value == 0.0) ? 0.0 : value; // canonicalize -0.0, 0.0 final long[] array = { Double.doubleToLongBits(d) }; // canonicalize all NaN forms diff --git a/src/test/java/com/yahoo/sketches/tuple/DirectArrayOfDoublesQuickSelectSketchTest.java b/src/test/java/com/yahoo/sketches/tuple/DirectArrayOfDoublesQuickSelectSketchTest.java index 7bc8b8e72..d97efad02 100644 --- a/src/test/java/com/yahoo/sketches/tuple/DirectArrayOfDoublesQuickSelectSketchTest.java +++ b/src/test/java/com/yahoo/sketches/tuple/DirectArrayOfDoublesQuickSelectSketchTest.java @@ -82,10 +82,8 @@ public void estimationMode() { for (int i = 1; i <= 8192; i++) sketch.update(i, new double[] {1.0}); Assert.assertTrue(sketch.isEstimationMode()); Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.01); - Assert.assertEquals(sketch.getEstimate(), sketch.getLowerBound(0)); - Assert.assertEquals(sketch.getEstimate(), sketch.getUpperBound(0)); Assert.assertTrue(sketch.getEstimate() >= sketch.getLowerBound(1)); - Assert.assertTrue(sketch.getEstimate() <= sketch.getUpperBound(1)); + Assert.assertTrue(sketch.getEstimate() < sketch.getUpperBound(1)); double[][] values = sketch.getValues(); Assert.assertTrue(values.length >= 4096); diff --git a/src/test/java/com/yahoo/sketches/tuple/HeapArrayOfDoublesQuickSelectSketchTest.java b/src/test/java/com/yahoo/sketches/tuple/HeapArrayOfDoublesQuickSelectSketchTest.java index d35e0a77d..99e3a9182 100644 --- a/src/test/java/com/yahoo/sketches/tuple/HeapArrayOfDoublesQuickSelectSketchTest.java +++ b/src/test/java/com/yahoo/sketches/tuple/HeapArrayOfDoublesQuickSelectSketchTest.java @@ -80,10 +80,8 @@ public void estimationMode() { for (int i = 1; i <= 8192; i++) sketch.update(i, new double[] {1.0}); Assert.assertTrue(sketch.isEstimationMode()); Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.01); - Assert.assertEquals(sketch.getEstimate(), sketch.getLowerBound(0)); - Assert.assertEquals(sketch.getEstimate(), sketch.getUpperBound(0)); Assert.assertTrue(sketch.getEstimate() >= sketch.getLowerBound(1)); - Assert.assertTrue(sketch.getEstimate() <= sketch.getUpperBound(1)); + Assert.assertTrue(sketch.getEstimate() < sketch.getUpperBound(1)); Assert.assertTrue(sketch.getRetainedEntries() > 4096); sketch.trim(); Assert.assertEquals(sketch.getRetainedEntries(), 4096); diff --git a/src/test/java/com/yahoo/sketches/tuple/UpdatableSketchWithDoubleSummaryTest.java b/src/test/java/com/yahoo/sketches/tuple/UpdatableSketchWithDoubleSummaryTest.java index 3ab764706..9e80b82c7 100644 --- a/src/test/java/com/yahoo/sketches/tuple/UpdatableSketchWithDoubleSummaryTest.java +++ b/src/test/java/com/yahoo/sketches/tuple/UpdatableSketchWithDoubleSummaryTest.java @@ -81,8 +81,6 @@ public void estimationMode() { for (int i = 1; i <= 8192; i++) sketch.update(i, 1.0); Assert.assertTrue(sketch.isEstimationMode()); Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.01); - Assert.assertEquals(sketch.getEstimate(), sketch.getLowerBound(0)); - Assert.assertEquals(sketch.getEstimate(), sketch.getUpperBound(0)); Assert.assertTrue(sketch.getEstimate() >= sketch.getLowerBound(1)); Assert.assertTrue(sketch.getEstimate() < sketch.getUpperBound(1));