@Override public int centroidCount() { return summary.size(); }
/** * Returns an upper bound on the number bytes that will be required to represent this histogram. */ @Override public int byteSize() { compress(); return 32 + summary.size() * 12; }
@Override public TDigest recordAllData() { if (summary.size() != 0) { throw new IllegalStateException("Can only ask to record added data on an empty summary"); } summary = new AVLGroupTree(true); return super.recordAllData(); }
/** * 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 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); } }
public double cdf(double x) { AVLGroupTree values = summary; if (values.size() == 0) { return Double.NaN; } else if (values.size() == 1) { if (x < values.mean(values.first())) return 0; else if (x > values.mean(values.first())) return 1; return 1 - interpolateTail(values, x, last, lastMean, max); assert values.size() >= 2; assert x >= firstMean; assert x <= lastMean;
@Override public void compress() { if (summary.size() <= 1) { return;
/** * Returns an upper bound on the number bytes that will be required to represent this histogram. */ @Override public int byteSize() { return 4 + 8 + 4 + summary.size() * 12; }
@Override public int centroidCount() { return summary.size(); }
@Override public TDigest recordAllData() { if (summary.size() != 0) { throw new IllegalStateException("Can only ask to record added data on an empty summary"); } summary = new AVLGroupTree(true); return super.recordAllData(); }
/** * Outputs a histogram as bytes using a particularly cheesy encoding. */ @Override public void asBytes(ByteBuffer buf) { buf.putInt(VERBOSE_ENCODING); buf.putDouble(compression()); buf.putInt(summary.size()); for (Centroid centroid : summary) { buf.putDouble(centroid.mean()); } for (Centroid centroid : summary) { buf.putInt(centroid.count()); } }
@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 void compress() { if (summary.size() <= 1) { return; } AVLGroupTree centroids = summary; this.summary = new AVLGroupTree(recordAllData); final int[] nodes = new int[centroids.size()]; nodes[0] = centroids.first(); for (int i = 1; i < nodes.length; ++i) { nodes[i] = centroids.next(nodes[i-1]); assert nodes[i] != IntAVLTree.NIL; } assert centroids.next(nodes[nodes.length - 1]) == IntAVLTree.NIL; for (int i = centroids.size() - 1; i > 0; --i) { final int other = gen.nextInt(i + 1); final int tmp = nodes[other]; nodes[other] = nodes[i]; nodes[i] = tmp; } for (int node : nodes) { add(centroids.mean(node), centroids.count(node), centroids.data(node)); } }