Class BarSplittingBiasedHistogram
- java.lang.Object
-
- org.terracotta.statistics.derived.histogram.BarSplittingBiasedHistogram
-
- All Implemented Interfaces:
Histogram
public class BarSplittingBiasedHistogram extends java.lang.Object implements 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 Classes Modifier and Type Class Description (package private) static classBarSplittingBiasedHistogram.Bar-
Nested classes/interfaces inherited from interface org.terracotta.statistics.derived.histogram.Histogram
Histogram.Bucket
-
-
Field Summary
Fields Modifier and Type Field Description private doublealphaPhiprivate intbarCountprivate doublebarEpsilonprivate java.util.List<BarSplittingBiasedHistogram.Bar>barsprivate intbucketCountprivate static doubleDEFAULT_EXP_HISTOGRAM_EPSILONprivate static intDEFAULT_EXPANSION_FACTORprivate static doubleDEFAULT_MAX_COEFFICIENTprivate static doubleDEFAULT_PHIprivate double[]maxSizeTableprivate doublephiprivate doubleratioprivate longsizeprivate longwindow
-
Constructor Summary
Constructors Constructor Description BarSplittingBiasedHistogram(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) doublealphaPhi()(package private) java.util.List<BarSplittingBiasedHistogram.Bar>bars()(package private) intbucketCount()private 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)java.util.List<Histogram.Bucket>getBuckets()Returns the histograms bucketsdoublegetMaximum()The maximum value.doublegetMinimum()The minimum value.double[]getQuantileBounds(double quantile)Returns the bounds[minimum, maximum)on the given quantile.private doublemaxBarSize(int barIndex)private intmergeBars()protected static doublenextUpIfEqual(double test, double value)(package private) doublephi()longsize()private voidsplit(BarSplittingBiasedHistogram.Bar x, int xIndex)java.lang.StringtoString()
-
-
-
Field Detail
-
DEFAULT_MAX_COEFFICIENT
private static final double DEFAULT_MAX_COEFFICIENT
- See Also:
- Constant Field Values
-
DEFAULT_PHI
private static final double DEFAULT_PHI
- See Also:
- Constant Field Values
-
DEFAULT_EXPANSION_FACTOR
private static final int DEFAULT_EXPANSION_FACTOR
- See Also:
- Constant Field Values
-
DEFAULT_EXP_HISTOGRAM_EPSILON
private static final double DEFAULT_EXP_HISTOGRAM_EPSILON
- See Also:
- Constant Field Values
-
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
private final java.util.List<BarSplittingBiasedHistogram.Bar> bars
-
maxSizeTable
private final double[] maxSizeTable
-
size
private long size
-
-
Constructor Detail
-
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 Detail
-
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getBuckets
public java.util.List<Histogram.Bucket> 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
private void split(BarSplittingBiasedHistogram.Bar x, int xIndex)
-
mergeBars
private int mergeBars()
-
getBarIndex
private int getBarIndex(double value)
-
size
public long size()
-
bars
java.util.List<BarSplittingBiasedHistogram.Bar> bars()
-
alphaPhi
double alphaPhi()
-
phi
double phi()
-
bucketCount
int bucketCount()
-
-