use of org.apache.datasketches.theta.UpdateSketch 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);
}
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class AdoubleAnotBTest method aNotBNullEmptyCombinations.
/**
**************************************
*/
@Test
public void aNotBNullEmptyCombinations() {
final AnotB<DoubleSummary> aNotB = new AnotB<>();
// calling getResult() before calling update() should yield an empty set
final CompactSketch<DoubleSummary> result = aNotB.getResult(true);
results.set(0, true, 0.0, 0.0, 0.0).check(result);
final UpdatableSketch<Double, DoubleSummary> sketch = buildUpdatableTuple();
final UpdateSketch skTheta = buildUpdateTheta();
threeMethodsWithTheta(aNotB, null, null, null, results);
threeMethodsWithTheta(aNotB, sketch, null, null, results);
threeMethodsWithTheta(aNotB, null, sketch, null, results);
threeMethodsWithTheta(aNotB, sketch, sketch, null, results);
threeMethodsWithTheta(aNotB, null, null, skTheta, results);
threeMethodsWithTheta(aNotB, sketch, null, skTheta, results);
threeMethodsWithTheta(aNotB, null, sketch, skTheta, results);
threeMethodsWithTheta(aNotB, sketch, sketch, skTheta, results);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class AdoubleAnotBTest method aNotBExactOverlap.
@Test
public void aNotBExactOverlap() {
final UpdatableSketch<Double, DoubleSummary> sketchA = buildUpdatableTuple();
sketchA.update(1, 1.0);
sketchA.update(1, 1.0);
sketchA.update(2, 1.0);
sketchA.update(2, 1.0);
final UpdatableSketch<Double, DoubleSummary> sketchB = buildUpdatableTuple();
sketchB.update(2, 1.0);
sketchB.update(2, 1.0);
sketchB.update(3, 1.0);
sketchB.update(3, 1.0);
final UpdateSketch skThetaB = buildUpdateTheta();
skThetaB.update(2);
skThetaB.update(3);
final AnotB<DoubleSummary> aNotB = new AnotB<>();
results.set(1, false, 1.0, 0.0, 2.0);
threeMethodsWithTheta(aNotB, sketchA, sketchB, skThetaB, results);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class AdoubleAnotBTest method aNotBEmptyExact.
@Test
public void aNotBEmptyExact() {
final UpdatableSketch<Double, DoubleSummary> sketchA = buildUpdatableTuple();
final UpdatableSketch<Double, DoubleSummary> sketchB = buildUpdatableTuple();
sketchB.update(1, 1.0);
sketchB.update(2, 1.0);
final UpdateSketch skThetaB = buildUpdateTheta();
skThetaB.update(1);
skThetaB.update(2);
final AnotB<DoubleSummary> aNotB = new AnotB<>();
results.set(0, true, 0.0, 0.0, 0.0);
threeMethodsWithTheta(aNotB, sketchA, sketchB, skThetaB, results);
}
use of org.apache.datasketches.theta.UpdateSketch in project sketches-core by DataSketches.
the class AdoubleAnotBTest method aNotBEstimationOverlapLargeB.
@Test
public void aNotBEstimationOverlapLargeB() {
final UpdatableSketch<Double, DoubleSummary> sketchA = buildUpdatableTuple();
for (int i = 0; i < 10_000; i++) {
sketchA.update(i, 1.0);
}
final UpdatableSketch<Double, DoubleSummary> sketchB = buildUpdatableTuple();
for (int i = 0; i < 100_000; i++) {
sketchB.update(i + 8000, 1.0);
}
final UpdateSketch skThetaB = buildUpdateTheta();
for (int i = 0; i < 100_000; i++) {
skThetaB.update(i + 8000);
}
final int expected = 8_000;
final AnotB<DoubleSummary> aNotB = new AnotB<>();
results.set(376, false, expected, 0.1, 1.0);
threeMethodsWithTheta(aNotB, sketchA, sketchB, skThetaB, results);
// same thing, but compact sketches
threeMethodsWithTheta(aNotB, sketchA.compact(), sketchB.compact(), skThetaB.compact(), results);
}
Aggregations