use of com.tdunning.math.stats.Centroid in project elasticsearch by elastic.
the class TDigestState method hashCode.
@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;
}
use of com.tdunning.math.stats.Centroid in project java by wavefrontHQ.
the class FlushProcessor method processHistogram.
@Override
public void processHistogram(MetricName name, Histogram histogram, FlushProcessorContext context) {
if (histogram instanceof WavefrontHistogram) {
WavefrontHistogram wavefrontHistogram = (WavefrontHistogram) histogram;
if (useWavefrontHistograms) {
// export Wavefront histograms in its native format
if (wavefrontHistogram.count() == 0)
return;
for (WavefrontHistogram.MinuteBin bin : wavefrontHistogram.bins(true)) {
if (bin.getDist().size() == 0)
continue;
int size = bin.getDist().centroids().size();
List<Double> centroids = new ArrayList<>(size);
List<Integer> counts = new ArrayList<>(size);
for (Centroid centroid : bin.getDist().centroids()) {
centroids.add(centroid.mean());
counts.add(centroid.count());
}
context.report(wavefront.report.Histogram.newBuilder().setDuration(// minute bins
60_000).setType(HistogramType.TDIGEST).setBins(centroids).setCounts(counts).build(), bin.getMinMillis());
histogramCounter.inc();
}
} else {
// convert Wavefront histogram to Yammer-style histogram
TDigest tDigest = new AVLTreeDigest(100);
List<WavefrontHistogram.MinuteBin> bins = wavefrontHistogram.bins(true);
bins.stream().map(WavefrontHistogram.MinuteBin::getDist).forEach(tDigest::add);
context.reportSubMetric(tDigest.centroids().stream().mapToLong(Centroid::count).sum(), "count");
Summarizable summarizable = new Summarizable() {
@Override
public double max() {
return tDigest.centroids().stream().map(Centroid::mean).max(Comparator.naturalOrder()).orElse(Double.NaN);
}
@Override
public double min() {
return tDigest.centroids().stream().map(Centroid::mean).min(Comparator.naturalOrder()).orElse(Double.NaN);
}
@Override
public double mean() {
Centroid mean = tDigest.centroids().stream().reduce((x, y) -> new Centroid(x.mean() + (y.mean() * y.count()), x.count() + y.count())).orElse(null);
return mean == null || tDigest.centroids().size() == 0 ? Double.NaN : mean.mean() / mean.count();
}
@Override
public double stdDev() {
return Double.NaN;
}
@Override
public double sum() {
return Double.NaN;
}
};
for (Map.Entry<String, Double> entry : MetricsToTimeseries.explodeSummarizable(summarizable, reportEmptyHistogramStats).entrySet()) {
if (!entry.getValue().isNaN()) {
context.reportSubMetric(entry.getValue(), entry.getKey());
}
}
Sampling sampling = () -> new Snapshot(new double[0]) {
@Override
public double get75thPercentile() {
return tDigest.quantile(.75);
}
@Override
public double get95thPercentile() {
return tDigest.quantile(.95);
}
@Override
public double get98thPercentile() {
return tDigest.quantile(.98);
}
@Override
public double get999thPercentile() {
return tDigest.quantile(.999);
}
@Override
public double get99thPercentile() {
return tDigest.quantile(.99);
}
@Override
public double getMedian() {
return tDigest.quantile(.50);
}
@Override
public double getValue(double quantile) {
return tDigest.quantile(quantile);
}
@Override
public double[] getValues() {
return new double[0];
}
@Override
public int size() {
return (int) tDigest.size();
}
};
for (Map.Entry<String, Double> entry : MetricsToTimeseries.explodeSampling(sampling, reportEmptyHistogramStats).entrySet()) {
if (!entry.getValue().isNaN()) {
context.reportSubMetric(entry.getValue(), entry.getKey());
}
}
sentCounter.inc();
}
} else {
context.reportSubMetric(histogram.count(), "count");
for (Map.Entry<String, Double> entry : MetricsToTimeseries.explodeSummarizable(histogram, reportEmptyHistogramStats).entrySet()) {
if (!entry.getValue().isNaN()) {
context.reportSubMetric(entry.getValue(), entry.getKey());
}
}
for (Map.Entry<String, Double> entry : MetricsToTimeseries.explodeSampling(histogram, reportEmptyHistogramStats).entrySet()) {
if (!entry.getValue().isNaN()) {
context.reportSubMetric(entry.getValue(), entry.getKey());
}
}
sentCounter.inc();
histogram.clear();
}
}
use of com.tdunning.math.stats.Centroid in project elasticsearch by elastic.
the class TDigestState method write.
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());
}
}
use of com.tdunning.math.stats.Centroid in project elasticsearch by elastic.
the class TDigestState method equals.
@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;
}
use of com.tdunning.math.stats.Centroid in project crate by crate.
the class TDigestState method write.
public static void write(TDigestState state, StreamOutput out) throws IOException {
out.writeDouble(state.compression);
out.writeDoubleArray(state.fractions);
out.writeVInt(state.centroidCount());
for (Centroid centroid : state.centroids()) {
out.writeDouble(centroid.mean());
out.writeVLong(centroid.count());
}
}
Aggregations