Class StandardDeviation
- All Implemented Interfaces:
Serializable
,StorelessUnivariateStatistic
,UnivariateStatistic
,MathArrays.Function
Variance
instance. The isBiasCorrected
property 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"). See
Variance
for 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()
or
clear()
method, it must be synchronized externally.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a StandardDeviation.StandardDeviation
(boolean isBiasCorrected) Contructs a StandardDeviation with the specified value for theisBiasCorrected
property.StandardDeviation
(boolean isBiasCorrected, SecondMoment m2) Contructs a StandardDeviation with the specified value for theisBiasCorrected
property and the supplied external moment.Constructs a StandardDeviation from an external second moment.StandardDeviation
(StandardDeviation original) Copy constructor, creates a newStandardDeviation
identical to theoriginal
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the internal state of the Statisticcopy()
Returns a copy of the statistic with the same internal state.static void
copy
(StandardDeviation source, StandardDeviation dest) Copies source to dest.double
evaluate
(double[] values) Returns the Standard Deviation of the entries in the input array, orDouble.NaN
if the array is empty.double
evaluate
(double[] values, double mean) Returns the Standard Deviation of the entries in the input array, using the precomputed mean value.double
evaluate
(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.double
evaluate
(double[] values, int begin, int length) Returns the Standard Deviation of the entries in the specified portion of the input array, orDouble.NaN
if the designated subarray is empty.long
getN()
Returns the number of values that have been added.double
Returns the current value of the Statistic.void
increment
(double d) Updates the internal state of the statistic to reflect the addition of the new value.boolean
void
setBiasCorrected
(boolean isBiasCorrected) Methods inherited from class org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic
equals, hashCode, incrementAll, incrementAll
Methods inherited from class org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic
evaluate, getData, getDataRef, setData, setData, test, test, test, test
-
Constructor Details
-
StandardDeviation
public StandardDeviation()Constructs a StandardDeviation. Sets the underlyingVariance
instance'sisBiasCorrected
property to true. -
StandardDeviation
Constructs a StandardDeviation from an external second moment.- Parameters:
m2
- the external moment
-
StandardDeviation
Copy constructor, creates a newStandardDeviation
identical to theoriginal
- Parameters:
original
- theStandardDeviation
instance to copy- Throws:
NullArgumentException
- if original is null
-
StandardDeviation
public StandardDeviation(boolean isBiasCorrected) Contructs a StandardDeviation with the specified value for theisBiasCorrected
property. If this property is set totrue
, theVariance
used in computing results will use the bias-corrected, or "sample" formula. SeeVariance
for details.- Parameters:
isBiasCorrected
- whether or not the variance computation will use the bias-corrected formula
-
StandardDeviation
Contructs a StandardDeviation with the specified value for theisBiasCorrected
property and the supplied external moment. IfisBiasCorrected
is set totrue
, theVariance
used in computing results will use the bias-corrected, or "sample" formula. SeeVariance
for details.- Parameters:
isBiasCorrected
- whether or not the variance computation will use the bias-corrected formulam2
- the external moment
-
-
Method Details
-
increment
public void increment(double d) Updates the internal state of the statistic to reflect the addition of the new value.- Specified by:
increment
in interfaceStorelessUnivariateStatistic
- Specified by:
increment
in classAbstractStorelessUnivariateStatistic
- Parameters:
d
- the new value.
-
getN
public long getN()Returns the number of values that have been added.- Specified by:
getN
in interfaceStorelessUnivariateStatistic
- Returns:
- the number of values.
-
getResult
public double getResult()Returns the current value of the Statistic.- Specified by:
getResult
in interfaceStorelessUnivariateStatistic
- Specified by:
getResult
in classAbstractStorelessUnivariateStatistic
- Returns:
- value of the statistic,
Double.NaN
if it has been cleared or just instantiated.
-
clear
public void clear()Clears the internal state of the Statistic- Specified by:
clear
in interfaceStorelessUnivariateStatistic
- Specified by:
clear
in classAbstractStorelessUnivariateStatistic
-
evaluate
Returns the Standard Deviation of the entries in the input array, orDouble.NaN
if the array is empty.Returns 0 for a single-value (i.e. length = 1) sample.
Throws
MathIllegalArgumentException
if the array is null.Does not change the internal state of the statistic.
- Specified by:
evaluate
in interfaceMathArrays.Function
- Specified by:
evaluate
in interfaceUnivariateStatistic
- Overrides:
evaluate
in classAbstractStorelessUnivariateStatistic
- 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:
-
evaluate
Returns the Standard Deviation of the entries in the specified portion of the input array, orDouble.NaN
if the designated subarray is empty.Returns 0 for a single-value (i.e. length = 1) sample.
Throws
MathIllegalArgumentException
if the array is null.Does not change the internal state of the statistic.
- Specified by:
evaluate
in interfaceMathArrays.Function
- Specified by:
evaluate
in interfaceUnivariateStatistic
- Overrides:
evaluate
in classAbstractStorelessUnivariateStatistic
- Parameters:
values
- the input arraybegin
- index of the first array element to includelength
- 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:
-
evaluate
public 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.NaN
if 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
IllegalArgumentException
if the array is null.Does not change the internal state of the statistic.
- Parameters:
values
- the input arraymean
- the precomputed mean valuebegin
- index of the first array element to includelength
- 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
-
evaluate
Returns the Standard Deviation of the entries in the input array, using the precomputed mean value. ReturnsDouble.NaN
if 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
MathIllegalArgumentException
if the array is null.Does not change the internal state of the statistic.
- Parameters:
values
- the input arraymean
- the precomputed mean value- Returns:
- the standard deviation of the values or Double.NaN if length = 0
- Throws:
MathIllegalArgumentException
- if the array is null
-
isBiasCorrected
public boolean isBiasCorrected()- Returns:
- Returns the isBiasCorrected.
-
setBiasCorrected
public void setBiasCorrected(boolean isBiasCorrected) - Parameters:
isBiasCorrected
- The isBiasCorrected to set.
-
copy
Returns a copy of the statistic with the same internal state.- Specified by:
copy
in interfaceStorelessUnivariateStatistic
- Specified by:
copy
in interfaceUnivariateStatistic
- Specified by:
copy
in classAbstractStorelessUnivariateStatistic
- Returns:
- a copy of the statistic
-
copy
public static void copy(StandardDeviation source, StandardDeviation dest) throws NullArgumentException Copies source to dest.Neither source nor dest can be null.
- Parameters:
source
- StandardDeviation to copydest
- StandardDeviation to copy to- Throws:
NullArgumentException
- if either source or dest is null
-