use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class TupleExamplesTest method example3.
@Test
public void example3() {
// 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, stateless: tuple1, tuple2
final Union<IntegerSummary> union = new Union<>(isso);
final CompactSketch<IntegerSummary> ucsk = union.union(tupleSk, thetaSk, ufactory.newSummary().update(1));
int entries = ucsk.getRetainedEntries();
println("Union: " + 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 stateless: tuple1, tuple2
final Intersection<IntegerSummary> inter = new Intersection<>(isso);
final CompactSketch<IntegerSummary> icsk = inter.intersect(tupleSk, thetaSk, ufactory.newSummary().update(1));
entries = icsk.getRetainedEntries();
println("Intersection: " + entries);
final SketchIterator<IntegerSummary> iiter = icsk.iterator();
counter = 1;
while (iiter.next()) {
final int i = iiter.getSummary().getValue();
// 9 entries = 2
println(counter++ + ", " + i);
assertEquals(i, 1);
}
}
use of org.apache.datasketches.theta.UpdateSketch 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);
}
use of org.apache.datasketches.theta.UpdateSketch 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) {
}
}
use of org.apache.datasketches.theta.UpdateSketch 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);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class CornerCaseTupleSetOperationsTest method estimationDegenerate.
@Test
public void estimationDegenerate() {
IntegerSketch tupleA = getTupleSketch(SkType.ESTIMATION, MIDP_FLT, LT_LOWP_V);
IntegerSketch tupleB = getTupleSketch(SkType.DEGENERATE, LOWP_FLT, GT_LOWP_V);
UpdateSketch thetaB = getThetaSketch(SkType.DEGENERATE, LOWP_FLT, GT_LOWP_V);
final double expectedIntersectTheta = LOWP_FLT;
final int expectedIntersectCount = 0;
final boolean expectedIntersectEmpty = false;
final double expectedAnotbTheta = LOWP_FLT;
final int expectedAnotbCount = 1;
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);
}
Aggregations