@Test(expectedExceptions = SketchesArgumentException.class) public void incompatibleSeeds() { ArrayOfDoublesSketch sketchA = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(1).build(); ArrayOfDoublesSketch sketchB = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(2).build(); ArrayOfDoublesAnotB aNotB = new ArrayOfDoublesSetOperationBuilder().setSeed(3).buildAnotB(); aNotB.update(sketchA, sketchB); }
@Test(expectedExceptions = SketchesArgumentException.class) public void incompatibleSeedA() { ArrayOfDoublesSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(1).build(); ArrayOfDoublesAnotB aNotB = new ArrayOfDoublesSetOperationBuilder().buildAnotB(); aNotB.update(sketch, null); }
@Test(expectedExceptions = SketchesArgumentException.class) public void incompatibleSeedB() { ArrayOfDoublesSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(1).build(); ArrayOfDoublesAnotB aNotB = new ArrayOfDoublesSetOperationBuilder().buildAnotB(); aNotB.update(null, sketch); }
@Test(expectedExceptions = SketchesArgumentException.class) public void incompatibleSeeds() { ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(1).build(); ArrayOfDoublesUnion union = new ArrayOfDoublesSetOperationBuilder().setSeed(2).buildUnion(); union.update(sketch); }
@Test(expectedExceptions = SketchesArgumentException.class) public void incompatibleSeeds() { ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(1).build(); ArrayOfDoublesIntersection intersection = new ArrayOfDoublesSetOperationBuilder().setSeed(2).buildIntersection(); intersection.update(sketch, combiner); } }
@Test public void heapToDirectWithSeed() { long seed = 1; double[] values = {1.0}; ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build(); sketch1.update("a", values); sketch1.update("b", values); sketch1.update("c", values); ArrayOfDoublesUpdatableSketch sketch2 = ArrayOfDoublesUpdatableSketch.wrap(WritableMemory.wrap(sketch1.toByteArray()), seed); sketch2.update("b", values); sketch2.update("c", values); sketch2.update("d", values); Assert.assertEquals(sketch2.getEstimate(), 4.0); }
@Test public void heapExactModeCustomSeed() { long seed = 1234567890; ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build(); sketch1.update(1, new double[] {1}); sketch1.update(1, new double[] {1}); sketch1.update(2, new double[] {1}); sketch1.update(2, new double[] {1}); ArrayOfDoublesUpdatableSketch sketch2 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build(); sketch2.update(2, new double[] {1}); sketch2.update(2, new double[] {1}); sketch2.update(3, new double[] {1}); sketch2.update(3, new double[] {1}); ArrayOfDoublesIntersection intersection = new ArrayOfDoublesSetOperationBuilder().setSeed(seed).buildIntersection(); intersection.update(sketch1, combiner); intersection.update(sketch2, combiner); ArrayOfDoublesCompactSketch result = intersection.getResult(); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getRetainedEntries(), 1); Assert.assertEquals(result.getEstimate(), 1.0); Assert.assertEquals(result.getLowerBound(1), 1.0); Assert.assertEquals(result.getUpperBound(1), 1.0); double[][] values = result.getValues(); for (int i = 0; i < values.length; i++) Assert.assertEquals(values[i][0], 4.0); }
@Test public void heapSerializeDeserializeWithSeed() { long seed = 1; int key = 0; ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build(); for (int i = 0; i < 8192; i++) { sketch1.update(key++, new double[] {1.0}); } key -= 4096; // overlap half of the entries ArrayOfDoublesUpdatableSketch sketch2 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build(); for (int i = 0; i < 8192; i++) { sketch2.update(key++, new double[] {1.0}); } ArrayOfDoublesUnion union1 = new ArrayOfDoublesSetOperationBuilder().setSeed(seed).buildUnion(); union1.update(sketch1); union1.update(sketch2); ArrayOfDoublesUnion union2 = ArrayOfDoublesUnion.heapify(Memory.wrap(union1.toByteArray()), seed); ArrayOfDoublesCompactSketch result = union2.getResult(); Assert.assertEquals(result.getEstimate(), 12288.0, 12288 * 0.01); }
@Test public void exactModeCustomSeed() { long seed = 1234567890; ArrayOfDoublesUpdatableSketch sketchA = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build(); sketchA.update(1, new double[] {1}); sketchA.update(2, new double[] {1}); sketchA.update(3, new double[] {1}); sketchA.update(4, new double[] {1}); sketchA.update(5, new double[] {1}); ArrayOfDoublesUpdatableSketch sketchB = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build(); sketchB.update(3, new double[] {1}); sketchB.update(4, new double[] {1}); sketchB.update(5, new double[] {1}); sketchB.update(6, new double[] {1}); sketchB.update(7, new double[] {1}); ArrayOfDoublesAnotB aNotB = new ArrayOfDoublesSetOperationBuilder().setSeed(seed).buildAnotB(); aNotB.update(sketchA, sketchB); ArrayOfDoublesCompactSketch result = aNotB.getResult(); Assert.assertFalse(result.isEmpty()); Assert.assertEquals(result.getRetainedEntries(), 2); Assert.assertEquals(result.getEstimate(), 2.0); Assert.assertEquals(result.getLowerBound(1), 2.0); Assert.assertEquals(result.getUpperBound(1), 2.0); ArrayOfDoublesSketchIterator it = result.iterator(); while (it.next()) { Assert.assertEquals(it.getValues(), new double[] {1}); } }
@Test public void directToHeapWithSeed() { long seed = 1; double[] values = {1.0}; ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed).build( WritableMemory.wrap(new byte[1000000])); sketch1.update("a", values); sketch1.update("b", values); sketch1.update("c", values); ArrayOfDoublesUpdatableSketch sketch2 = ArrayOfDoublesUpdatableSketch.heapify(Memory.wrap(sketch1.toByteArray()), seed); sketch2.update("b", values); sketch2.update("c", values); sketch2.update("d", values); Assert.assertEquals(sketch2.getEstimate(), 4.0); }
@Test public void directSerializeDeserializeWithSeed() { long seed = 1; int key = 0; ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed) .build(WritableMemory.wrap(new byte[1000000])); for (int i = 0; i < 8192; i++) { sketch1.update(key++, new double[] {1.0}); } key -= 4096; // overlap half of the entries ArrayOfDoublesUpdatableSketch sketch2 = new ArrayOfDoublesUpdatableSketchBuilder().setSeed(seed) .build(WritableMemory.wrap(new byte[1000000])); for (int i = 0; i < 8192; i++) { sketch2.update(key++, new double[] {1.0}); } ArrayOfDoublesUnion union1 = new ArrayOfDoublesSetOperationBuilder().setSeed(seed) .buildUnion(WritableMemory.wrap(new byte[1000000])); union1.update(sketch1); union1.update(sketch2); ArrayOfDoublesUnion union2 = ArrayOfDoublesUnion.wrap(WritableMemory.wrap(union1.toByteArray()), seed); ArrayOfDoublesCompactSketch result = union2.getResult(WritableMemory.wrap(new byte[1000000])); Assert.assertEquals(result.getEstimate(), 12288.0, 12288 * 0.01); }