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 ofSummaryStatistics
that 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 void
addValue(double value)
Add a value to the data.void
clear()
Resets all statistics and storage.SynchronizedSummaryStatistics
copy()
Returns a copy of this SynchronizedSummaryStatistics instance with the same internal state.static void
copy(SynchronizedSummaryStatistics source, SynchronizedSummaryStatistics dest)
Copies source to dest.boolean
equals(Object object)
Returns true iffobject
is aSummaryStatistics
instance and all statistics have the same values as this.StorelessUnivariateStatistic
getGeoMeanImpl()
Returns the currently configured geometric mean implementation.double
getGeometricMean()
Returns the geometric mean of the values that have been added.double
getMax()
Returns the maximum of the values that have been added.StorelessUnivariateStatistic
getMaxImpl()
Returns the currently configured maximum implementation.double
getMean()
Returns the mean of the values that have been added.StorelessUnivariateStatistic
getMeanImpl()
Returns the currently configured mean implementation.double
getMin()
Returns the minimum of the values that have been added.StorelessUnivariateStatistic
getMinImpl()
Returns the currently configured minimum implementation.long
getN()
Returns the number of available values.double
getPopulationVariance()
Returns the population variance of the values that have been added.double
getQuadraticMean()
Returns the quadratic mean, a.k.a.double
getStandardDeviation()
Returns the standard deviation of the values that have been added.double
getSum()
Returns the sum of the values that have been added.StorelessUnivariateStatistic
getSumImpl()
Returns the currently configured Sum implementation.StorelessUnivariateStatistic
getSumLogImpl()
Returns the currently configured sum of logs implementation.StatisticalSummary
getSummary()
Return aStatisticalSummaryValues
instance reporting current statistics.double
getSumsq()
Returns the sum of the squares of the values that have been added.StorelessUnivariateStatistic
getSumsqImpl()
Returns the currently configured sum of squares implementation.double
getVariance()
Returns the (sample) variance of the available values.StorelessUnivariateStatistic
getVarianceImpl()
Returns the currently configured variance implementation.int
hashCode()
Returns hash code based on values of statistics.void
setGeoMeanImpl(StorelessUnivariateStatistic geoMeanImpl)
Sets the implementation for the geometric mean.void
setMaxImpl(StorelessUnivariateStatistic maxImpl)
Sets the implementation for the maximum.void
setMeanImpl(StorelessUnivariateStatistic meanImpl)
Sets the implementation for the mean.void
setMinImpl(StorelessUnivariateStatistic minImpl)
Sets the implementation for the minimum.void
setSumImpl(StorelessUnivariateStatistic sumImpl)
Sets the implementation for the Sum.void
setSumLogImpl(StorelessUnivariateStatistic sumLogImpl)
Sets the implementation for the sum of logs.void
setSumsqImpl(StorelessUnivariateStatistic sumsqImpl)
Sets the implementation for the sum of squares.void
setVarianceImpl(StorelessUnivariateStatistic varianceImpl)
Sets the implementation for the variance.String
toString()
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
- theSynchronizedSummaryStatistics
instance to copy- Throws:
NullArgumentException
- if original is null
-
-
Method Detail
-
getSummary
public StatisticalSummary getSummary()
Return aStatisticalSummaryValues
instance reporting current statistics.- Overrides:
getSummary
in classSummaryStatistics
- Returns:
- Current values of statistics
-
addValue
public void addValue(double value)
Add a value to the data.- Overrides:
addValue
in classSummaryStatistics
- Parameters:
value
- the value to add
-
getN
public long getN()
Returns the number of available values.- Specified by:
getN
in interfaceStatisticalSummary
- Overrides:
getN
in classSummaryStatistics
- Returns:
- The number of available values
-
getSum
public double getSum()
Returns the sum of the values that have been added.- Specified by:
getSum
in interfaceStatisticalSummary
- Overrides:
getSum
in classSummaryStatistics
- Returns:
- The sum or
Double.NaN
if 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:
getSumsq
in 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:
getMean
in interfaceStatisticalSummary
- Overrides:
getMean
in 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:
getStandardDeviation
in interfaceStatisticalSummary
- Overrides:
getStandardDeviation
in classSummaryStatistics
- Returns:
- the standard deviation
-
getQuadraticMean
public double getQuadraticMean()
Returns the quadratic mean, a.k.a. root-mean-square of the available values- Overrides:
getQuadraticMean
in classSummaryStatistics
- Returns:
- The quadratic mean or
Double.NaN
if 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 - 1
in the denominator). UseSummaryStatistics.getPopulationVariance()
for the non-bias-corrected population variance.Double.NaN is returned if no values have been added.
- Specified by:
getVariance
in interfaceStatisticalSummary
- Overrides:
getVariance
in 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:
getPopulationVariance
in 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:
getMax
in interfaceStatisticalSummary
- Overrides:
getMax
in 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:
getMin
in interfaceStatisticalSummary
- Overrides:
getMin
in 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:
getGeometricMean
in classSummaryStatistics
- Returns:
- the geometric mean
-
toString
public String toString()
Generates a text report displaying summary statistics from values that have been added.- Overrides:
toString
in classSummaryStatistics
- Returns:
- String with line feeds displaying statistics
-
clear
public void clear()
Resets all statistics and storage.- Overrides:
clear
in classSummaryStatistics
-
equals
public boolean equals(Object object)
Returns true iffobject
is aSummaryStatistics
instance and all statistics have the same values as this.- Overrides:
equals
in 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:
hashCode
in classSummaryStatistics
- Returns:
- hash code
-
getSumImpl
public StorelessUnivariateStatistic getSumImpl()
Returns the currently configured Sum implementation.- Overrides:
getSumImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setSumImpl
in 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:
getSumsqImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setSumsqImpl
in 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:
getMinImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setMinImpl
in 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:
getMaxImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setMaxImpl
in 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:
getSumLogImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setSumLogImpl
in 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:
getGeoMeanImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setGeoMeanImpl
in 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:
getMeanImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setMeanImpl
in 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:
getVarianceImpl
in 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
addValue
has been used to add data. If it is activated after data has been added, an IllegalStateException will be thrown.- Overrides:
setVarianceImpl
in 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:
copy
in 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
-
-