use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class CornerCaseTupleSetOperationsTest method EmptyDegenerate.
@Test
public void EmptyDegenerate() {
IntegerSketch tupleA = getTupleSketch(SkType.EMPTY, 0, 0);
IntegerSketch tupleB = getTupleSketch(SkType.DEGENERATE, LOWP_FLT, GT_LOWP_V);
UpdateSketch thetaB = getThetaSketch(SkType.DEGENERATE, LOWP_FLT, GT_LOWP_V);
final double expectedIntersectTheta = 1.0;
final int expectedIntersectCount = 0;
final boolean expectedIntersectEmpty = true;
final double expectedAnotbTheta = 1.0;
final int expectedAnotbCount = 0;
final boolean expectedAnotbEmpty = true;
final double expectedUnionTheta = LOWP_FLT;
final int expectedUnionCount = 0;
final boolean expectedUnionEmpty = false;
checks(tupleA, tupleB, thetaB, expectedIntersectTheta, expectedIntersectCount, expectedIntersectEmpty, expectedAnotbTheta, expectedAnotbCount, expectedAnotbEmpty, expectedUnionTheta, expectedUnionCount, expectedUnionEmpty);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class CornerCaseTupleSetOperationsTest method exactExact.
@Test
public void exactExact() {
IntegerSketch tupleA = getTupleSketch(SkType.EXACT, 0, GT_MIDP_V);
IntegerSketch tupleB = getTupleSketch(SkType.EXACT, 0, GT_MIDP_V);
UpdateSketch thetaB = getThetaSketch(SkType.EXACT, 0, GT_MIDP_V);
final double expectedIntersectTheta = 1.0;
final int expectedIntersectCount = 1;
final boolean expectedIntersectEmpty = false;
final double expectedAnotbTheta = 1.0;
final int expectedAnotbCount = 0;
final boolean expectedAnotbEmpty = true;
final double expectedUnionTheta = 1.0;
final int expectedUnionCount = 1;
final boolean expectedUnionEmpty = false;
checks(tupleA, tupleB, thetaB, expectedIntersectTheta, expectedIntersectCount, expectedIntersectEmpty, expectedAnotbTheta, expectedAnotbCount, expectedAnotbEmpty, expectedUnionTheta, expectedUnionCount, expectedUnionEmpty);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class CornerCaseTupleSetOperationsTest method estimationExact.
@Test
public void estimationExact() {
IntegerSketch tupleA = getTupleSketch(SkType.ESTIMATION, LOWP_FLT, LT_LOWP_V);
IntegerSketch tupleB = getTupleSketch(SkType.EXACT, 0, LT_LOWP_V);
UpdateSketch thetaB = getThetaSketch(SkType.EXACT, 0, LT_LOWP_V);
final double expectedIntersectTheta = LOWP_FLT;
final int expectedIntersectCount = 1;
final boolean expectedIntersectEmpty = false;
final double expectedAnotbTheta = LOWP_FLT;
final int expectedAnotbCount = 0;
final boolean expectedAnotbEmpty = false;
final double expectedUnionTheta = LOWP_FLT;
final int expectedUnionCount = 1;
final boolean expectedUnionEmpty = false;
checks(tupleA, tupleB, thetaB, expectedIntersectTheta, expectedIntersectCount, expectedIntersectEmpty, expectedAnotbTheta, expectedAnotbCount, expectedAnotbEmpty, expectedUnionTheta, expectedUnionCount, expectedUnionEmpty);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class BoundsOnRatiosInThetaSketchedSetsTest method checkAbnormalReturns.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkAbnormalReturns() {
// 4K
final UpdateSketch skA = Sketches.updateSketchBuilder().build();
final UpdateSketch skC = Sketches.updateSketchBuilder().build();
final int uA = 100000;
final int uC = 10000;
for (int i = 0; i < uA; i++) {
skA.update(i);
}
for (int i = 0; i < uC; i++) {
skC.update(i + (uA / 2));
}
BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skC);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class BoundsOnRatiosInThetaSketchedSetsTest method checkNormalReturns.
@Test
public void checkNormalReturns() {
// 4K
final UpdateSketch skA = Sketches.updateSketchBuilder().build();
final UpdateSketch skC = Sketches.updateSketchBuilder().build();
final int uA = 10000;
final int uC = 100000;
for (int i = 0; i < uA; i++) {
skA.update(i);
}
for (int i = 0; i < uC; i++) {
skC.update(i + (uA / 2));
}
final Intersection inter = Sketches.setOperationBuilder().buildIntersection();
inter.intersect(skA);
inter.intersect(skC);
final CompactSketch skB = inter.getResult();
double est = BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skB);
double lb = BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(skA, skB);
double ub = BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA(skA, skB);
assertTrue(ub > est);
assertTrue(est > lb);
assertEquals(est, 0.5, .03);
println("ub : " + ub);
println("est: " + est);
println("lb : " + lb);
// skA is now empty
skA.reset();
est = BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skB);
lb = BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(skA, skB);
ub = BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA(skA, skB);
println("ub : " + ub);
println("est: " + est);
println("lb : " + lb);
// Now both are empty
skC.reset();
est = BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skC);
lb = BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(skA, skC);
ub = BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA(skA, skC);
println("ub : " + ub);
println("est: " + est);
println("lb : " + lb);
}
Aggregations