Search in sources :

Example 1 with UpdateSketchBuilder

use of org.apache.datasketches.theta.UpdateSketchBuilder in project sketches-core by DataSketches.

the class AdoubleIntersectionTest method checkExactIntersectionWithThetaDisjoint.

@Test
public void checkExactIntersectionWithThetaDisjoint() {
    final UpdateSketch thSkA = new UpdateSketchBuilder().setLogNominalEntries(10).build();
    final UpdateSketch thSkB = new UpdateSketchBuilder().setLogNominalEntries(10).build();
    int key = 0;
    for (int i = 0; i < 32; i++) {
        thSkA.update(key++);
    }
    for (int i = 0; i < 32; i++) {
        thSkB.update(key++);
    }
    final DoubleSummary dsum = new DoubleSummaryFactory(mode).newSummary();
    final Intersection<DoubleSummary> intersection = new Intersection<>(new DoubleSummarySetOperations(mode, mode));
    CompactSketch<DoubleSummary> result;
    intersection.intersect(thSkA, dsum);
    intersection.intersect(thSkB, dsum);
    result = intersection.getResult();
    Assert.assertEquals(result.getRetainedEntries(), 0);
    // an intersection with no entries must survive more updates
    intersection.intersect(thSkA, dsum);
    result = intersection.getResult();
    Assert.assertEquals(result.getRetainedEntries(), 0);
    intersection.reset();
}
Also used : Intersection(org.apache.datasketches.tuple.Intersection) UpdateSketchBuilder(org.apache.datasketches.theta.UpdateSketchBuilder) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 2 with UpdateSketchBuilder

use of org.apache.datasketches.theta.UpdateSketchBuilder in project sketches-core by DataSketches.

the class CornerCaseTupleSetOperationsTest method getThetaSketch.

// NOTE: p and value arguments are used for every case
private static UpdateSketch getThetaSketch(SkType skType, float p, long updateKey) {
    UpdateSketchBuilder bldr = new UpdateSketchBuilder();
    bldr.setLogNominalEntries(4);
    bldr.setResizeFactor(ResizeFactor.X4);
    UpdateSketch sk;
    switch(skType) {
        case EMPTY:
            {
                // { 1.0,  0, T} p and value are not used
                sk = bldr.build();
                break;
            }
        case EXACT:
            {
                // { 1.0, >0, F} p is not used
                sk = bldr.build();
                sk.update(updateKey);
                break;
            }
        case ESTIMATION:
            {
                // {<1.0, >0, F}
                checkValidUpdate(p, updateKey);
                bldr.setP(p);
                sk = bldr.build();
                sk.update(updateKey);
                break;
            }
        case DEGENERATE:
            {
                // {<1.0,  0, F}
                checkInvalidUpdate(p, updateKey);
                bldr.setP(p);
                sk = bldr.build();
                sk.update(updateKey);
                break;
            }
        // should not happen
        default:
            {
                return null;
            }
    }
    return sk;
}
Also used : UpdateSketchBuilder(org.apache.datasketches.theta.UpdateSketchBuilder) UpdateSketch(org.apache.datasketches.theta.UpdateSketch)

Example 3 with UpdateSketchBuilder

use of org.apache.datasketches.theta.UpdateSketchBuilder in project sketches-core by DataSketches.

the class AdoubleIntersectionTest method checkEstimatingIntersectionWithThetaOverlapping.

@Test
public void checkEstimatingIntersectionWithThetaOverlapping() {
    final UpdateSketch thSkA = new UpdateSketchBuilder().setLogNominalEntries(4).build();
    final UpdateSketch thSkB = new UpdateSketchBuilder().setLogNominalEntries(10).build();
    // dense mode, low theta
    for (int i = 0; i < 64; i++) {
        thSkA.update(i);
    }
    // exact overlapping
    for (int i = 32; i < 96; i++) {
        thSkB.update(i);
    }
    final DoubleSummary dsum = new DoubleSummaryFactory(mode).newSummary();
    final Intersection<DoubleSummary> intersection = new Intersection<>(new DoubleSummarySetOperations(mode, mode));
    CompactSketch<DoubleSummary> result;
    intersection.intersect(thSkA, dsum);
    intersection.intersect(thSkB, dsum);
    result = intersection.getResult();
    Assert.assertEquals(result.getRetainedEntries(), 14);
    thSkB.reset();
    // exact, disjoint
    for (int i = 100; i < 164; i++) {
        thSkB.update(i);
    }
    // remove existing entries
    intersection.intersect(thSkB, dsum);
    result = intersection.getResult();
    Assert.assertEquals(result.getRetainedEntries(), 0);
    intersection.intersect(thSkB, dsum);
    result = intersection.getResult();
    Assert.assertEquals(result.getRetainedEntries(), 0);
}
Also used : Intersection(org.apache.datasketches.tuple.Intersection) UpdateSketchBuilder(org.apache.datasketches.theta.UpdateSketchBuilder) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 4 with UpdateSketchBuilder

