/** * Creates an AVLTreeDigest. AVLTreeDigest is nearly the best known implementation right now. * * @param compression The compression parameter. 100 is a common value for normal uses. 1000 is extremely large. * The number of centroids retained will be a smallish (usually less than 10) multiple of this number. * @return the AvlTreeDigest */ @SuppressWarnings("WeakerAccess") public static TDigest createAvlTreeDigest(double compression) { return new AVLTreeDigest(compression); }
double max = buf.getDouble(); double compression = buf.getDouble(); AVLTreeDigest r = new AVLTreeDigest(compression); r.setMinMax(min, max); int n = buf.getInt(); double[] means = new double[n]; r.add(means[i], buf.getInt()); double max = buf.getDouble(); double compression = buf.getDouble(); AVLTreeDigest r = new AVLTreeDigest(compression); r.setMinMax(min, max); int n = buf.getInt(); double[] means = new double[n]; int z = decode(buf); r.add(means[i], z);
/** * Returns an upper bound on the number of bytes that will be required to represent this histogram in * the tighter representation. */ @Override public int smallByteSize() { int bound = byteSize(); ByteBuffer buf = ByteBuffer.allocate(bound); asSmallBytes(buf); return buf.position(); }
@Override public void asSmallBytes(ByteBuffer buf) { buf.putInt(SMALL_ENCODING); buf.putDouble(min); buf.putDouble(max); buf.putDouble(compression()); buf.putInt(summary.size()); double x = 0; for (Centroid centroid : summary) { double delta = centroid.mean() - x; x = centroid.mean(); buf.putFloat((float) delta); } for (Centroid centroid : summary) { int n = centroid.count(); encode(buf, n); } }
protected static AVLTreeDigest delegateMerge(double compression, List<AVLTreeDigest> subData) { int n = Math.max(1, subData.size() / 4); AVLTreeDigest r = new AVLTreeDigest(compression); if (subData.get(0).isRecording()) { r.recordAllData(); } for (int i = 0; i < subData.size(); i += n) { if (n > 1) { r.add(delegateMerge(compression, subData.subList(i, Math.min(i + n, subData.size())))); } else { r.add(subData.get(i)); } } return r; } }
if (encoding == VERBOSE_ENCODING) { double compression = buf.getDouble(); AVLTreeDigest r = new AVLTreeDigest(compression); int n = buf.getInt(); double[] means = new double[n]; r.add(means[i], buf.getInt()); AVLTreeDigest r = new AVLTreeDigest(compression); int n = buf.getInt(); double[] means = new double[n]; int z = decode(buf); r.add(means[i], z);
public int peekLength(ByteBuffer in) { int mark = in.position(); AVLTreeDigest.fromBytes(in); int total = in.position() - mark; in.position(mark); return total; }
@Override public void add(double x, int w) { add(x, w, (List<Double>) null); }
public void add(double x, int w, List<Double> data) { checkValue(x); if (x < min) { min = x; centroid = weightedAverage(centroid, count, x, w); count += w; summary.update(closest, centroid, count, d, false); compress();
/** * Outputs a histogram as bytes using a particularly cheesy encoding. */ @Override public void asBytes(ByteBuffer buf) { buf.putInt(VERBOSE_ENCODING); buf.putDouble(min); buf.putDouble(max); buf.putDouble((float) compression()); buf.putInt(summary.size()); for (Centroid centroid : summary) { buf.putDouble(centroid.mean()); } for (Centroid centroid : summary) { buf.putInt(centroid.count()); } }
public void add(double x, int w, List<Double> data) { checkValue(x); int start = summary.floor(x); if (start == IntAVLTree.NIL) { compress();
@Override public int byteSize() { return m_delegate.byteSize(); }
@Override public void asSmallBytes(ByteBuffer buff) { m_delegate.asSmallBytes(buff); }
public void readRegisters(ByteBuffer in) { registers = AVLTreeDigest.fromBytes(in); compression = registers.compression(); }
@Override void add(double x, int w, Centroid base) { if (x != base.mean() || w != base.count()) { throw new IllegalArgumentException(); } add(x, w, base.data()); }
@Override public void asSmallBytes(ByteBuffer buf) { buf.putInt(SMALL_ENCODING); buf.putDouble(compression()); buf.putInt(summary.size()); double x = 0; for (Centroid centroid : summary) { double delta = centroid.mean() - x; x = centroid.mean(); buf.putFloat((float) delta); } for (Centroid centroid : summary) { int n = centroid.count(); encode(buf, n); } }
@Override public double compression() { return m_delegate.compression(); }
@Override TDigest create(double compression) { return new AVLTreeDigest(compression); }
/** * Returns an upper bound on the number of bytes that will be required to represent this histogram in * the tighter representation. */ @Override public int smallByteSize() { int bound = byteSize(); ByteBuffer buf = ByteBuffer.allocate(bound); asSmallBytes(buf); return buf.position(); }