Top Description Inners Fields Constructors Methods
org.terracotta.statistics.derived.histogram

public Class BarSplittingBiasedHistogram

extends Object
implements Histogram
Class Inheritance
All Implemented Interfaces
org.terracotta.statistics.derived.histogram.Histogram
Imports
java.util.ArrayList, .Iterator, .List, .ListIterator

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.

See Also
Fast Computation of Approximate Biased Histograms on Sliding Windows over Data Streams

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final double
private final int
private final double
private final List<BarSplittingBiasedHistogram.Bar>
private final int
private static final double
private static final int
private static final double
private static final double
private final double[]
private final double
private final double
private long
private final long

Constructor Summary

AccessConstructor and Description
public
BarSplittingBiasedHistogram(double
relative split threshold
maxCoefficient
,
double
histogram bucket bias factor
phi
,
int
number of bars per bucket
expansionFactor
,
int
number of buckets
bucketCount
,
double
bar count relative error
barEpsilon
,
long
sliding window size
window
)

Create a histogram maintained over a sliding time window.

public
BarSplittingBiasedHistogram(int
number of buckets
bucketCount
,
long
sliding window size
window
)

Create a histogram maintained over a sliding time window.

public
BarSplittingBiasedHistogram(double
histogram bucket bias factor
phi
,
int
number of buckets
bucketCount
,
long
sliding window size
window
)

Create a histogram maintained over a sliding time window.

Method Summary

Modifier and TypeMethod and Description
pack-priv double
pack-priv List<BarSplittingBiasedHistogram.Bar>
bars()

pack-priv int
private double[]
evaluateQuantileFromMax(double quantile)

private double[]
evaluateQuantileFromMin(double quantile)

public void
event(double
event value
value
,
long
event time
time
)

Implements org.terracotta.statistics.derived.histogram.Histogram.event.

Record an event of the given value occuring at he given time
public void
expire(long
current timestamp
time
)

Implements org.terracotta.statistics.derived.histogram.Histogram.expire.

Expire old events from all buckets.
private int
getBarIndex(double value)

public List<Histogram.Bucket>
public double
public double
public double[]
getQuantileBounds(double
desired quantile
quantile
)

Implements org.terracotta.statistics.derived.histogram.Histogram.getQuantileBounds.

Returns the bounds [minimum, maximum) on the given quantile.
public double[]
private double
maxBarSize(int barIndex)

private int
protected static double
nextUpIfEqual(double test, double value)

pack-priv double
phi()

public long
private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

alphaPhiback to summary
private final double alphaPhi
barCountback to summary
private final int barCount
barEpsilonback to summary
private final double barEpsilon
barsback to summary
private final List<BarSplittingBiasedHistogram.Bar> bars
bucketCountback to summary
private final int bucketCount
DEFAULT_EXP_HISTOGRAM_EPSILONback to summary
private static final double DEFAULT_EXP_HISTOGRAM_EPSILON
DEFAULT_EXPANSION_FACTORback to summary
private static final int DEFAULT_EXPANSION_FACTOR
DEFAULT_MAX_COEFFICIENTback to summary
private static final double DEFAULT_MAX_COEFFICIENT
DEFAULT_PHIback to summary
private static final double DEFAULT_PHI
maxSizeTableback to summary
private final double[] maxSizeTable
phiback to summary
private final double phi
ratioback to summary
private final double ratio
sizeback to summary
private long size
windowback to summary
private final long window

Constructor Detail

BarSplittingBiasedHistogramback to summary
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 window sliding window
  • consists of bucketCount buckets
  • where b1.size() ~= b0.size * phi
  • with each bucket internally composed of expansionFactor bars
  • with each bar maintaining a count accurate with a fractional error of barEpsilon
  • where bars are split when there size exceeds maxCoefficient of their target size
Parameters
maxCoefficient:double

relative split threshold

phi:double

histogram bucket bias factor

expansionFactor:int

number of bars per bucket

bucketCount:int

number of buckets

barEpsilon:double

bar count relative error

window:long

sliding window size

BarSplittingBiasedHistogramback to summary
public BarSplittingBiasedHistogram(int bucketCount, long window)

Create a histogram maintained over a sliding time window.

The constructed histogram is:

  • maintained over window sliding window
  • consists of bucketCount buckets
  • where b1.size() ~= b0.size * 0.7
Parameters
bucketCount:int

number of buckets

window:long

sliding window size

BarSplittingBiasedHistogramback to summary
public BarSplittingBiasedHistogram(double phi, int bucketCount, long window)

Create a histogram maintained over a sliding time window.

The constructed histogram is:

  • maintained over window sliding window
  • consists of bucketCount buckets
  • where b1.size() ~= b0.size * phi
Parameters
phi:double

histogram bucket bias factor

bucketCount:int

number of buckets

window:long

sliding window size

Method Detail

