Search in sources :

Example 6 with DoubleSummary

use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.

the class TupleExamples2Test method example4.

@Test
public void example4() {
    // stateful: tuple, theta, Mode=sum for both, use dsso0
    // Load source sketches
    final UpdatableSketch<Double, DoubleSummary> tupleSk = tupleBldr.build();
    final UpdateSketch thetaSk = thetaBldr.build();
    for (int i = 1; i <= 12; i++) {
        tupleSk.update(i, 1.0);
        thetaSk.update(i + 3);
    }
    // Union
    final Union<DoubleSummary> union = new Union<>(dsso0);
    union.union(tupleSk);
    union.union(thetaSk, ufactory.newSummary().update(1.0));
    final CompactSketch<DoubleSummary> ucsk = union.getResult();
    int entries = ucsk.getRetainedEntries();
    println("Union Stateful: tuple, theta: " + entries);
    final SketchIterator<DoubleSummary> uiter = ucsk.iterator();
    int counter = 1;
    int twos = 0;
    int ones = 0;
    while (uiter.next()) {
        final int i = (int) uiter.getSummary().getValue();
        // 9 entries = 2, 6 entries = 1
        println(counter++ + ", " + i);
        if (i == 1) {
            ones++;
        }
        if (i == 2) {
            twos++;
        }
    }
    assertEquals(ones, 6);
    assertEquals(twos, 9);
    // Intersection
    final Intersection<DoubleSummary> inter = new Intersection<>(dsso0);
    inter.intersect(tupleSk);
    inter.intersect(thetaSk, ifactory.newSummary().update(1.0));
    final CompactSketch<DoubleSummary> icsk = inter.getResult();
    entries = icsk.getRetainedEntries();
    println("Intersection Stateful: tuple, theta: " + entries);
    final SketchIterator<DoubleSummary> iiter = icsk.iterator();
    counter = 1;
    while (iiter.next()) {
        final int i = (int) iiter.getSummary().getValue();
        // 9 entries = 1
        println(counter++ + ", " + i);
        assertEquals(i, 2);
    }
}
Also used : DoubleSummary(org.apache.datasketches.tuple.adouble.DoubleSummary) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 7 with DoubleSummary

use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.

the class CompactSketchWithDoubleSummaryTest method serializeDeserializeSmallExact.

@Test
public void serializeDeserializeSmallExact() {
    UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode)).build();
    us.update("a", 1.0);
    us.update("b", 1.0);
    us.update("c", 1.0);
    CompactSketch<DoubleSummary> sketch1 = us.compact();
    Sketch<DoubleSummary> sketch2 = Sketches.heapifySketch(Memory.wrap(sketch1.toByteArray()), new DoubleSummaryDeserializer());
    Assert.assertFalse(sketch2.isEmpty());
    Assert.assertFalse(sketch2.isEstimationMode());
    Assert.assertEquals(sketch2.getEstimate(), 3.0);
    Assert.assertEquals(sketch2.getLowerBound(1), 3.0);
    Assert.assertEquals(sketch2.getUpperBound(1), 3.0);
    Assert.assertEquals(sketch2.getRetainedEntries(), 3);
    Assert.assertEquals(sketch2.getThetaLong(), Long.MAX_VALUE);
    Assert.assertEquals(sketch2.getTheta(), 1.0);
    SketchIterator<DoubleSummary> it = sketch2.iterator();
    int count = 0;
    while (it.next()) {
        Assert.assertEquals(it.getSummary().getValue(), 1.0);
        count++;
    }
    Assert.assertEquals(count, 3);
}
Also used : DoubleSummary(org.apache.datasketches.tuple.adouble.DoubleSummary) DoubleSummaryDeserializer(org.apache.datasketches.tuple.adouble.DoubleSummaryDeserializer) DoubleSummaryFactory(org.apache.datasketches.tuple.adouble.DoubleSummaryFactory) Test(org.testng.annotations.Test)

