Search in sources :

Example 41 with UpdateSketch

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);
}
Also used : UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 42 with UpdateSketch

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);
}
Also used : UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 43 with UpdateSketch

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);
}
Also used : UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 44 with UpdateSketch

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);
}
Also used : UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 45 with UpdateSketch

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);
}
Also used : Intersection(org.apache.datasketches.theta.Intersection) CompactSketch(org.apache.datasketches.theta.CompactSketch) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Aggregations

UpdateSketch (org.apache.datasketches.theta.UpdateSketch)46 Test (org.testng.annotations.Test)42 DoubleSummary (org.apache.datasketches.tuple.adouble.DoubleSummary)12 AnotB (org.apache.datasketches.tuple.AnotB)6 JaccardSimilarity.dissimilarityTest (org.apache.datasketches.tuple.JaccardSimilarity.dissimilarityTest)6 JaccardSimilarity.similarityTest (org.apache.datasketches.tuple.JaccardSimilarity.similarityTest)6 UpdateSketchBuilder (org.apache.datasketches.theta.UpdateSketchBuilder)5 Intersection (org.apache.datasketches.tuple.Intersection)4 MapBasedRow (org.apache.druid.data.input.MapBasedRow)3 TestColumnSelectorFactory (org.apache.druid.query.groupby.epinephelinae.TestColumnSelectorFactory)3 Test (org.junit.Test)3 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)2 IntegerSummary (org.apache.datasketches.tuple.aninteger.IntegerSummary)2 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)2 SketchesStateException (org.apache.datasketches.SketchesStateException)1 CompactSketch (org.apache.datasketches.theta.CompactSketch)1 Intersection (org.apache.datasketches.theta.Intersection)1 Union (org.apache.datasketches.tuple.Union)1 SketchHolder (org.apache.druid.query.aggregation.datasketches.theta.SketchHolder)1 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)1