@Override public Object finalizeComputation(final Object object) { return ((DoublesSketch) object).getN(); }
@Override public Object compute(final Map<String, Object> combinedAggregators) { final DoublesSketch sketch = (DoublesSketch) field.compute(combinedAggregators); final double[] histogram = sketch.getPMF(splitPoints); for (int i = 0; i < histogram.length; i++) { histogram[i] *= sketch.getN(); } return histogram; }
@Test public void testAggregate() { final DoublesSketchAggregator sketchAggregator = new DoublesSketchAggregator(); DoublesSketch currentState = sketch1; assertEquals(3L, currentState.getN()); assertEquals(2.0D, currentState.getQuantile(0.5D), DELTA); currentState = sketchAggregator.apply(currentState, sketch2); assertEquals(7L, currentState.getN()); assertEquals(4.0D, currentState.getQuantile(0.5D), DELTA); }
/** * Returns true if this sketch is empty * @return true if this sketch is empty */ public boolean isEmpty() { return getN() == 0; }
/** * Returns true if this sketch is in estimation mode. * @return true if this sketch is in estimation mode. */ public boolean isEstimationMode() { return getN() >= (2L * k_); }
Assert.assertTrue(obj instanceof DoublesSketch); DoublesSketch ds = (DoublesSketch) obj; Assert.assertEquals(40, ds.getN()); Assert.assertEquals(1.0, ds.getMinValue(), 0); Assert.assertEquals(1.0, ds.getMaxValue(), 0);
Assert.assertTrue(obj instanceof DoublesSketch); DoublesSketch ds = (DoublesSketch) obj; Assert.assertEquals(40, ds.getN()); Assert.assertEquals(1.0, ds.getMinValue(), 0); Assert.assertEquals(1.0, ds.getMaxValue(), 0);
Assert.assertTrue(obj instanceof DoublesSketch); DoublesSketch ds = (DoublesSketch) obj; Assert.assertEquals(40, ds.getN()); Assert.assertEquals(1.0, ds.getMinValue(), 0); Assert.assertEquals(1.0, ds.getMaxValue(), 0);
Assert.assertTrue(quantilesObj instanceof DoublesSketch); DoublesSketch ds = (DoublesSketch) quantilesObj; Assert.assertEquals(40, ds.getN()); Assert.assertEquals(1.0, ds.getMinValue(), 0); Assert.assertEquals(1.0, ds.getMaxValue(), 0);
Assert.assertTrue(obj instanceof DoublesSketch); DoublesSketch ds = (DoublesSketch) obj; Assert.assertEquals(40, ds.getN()); Assert.assertEquals(2.0, ds.getMinValue(), 0); Assert.assertEquals(2.0, ds.getMaxValue(), 0);
@Override double get(final int index) { assert index >= 0 && index < numItems_; assert n_ == ds_.getN(); return ds_.getCombinedBuffer()[offset_ + index]; }
@Override double set(final int index, final double value) { assert index >= 0 && index < numItems_; assert n_ == ds_.getN(); final int idxOffset = offset_ + index; final double oldVal = ds_.getCombinedBuffer()[idxOffset]; ds_.getCombinedBuffer()[idxOffset] = value; return oldVal; }
@Override double get(final int index) { assert index >= 0 && index < numItems_; assert n_ == ds_.getN(); final int idxOffset = offset_ + (index << 3); return ds_.getMemory().getDouble(idxOffset); }
/** * Computes the number of retained items (samples) in the sketch * @return the number of retained items (samples) in the sketch */ public int getRetainedItems() { return Util.computeRetainedItems(getK(), getN()); }
/** * Returns the number of bytes this sketch would require to store in compact form, which is not * updatable. * @return the number of bytes this sketch would require to store in compact form. */ public int getCompactStorageBytes() { return getCompactStorageBytes(getK(), getN()); }
/** * Returns the number of bytes this sketch would require to store in updatable form. * This uses roughly 2X the storage of the compact form. * @return the number of bytes this sketch would require to store in updatable form. */ public int getUpdatableStorageBytes() { return getUpdatableStorageBytes(getK(), getN()); }
@Override double set(final int index, final double value) { assert index >= 0 && index < numItems_; assert n_ == ds_.getN(); assert !ds_.isCompact(); // can't write to a compact sketch final int idxOffset = offset_ + (index << 3); final WritableMemory mem = ds_.getMemory(); final double oldVal = mem.getDouble(idxOffset); mem.putDouble(idxOffset, value); return oldVal; }
@Test public void wrapEmptyCompactSketch() { final CompactDoublesSketch s1 = DoublesSketch.builder().build().compact(); final Memory mem = Memory.wrap(ByteBuffer.wrap(s1.toByteArray()).order(ByteOrder.nativeOrder())); final DoublesSketch s2 = DoublesSketch.wrap(mem); assertTrue(s2.isEmpty()); assertEquals(s2.getN(), 0); assertTrue(Double.isNaN(s2.getMinValue())); assertTrue(Double.isNaN(s2.getMaxValue())); }
@Test public void checkUnionUpdateLogicDirectDownsampled() { final DirectUpdateDoublesSketch qs1 = (DirectUpdateDoublesSketch) buildAndLoadDQS(256, 1000); final DirectUpdateDoublesSketch qs2 = (DirectUpdateDoublesSketch) buildAndLoadDQS(128, 2000); final DoublesSketch result = DoublesUnionImpl.updateLogic(128, qs1, qs2); assertEquals(result.getMaxValue(), 2000.0, 0.0); assertEquals(result.getMinValue(), 1.0, 0.0); assertEquals(result.getN(), 3000); assertEquals(result.getK(), 128); }
@Test public void updateWithDoubleValueOnly() { final DoublesUnion union = DoublesUnion.builder().build(); union.update(123.456); final DoublesSketch qs = union.getResultAndReset(); assertEquals(qs.getN(), 1); }