Class StandardDeviation
- All Implemented Interfaces:
Serializable,DoubleConsumer,StorelessUnivariateStatistic,UnivariateStatistic,MathArrays.Function
The standard deviation is the positive square root of the variance.
This implementation wraps a 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) 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.Constructs a StandardDeviation from an external second moment.StandardDeviation(StandardDeviation original) Copy constructor, creates a newStandardDeviationidentical to theoriginal. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the internal state of the Statisticcopy()Returns a copy of the statistic with the same internal state.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.doubleReturns the current value of the Statistic.voidincrement(double d) Updates the internal state of the statistic to reflect the addition of the new value.booleanCheck if bias is corrected.withBiasCorrection(boolean biasCorrection) Returns a new copy of this standard deviation with the given bias correction setting.Methods inherited from class org.hipparchus.stat.descriptive.AbstractStorelessUnivariateStatistic
equals, hashCode, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.function.DoubleConsumer
andThenMethods inherited from interface org.hipparchus.stat.descriptive.StorelessUnivariateStatistic
accept, incrementAll, incrementAllMethods inherited from interface org.hipparchus.stat.descriptive.UnivariateStatistic
evaluate
-
Constructor Details
-
StandardDeviation
public StandardDeviation()Constructs a StandardDeviation. Sets the underlyingVarianceinstance'sisBiasCorrectedproperty to true. -
StandardDeviation
Constructs a StandardDeviation from an external second moment.- Parameters:
m2- the external moment
-
StandardDeviation
public 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
-
StandardDeviation
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 formulam2- the external moment
-
StandardDeviation
Copy constructor, creates a newStandardDeviationidentical to theoriginal.- Parameters:
original- theStandardDeviationinstance to copy- Throws:
NullArgumentException- if original is null
-
-
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:
incrementin interfaceStorelessUnivariateStatistic- Specified by:
incrementin classAbstractStorelessUnivariateStatistic- Parameters:
d- the new value.
-
getN
public long getN()Returns the number of values that have been added.- Specified by:
getNin interfaceStorelessUnivariateStatistic- Returns:
- the number of values.
-
getResult
public double getResult()Returns the current value of the Statistic.- Specified by:
getResultin interfaceStorelessUnivariateStatistic- Specified by:
getResultin classAbstractStorelessUnivariateStatistic- Returns:
- value of the statistic,
Double.NaNif it has been cleared or just instantiated.
-
clear
public void clear()Clears the internal state of the Statistic- Specified by:
clearin interfaceStorelessUnivariateStatistic- Specified by:
clearin classAbstractStorelessUnivariateStatistic
-
evaluate
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.
Does not change the internal state of the statistic.
- Specified by:
evaluatein interfaceMathArrays.Function- Specified by:
evaluatein interfaceStorelessUnivariateStatistic- Specified by:
evaluatein interfaceUnivariateStatistic- 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.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.
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.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.
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()Check if bias is corrected.- Returns:
- Returns the isBiasCorrected.
-
withBiasCorrection
Returns a new copy of this standard deviation with the given bias correction setting.- Parameters:
biasCorrection- The bias correction flag to set.- Returns:
- a copy of this instance with the given bias correction setting
-
copy
Returns a copy of the statistic with the same internal state.- Specified by:
copyin interfaceStorelessUnivariateStatistic- Specified by:
copyin interfaceUnivariateStatistic- Specified by:
copyin classAbstractStorelessUnivariateStatistic- Returns:
- a copy of the statistic
-