Class SummaryStatistics
- java.lang.Object
-
- org.apache.commons.math4.legacy.stat.descriptive.SummaryStatistics
-
- All Implemented Interfaces:
StatisticalSummary
- Direct Known Subclasses:
SynchronizedSummaryStatistics
public class SummaryStatistics extends Object implements StatisticalSummary
Computes summary statistics for a stream of data values added using the
addValuemethod. The data values are not stored in memory, so this class can be used to compute statistics for very large data streams.The
StorelessUnivariateStatisticinstances used to maintain summary state and compute statistics are configurable via setters. For example, the default implementation for the variance can be overridden by callingsetVarianceImpl(StorelessUnivariateStatistic). Actual parameters to these methods must implement theStorelessUnivariateStatisticinterface and configuration must be completed beforeaddValueis called. No configuration is necessary to use the default, commons-math provided implementations.Note: This class is not thread-safe. Use
SynchronizedSummaryStatisticsif concurrent access from multiple threads is required.
-
-
Constructor Summary
Constructors Constructor Description SummaryStatistics()Construct a SummaryStatistics instance.SummaryStatistics(SummaryStatistics original)A copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddValue(double value)Add a value to the data.voidclear()Resets all statistics and storage.SummaryStatisticscopy()Returns a copy of this SummaryStatistics instance with the same internal state.static voidcopy(SummaryStatistics source, SummaryStatistics dest)Copies source to dest.booleanequals(Object object)Returns true iffobjectis aSummaryStatisticsinstance and all statistics have the same values as this.StorelessUnivariateStatisticgetGeoMeanImpl()Returns the currently configured geometric mean implementation.doublegetGeometricMean()Returns the geometric mean of the values that have been added.doublegetMax()Returns the maximum of the values that have been added.StorelessUnivariateStatisticgetMaxImpl()Returns the currently configured maximum implementation.doublegetMean()Returns the mean of the values that have been added.StorelessUnivariateStatisticgetMeanImpl()Returns the currently configured mean implementation.doublegetMin()Returns the minimum of the values that have been added.StorelessUnivariateStatisticgetMinImpl()Returns the currently configured minimum implementation.longgetN()Returns the number of available values.doublegetPopulationVariance()Returns the population variance of the values that have been added.doublegetQuadraticMean()Returns the quadratic mean, a.k.a.doublegetSecondMoment()Returns a statistic related to the Second Central Moment.doublegetStandardDeviation()Returns the standard deviation of the values that have been added.doublegetSum()Returns the sum of the values that have been added.StorelessUnivariateStatisticgetSumImpl()Returns the currently configured Sum implementation.StorelessUnivariateStatisticgetSumLogImpl()Returns the currently configured sum of logs implementation.StatisticalSummarygetSummary()Return aStatisticalSummaryValuesinstance reporting current statistics.doublegetSumOfLogs()Returns the sum of the logs of the values that have been added.doublegetSumsq()Returns the sum of the squares of the values that have been added.StorelessUnivariateStatisticgetSumsqImpl()Returns the currently configured sum of squares implementation.doublegetVariance()Returns the (sample) variance of the available values.StorelessUnivariateStatisticgetVarianceImpl()Returns the currently configured variance implementation.inthashCode()Returns hash code based on values of statistics.voidsetGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl)Sets the implementation for the geometric mean.voidsetMaxImpl(StorelessUnivariateStatistic maxImpl)Sets the implementation for the maximum.voidsetMeanImpl(StorelessUnivariateStatistic meanImpl)Sets the implementation for the mean.voidsetMinImpl(StorelessUnivariateStatistic minImpl)Sets the implementation for the minimum.voidsetSumImpl(StorelessUnivariateStatistic sumImpl)Sets the implementation for the Sum.voidsetSumLogImpl(StorelessUnivariateStatistic sumLogImpl)Sets the implementation for the sum of logs.voidsetSumsqImpl(StorelessUnivariateStatistic sumsqImpl)Sets the implementation for the sum of squares.voidsetVarianceImpl(StorelessUnivariateStatistic varianceImpl)Sets the implementation for the variance.StringtoString()Generates a text report displaying summary statistics from values that have been added.
-
-
-
Constructor Detail
-
SummaryStatistics
public SummaryStatistics()
Construct a SummaryStatistics instance.
-
SummaryStatistics
public SummaryStatistics(SummaryStatistics original) throws NullArgumentException
A copy constructor. Creates a deep-copy of theoriginal.- Parameters:
original- theSummaryStatisticsinstance to copy- Throws:
NullArgumentException- if original is null
-
-
Method Detail
-
getSummary
public StatisticalSummary getSummary()
Return aStatisticalSummaryValuesinstance reporting current statistics.- Returns:
- Current values of statistics
-
addValue
public void addValue(double value)
Add a value to the data.- Parameters:
value- the value to add
-
getN
public long getN()
Returns the number of available values.- Specified by:
getNin interfaceStatisticalSummary- Returns:
- The number of available values
-
getSum
public double getSum()
Returns the sum of the values that have been added.- Specified by:
getSumin interfaceStatisticalSummary- Returns:
- The sum or
Double.NaNif no values have been added
-
getSumsq
public double getSumsq()
Returns the sum of the squares of the values that have been added.Double.NaN is returned if no values have been added.
- Returns:
- The sum of squares
-
getMean
public double getMean()
Returns the mean of the values that have been added.Double.NaN is returned if no values have been added.
- Specified by:
getMeanin interfaceStatisticalSummary- Returns:
- the mean
-
getStandardDeviation
public double getStandardDeviation()
Returns the standard deviation of the values that have been added.Double.NaN is returned if no values have been added.
- Specified by:
getStandardDeviationin interfaceStatisticalSummary- Returns:
- the standard deviation
-
getQuadraticMean
public double getQuadraticMean()
Returns the quadratic mean, a.k.a. root-mean-square of the available values- Returns:
- The quadratic mean or
Double.NaNif no values have been added.
-
getVariance
public double getVariance()
Returns the (sample) variance of the available values.This method returns the bias-corrected sample variance (using
n - 1in the denominator). UsegetPopulationVariance()for the non-bias-corrected population variance.Double.NaN is returned if no values have been added.
- Specified by:
getVariancein interfaceStatisticalSummary- Returns:
- the variance
-
getPopulationVariance
public double getPopulationVariance()
Returns the population variance of the values that have been added.Double.NaN is returned if no values have been added.
- Returns:
- the population variance
-
getMax
public double getMax()
Returns the maximum of the values that have been added.Double.NaN is returned if no values have been added.
- Specified by:
getMaxin interfaceStatisticalSummary- Returns:
- the maximum
-
getMin
public double getMin()
Returns the minimum of the values that have been added.Double.NaN is returned if no values have been added.
- Specified by:
getMinin interfaceStatisticalSummary- Returns:
- the minimum
-
getGeometricMean
public double getGeometricMean()
Returns the geometric mean of the values that have been added.Double.NaN is returned if no values have been added.
- Returns:
- the geometric mean
-
getSumOfLogs
public double getSumOfLogs()
Returns the sum of the logs of the values that have been added.Double.NaN is returned if no values have been added.
- Returns:
- the sum of logs
- Since:
- 1.2
-
getSecondMoment
public double getSecondMoment()
Returns a statistic related to the Second Central Moment. Specifically, what is returned is the sum of squared deviations from the sample mean among the values that have been added.Returns
Double.NaNif no data values have been added and returns0if there is just one value in the data set.- Returns:
- second central moment statistic
- Since:
- 2.0
-
toString
public String toString()
Generates a text report displaying summary statistics from values that have been added.
-
clear
public void clear()
Resets all statistics and storage.
-
equals
public boolean equals(Object object)
Returns true iffobjectis aSummaryStatisticsinstance and all statistics have the same values as this.
-
hashCode
public int hashCode()
Returns hash code based on values of statistics.
-
getSumImpl
public StorelessUnivariateStatistic getSumImpl()
Returns the currently configured Sum implementation.- Returns:
- the StorelessUnivariateStatistic implementing the sum
- Since:
- 1.2
-
setSumImpl
public void setSumImpl(StorelessUnivariateStatistic sumImpl) throws MathIllegalStateException
Sets the implementation for the Sum.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
sumImpl- the StorelessUnivariateStatistic instance to use for computing the Sum- Throws:
MathIllegalStateException- if data has already been added (i.e if n >0)- Since:
- 1.2
-
getSumsqImpl
public StorelessUnivariateStatistic getSumsqImpl()
Returns the currently configured sum of squares implementation.- Returns:
- the StorelessUnivariateStatistic implementing the sum of squares
- Since:
- 1.2
-
setSumsqImpl
public void setSumsqImpl(StorelessUnivariateStatistic sumsqImpl) throws MathIllegalStateException
Sets the implementation for the sum of squares.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
sumsqImpl- the StorelessUnivariateStatistic instance to use for computing the sum of squares- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)- Since:
- 1.2
-
getMinImpl
public StorelessUnivariateStatistic getMinImpl()
Returns the currently configured minimum implementation.- Returns:
- the StorelessUnivariateStatistic implementing the minimum
- Since:
- 1.2
-
setMinImpl
public void setMinImpl(StorelessUnivariateStatistic minImpl) throws MathIllegalStateException
Sets the implementation for the minimum.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
minImpl- the StorelessUnivariateStatistic instance to use for computing the minimum- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)- Since:
- 1.2
-
getMaxImpl
public StorelessUnivariateStatistic getMaxImpl()
Returns the currently configured maximum implementation.- Returns:
- the StorelessUnivariateStatistic implementing the maximum
- Since:
- 1.2
-
setMaxImpl
public void setMaxImpl(StorelessUnivariateStatistic maxImpl) throws MathIllegalStateException
Sets the implementation for the maximum.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
maxImpl- the StorelessUnivariateStatistic instance to use for computing the maximum- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)- Since:
- 1.2
-
getSumLogImpl
public StorelessUnivariateStatistic getSumLogImpl()
Returns the currently configured sum of logs implementation.- Returns:
- the StorelessUnivariateStatistic implementing the log sum
- Since:
- 1.2
-
setSumLogImpl
public void setSumLogImpl(StorelessUnivariateStatistic sumLogImpl) throws MathIllegalStateException
Sets the implementation for the sum of logs.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
sumLogImpl- the StorelessUnivariateStatistic instance to use for computing the log sum- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)- Since:
- 1.2
-
getGeoMeanImpl
public StorelessUnivariateStatistic getGeoMeanImpl()
Returns the currently configured geometric mean implementation.- Returns:
- the StorelessUnivariateStatistic implementing the geometric mean
- Since:
- 1.2
-
setGeoMeanImpl
public void setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl) throws MathIllegalStateException
Sets the implementation for the geometric mean.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
geoMeanImpl- the StorelessUnivariateStatistic instance to use for computing the geometric mean- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)- Since:
- 1.2
-
getMeanImpl
public StorelessUnivariateStatistic getMeanImpl()
Returns the currently configured mean implementation.- Returns:
- the StorelessUnivariateStatistic implementing the mean
- Since:
- 1.2
-
setMeanImpl
public void setMeanImpl(StorelessUnivariateStatistic meanImpl) throws MathIllegalStateException
Sets the implementation for the mean.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
meanImpl- the StorelessUnivariateStatistic instance to use for computing the mean- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)- Since:
- 1.2
-
getVarianceImpl
public StorelessUnivariateStatistic getVarianceImpl()
Returns the currently configured variance implementation.- Returns:
- the StorelessUnivariateStatistic implementing the variance
- Since:
- 1.2
-
setVarianceImpl
public void setVarianceImpl(StorelessUnivariateStatistic varianceImpl) throws MathIllegalStateException
Sets the implementation for the variance.
This method cannot be activated after data has been added - i.e., after
addValuehas been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Parameters:
varianceImpl- the StorelessUnivariateStatistic instance to use for computing the variance- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)- Since:
- 1.2
-
copy
public SummaryStatistics copy()
Returns a copy of this SummaryStatistics instance with the same internal state.- Returns:
- a copy of this
-
copy
public static void copy(SummaryStatistics source, SummaryStatistics dest) throws NullArgumentException
Copies source to dest.Neither source nor dest can be null.
- Parameters:
source- SummaryStatistics to copydest- SummaryStatistics to copy to- Throws:
NullArgumentException- if either source or dest is null
-
-