alphaPhiback to summary
pack-priv double alphaPhi()
barsback to summary
pack-priv List<BarSplittingBiasedHistogram.Bar> bars()
bucketCountback to summary
pack-priv int bucketCount()
evaluateQuantileFromMaxback to summary
private double[] evaluateQuantileFromMax(double quantile)
evaluateQuantileFromMinback to summary
private double[] evaluateQuantileFromMin(double quantile)
eventback to summary
public void event(double value, long time)

Implements org.terracotta.statistics.derived.histogram.Histogram.event.

Record an event of the given value occuring at he given time

Parameters
value:double

event value

time:long

event time

expireback to summary
public void expire(long time)

Implements org.terracotta.statistics.derived.histogram.Histogram.expire.

Expire old events from all buckets.

Parameters
time:long

current timestamp

getBarIndexback to summary
private int getBarIndex(double value)
getBucketsback to summary
public List<Histogram.Bucket> getBuckets()

Implements org.terracotta.statistics.derived.histogram.Histogram.getBuckets.

Doc from org.terracotta.statistics.derived.histogram.Histogram.getBuckets.

Returns the histograms buckets

Returns:List<Histogram.Bucket>

the histogram buckets

Annotations
@Override
getMaximumback to summary
public double getMaximum()

Overrides default org.terracotta.statistics.derived.histogram.Histogram.getMaximum.

Doc from org.terracotta.statistics.derived.histogram.Histogram.getMaximum.

The maximum value.

This is equal to highest double value strictly less than the exclusive upper bound of the last (1.0) quantile.

Returns:double

the maximum value

Annotations
@Override
getMinimumback to summary
public double getMinimum()

Overrides default org.terracotta.statistics.derived.histogram.Histogram.getMinimum.

Doc from org.terracotta.statistics.derived.histogram.Histogram.getMinimum.

The minimum value.

This is equal to the inclusive lower bound of the zeroth (0.0) quantile.

Returns:double

the minimum value

Annotations
@Override
getQuantileBoundsback to summary
public double[] getQuantileBounds(double quantile)

Implements org.terracotta.statistics.derived.histogram.Histogram.getQuantileBounds.

Doc from org.terracotta.statistics.derived.histogram.Histogram.getQuantileBounds.

Returns the bounds [minimum, maximum) on the given quantile.

Parameters
quantile:double

desired quantile

Returns:double[]

the quantile bounds

Annotations
@Override
getSizeBoundsback to summary
public double[] getSizeBounds()

Implements org.terracotta.statistics.derived.histogram.Histogram.getSizeBounds.

Returns:double[]

Doc from org.terracotta.statistics.derived.histogram.Histogram.getSizeBounds.

the bounds on the number of elements in the histogram

Annotations
@Override
maxBarSizeback to summary
private double maxBarSize(int barIndex)
mergeBarsback to summary
private int mergeBars()
nextUpIfEqualback to summary
protected static double nextUpIfEqual(double test, double value)
phiback to summary
pack-priv double phi()
sizeback to summary
public long size()

Implements org.terracotta.statistics.derived.histogram.Histogram.size.

Returns:long

Doc from org.terracotta.statistics.derived.histogram.Histogram.size.

the number of elements in the histogram

Annotations
@Override
splitback to summary
private void split(BarSplittingBiasedHistogram.Bar x, int xIndex)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.terracotta.statistics.derived.histogram back to summary

pack-priv final Class BarSplittingBiasedHistogram.Bar

extends Object
Class Inheritance
  • java.lang.Object
  • org.terracotta.statistics.derived.histogram.BarSplittingBiasedHistogram.Bar

Field Summary

Modifier and TypeField and Description
private final ExponentialHistogram
private double
private double

Constructor Summary

AccessConstructor and Description
pack-priv
Bar(double epsilon, long window)

private
Bar(ExponentialHistogram eh, double minimum, double maximum)

Method Summary

Modifier and TypeMethod and Description
pack-priv long
pack-priv double
pack-priv long
expire(long time)

pack-priv void
insert(double value, long time)

pack-priv double
pack-priv void
pack-priv double
pack-priv BarSplittingBiasedHistogram.Bar
split(double targetRatio)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ehback to summary
private final ExponentialHistogram eh
maximumback to summary
private double maximum
minimumback to summary
private double minimum

Constructor Detail

Barback to summary
pack-priv Bar(double epsilon, long window)
Barback to summary
private Bar(ExponentialHistogram eh, double minimum, double maximum)

Method Detail

countback to summary
pack-priv long count()
epsilonback to summary
pack-priv double epsilon()
expireback to summary
pack-priv long expire(long time)
insertback to summary
pack-priv void insert(double value, long time)
maximumback to summary
pack-priv double maximum()
mergeback to summary
pack-priv void merge(BarSplittingBiasedHistogram.Bar higher)
minimumback to summary
pack-priv double minimum()
splitback to summary
pack-priv BarSplittingBiasedHistogram.Bar split(double targetRatio)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override