@Override public int centroidCount() { mergeNewValues(); return lastUsedCell; }
/** * Merges any pending inputs and compresses the data down to the public setting. * Note that this typically loses a bit of precision and thus isn't a thing to * be doing all the time. It is best done only when we want to show results to * the outside world. */ @Override public void compress() { mergeNewValues(true, publicCompression); }
private void mergeNewValues() { mergeNewValues(false, compression); }
private void add(double x, int w, List<Double> history) { if (Double.isNaN(x)) { throw new IllegalArgumentException("Cannot add NaN to t-digest"); } if (tempUsed >= tempWeight.length - lastUsedCell - 1) { mergeNewValues(); } int where = tempUsed++; tempWeight[where] = w; tempMean[where] = x; unmergedWeight += w; if (x < min) { min = x; } if (x > max) { max = x; } if (data != null) { if (tempData == null) { tempData = new ArrayList<>(); } while (tempData.size() <= where) { tempData.add(new ArrayList<Double>()); } if (history == null) { history = Collections.singletonList(x); } tempData.get(where).addAll(history); } }
@Override public double cdf(double x) { mergeNewValues();
throw new IllegalArgumentException("q should be in [0,1], got " + q); mergeNewValues();