use of org.apache.datasketches.theta.UpdateSketch 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]);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class BoundsOnRatiosInTupleSketchedSetsTest method checkAbnormalReturns2.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkAbnormalReturns2() {
// tuple, theta
// 4K
final UpdatableSketch<Double, DoubleSummary> skA = tupleBldr.build();
final UpdateSketch skC = thetaBldr.build();
final int uA = 100000;
final int uC = 10000;
for (int i = 0; i < uA; i++) {
skA.update(i, constSummary);
}
for (int i = 0; i < uC; i++) {
skC.update(i + (uA / 2));
}
BoundsOnRatiosInTupleSketchedSets.getEstimateOfBoverA(skA, skC);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class BoundsOnRatiosInTupleSketchedSetsTest method checkNormalReturns2.
@Test
public void checkNormalReturns2() {
// tuple, theta
// 4K
final UpdatableSketch<Double, DoubleSummary> skA = tupleBldr.build();
final UpdateSketch skC = thetaBldr.build();
final int uA = 10000;
final int uC = 100000;
for (int i = 0; i < uA; i++) {
skA.update(i, constSummary);
}
for (int i = 0; i < uC; i++) {
skC.update(i + (uA / 2));
}
final Intersection<DoubleSummary> inter = new Intersection<>(dsso);
inter.intersect(skA);
inter.intersect(skC, factory.newSummary());
final Sketch<DoubleSummary> skB = inter.getResult();
double est = BoundsOnRatiosInTupleSketchedSets.getEstimateOfBoverA(skA, skB);
double lb = BoundsOnRatiosInTupleSketchedSets.getLowerBoundForBoverA(skA, skB);
double ub = BoundsOnRatiosInTupleSketchedSets.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 = BoundsOnRatiosInTupleSketchedSets.getEstimateOfBoverA(skA, skB);
lb = BoundsOnRatiosInTupleSketchedSets.getLowerBoundForBoverA(skA, skB);
ub = BoundsOnRatiosInTupleSketchedSets.getUpperBoundForBoverA(skA, skB);
println("ub : " + ub);
println("est: " + est);
println("lb : " + lb);
// Now both are empty
skC.reset();
est = BoundsOnRatiosInTupleSketchedSets.getEstimateOfBoverA(skA, skC);
lb = BoundsOnRatiosInTupleSketchedSets.getLowerBoundForBoverA(skA, skC);
ub = BoundsOnRatiosInTupleSketchedSets.getUpperBoundForBoverA(skA, skC);
println("ub : " + ub);
println("est: " + est);
println("lb : " + lb);
}
use of org.apache.datasketches.theta.UpdateSketch in project druid by druid-io.
the class SketchAggregationTest method testRelocation.
@Test
public void testRelocation() {
final TestColumnSelectorFactory columnSelectorFactory = GrouperTestUtil.newColumnSelectorFactory();
SketchHolder sketchHolder = SketchHolder.of(Sketches.updateSketchBuilder().setNominalEntries(16).build());
UpdateSketch updateSketch = (UpdateSketch) sketchHolder.getSketch();
updateSketch.update(1);
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("sketch", sketchHolder)));
SketchHolder[] holders = helper.runRelocateVerificationTest(new SketchMergeAggregatorFactory("sketch", "sketch", 16, false, true, 2), columnSelectorFactory, SketchHolder.class);
Assert.assertEquals(holders[0].getEstimate(), holders[1].getEstimate(), 0);
}
use of org.apache.datasketches.theta.UpdateSketch in project druid by druid-io.
the class OldApiSketchAggregationTest method testRelocation.
@Test
public void testRelocation() {
final TestColumnSelectorFactory columnSelectorFactory = GrouperTestUtil.newColumnSelectorFactory();
SketchHolder sketchHolder = SketchHolder.of(Sketches.updateSketchBuilder().setNominalEntries(16).build());
UpdateSketch updateSketch = (UpdateSketch) sketchHolder.getSketch();
updateSketch.update(1);
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("sketch", sketchHolder)));
SketchHolder[] holders = helper.runRelocateVerificationTest(new OldSketchMergeAggregatorFactory("sketch", "sketch", 16, false), columnSelectorFactory, SketchHolder.class);
Assert.assertEquals(holders[0].getEstimate(), holders[1].getEstimate(), 0);
}
Aggregations