Class SynchronizedSummaryStatistics
- java.lang.Object
-
- org.apache.commons.math4.legacy.stat.descriptive.SummaryStatistics
-
- org.apache.commons.math4.legacy.stat.descriptive.SynchronizedSummaryStatistics
-
- All Implemented Interfaces:
StatisticalSummary
public class SynchronizedSummaryStatistics extends SummaryStatistics
Implementation ofSummaryStatisticsthat is safe to use in a multithreaded environment. Multiple threads can safely operate on a single instance without causing runtime exceptions due to race conditions. In effect, this implementation makes modification and access methods atomic operations for a single instance. That is to say, as one thread is computing a statistic from the instance, no other thread can modify the instance nor compute another statistic.- Since:
- 1.2
-
-
Constructor Summary
Constructors Constructor Description SynchronizedSummaryStatistics()Construct a SynchronizedSummaryStatistics instance.SynchronizedSummaryStatistics(SynchronizedSummaryStatistics 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.SynchronizedSummaryStatisticscopy()Returns a copy of this SynchronizedSummaryStatistics instance with the same internal state.static voidcopy(SynchronizedSummaryStatistics source, SynchronizedSummaryStatistics 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.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.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.-
Methods inherited from class org.apache.commons.math4.legacy.stat.descriptive.SummaryStatistics
copy, getSecondMoment, getSumOfLogs
-
-
-
-
Constructor Detail
-
SynchronizedSummaryStatistics
public SynchronizedSummaryStatistics()
Construct a SynchronizedSummaryStatistics instance.
-
SynchronizedSummaryStatistics
public SynchronizedSummaryStatistics(SynchronizedSummaryStatistics original) throws NullArgumentException
A copy constructor. Creates a deep-copy of theoriginal.- Parameters:
original- theSynchronizedSummaryStatisticsinstance to copy- Throws:
NullArgumentException- if original is null
-
-
Method Detail
-
getSummary
public StatisticalSummary getSummary()
Return aStatisticalSummaryValuesinstance reporting current statistics.- Overrides:
getSummaryin classSummaryStatistics- Returns:
- Current values of statistics
-
addValue
public void addValue(double value)
Add a value to the data.- Overrides:
addValuein classSummaryStatistics- Parameters:
value- the value to add
-
getN
public long getN()
Returns the number of available values.- Specified by:
getNin interfaceStatisticalSummary- Overrides:
getNin classSummaryStatistics- Returns:
- The number of available values
-
getSum
public double getSum()
Returns the sum of the values that have been added.- Specified by:
getSumin interfaceStatisticalSummary- Overrides:
getSumin classSummaryStatistics- 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.
- Overrides:
getSumsqin classSummaryStatistics- 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- Overrides:
getMeanin classSummaryStatistics- 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- Overrides:
getStandardDeviationin classSummaryStatistics- Returns:
- the standard deviation
-
getQuadraticMean
public double getQuadraticMean()
Returns the quadratic mean, a.k.a. root-mean-square of the available values- Overrides:
getQuadraticMeanin classSummaryStatistics- 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). UseSummaryStatistics.getPopulationVariance()for the non-bias-corrected population variance.Double.NaN is returned if no values have been added.
- Specified by:
getVariancein interfaceStatisticalSummary- Overrides:
getVariancein classSummaryStatistics- 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.
- Overrides:
getPopulationVariancein classSummaryStatistics- 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- Overrides:
getMaxin classSummaryStatistics- 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- Overrides:
getMinin classSummaryStatistics- 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.
- Overrides:
getGeometricMeanin classSummaryStatistics- Returns:
- the geometric mean
-
toString
public String toString()
Generates a text report displaying summary statistics from values that have been added.- Overrides:
toStringin classSummaryStatistics- Returns:
- String with line feeds displaying statistics
-
clear
public void clear()
Resets all statistics and storage.- Overrides:
clearin classSummaryStatistics
-
equals
public boolean equals(Object object)
Returns true iffobjectis aSummaryStatisticsinstance and all statistics have the same values as this.- Overrides:
equalsin classSummaryStatistics- Parameters:
object- the object to test equality against.- Returns:
- true if object equals this
-
hashCode
public int hashCode()
Returns hash code based on values of statistics.- Overrides:
hashCodein classSummaryStatistics- Returns:
- hash code
-
getSumImpl
public StorelessUnivariateStatistic getSumImpl()
Returns the currently configured Sum implementation.- Overrides:
getSumImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the sum
-
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.- Overrides:
setSumImplin classSummaryStatistics- Parameters:
sumImpl- the StorelessUnivariateStatistic instance to use for computing the Sum- Throws:
MathIllegalStateException- if data has already been added (i.e if n >0)
-
getSumsqImpl
public StorelessUnivariateStatistic getSumsqImpl()
Returns the currently configured sum of squares implementation.- Overrides:
getSumsqImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the sum of squares
-
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.- Overrides:
setSumsqImplin classSummaryStatistics- 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)
-
getMinImpl
public StorelessUnivariateStatistic getMinImpl()
Returns the currently configured minimum implementation.- Overrides:
getMinImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the minimum
-
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.- Overrides:
setMinImplin classSummaryStatistics- Parameters:
minImpl- the StorelessUnivariateStatistic instance to use for computing the minimum- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)
-
getMaxImpl
public StorelessUnivariateStatistic getMaxImpl()
Returns the currently configured maximum implementation.- Overrides:
getMaxImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the maximum
-
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.- Overrides:
setMaxImplin classSummaryStatistics- Parameters:
maxImpl- the StorelessUnivariateStatistic instance to use for computing the maximum- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)
-
getSumLogImpl
public StorelessUnivariateStatistic getSumLogImpl()
Returns the currently configured sum of logs implementation.- Overrides:
getSumLogImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the log sum
-
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.- Overrides:
setSumLogImplin classSummaryStatistics- 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)
-
getGeoMeanImpl
public StorelessUnivariateStatistic getGeoMeanImpl()
Returns the currently configured geometric mean implementation.- Overrides:
getGeoMeanImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the geometric mean
-
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.- Overrides:
setGeoMeanImplin classSummaryStatistics- 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)
-
getMeanImpl
public StorelessUnivariateStatistic getMeanImpl()
Returns the currently configured mean implementation.- Overrides:
getMeanImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the mean
-
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.- Overrides:
setMeanImplin classSummaryStatistics- Parameters:
meanImpl- the StorelessUnivariateStatistic instance to use for computing the mean- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)
-
getVarianceImpl
public StorelessUnivariateStatistic getVarianceImpl()
Returns the currently configured variance implementation.- Overrides:
getVarianceImplin classSummaryStatistics- Returns:
- the StorelessUnivariateStatistic implementing the variance
-
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.- Overrides:
setVarianceImplin classSummaryStatistics- Parameters:
varianceImpl- the StorelessUnivariateStatistic instance to use for computing the variance- Throws:
MathIllegalStateException- if data has already been added (i.e if n > 0)
-
copy
public SynchronizedSummaryStatistics copy()
Returns a copy of this SynchronizedSummaryStatistics instance with the same internal state.- Overrides:
copyin classSummaryStatistics- Returns:
- a copy of this
-
copy
public static void copy(SynchronizedSummaryStatistics source, SynchronizedSummaryStatistics dest) throws NullArgumentException
Copies source to dest.Neither source nor dest can be null.
Acquires synchronization lock on source, then dest before copying.
- Parameters:
source- SynchronizedSummaryStatistics to copydest- SynchronizedSummaryStatistics to copy to- Throws:
NullArgumentException- if either source or dest is null
-
-