use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class TupleExamplesTest method example1.
@Test
public void example1() {
// Load source sketches
final UpdatableSketch<Integer, IntegerSummary> tupleSk = tupleBldr.build();
final UpdateSketch thetaSk = thetaBldr.build();
for (int i = 1; i <= 12; i++) {
tupleSk.update(i, 1);
thetaSk.update(i + 3);
}
// Union stateful: tuple, theta
final Union<IntegerSummary> union = new Union<>(isso);
union.union(tupleSk);
union.union(thetaSk, ufactory.newSummary().update(1));
final CompactSketch<IntegerSummary> ucsk = union.getResult();
int entries = ucsk.getRetainedEntries();
println("Union Stateful: tuple, theta: " + entries);
final SketchIterator<IntegerSummary> uiter = ucsk.iterator();
int counter = 1;
int twos = 0;
int ones = 0;
while (uiter.next()) {
final int i = 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 stateful: tuple, theta
final Intersection<IntegerSummary> inter = new Intersection<>(isso);
inter.intersect(tupleSk);
inter.intersect(thetaSk, ifactory.newSummary().update(1));
final CompactSketch<IntegerSummary> icsk = inter.getResult();
entries = icsk.getRetainedEntries();
println("Intersection Stateful: tuple, theta: " + entries);
final SketchIterator<IntegerSummary> iiter = icsk.iterator();
counter = 1;
while (iiter.next()) {
final int i = iiter.getSummary().getValue();
// 9 entries = 1
println(counter++ + ", " + i);
assertEquals(i, 1);
}
}
use of org.apache.datasketches.theta.UpdateSketch 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();
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class CornerCaseTupleSetOperationsTest method emptyEstimation.
@Test
public void emptyEstimation() {
IntegerSketch tupleA = getTupleSketch(SkType.EMPTY, 0, 0);
IntegerSketch tupleB = getTupleSketch(SkType.ESTIMATION, LOWP_FLT, LT_LOWP_V);
UpdateSketch thetaB = getThetaSketch(SkType.ESTIMATION, LOWP_FLT, LT_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 = 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 exactEstimation.
@Test
public void exactEstimation() {
IntegerSketch tupleA = getTupleSketch(SkType.EXACT, 0, LT_LOWP_V);
IntegerSketch tupleB = getTupleSketch(SkType.ESTIMATION, LOWP_FLT, LT_LOWP_V);
UpdateSketch thetaB = getThetaSketch(SkType.ESTIMATION, LOWP_FLT, 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 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;
}
Aggregations