Class StandardDeviation
- java.lang.Object
- 
- org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatistic
- 
- org.apache.commons.math4.legacy.stat.descriptive.moment.StandardDeviation
 
 
- 
- All Implemented Interfaces:
- MathArrays.Function,- StorelessUnivariateStatistic,- UnivariateStatistic
 
 public class StandardDeviation extends AbstractStorelessUnivariateStatistic Computes the sample standard deviation. The standard deviation is the positive square root of the variance. This implementation wraps aVarianceinstance. TheisBiasCorrectedproperty of the wrapped Variance instance is exposed, so that this class can be used to compute both the "sample standard deviation" (the square root of the bias-corrected "sample variance") or the "population standard deviation" (the square root of the non-bias-corrected "population variance"). SeeVariancefor more information.Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the increment()orclear()method, it must be synchronized externally.
- 
- 
Constructor SummaryConstructors Constructor Description StandardDeviation()Constructs a StandardDeviation.StandardDeviation(boolean isBiasCorrected)Constructs a StandardDeviation with the specified value for theisBiasCorrectedproperty.StandardDeviation(boolean isBiasCorrected, SecondMoment m2)Constructs a StandardDeviation with the specified value for theisBiasCorrectedproperty and the supplied external moment.StandardDeviation(SecondMoment m2)Constructs a StandardDeviation from an external second moment.StandardDeviation(StandardDeviation original)Copy constructor, creates a newStandardDeviationidentical to theoriginal.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the internal state of the Statistic.StandardDeviationcopy()Returns a copy of the statistic with the same internal state.static voidcopy(StandardDeviation source, StandardDeviation dest)Copies source to dest.doubleevaluate(double[] values)Returns the Standard Deviation of the entries in the input array, orDouble.NaNif the array is empty.doubleevaluate(double[] values, double mean)Returns the Standard Deviation of the entries in the input array, using the precomputed mean value.doubleevaluate(double[] values, double mean, int begin, int length)Returns the Standard Deviation of the entries in the specified portion of the input array, using the precomputed mean value.doubleevaluate(double[] values, int begin, int length)Returns the Standard Deviation of the entries in the specified portion of the input array, orDouble.NaNif the designated subarray is empty.longgetN()Returns the number of values that have been added.doublegetResult()Returns the current value of the Statistic.voidincrement(double d)Updates the internal state of the statistic to reflect the addition of the new value.booleanisBiasCorrected()voidsetBiasCorrected(boolean isBiasCorrected)- 
Methods inherited from class org.apache.commons.math4.legacy.stat.descriptive.AbstractStorelessUnivariateStatisticequals, hashCode, incrementAll, incrementAll
 
- 
 
- 
- 
- 
Constructor Detail- 
StandardDeviationpublic StandardDeviation() Constructs a StandardDeviation. Sets the underlyingVarianceinstance'sisBiasCorrectedproperty to true.
 - 
StandardDeviationpublic StandardDeviation(SecondMoment m2) Constructs a StandardDeviation from an external second moment.- Parameters:
- m2- the external moment
 
 - 
StandardDeviationpublic StandardDeviation(StandardDeviation original) throws NullArgumentException Copy constructor, creates a newStandardDeviationidentical to theoriginal.- Parameters:
- original- the- StandardDeviationinstance to copy
- Throws:
- NullArgumentException- if original is null
 
 - 
StandardDeviationpublic StandardDeviation(boolean isBiasCorrected) Constructs a StandardDeviation with the specified value for theisBiasCorrectedproperty. If this property is set totrue, theVarianceused in computing results will use the bias-corrected, or "sample" formula. SeeVariancefor details.- Parameters:
- isBiasCorrected- whether or not the variance computation will use the bias-corrected formula
 
 - 
StandardDeviationpublic StandardDeviation(boolean isBiasCorrected, SecondMoment m2) Constructs a StandardDeviation with the specified value for theisBiasCorrectedproperty and the supplied external moment. IfisBiasCorrectedis set totrue, theVarianceused in computing results will use the bias-corrected, or "sample" formula. SeeVariancefor details.- Parameters:
- isBiasCorrected- whether or not the variance computation will use the bias-corrected formula
- m2- the external moment
 
 
- 
 - 
Method Detail- 
incrementpublic void increment(double d) Updates the internal state of the statistic to reflect the addition of the new value.- Specified by:
- incrementin interface- StorelessUnivariateStatistic
- Specified by:
- incrementin class- AbstractStorelessUnivariateStatistic
- Parameters:
- d- the new value.
 
 - 
getNpublic long getN() Returns the number of values that have been added.- Returns:
- the number of values.
 
 - 
