/// <summary> /// Merge two T-Digests /// </summary> /// <param name="a">The first T-Digest</param> /// <param name="b">The second T-Digest</param> /// <returns>A T-Digest created by merging the specified T-Digests</returns> public static TDigest Merge(TDigest a, TDigest b) { TDigest merged = new TDigest(); Centroid[] combined = a._centroids.Values.Concat(b._centroids.Values).ToArray(); combined.Shuffle(); foreach (var c in combined) { merged.Add(c.Mean, c.Count); } merged._newAvg = ((a._newAvg * a._count) + (b._newAvg * b._count)) / (a.Count + b.Count); merged._oldAvg = ((a._oldAvg * (a.Count - 1)) + (b._oldAvg * (b.Count - 1))) / (a._count + b._count - 2); return(merged); }
private bool Compress() { TDigest newTDigest = new TDigest(Accuracy, CompressionConstant); List <Centroid> temp = _centroids.Values.ToList(); temp.Shuffle(); foreach (Centroid centroid in temp) { newTDigest.Add(centroid.Mean, centroid.Count); } _centroids = newTDigest._centroids; return(true); }