/** * Turns on internal data recording. */ @Override public TDigest recordAllData() { super.recordAllData(); data = new ArrayList<>(); tempData = new ArrayList<>(); return this; }
/** * Adds a sample to a histogram. * * @param x The value to add. */ @Override public void add(double x) { add(x, 1); }
public void add(double x, int w, Iterable<? extends Double> data) { if (actualData != null) { if (data != null) { for (Double old : data) { actualData.add(old); } } else { actualData.add(x); } } centroid = AbstractTDigest.weightedAverage(centroid, count, x, w); count += w; }
/** * Same as {@link #weightedAverageSorted(double, double, double, double)} but flips * the order of the variables if <code>x2</code> is greater than * <code>x1</code>. */ static double weightedAverage(double x1, double w1, double x2, double w2) { if (x1 <= x2) { return weightedAverageSorted(x1, w1, x2, w2); } else { return weightedAverageSorted(x2, w2, x1, w1); } }
return (r + a.count() * AbstractTDigest.interpolate(x, a.mean() - left, a.mean() + right)) / totalWeight; a = b; if (x < a.mean() + right) { return (r + a.count() * AbstractTDigest.interpolate(x, a.mean() - left, a.mean() + right)) / totalWeight; } else { return 1;
@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(); }
@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); } }
/** * Turns on internal data recording. */ @Override public TDigest recordAllData() { super.recordAllData(); data = new ArrayList<>(); mergeData = new ArrayList<>(); return this; }
/** * Adds a sample to a histogram. * * @param x The value to add. */ @Override public void add(double x) { add(x, 1); }
/** * Turns on internal data recording. */ @Override public TDigest recordAllData() { super.recordAllData(); data = new ArrayList<>(); mergeData = new ArrayList<>(); return this; }
@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); } }
@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(); }
protected static TDigest merge(Iterable<TDigest> subData, Random gen, TDigest r) { List<Centroid> centroids = new ArrayList<Centroid>(); boolean recordAll = false; for (TDigest digest : subData) { for (Centroid centroid : digest.centroids()) { centroids.add(centroid); } recordAll |= digest.isRecording(); } Collections.shuffle(centroids, gen); if (recordAll) { r.recordAllData(); } for (Centroid c : centroids) { if (r.isRecording()) { // TODO should do something better here. } ((AbstractTDigest) r).add(c.mean(), c.count(), c); } return r; }