public class TDigest
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
TDigest.Group |
Modifier and Type | Field and Description |
---|---|
static int |
SMALL_ENCODING |
static int |
VERBOSE_ENCODING |
Constructor and Description |
---|
TDigest(double compression)
A histogram structure that will record a sketch of a distribution.
|
TDigest(double compression,
java.util.Random random) |
Modifier and Type | Method and Description |
---|---|
void |
add(double x)
Adds a sample to a histogram.
|
void |
add(double x,
int w)
Adds a sample to a histogram.
|
void |
add(TDigest other) |
void |
asBytes(java.nio.ByteBuffer buf)
Outputs a histogram as bytes using a particularly cheesy encoding.
|
void |
asSmallBytes(java.nio.ByteBuffer buf) |
int |
byteSize()
Returns an upper bound on the number bytes that will be required to
represent this histogram.
|
double |
cdf(double x) |
int |
centroidCount() |
java.lang.Iterable<? extends TDigest.Group> |
centroids() |
void |
compress() |
double |
compression() |
static int |
decode(java.nio.ByteBuffer buf) |
static void |
encode(java.nio.ByteBuffer buf,
int n) |
static TDigest |
fromBytes(java.nio.ByteBuffer buf)
Reads a histogram from a byte buffer
|
static TDigest |
merge(double compression,
java.lang.Iterable<TDigest> subData) |
double |
quantile(double q) |
TDigest |
recordAllData()
Sets up so that all centroids will record all data assigned to them.
|
int |
size()
Returns the number of samples represented in this histogram.
|
int |
smallByteSize()
Returns an upper bound on the number of bytes that will be required to
represent this histogram in the tighter representation.
|
public static final int VERBOSE_ENCODING
public static final int SMALL_ENCODING
public TDigest(double compression)
compression
- How should accuracy be traded for size? A value of N
here will give quantile errors almost always less than 3/N with
considerably smaller errors expected for extreme quantiles.
Conversely, you should expect to track about 5 N centroids for
this accuracy.public TDigest(double compression, java.util.Random random)
public void add(double x)
x
- The value to add.public void add(double x, int w)
x
- The value to add.w
- The weight of this point.public void add(TDigest other)
public void compress()
public int size()
public double cdf(double x)
x
- the value at which the CDF should be evaluatedpublic double quantile(double q)
q
- The quantile desired. Can be in the range [0,1].public int centroidCount()
public java.lang.Iterable<? extends TDigest.Group> centroids()
public double compression()
public TDigest recordAllData()
public int byteSize()
public int smallByteSize()
public void asBytes(java.nio.ByteBuffer buf)
public void asSmallBytes(java.nio.ByteBuffer buf)
public static void encode(java.nio.ByteBuffer buf, int n)
public static int decode(java.nio.ByteBuffer buf)
public static TDigest fromBytes(java.nio.ByteBuffer buf)