Search in sources :

Example 6 with Centroid

use of com.tdunning.math.stats.Centroid in project beam by apache.

the class TDigestQuantilesTest method encodeDecodeEquals.

private <T> boolean encodeDecodeEquals(MergingDigest tDigest) throws IOException {
    MergingDigest decoded = CoderUtils.clone(new MergingDigestCoder(), tDigest);
    boolean equal = true;
    // the only way to compare the two sketches is to compare them centroid by centroid.
    // Indeed, the means are doubles but are encoded as float and cast during decoding.
    // This entails a small approximation that makes the centroids different after decoding.
    Iterator<Centroid> it1 = decoded.centroids().iterator();
    Iterator<Centroid> it2 = tDigest.centroids().iterator();
    for (int i = 0; i < decoded.centroids().size(); i++) {
        Centroid c1 = it1.next();
        Centroid c2 = it2.next();
        if ((float) c1.mean() != (float) c2.mean() || c1.count() != c2.count()) {
            equal = false;
            break;
        }
    }
    return equal;
}
Also used : MergingDigest(com.tdunning.math.stats.MergingDigest) Centroid(com.tdunning.math.stats.Centroid) MergingDigestCoder(org.apache.beam.sdk.extensions.sketching.TDigestQuantiles.MergingDigestCoder)

Example 7 with Centroid

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());
    }
}
Also used : Centroid(com.tdunning.math.stats.Centroid)

Aggregations

Centroid (com.tdunning.math.stats.Centroid)7 AVLTreeDigest (com.tdunning.math.stats.AVLTreeDigest)1 MergingDigest (com.tdunning.math.stats.MergingDigest)1 TDigest (com.tdunning.math.stats.TDigest)1 MetricsToTimeseries (com.wavefront.common.MetricsToTimeseries)1 Metrics (com.yammer.metrics.Metrics)1 Counter (com.yammer.metrics.core.Counter)1 DeltaCounter (com.yammer.metrics.core.DeltaCounter)1 Gauge (com.yammer.metrics.core.Gauge)1 Histogram (com.yammer.metrics.core.Histogram)1 Metered (com.yammer.metrics.core.Metered)1 MetricName (com.yammer.metrics.core.MetricName)1 MetricProcessor (com.yammer.metrics.core.MetricProcessor)1 Sampling (com.yammer.metrics.core.Sampling)1 Summarizable (com.yammer.metrics.core.Summarizable)1 Timer (com.yammer.metrics.core.Timer)1 WavefrontHistogram (com.yammer.metrics.core.WavefrontHistogram)1 Snapshot (com.yammer.metrics.stats.Snapshot)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1