Example 8 with DoubleSummary

use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.

the class CompactSketchWithDoubleSummaryTest method deserializeWrongType.

@SuppressWarnings("deprecation")
@Test(expectedExceptions = SketchesArgumentException.class)
public void deserializeWrongType() {
    UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode)).build();
    for (int i = 0; i < 8192; i++) {
        us.update(i, 1.0);
    }
    CompactSketch<DoubleSummary> sketch1 = us.compact();
    Sketches.heapifyUpdatableSketch(Memory.wrap(sketch1.toByteArray()), new DoubleSummaryDeserializer(), new DoubleSummaryFactory(mode));
}
Also used : DoubleSummary(org.apache.datasketches.tuple.adouble.DoubleSummary) DoubleSummaryDeserializer(org.apache.datasketches.tuple.adouble.DoubleSummaryDeserializer) DoubleSummaryFactory(org.apache.datasketches.tuple.adouble.DoubleSummaryFactory) Test(org.testng.annotations.Test)

Example 9 with DoubleSummary

use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.

the class JaccardSimilarityTest method checkMinK2.

@Test
public void checkMinK2() {
    // tuple, theta
    // 4096
    final UpdatableSketch<Double, DoubleSummary> skA = tupleBldr.build();
    // 4096
    final UpdateSketch skB = UpdateSketch.builder().build();
    skA.update(1, constSummary);
    skB.update(1);
    double[] result = jaccard(skA, skB, factory.newSummary(), dsso);
    println(result[0] + ", " + result[1] + ", " + result[2]);
    for (int i = 1; i < 4096; i++) {
        skA.update(i, constSummary);
        skB.update(i);
    }
    result = jaccard(skA, skB, factory.newSummary(), dsso);
    println(result[0] + ", " + result[1] + ", " + result[2]);
}
Also used : DoubleSummary(org.apache.datasketches.tuple.adouble.DoubleSummary) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) JaccardSimilarity.similarityTest(org.apache.datasketches.tuple.JaccardSimilarity.similarityTest) Test(org.testng.annotations.Test) JaccardSimilarity.dissimilarityTest(org.apache.datasketches.tuple.JaccardSimilarity.dissimilarityTest)

Example 10 with DoubleSummary

use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.

the class MiscTest method checkUpdatableSketchBuilderReset.

@Test
public void checkUpdatableSketchBuilderReset() {
    final DoubleSummary.Mode mode = Mode.Sum;
    final UpdatableSketchBuilder<Double, DoubleSummary> bldr = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode));
    bldr.reset();
    final UpdatableSketch<Double, DoubleSummary> sk = bldr.build();
    assertTrue(sk.isEmpty());
}
Also used : Mode(org.apache.datasketches.tuple.adouble.DoubleSummary.Mode) DoubleSummary(org.apache.datasketches.tuple.adouble.DoubleSummary) DoubleSummaryFactory(org.apache.datasketches.tuple.adouble.DoubleSummaryFactory) Test(org.testng.annotations.Test)

Aggregations

DoubleSummary (org.apache.datasketches.tuple.adouble.DoubleSummary)18 Test (org.testng.annotations.Test)18 UpdateSketch (org.apache.datasketches.theta.UpdateSketch)12 JaccardSimilarity.dissimilarityTest (org.apache.datasketches.tuple.JaccardSimilarity.dissimilarityTest)6 JaccardSimilarity.similarityTest (org.apache.datasketches.tuple.JaccardSimilarity.similarityTest)6 DoubleSummaryFactory (org.apache.datasketches.tuple.adouble.DoubleSummaryFactory)5 DoubleSummaryDeserializer (org.apache.datasketches.tuple.adouble.DoubleSummaryDeserializer)4 Mode (org.apache.datasketches.tuple.adouble.DoubleSummary.Mode)2 Intersection (org.apache.datasketches.tuple.Intersection)1