Skip to content

Commit c5719be

Browse files
author
Lee Rhodes
committed
Merge branch 'master' of git@github.com:DataSketches/sketches-core.git
2 parents e541397 + e3f0e5b commit c5719be

8 files changed

Lines changed: 12 additions & 29 deletions

src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package com.yahoo.sketches.tuple;
66

7+
import com.yahoo.sketches.BinomialBoundsN;
8+
79
/**
810
* This is a base class for a specialized version of a tuple sketch, where an array of double values is associated with each key.
911
* A primitive array is used here, as opposed to a generic Summary object, for performance reasons.
@@ -54,7 +56,7 @@ public double getEstimate() {
5456
*/
5557
public double getUpperBound(final int numStdDev) {
5658
if (!isEstimationMode()) return getRetainedEntries();
57-
return Util.upperBound(getEstimate(), getTheta(), numStdDev);
59+
return BinomialBoundsN.getUpperBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_);
5860
}
5961

6062
/**
@@ -66,7 +68,7 @@ public double getUpperBound(final int numStdDev) {
6668
*/
6769
public double getLowerBound(final int numStdDev) {
6870
if (!isEstimationMode()) return getRetainedEntries();
69-
return Util.lowerBound(getEstimate(), getTheta(), numStdDev);
71+
return BinomialBoundsN.getLowerBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_);
7072
}
7173

7274
/**

src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUpdatableSketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class ArrayOfDoublesUpdatableSketch extends ArrayOfDoublesSketch
2828
* @param values The given values
2929
*/
3030
public void update(final long key, final double[] values) {
31-
update(Util.longToLongArray(key), values);
31+
update(new long[] {key}, values);
3232
}
3333

3434
/**

src/main/java/com/yahoo/sketches/tuple/Sketch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package com.yahoo.sketches.tuple;
66

7+
import com.yahoo.sketches.BinomialBoundsN;
8+
79
/**
810
* This is an equivalent to com.yahoo.sketches.theta.Sketch with
911
* addition of a user-defined Summary object associated with every unique entry
@@ -37,7 +39,7 @@ public double getEstimate() {
3739
*/
3840
public double getUpperBound(final int numStdDev) {
3941
if (!isEstimationMode()) return getRetainedEntries();
40-
return Util.upperBound(getEstimate(), getTheta(), numStdDev);
42+
return BinomialBoundsN.getUpperBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_);
4143
}
4244

4345
/**
@@ -49,7 +51,7 @@ public double getUpperBound(final int numStdDev) {
4951
*/
5052
public double getLowerBound(final int numStdDev) {
5153
if (!isEstimationMode()) return getRetainedEntries();
52-
return Util.lowerBound(getEstimate(), getTheta(), numStdDev);
54+
return BinomialBoundsN.getLowerBound(getRetainedEntries(), getTheta(), numStdDev, isEmpty_);
5355
}
5456

5557
/**

src/main/java/com/yahoo/sketches/tuple/UpdatableSketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class UpdatableSketch<U, S extends UpdatableSummary<U>> extends QuickSele
5656
* @param value The given U value
5757
*/
5858
public void update(final long key, final U value) {
59-
update(Util.longToLongArray(key), value);
59+
update(new long[] {key}, value);
6060
}
6161

6262
/**

src/main/java/com/yahoo/sketches/tuple/Util.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@ static final int startingSubMultiple(final int lgTarget, final int lgResizeRatio
2727
return lgStart;
2828
}
2929

30-
static final double upperBound(final double estimate, final double theta, final double numStdDev) {
31-
double dsq = numStdDev * numStdDev * ((1.0 / theta) - 1.0);
32-
return estimate + (dsq / 2.0) + ((Math.sqrt(dsq) / 2.0) * Math.sqrt((4.0 * estimate) + dsq));
33-
}
34-
35-
static final double lowerBound(final double estimate, final double theta, final double numStdDev) {
36-
double dsq = numStdDev * numStdDev * ((1.0 / theta) - 1.0);
37-
return estimate + (dsq / 2.0) - ((Math.sqrt(dsq) / 2.0) * Math.sqrt((4.0 * estimate) + dsq));
38-
}
39-
40-
static final long[] longToLongArray(final long value) {
41-
final long[] array = { value };
42-
return array;
43-
}
44-
4530
static final long[] doubleToLongArray(final double value) {
4631
final double d = (value == 0.0) ? 0.0 : value; // canonicalize -0.0, 0.0
4732
final long[] array = { Double.doubleToLongBits(d) }; // canonicalize all NaN forms

src/test/java/com/yahoo/sketches/tuple/DirectArrayOfDoublesQuickSelectSketchTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ public void estimationMode() {
8282
for (int i = 1; i <= 8192; i++) sketch.update(i, new double[] {1.0});
8383
Assert.assertTrue(sketch.isEstimationMode());
8484
Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.01);
85-
Assert.assertEquals(sketch.getEstimate(), sketch.getLowerBound(0));
86-
Assert.assertEquals(sketch.getEstimate(), sketch.getUpperBound(0));
8785
Assert.assertTrue(sketch.getEstimate() >= sketch.getLowerBound(1));
88-
Assert.assertTrue(sketch.getEstimate() <= sketch.getUpperBound(1));
86+
Assert.assertTrue(sketch.getEstimate() < sketch.getUpperBound(1));
8987

9088
double[][] values = sketch.getValues();
9189
Assert.assertTrue(values.length >= 4096);

src/test/java/com/yahoo/sketches/tuple/HeapArrayOfDoublesQuickSelectSketchTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ public void estimationMode() {
8080
for (int i = 1; i <= 8192; i++) sketch.update(i, new double[] {1.0});
8181
Assert.assertTrue(sketch.isEstimationMode());
8282
Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.01);
83-
Assert.assertEquals(sketch.getEstimate(), sketch.getLowerBound(0));
84-
Assert.assertEquals(sketch.getEstimate(), sketch.getUpperBound(0));
8583
Assert.assertTrue(sketch.getEstimate() >= sketch.getLowerBound(1));
86-
Assert.assertTrue(sketch.getEstimate() <= sketch.getUpperBound(1));
84+
Assert.assertTrue(sketch.getEstimate() < sketch.getUpperBound(1));
8785
Assert.assertTrue(sketch.getRetainedEntries() > 4096);
8886
sketch.trim();
8987
Assert.assertEquals(sketch.getRetainedEntries(), 4096);

src/test/java/com/yahoo/sketches/tuple/UpdatableSketchWithDoubleSummaryTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ public void estimationMode() {
8181
for (int i = 1; i <= 8192; i++) sketch.update(i, 1.0);
8282
Assert.assertTrue(sketch.isEstimationMode());
8383
Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.01);
84-
Assert.assertEquals(sketch.getEstimate(), sketch.getLowerBound(0));
85-
Assert.assertEquals(sketch.getEstimate(), sketch.getUpperBound(0));
8684
Assert.assertTrue(sketch.getEstimate() >= sketch.getLowerBound(1));
8785
Assert.assertTrue(sketch.getEstimate() < sketch.getUpperBound(1));
8886

0 commit comments

Comments
 (0)