use of org.apache.datasketches.theta.UpdateSketchBuilder 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.UpdateSketchBuilder 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;
}
use of org.apache.datasketches.theta.UpdateSketchBuilder 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.UpdateSketchBuilder 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.UpdateSketchBuilder 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);
}
Aggregations