public class DubboMergingDigest extends DubboAbstractTDigest
This can be very fast because the cost of sorting and merging is amortized over several insertion. If we keep N centroids total and have the input array is k long, then the amortized cost is something like
N/k + log k
These costs even out when N/k = log k. Balancing costs is often a good place to start in optimizing an algorithm. For different values of compression factor, the following table shows estimated asymptotic values of N and suggested values of k:
| Compression | N | k |
| 50 | 78 | 25 |
| 100 | 157 | 42 |
| 200 | 314 | 73 |
The virtues of this kind of t-digest implementation include:
The current implementation takes the liberty of using ping-pong buffers for implementing the merge resulting in a substantial memory penalty, but the complexity of an in place merge was not considered as worthwhile since even with the overhead, the memory cost is less than 40 bytes per centroid which is much less than half what the AVLTreeDigest uses and no dynamic allocation is required at all.
| Modifier and Type | Class and Description |
|---|---|
static class |
DubboMergingDigest.Encoding |
| Modifier and Type | Field and Description |
|---|---|
boolean |
useAlternatingSort |
boolean |
useTwoLevelCompression |
static boolean |
useWeightLimit |
| Constructor and Description |
|---|
DubboMergingDigest(double compression)
Allocates a buffer merging t-digest.
|
DubboMergingDigest(double compression,
int bufferSize)
If you know the size of the temporary buffer for incoming points, you can use this entry point.
|
DubboMergingDigest(double compression,
int bufferSize,
int size)
Fully specified constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(double x,
int w) |
void |
add(List<? extends com.tdunning.math.stats.TDigest> others) |
void |
asBytes(ByteBuffer buf) |
void |
asSmallBytes(ByteBuffer buf) |
int |
byteSize() |
double |
cdf(double x) |
int |
centroidCount() |
Collection<com.tdunning.math.stats.Centroid> |
centroids() |
void |
compress()
Merges any pending inputs and compresses the data down to the public setting.
|
double |
compression() |
double |
getMax() |
double |
getMin() |
com.tdunning.math.stats.ScaleFunction |
getScaleFunction() |
double |
quantile(double q) |
com.tdunning.math.stats.TDigest |
recordAllData()
Turns on internal data recording.
|
void |
setScaleFunction(com.tdunning.math.stats.ScaleFunction scaleFunction) |
long |
size() |
int |
smallByteSize() |
String |
toString() |
add, add, isRecordingpublic boolean useAlternatingSort
public boolean useTwoLevelCompression
public static boolean useWeightLimit
public DubboMergingDigest(double compression)
compression - The compression factorpublic DubboMergingDigest(double compression,
int bufferSize)
compression - Compression factor for t-digest. Same as 1/\delta in the paper.bufferSize - How many samples to retain before merging.public DubboMergingDigest(double compression,
int bufferSize,
int size)
compression - Compression factorbufferSize - Number of temporary centroidssize - Size of main bufferpublic double getMin()
getMin in class com.tdunning.math.stats.TDigestpublic double getMax()
getMax in class com.tdunning.math.stats.TDigestpublic com.tdunning.math.stats.TDigest recordAllData()
recordAllData in class DubboAbstractTDigestpublic void add(double x,
int w)
add in class com.tdunning.math.stats.TDigestpublic void add(List<? extends com.tdunning.math.stats.TDigest> others)
add in class com.tdunning.math.stats.TDigestpublic void compress()
compress in class com.tdunning.math.stats.TDigestpublic long size()
size in class com.tdunning.math.stats.TDigestpublic double cdf(double x)
cdf in class com.tdunning.math.stats.TDigestpublic double quantile(double q)
quantile in class com.tdunning.math.stats.TDigestpublic int centroidCount()
centroidCount in class com.tdunning.math.stats.TDigestpublic Collection<com.tdunning.math.stats.Centroid> centroids()
centroids in class com.tdunning.math.stats.TDigestpublic double compression()
compression in class com.tdunning.math.stats.TDigestpublic int byteSize()
byteSize in class com.tdunning.math.stats.TDigestpublic int smallByteSize()
smallByteSize in class com.tdunning.math.stats.TDigestpublic com.tdunning.math.stats.ScaleFunction getScaleFunction()
public void setScaleFunction(com.tdunning.math.stats.ScaleFunction scaleFunction)
setScaleFunction in class com.tdunning.math.stats.TDigestpublic void asBytes(ByteBuffer buf)
asBytes in class com.tdunning.math.stats.TDigestpublic void asSmallBytes(ByteBuffer buf)
asSmallBytes in class com.tdunning.math.stats.TDigestCopyright © 2011–2020 The Apache Software Foundation. All rights reserved.