getResultpublic double getResult() Returns the current value of the Statistic.- Specified by:
- getResultin interface- StorelessUnivariateStatistic
- Specified by:
- getResultin class- AbstractStorelessUnivariateStatistic
- Returns:
- value of the statistic, Double.NaNif it has been cleared or just instantiated.
 
 - 
clearpublic void clear() Clears the internal state of the Statistic.- Specified by:
- clearin interface- StorelessUnivariateStatistic
- Specified by:
- clearin class- AbstractStorelessUnivariateStatistic
 
 - 
evaluatepublic double evaluate(double[] values) throws MathIllegalArgumentException Returns the Standard Deviation of the entries in the input array, orDouble.NaNif the array is empty.Returns 0 for a single-value (i.e. length = 1) sample. Throws MathIllegalArgumentExceptionif the array is null.Does not change the internal state of the statistic. - Specified by:
- evaluatein interface- MathArrays.Function
- Specified by:
- evaluatein interface- UnivariateStatistic
- Overrides:
- evaluatein class- AbstractStorelessUnivariateStatistic
- Parameters:
- values- the input array
- Returns:
- the standard deviation of the values or Double.NaN if length = 0
- Throws:
- MathIllegalArgumentException- if the array is null
- See Also:
- UnivariateStatistic.evaluate(double[])
 
 - 
evaluatepublic double evaluate(double[] values, int begin, int length) throws MathIllegalArgumentException Returns the Standard Deviation of the entries in the specified portion of the input array, orDouble.NaNif the designated subarray is empty.Returns 0 for a single-value (i.e. length = 1) sample. Throws MathIllegalArgumentExceptionif the array is null.Does not change the internal state of the statistic. - Specified by:
- evaluatein interface- MathArrays.Function
- Specified by:
- evaluatein interface- UnivariateStatistic
- Overrides:
- evaluatein class- AbstractStorelessUnivariateStatistic
- Parameters:
- values- the input array
- begin- index of the first array element to include
- length- the number of elements to include
- Returns:
- the standard deviation of the values or Double.NaN if length = 0
- Throws:
- MathIllegalArgumentException- if the array is null or the array index parameters are not valid
- See Also:
- UnivariateStatistic.evaluate(double[], int, int)
 
 - 
evaluatepublic double evaluate(double[] values, double mean, int begin, int length) throws MathIllegalArgumentException Returns the Standard Deviation of the entries in the specified portion of the input array, using the precomputed mean value. ReturnsDouble.NaNif the designated subarray is empty.Returns 0 for a single-value (i.e. length = 1) sample. The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed. Throws IllegalArgumentExceptionif the array is null.Does not change the internal state of the statistic. - Parameters:
- values- the input array
- mean- the precomputed mean value
- begin- index of the first array element to include
- length- the number of elements to include
- Returns:
- the standard deviation of the values or Double.NaN if length = 0
- Throws:
- MathIllegalArgumentException- if the array is null or the array index parameters are not valid
 
 - 
evaluatepublic double evaluate(double[] values, double mean) throws MathIllegalArgumentException Returns the Standard Deviation of the entries in the input array, using the precomputed mean value. ReturnsDouble.NaNif the designated subarray is empty.Returns 0 for a single-value (i.e. length = 1) sample. The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed. Throws MathIllegalArgumentExceptionif the array is null.Does not change the internal state of the statistic. - Parameters:
- values- the input array
- mean- the precomputed mean value
- Returns:
- the standard deviation of the values or Double.NaN if length = 0
- Throws:
- MathIllegalArgumentException- if the array is null
 
 - 
isBiasCorrectedpublic boolean isBiasCorrected() - Returns:
- Returns the isBiasCorrected.
 
 - 
setBiasCorrectedpublic void setBiasCorrected(boolean isBiasCorrected) - Parameters:
- isBiasCorrected- The isBiasCorrected to set.
 
 - 
copypublic StandardDeviation copy() Returns a copy of the statistic with the same internal state.- Specified by:
- copyin interface- StorelessUnivariateStatistic
- Specified by:
- copyin interface- UnivariateStatistic
- Specified by:
- copyin class- AbstractStorelessUnivariateStatistic
- Returns:
- a copy of the statistic
 
 - 
copypublic static void copy(StandardDeviation source, StandardDeviation dest) throws NullArgumentException Copies source to dest.Neither source nor dest can be null. - Parameters:
- source- StandardDeviation to copy
- dest- StandardDeviation to copy to
- Throws:
- NullArgumentException- if either source or dest is null
 
 
- 
 
-