public class DescriptiveStatistics extends Object implements StatisticalSummary, Serializable
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, SummaryStatistics
, 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. Use SynchronizedDescriptiveStatistics
if concurrent access from multiple
threads is required.
Modifier and Type | Field and Description |
---|---|
static int |
INFINITE_WINDOW
Represents an infinite window size.
|
protected int |
windowSize
hold the window size
|
Constructor and Description |
---|
DescriptiveStatistics()
Construct a DescriptiveStatistics instance with an infinite window
|
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 window)
Construct a DescriptiveStatistics instance with the specified window
|
Modifier and Type | Method and Description |
---|---|
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.
|
static void |
copy(DescriptiveStatistics source,
DescriptiveStatistics dest)
Copies source to dest.
|
double |
getElement(int index)
Returns the element at the specified index
|
double |
getGeometricMean()
Returns the
geometric mean of the available values
|
UnivariateStatistic |
getGeometricMeanImpl()
Returns the currently configured geometric mean implementation.
|
double |
getKurtosis()
Returns the Kurtosis of the available values.
|
UnivariateStatistic |
getKurtosisImpl()
Returns the currently configured kurtosis implementation.
|
double |
getMax()
Returns the maximum of the available values
|
UnivariateStatistic |
getMaxImpl()
Returns the currently configured maximum implementation.
|
double |
getMean()
Returns the
arithmetic mean of the available values
|
UnivariateStatistic |
getMeanImpl()
Returns the currently configured mean implementation.
|
double |
getMin()
Returns the minimum of the available values
|
UnivariateStatistic |
getMinImpl()
Returns the currently configured minimum implementation.
|
long |
getN()
Returns the number of available values
|
double |
getPercentile(double p)
Returns an estimate for the pth percentile of the stored values.
|
UnivariateStatistic |
getPercentileImpl()
Returns the currently configured percentile implementation.
|
double |
getPopulationVariance()
Returns the
population variance of the available values.
|
double |
getSkewness()
Returns the skewness of the available values.
|
UnivariateStatistic |
getSkewnessImpl()
Returns the currently configured skewness implementation.
|
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.
|
UnivariateStatistic |
getSumImpl()
Returns the currently configured sum implementation.
|
double |
getSumsq()
Returns the sum of the squares of the available values.
|
UnivariateStatistic |
getSumsqImpl()
Returns the currently configured sum of squares implementation.
|
double[] |
getValues()
Returns the current set of values in an array of double primitives.
|
double |
getVariance()
Returns the (sample) variance of the available values.
|
UnivariateStatistic |
getVarianceImpl()
Returns the currently configured variance implementation.
|
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 |
setGeometricMeanImpl(UnivariateStatistic geometricMeanImplIn)
Sets the implementation for the gemoetric mean.
|
void |
setKurtosisImpl(UnivariateStatistic kurtosisImplIn)
Sets the implementation for the kurtosis.
|
void |
setMaxImpl(UnivariateStatistic maxImplIn)
Sets the implementation for the maximum.
|
void |
setMeanImpl(UnivariateStatistic meanImplIn)
Sets the implementation for the mean.
|
void |
setMinImpl(UnivariateStatistic minImplIn)
Sets the implementation for the minimum.
|
void |
setPercentileImpl(UnivariateStatistic percentileImplIn)
Sets the implementation to be used by
getPercentile(double) . |
void |
setSkewnessImpl(UnivariateStatistic skewnessImplIn)
Sets the implementation for the skewness.
|
void |
setSumImpl(UnivariateStatistic sumImplIn)
Sets the implementation for the sum.
|
void |
setSumsqImpl(UnivariateStatistic sumsqImplIn)
Sets the implementation for the sum of squares.
|
void |
setVarianceImpl(UnivariateStatistic varianceImplIn)
Sets the implementation for the variance.
|
void |
setWindowSize(int windowSizeIn)
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.
|
public 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.protected int windowSize
public DescriptiveStatistics()
public DescriptiveStatistics(int window)
window
- 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[].public DescriptiveStatistics(DescriptiveStatistics original)
original
- DescriptiveStatistics instance to copyNullArgumentException
- if original is nullpublic void addValue(double v)
v
- the value to be addedpublic void removeMostRecentValue()
MathIllegalStateException
- if there are no elements storedpublic double replaceMostRecentValue(double v)
v
- the value to replace the most recent stored valueMathIllegalStateException
- if there are no elements storedpublic double getMean()
getMean
in interface StatisticalSummary
public double getGeometricMean()
public double getVariance()
This method returns the bias-corrected sample variance (using n - 1
in the denominator). Use
getPopulationVariance()
for the non-bias-corrected population variance.
getVariance
in interface StatisticalSummary
public double getPopulationVariance()
public double getStandardDeviation()
getStandardDeviation
in interface StatisticalSummary
public double getSkewness()
public double getKurtosis()
public double getMax()
getMax
in interface StatisticalSummary
public double getMin()
getMin
in interface StatisticalSummary
public long getN()
getN
in interface StatisticalSummary
public double getSum()
getSum
in interface StatisticalSummary
public double getSumsq()
public void clear()
public int getWindowSize()
public void setWindowSize(int windowSizeIn)
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.windowSizeIn
- 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 elementpublic double getPercentile(double p)
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)MathIllegalStateException
- if percentile implementation has been
overridden and the supplied implementation does not support setQuantileMathIllegalArgumentException
- if p is not a valid quantilepublic String toString()
public double apply(UnivariateStatistic stat)
stat
- the statistic to applypublic UnivariateStatistic getMeanImpl()
public void setMeanImpl(UnivariateStatistic meanImplIn)
Sets the implementation for the mean.
meanImplIn
- the UnivariateStatistic instance to use
for computing the meanpublic UnivariateStatistic getGeometricMeanImpl()
public void setGeometricMeanImpl(UnivariateStatistic geometricMeanImplIn)
Sets the implementation for the gemoetric mean.
geometricMeanImplIn
- the UnivariateStatistic instance to use
for computing the geometric meanpublic UnivariateStatistic getKurtosisImpl()
public void setKurtosisImpl(UnivariateStatistic kurtosisImplIn)
Sets the implementation for the kurtosis.
kurtosisImplIn
- the UnivariateStatistic instance to use
for computing the kurtosispublic UnivariateStatistic getMaxImpl()
public void setMaxImpl(UnivariateStatistic maxImplIn)
Sets the implementation for the maximum.
maxImplIn
- the UnivariateStatistic instance to use
for computing the maximumpublic UnivariateStatistic getMinImpl()
public void setMinImpl(UnivariateStatistic minImplIn)
Sets the implementation for the minimum.
minImplIn
- the UnivariateStatistic instance to use
for computing the minimumpublic UnivariateStatistic getPercentileImpl()
public void setPercentileImpl(UnivariateStatistic percentileImplIn)
getPercentile(double)
.
The supplied UnivariateStatistic
must provide a setQuantile(double)
method; otherwise
IllegalArgumentException
is thrown.percentileImplIn
- the percentileImpl to setMathIllegalArgumentException
- if the supplied implementation does not
provide a setQuantile
methodpublic UnivariateStatistic getSkewnessImpl()
public void setSkewnessImpl(UnivariateStatistic skewnessImplIn)
Sets the implementation for the skewness.
skewnessImplIn
- the UnivariateStatistic instance to use
for computing the skewnesspublic UnivariateStatistic getVarianceImpl()
public void setVarianceImpl(UnivariateStatistic varianceImplIn)
Sets the implementation for the variance.
varianceImplIn
- the UnivariateStatistic instance to use
for computing the variancepublic UnivariateStatistic getSumsqImpl()
public void setSumsqImpl(UnivariateStatistic sumsqImplIn)
Sets the implementation for the sum of squares.
sumsqImplIn
- the UnivariateStatistic instance to use
for computing the sum of squarespublic UnivariateStatistic getSumImpl()
public void setSumImpl(UnivariateStatistic sumImplIn)
Sets the implementation for the sum.
sumImplIn
- the UnivariateStatistic instance to use
for computing the sumpublic DescriptiveStatistics copy()
public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest)
Neither source nor dest can be null.
source
- DescriptiveStatistics to copydest
- DescriptiveStatistics to copy toNullArgumentException
- if either source or dest is nullCopyright © 2023 CNES. All rights reserved.