@Override public void add(TDigest other) { List<Centroid> tmp = new ArrayList<>(); for (Centroid centroid : other.centroids()) { tmp.add(centroid); } Collections.shuffle(tmp, gen); for (Centroid centroid : tmp) { add(centroid.mean(), centroid.count(), centroid); } }
/** * 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()); } }
@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(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); } }
@Override public boolean add(Centroid centroid) { add(centroid.mean(), centroid.count(), centroid.data()); return true; }
@Override public void add(List<? extends TDigest> others) { for (TDigest other : others) { setMinMax(Math.min(min, other.getMin()), Math.max(max, other.getMax())); for (Centroid centroid : other.centroids()) { add(centroid.mean(), centroid.count(), recordAllData ? centroid.data() : null); } } }
for (Centroid centroid : other.centroids()) { m[offset] = centroid.mean(); w[offset] = centroid.count(); if (recordAllData) { assert data != null;
@Override public int hashCode() { int h = getClass().hashCode(); h = 31 * h + Double.hashCode(compression); for (Centroid centroid : centroids()) { h = 31 * h + Double.hashCode(centroid.mean()); h = 31 * h + centroid.count(); } return h; } }
@Override public boolean equals(Object obj) { if (obj == null || obj instanceof TDigestState == false) { return false; } TDigestState that = (TDigestState) obj; if (compression != that.compression) { return false; } Iterator<? extends Centroid> thisCentroids = centroids().iterator(); Iterator<? extends Centroid> thatCentroids = that.centroids().iterator(); while (thisCentroids.hasNext()) { if (thatCentroids.hasNext() == false) { return false; } Centroid thisNext = thisCentroids.next(); Centroid thatNext = thatCentroids.next(); if (thisNext.mean() != thatNext.mean() || thisNext.count() != thatNext.count()) { return false; } } return thatCentroids.hasNext() == false; }
static double computeMedianAbsoluteDeviation(TDigestState valuesSketch) { if (valuesSketch.size() == 0) { return Double.NaN; } else { final double approximateMedian = valuesSketch.quantile(0.5); final TDigestState approximatedDeviationsSketch = new TDigestState(valuesSketch.compression()); valuesSketch.centroids().forEach(centroid -> { final double deviation = Math.abs(approximateMedian - centroid.mean()); approximatedDeviationsSketch.add(deviation, centroid.count()); }); return approximatedDeviationsSketch.quantile(0.5); } }
public static void write(TDigestState state, StreamOutput out) throws IOException { out.writeDouble(state.compression); out.writeVInt(state.centroidCount()); for (Centroid centroid : state.centroids()) { out.writeDouble(centroid.mean()); out.writeVLong(centroid.count()); } }
public GroupTree(Centroid leaf) { size = depth = 1; this.leaf = leaf; count = leaf.count(); left = right = null; }
@Override public int hashCode() { int h = getClass().hashCode(); h = 31 * h + Double.hashCode(compression); for (Centroid centroid : centroids()) { h = 31 * h + Double.hashCode(centroid.mean()); h = 31 * h + centroid.count(); } return h; } }
@Override public double mean() { Collection<Centroid> centroids = snapshot().centroids(); return centroids.size() == 0 ? Double.NaN : centroids.stream().mapToDouble(c -> (c.count() * c.mean()) / centroids.size()).sum(); }
@Override public double mean() { Collection<Centroid> centroids = snapshot().centroids(); return centroids.size() == 0 ? Double.NaN : centroids.stream().mapToDouble(c -> (c.count() * c.mean()) / centroids.size()).sum(); }
@Override public void add(TDigest other) { List<Centroid> tmp = new ArrayList<Centroid>(); for (Centroid centroid : other.centroids()) { tmp.add(centroid); } Collections.shuffle(tmp, gen); for (Centroid centroid : tmp) { add(centroid.mean(), centroid.count(), centroid); } }
public static void write(TDigestState state, StreamOutput out) throws IOException { out.writeDouble(state.compression); out.writeVInt(state.centroidCount()); for (Centroid centroid : state.centroids()) { out.writeDouble(centroid.mean()); out.writeVLong(centroid.count()); } }
public static void write(TDigestState state, StreamOutput out) throws IOException { out.writeDouble(state.compression); out.writeVInt(state.centroidCount()); for (Centroid centroid : state.centroids()) { out.writeDouble(centroid.mean()); out.writeVLong(centroid.count()); } }
public static void write(TDigestState state, StreamOutput out) throws IOException { out.writeDouble(state.compression); out.writeVInt(state.centroidCount()); for (Centroid centroid : state.centroids()) { out.writeDouble(centroid.mean()); out.writeVLong(centroid.count()); } }