public class DescriptiveStatistics extends Object implements StatisticalSummary, DoubleConsumer, Serializable
The windowSize
property sets a limit on the number
of values that can be stored in the dataset. The default value, INFINITE_WINDOW,
puts no limit on the size of the dataset. This value should be used with
caution, as the backing store will grow without bound in this case.
For very large datasets, StreamingStatistics
, which does not store
the dataset, should be used instead of this class. If windowSize
is not INFINITE_WINDOW and more values are added than can be stored in the
dataset, new values are added in a "rolling" manner, with new values replacing
the "oldest" values in the dataset.
Note: this class is not threadsafe.
Modifier and Type | Field and Description |
---|---|
protected static int |
INFINITE_WINDOW
Represents an infinite window size.
|
Modifier | Constructor and Description |
---|---|
|
DescriptiveStatistics()
Construct a DescriptiveStatistics instance with an infinite window.
|
protected |
DescriptiveStatistics(DescriptiveStatistics original)
Copy constructor.
|
|
DescriptiveStatistics(double[] initialDoubleArray)
Construct a DescriptiveStatistics instance with an infinite window
and the initial data values in double[] initialDoubleArray.
|
|
DescriptiveStatistics(int size)
Construct a DescriptiveStatistics instance with the specified window.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(double v) |
void |
addValue(double v)
Adds the value to the dataset.
|
double |
apply(UnivariateStatistic stat)
Apply the given statistic to the data associated with this set of statistics.
|
void |
clear()
Resets all statistics and storage.
|
DescriptiveStatistics |
copy()
Returns a copy of this DescriptiveStatistics instance with the same internal state.
|
double |
getElement(int index)
Returns the element at the specified index
|
double |
getGeometricMean()
Returns the geometric mean of the available values.
|
double |
getKurtosis()
Returns the Kurtosis of the available values.
|
double |
getMax()
Returns the maximum of the available values
|
double |
getMean()
Returns the
arithmetic mean of the available values
|
double |
getMin()
Returns the minimum of the available values
|
long |
getN()
Returns the number of available values
|
double |
getPercentile(double p)
Returns an estimate for the pth percentile of the stored values.
|
double |
getPopulationVariance()
Returns the population variance of the available values.
|
double |
getQuadraticMean()
Returns the quadratic mean of the available values.
|
double |
getSkewness()
Returns the skewness of the available values.
|
double[] |
getSortedValues()
Returns the current set of values in an array of double primitives,
sorted in ascending order.
|
double |
getStandardDeviation()
Returns the standard deviation of the available values.
|
double |
getSum()
Returns the sum of the values that have been added to Univariate.
|
double |
getSumOfSquares()
Returns the sum of the squares of the available values.
|
double[] |
getValues()
Returns the current set of values in an array of double primitives.
|
double |
getVariance()
Returns the variance of the available values.
|
int |
getWindowSize()
Returns the maximum number of values that can be stored in the
dataset, or INFINITE_WINDOW (-1) if there is no limit.
|
void |
removeMostRecentValue()
Removes the most recent value from the dataset.
|
double |
replaceMostRecentValue(double v)
Replaces the most recently stored value with the given value.
|
void |
setWindowSize(int windowSize)
WindowSize controls the number of values that contribute to the
reported statistics.
|
String |
toString()
Generates a text report displaying univariate statistics from values
that have been added.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
aggregate, aggregate
andThen
protected static final int INFINITE_WINDOW
getWindowSize()
returns this value, there is no limit to the number of data values
that can be stored in the dataset.public DescriptiveStatistics()
public DescriptiveStatistics(int size) throws MathIllegalArgumentException
size
- the window size.MathIllegalArgumentException
- if window size is less than 1 but
not equal to INFINITE_WINDOW
public DescriptiveStatistics(double[] initialDoubleArray)
initialDoubleArray
- the initial double[].NullArgumentException
- if the input array is nullprotected DescriptiveStatistics(DescriptiveStatistics original)
Construct a new DescriptiveStatistics instance that is a copy of original.
original
- DescriptiveStatistics instance to copyNullArgumentException
- if original is nullpublic DescriptiveStatistics copy()
public void addValue(double v)
v
- the value to be addedpublic void accept(double v)
accept
in interface DoubleConsumer
public void clear()
public void removeMostRecentValue() throws MathIllegalStateException
MathIllegalStateException
- if there are no elements storedpublic double replaceMostRecentValue(double v) throws MathIllegalStateException
v
- the value to replace the most recent stored valueMathIllegalStateException
- if there are no elements storedpublic double apply(UnivariateStatistic stat)
stat
- the statistic to applypublic double getMean()
getMean
in interface StatisticalSummary
public double getGeometricMean()
See GeometricMean
for details on the computing algorithm.
public double getStandardDeviation()
getStandardDeviation
in interface StatisticalSummary
public double getQuadraticMean()
Double.NaN
if no values
have been added.public double getVariance()
getVariance
in interface StatisticalSummary
public double getPopulationVariance()
public double getSkewness()
public double getKurtosis()
public double getMax()
getMax
in interface StatisticalSummary
public double getMin()
getMin
in interface StatisticalSummary
public double getSum()
getSum
in interface StatisticalSummary
public double getSumOfSquares()
public double getPercentile(double p) throws MathIllegalArgumentException
The implementation provided here follows the first estimation procedure presented here.
Preconditions:
0 < p ≤ 100
(otherwise an
MathIllegalArgumentException
is thrown)Double.NaN
otherwise)p
- the requested percentile (scaled from 0 - 100)MathIllegalArgumentException
- if p is not a valid quantilepublic long getN()
getN
in interface StatisticalSummary
public int getWindowSize()
public void setWindowSize(int windowSize) throws MathIllegalArgumentException
windowSize
is decreased as a result
of this call and there are more than the new value of elements in the
current dataset, values from the front of the array are discarded to
reduce the dataset to windowSize
elements.windowSize
- sets the size of the window.MathIllegalArgumentException
- if window size is less than 1 but
not equal to INFINITE_WINDOW
public double[] getValues()
public double[] getSortedValues()
public double getElement(int index)
index
- The Index of the elementCopyright © 2016–2020 Hipparchus.org. All rights reserved.