public class QuantileTracker extends Object
Tracks quantile value estimates for some metric. The range over which to track values as well as the margin of error are configurable.
For example, if we wanted to track values between 1.0 and 100.0 with a margin of error of 2%, we could create a quantiler like so:
QuantileTracker quantiler = new QuantileTracker(1.0d, 100.0d, 0.02d);
We could then supply our data points using the increment(double)
method and retrieve quantile estimates for the 50th percentile
(i.e., the median), the 90th percentile, and the 99th percentile using
estimateQuantiles(double...)
like so:
QuantileTracker.Range[] results = quantiler.estimateQuantiles(0.5d, 0.9d, 0.99d);
A tracker works by creating an array of long integers, each of which represents a count of the number of data points that have fallen in a particular range of values. These ranges are allocated such that, between the specified minimum and maximum, no range is wider than the specified margin of error (where the error is applied with respect to the value of the lower bound). If you created a tracker with parameters as in the example above, the first count would represent the values between 1.00 and 1.02, the second would represent the values between 1.02 and 1.0404, etc. Results are returned as the lower and upper bounds of the bins to which the specified quantiles belong.
The size of the array required can be found as follows, where min
,
max
, and err
correspond to the parameters used to construct
the quantile tracker:
floor(ln(max / min) / ln(1 + err)) + 1
For our example, this would evaluate as:
arrayLength = floor(ln(100.0 / 1.0) / ln(1 + 0.02)) + 1 = floor(ln(100.0) / ln(1.02)) + 1 = floor(232.55349) + 1 = 233
Since our values are longs, this works out to about 1.8 KB.
Modifier and Type | Class and Description |
---|---|
class |
QuantileTracker.Range
Container for the boundaries that represent a quantile value estimation
|
Constructor and Description |
---|
QuantileTracker(double min,
double max,
double error)
Constructs a new quantiler to operate over the specified range
with the specified margin of error.
|
Modifier and Type | Method and Description |
---|---|
QuantileTracker.Range[] |
estimateQuantiles(double... quantiles)
Estimates the value of each specified quantile and returns its lower
and upper bounds (the returned array is in the same order as the
specified quantiles.)
|
long |
getNumDataPoints() |
void |
increment(double value)
Adds the specified data point
|
public QuantileTracker(double min, double max, double error)
public long getNumDataPoints()
public void increment(double value)
public QuantileTracker.Range[] estimateQuantiles(double... quantiles)
quantiles
- The quantiles to estimate (e.g. 0.5 for the median,
0.99 for the 99th percentile, etc.). They must be
between 0.0 and 1.0, exclusive, and in increasing order.Copyright © 2013, Oracle and/or its affiliates. All rights reserved.