Class BarSplittingBiasedHistogram
java.lang.Object
org.terracotta.statistics.derived.histogram.BarSplittingBiasedHistogram
- All Implemented Interfaces:
Histogram
An implementation of the histogram algorithm described in:
'Fast Computation of Approximate Biased Histograms on Sliding Windows over Data Streams' [H. Mousavi & C. Zaniolo]
This class is *not thread-safe*, safe consumption in a multi-threaded environment will require some form of external locking.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classNested classes/interfaces inherited from interface org.terracotta.statistics.derived.histogram.Histogram
Histogram.Bucket -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final doubleprivate final intprivate final doubleprivate final List<BarSplittingBiasedHistogram.Bar>private final intprivate static final doubleprivate static final intprivate static final doubleprivate static final doubleprivate final double[]private final doubleprivate final doubleprivate longprivate final long -
Constructor Summary
ConstructorsConstructorDescriptionBarSplittingBiasedHistogram(double maxCoefficient, double phi, int expansionFactor, int bucketCount, double barEpsilon, long window) Create a histogram maintained over a sliding time window.BarSplittingBiasedHistogram(double phi, int bucketCount, long window) Create a histogram maintained over a sliding time window.BarSplittingBiasedHistogram(int bucketCount, long window) Create a histogram maintained over a sliding time window. -
Method Summary
Modifier and TypeMethodDescription(package private) doublealphaPhi()(package private) List<BarSplittingBiasedHistogram.Bar>bars()(package private) intprivate double[]evaluateQuantileFromMax(double quantile) private double[]evaluateQuantileFromMin(double quantile) voidevent(double value, long time) Record an event of the givenvalueoccuring at he giventimevoidexpire(long time) Expire old events from all buckets.private intgetBarIndex(double value) Returns the histograms bucketsdoubleThe maximum value.doubleThe minimum value.double[]getQuantileBounds(double quantile) Returns the bounds[minimum, maximum)on the given quantile.private doublemaxBarSize(int barIndex) private intprotected static doublenextUpIfEqual(double test, double value) (package private) doublephi()longsize()private voidsplit(BarSplittingBiasedHistogram.Bar x, int xIndex) toString()
-
Field Details
-
DEFAULT_MAX_COEFFICIENT
private static final double DEFAULT_MAX_COEFFICIENT- See Also:
-
DEFAULT_PHI
private static final double DEFAULT_PHI- See Also:
-
DEFAULT_EXPANSION_FACTOR
private static final int DEFAULT_EXPANSION_FACTOR- See Also:
-
DEFAULT_EXP_HISTOGRAM_EPSILON
private static final double DEFAULT_EXP_HISTOGRAM_EPSILON- See Also:
-
barCount
private final int barCount -
bucketCount
private final int bucketCount -
barEpsilon
private final double barEpsilon -
window
private final long window -
phi
private final double phi -
alphaPhi
private final double alphaPhi -
ratio
private final double ratio -
bars
-
maxSizeTable
private final double[] maxSizeTable -
size
private long size
-
-
Constructor Details
-
BarSplittingBiasedHistogram
public BarSplittingBiasedHistogram(double maxCoefficient, double phi, int expansionFactor, int bucketCount, double barEpsilon, long window) Create a histogram maintained over a sliding time window.The constructed histogram is:
- maintained over
windowsliding window - consists of
bucketCountbuckets - where
b1.size() ~= b0.size * phi - with each bucket internally composed of
expansionFactorbars - with each bar maintaining a count accurate with a fractional error of
barEpsilon - where bars are split when there size exceeds
maxCoefficientof their target size
- Parameters:
maxCoefficient- relative split thresholdphi- histogram bucket bias factorexpansionFactor- number of bars per bucketbucketCount- number of bucketsbarEpsilon- bar count relative errorwindow- sliding window size
- maintained over
-
BarSplittingBiasedHistogram
public BarSplittingBiasedHistogram(int bucketCount, long window) Create a histogram maintained over a sliding time window.The constructed histogram is:
- maintained over
windowsliding window - consists of
bucketCountbuckets - where
b1.size() ~= b0.size * 0.7
- Parameters:
bucketCount- number of bucketswindow- sliding window size
- maintained over
-
BarSplittingBiasedHistogram
public BarSplittingBiasedHistogram(double phi, int bucketCount, long window) Create a histogram maintained over a sliding time window.The constructed histogram is:
- maintained over
windowsliding window - consists of
bucketCountbuckets - where
b1.size() ~= b0.size * phi
- Parameters:
phi- histogram bucket bias factorbucketCount- number of bucketswindow- sliding window size
- maintained over
-
-
Method Details
-
event
public void event(double value, long time) Record an event of the givenvalueoccuring at he giventime -
expire
public void expire(long time) Expire old events from all buckets. -
toString
-
getBuckets
Description copied from interface:HistogramReturns the histograms buckets- Specified by:
getBucketsin interfaceHistogram- Returns:
- the histogram buckets
-
nextUpIfEqual
protected static double nextUpIfEqual(double test, double value) -
getMinimum
public double getMinimum()Description copied from interface:HistogramThe minimum value.This is equal to the inclusive lower bound of the zeroth (0.0) quantile.
- Specified by:
getMinimumin interfaceHistogram- Returns:
- the minimum value
-
getMaximum
public double getMaximum()Description copied from interface:HistogramThe maximum value.This is equal to highest double value strictly less than the exclusive upper bound of the last (1.0) quantile.
- Specified by:
getMaximumin interfaceHistogram- Returns:
- the maximum value
-
getQuantileBounds
public double[] getQuantileBounds(double quantile) Description copied from interface:HistogramReturns the bounds[minimum, maximum)on the given quantile.- Specified by:
getQuantileBoundsin interfaceHistogram- Parameters:
quantile- desired quantile- Returns:
- the quantile bounds
-
evaluateQuantileFromMax
private double[] evaluateQuantileFromMax(double quantile) -
evaluateQuantileFromMin
private double[] evaluateQuantileFromMin(double quantile) -
maxBarSize
private double maxBarSize(int barIndex) -
split
-
mergeBars
private int mergeBars() -
getBarIndex
private int getBarIndex(double value) -
size
public long size() -
bars
List<BarSplittingBiasedHistogram.Bar> bars() -
alphaPhi
double alphaPhi() -
phi
double phi() -
bucketCount
int bucketCount()
-