use of org.apache.datasketches.theta.UpdateSketchBuilder in project sketches-core by DataSketches.

the class AdoubleIntersectionTest method checkExactIntersectionWithTheta.

@Test
public void checkExactIntersectionWithTheta() {
    final UpdateSketch thSkNull = null;
    final UpdateSketch thSkEmpty = new UpdateSketchBuilder().build();
    final UpdateSketch thSk10 = new UpdateSketchBuilder().build();
    final UpdateSketch thSk15 = new UpdateSketchBuilder().build();
    for (int i = 0; i < 10; i++) {
        thSk10.update(i);
    }
    // overlap = 5
    for (int i = 0; i < 10; i++) {
        thSk15.update(i + 5);
    }
    DoubleSummary dsum = new DoubleSummaryFactory(mode).newSummary();
    final Intersection<DoubleSummary> intersection = new Intersection<>(new DoubleSummarySetOperations(mode, mode));
    CompactSketch<DoubleSummary> result;
    try {
        intersection.getResult();
        fail();
    }// OK.
     catch (final SketchesStateException e) {
    }
    try {
        intersection.intersect(thSkNull, dsum);
        fail();
    }// OK
     catch (final SketchesArgumentException e) {
    }
    intersection.intersect(thSkEmpty, dsum);
    result = intersection.getResult();
    // Empty after empty first call
    Assert.assertTrue(result.isEmpty());
    intersection.reset();
    intersection.intersect(thSk10, dsum);
    result = intersection.getResult();
    // Returns valid first call
    Assert.assertEquals(result.getEstimate(), 10.0);
    intersection.reset();
    // Valid first call
    intersection.intersect(thSk10, dsum);
    intersection.intersect(thSkEmpty, dsum);
    result = intersection.getResult();
    // Returns Empty after empty second call
    Assert.assertTrue(result.isEmpty());
    intersection.reset();
    intersection.intersect(thSk10, dsum);
    intersection.intersect(thSk15, dsum);
    result = intersection.getResult();
    // Returns intersection
    Assert.assertEquals(result.getEstimate(), 5.0);
    intersection.reset();
    dsum = null;
    try {
        intersection.intersect(thSk10, dsum);
        fail();
    } catch (final SketchesArgumentException e) {
    }
}
Also used : Intersection(org.apache.datasketches.tuple.Intersection) SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) UpdateSketchBuilder(org.apache.datasketches.theta.UpdateSketchBuilder) SketchesStateException(org.apache.datasketches.SketchesStateException) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 5 with UpdateSketchBuilder

use of org.apache.datasketches.theta.UpdateSketchBuilder in project sketches-core by DataSketches.

the class AdoubleUnionTest method checkUnionUpdateWithTheta.

@Test
public void checkUnionUpdateWithTheta() {
    final Union<DoubleSummary> union = new Union<>(new DoubleSummarySetOperations(mode, mode));
    UpdateSketch usk = null;
    DoubleSummary dsum = null;
    try {
        union.union(usk, dsum);
        fail();
    } catch (final SketchesArgumentException e) {
    }
    usk = new UpdateSketchBuilder().build();
    try {
        union.union(usk, dsum);
        fail();
    } catch (final SketchesArgumentException e) {
    }
    dsum = new DoubleSummaryFactory(mode).newSummary();
    for (int i = 0; i < 10; i++) {
        usk.update(i);
    }
    union.union(usk, dsum);
    Assert.assertEquals(union.getResult().getEstimate(), 10.0);
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) UpdateSketchBuilder(org.apache.datasketches.theta.UpdateSketchBuilder) Union(org.apache.datasketches.tuple.Union) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Aggregations

UpdateSketch (org.apache.datasketches.theta.UpdateSketch)5 UpdateSketchBuilder (org.apache.datasketches.theta.UpdateSketchBuilder)5 Test (org.testng.annotations.Test)4 Intersection (org.apache.datasketches.tuple.Intersection)3 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)2 SketchesStateException (org.apache.datasketches.SketchesStateException)1 Union (org.apache.datasketches.tuple.Union)1