use of org.apache.datasketches.tuple.adouble.DoubleSummary 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.tuple.adouble.DoubleSummary 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.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.
the class CompactSketchWithDoubleSummaryTest method serialVersion1Compatibility.
@Test
public void serialVersion1Compatibility() throws Exception {
byte[] bytes = getResourceBytes("CompactSketchWithDoubleSummary4K_serialVersion1.sk");
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes), new DoubleSummaryDeserializer());
Assert.assertTrue(sketch.isEstimationMode());
Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.99);
Assert.assertEquals(sketch.getRetainedEntries(), 4096);
int count = 0;
SketchIterator<DoubleSummary> it = sketch.iterator();
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 1.0);
count++;
}
Assert.assertEquals(count, 4096);
}
use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.
the class CompactSketchWithDoubleSummaryTest method serializeDeserializeEstimation.
@Test
public void serializeDeserializeEstimation() throws Exception {
UpdatableSketch<Double, DoubleSummary> us = new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode)).build();
for (int i = 0; i < 8192; i++) {
us.update(i, 1.0);
}
us.trim();
CompactSketch<DoubleSummary> sketch1 = us.compact();
byte[] bytes = sketch1.toByteArray();
// for binary testing
// TestUtil.writeBytesToFile(bytes, "CompactSketchWithDoubleSummary4K.sk");
Sketch<DoubleSummary> sketch2 = Sketches.heapifySketch(Memory.wrap(bytes), new DoubleSummaryDeserializer());
Assert.assertFalse(sketch2.isEmpty());
Assert.assertTrue(sketch2.isEstimationMode());
Assert.assertEquals(sketch2.getEstimate(), sketch1.getEstimate());
Assert.assertEquals(sketch2.getThetaLong(), sketch1.getThetaLong());
SketchIterator<DoubleSummary> it = sketch2.iterator();
int count = 0;
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 1.0);
count++;
}
Assert.assertEquals(count, 4096);
}
use of org.apache.datasketches.tuple.adouble.DoubleSummary in project sketches-core by DataSketches.
the class JaccardSimilarityTest method checkExactMode2.
@Test
public void checkExactMode2() {
// tuple, theta
int k = 1 << 12;
int u = k;
double threshold = 0.9999;
println("Exact Mode, minK: " + k + "\t Th: " + threshold);
final UpdatableSketch<Double, DoubleSummary> measured = tupleBldr.setNominalEntries(k).build();
final UpdateSketch expected = thetaBldr.setNominalEntries(k).build();
for (int i = 0; i < (u - 1); i++) {
// one short
measured.update(i, constSummary);
expected.update(i);
}
double[] jResults = jaccard(measured, expected, factory.newSummary(), dsso);
boolean state = jResults[1] > threshold;
println(state + "\t" + jaccardString(jResults));
assertTrue(state);
state = exactlyEqual(measured, expected, factory.newSummary(), dsso);
assertTrue(state);
// now exactly k entries
measured.update(u - 1, constSummary);
// now exactly k entries but differs by one
expected.update(u);
jResults = jaccard(measured, expected, factory.newSummary(), dsso);
state = jResults[1] > threshold;
println(state + "\t" + jaccardString(jResults));
assertFalse(state);
state = exactlyEqual(measured, expected, factory.newSummary(), dsso);
assertFalse(state);
println("");
}
Aggregations