T
- the number type for these statistics@ThreadSafe public class DetailedStatistics<T extends Number> extends SimpleStatistics<T>
minimum
, maximum
, total (aggregate sum)
,
mean (average)
, median
, standard deviation
and the
histogram
of the values.
This class uses an efficient running calculation of the mean and standard deviation that is not as susceptible to roundoff errors as other traditional algorithms. The recursive algorithm is as follows, where M is the median value, sigma is the standard deviation, and S is a variable used in the calculation of sigma:
M(1) = x(1) S(1) = 0 M(k) = M(k-1) + ( x(k) - M(k-1) ) / k S(k) = S(k-1) + ( x(k) - M(k-1) ) * (x(k) - M(k))Then, the standard deviation for n values in x is
sigma = sqrt(S(n) / n)Unlike the other quantities, the median value (the value at which half of the values are greater and half the values are lower) cannot be calculated incrementally. Therefore, this class does record the values so that the median can be properly calculated. This fact should be kept in mind when performing statistics on large numbers of values.
This class is threadsafe.
math
Constructor and Description |
---|
DetailedStatistics(MathOperations<T> operations) |
Modifier and Type | Method and Description |
---|---|
protected void |
doAddValue(T value)
A method that can be overridden by subclasses when
add is called. |
protected void |
doReset()
Method that can be overridden by subclasses when
SimpleStatistics.reset() is called. |
Histogram<T> |
getHistogram()
Return the histogram of the
values . |
Histogram<T> |
getHistogram(int numSigmas)
Return the histogram of the
values . |
T |
getMedian()
Return the approximate mean (average) value represented as an instance of the operand type.
|
double |
getMedianValue()
Return the median value.
|
double |
getStandardDeviation()
Return the standard deviation.
|
List<T> |
getValues()
Get the values that have been recorded in these statistics.
|
String |
toString() |
add, getCount, getLock, getMathOperations, getMaximum, getMean, getMeanValue, getMinimum, getTotal, reset
public DetailedStatistics(MathOperations<T> operations)
public List<T> getValues()
added
in another thread.protected void doAddValue(T value)
SimpleStatistics
add
is called. This method is called within the
write lock, and does real work. Therefore, subclasses should call this method when they overwrite it.doAddValue
in class SimpleStatistics<T extends Number>
value
- the value already addedpublic T getMedian()
getMedianValue()
.count
is 0public double getMedianValue()
count
is 0getMedian()
public double getStandardDeviation()
count
is 0 or if all of the values are the same.public Histogram<T> getHistogram()
values
. This method returns a histogram where all of the buckets are
distributed normally and all have the same width. In this case, the 'numSigmas' should be set to 0. For other variations,
see getHistogram(int)
.getHistogram(int)
public Histogram<T> getHistogram(int numSigmas)
values
. This method is capable of creating two kinds of histograms. The
first kind is a histogram where all of the buckets are distributed normally and all have the same width. In this case, the
'numSigmas' should be set to 0. See getHistogram()
.
The second kind of histogram is more useful when most of the data that is clustered near one value. This histogram is
focused around the values that are up to 'numSigmas' above and below the median
, and all values
outside of this range are placed in the first and last bucket.
numSigmas
- the number of standard deviations from the median
, or 0 if the buckets of the
histogram should be evenly distributedgetHistogram()
protected void doReset()
SimpleStatistics
SimpleStatistics.reset()
is called. This method is called while the object is
locked for write and does work; therefore, the subclass should call this method.doReset
in class SimpleStatistics<T extends Number>
public String toString()
toString
in class SimpleStatistics<T extends Number>
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.