/** * Heapify the given Memory and seed as a ArrayOfDoublesSketch * @param mem the given Memory * @param seed the given seed * @return an ArrayOfDoublesSketch */ public static ArrayOfDoublesSketch heapifySketch(final Memory mem, final long seed) { return ArrayOfDoublesSketch.heapify(mem, seed); }
/** * Heapify the given Memory as an ArrayOfDoublesSketch * @param mem the given Memory * @return an ArrayOfDoublesSketch */ public static ArrayOfDoublesSketch heapify(final Memory mem) { return heapify(mem, DEFAULT_UPDATE_SEED); }
@Test public void serializeDeserializeSampling() { int sketchSize = 16384; int numberOfUniques = sketchSize; ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(sketchSize).setSamplingProbability(0.5f).build(); for (int i = 0; i < numberOfUniques; i++) sketch1.update(i, new double[] {1.0}); ArrayOfDoublesSketch sketch2 = ArrayOfDoublesSketch.heapify(Memory.wrap(sketch1.toByteArray())); Assert.assertTrue(sketch2.isEstimationMode()); Assert.assertEquals(sketch2.getEstimate() / numberOfUniques, 1.0, 0.01); Assert.assertEquals(sketch2.getRetainedEntries() / (double) numberOfUniques, 0.5, 0.01); Assert.assertEquals(sketch1.getTheta(), sketch2.getTheta()); }
/** * Heapify the given Memory as an ArrayOfDoublesSketch * @param mem the given Memory * @return an ArrayOfDoublesSketch */ public static ArrayOfDoublesSketch heapify(final Memory mem) { return heapify(mem, DEFAULT_UPDATE_SEED); }
/** * Heapify the given Memory and seed as a ArrayOfDoublesSketch * @param mem the given Memory * @param seed the given seed * @return an ArrayOfDoublesSketch */ public static ArrayOfDoublesSketch heapifySketch(final Memory mem, final long seed) { return ArrayOfDoublesSketch.heapify(mem, seed); }
@Test public void serializeDeserializeEstimationNoResize() throws Exception { ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder(). setResizeFactor(ResizeFactor.X1).build(); for (int j = 0; j < 10; j++) { for (int i = 0; i < 8192; i++) sketch1.update(i, new double[] {1.0}); } byte[] byteArray = sketch1.toByteArray(); //for visual testing //TestUtil.writeBytesToFile(byteArray, "ArrayOfDoublesQuickSelectSketch4K.data"); ArrayOfDoublesSketch sketch2 = ArrayOfDoublesSketch.heapify(Memory.wrap(byteArray)); Assert.assertTrue(sketch2.isEstimationMode()); Assert.assertEquals(sketch2.getEstimate(), 8192, 8192 * 0.99); Assert.assertEquals(sketch1.getTheta(), sketch2.getTheta()); double[][] values = sketch2.getValues(); Assert.assertTrue(values.length >= 4096); for (double[] array: values) Assert.assertEquals(array[0], 10.0); }