use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.
the class TupleExamples2Test method example3.
@Test
public void example3() {
// stateless: tuple1, tuple2, use dsso2
// 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<>(dsso2);
final CompactSketch<DoubleSummary> ucsk = union.union(tupleSk, thetaSk, ufactory.newSummary().update(1.0));
int entries = ucsk.getRetainedEntries();
println("Union: " + 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<>(dsso2);
final CompactSketch<DoubleSummary> icsk = inter.intersect(tupleSk, thetaSk, ufactory.newSummary().update(1.0));
entries = icsk.getRetainedEntries();
println("Intersection: " + entries);
final SketchIterator<DoubleSummary> iiter = icsk.iterator();
counter = 1;
while (iiter.next()) {
final int i = (int) iiter.getSummary().getValue();
// 9 entries = 2
println(counter++ + ", " + i);
assertEquals(i, 1);
}
}
use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.
the class TupleExamples2Test method example1.
@Test
public void example1() {
// stateful: tuple, theta, use dsso2
// 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<>(dsso2);
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<>(dsso2);
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, 1);
}
}
use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.
the class MiscTest method checkCopyCtor.
@Test
public void checkCopyCtor() {
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();
sk.update(1.0, 1.0);
assertEquals(sk.getRetainedEntries(), 1);
final UpdatableSketch<Double, DoubleSummary> sk2 = sk.copy();
assertEquals(sk2.getRetainedEntries(), 1);
}
Aggregations