Top Description Fields Constructors Methods
org.apache.commons.math3.stat.descriptive.moment

public Class StandardDeviation

extends AbstractStorelessUnivariateStatistic
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, org.apache.commons.math3.exception.MathIllegalArgumentException, .NullArgumentException, org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic, org.apache.commons.math3.util.FastMath, .MathUtils

Computes the sample standard deviation. 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.

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serializable version identifier

private Variance
variance

Wrapped Variance instance

Constructor Summary

AccessConstructor and Description
public
StandardDeviation()

Constructs a StandardDeviation.

public
StandardDeviation(final SecondMoment
the external moment
m2
)

Constructs a StandardDeviation from an external second moment.

public
StandardDeviation(StandardDeviation
the StandardDeviation instance to copy
original
)

Copy constructor, creates a new StandardDeviation identical to the original

public
StandardDeviation(boolean
whether or not the variance computation will use the bias-corrected formula
isBiasCorrected
)

Contructs a StandardDeviation with the specified value for the isBiasCorrected property.

public
StandardDeviation(boolean
whether or not the variance computation will use the bias-corrected formula
isBiasCorrected
,
SecondMoment
the external moment
m2
)

Contructs a StandardDeviation with the specified value for the isBiasCorrected property and the supplied external moment.

Method Summary

Modifier and TypeMethod and Description
public void
public StandardDeviation
public static void
copy(StandardDeviation
StandardDeviation to copy
source
,
StandardDeviation
StandardDeviation to copy to
dest
)

Copies source to dest.

public double

Returns:

the standard deviation of the values or Double.NaN if length = 0
evaluate
(final double[]
the input array
values
)

Overrides org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.evaluate.

Implements org.apache.commons.math3.stat.descriptive.UnivariateStatistic.evaluate.

Returns the Standard Deviation of the entries in the input array, or Double.NaN if the array is empty.

public double

Returns:

the standard deviation of the values or Double.NaN if length = 0
evaluate
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Overrides org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.evaluate.

Implements org.apache.commons.math3.stat.descriptive.UnivariateStatistic.evaluate.

Returns the Standard Deviation of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public double

Returns:

the standard deviation of the values or Double.NaN if length = 0
evaluate
(final double[]
the input array
values
,
final double
the precomputed mean value
mean
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the Standard Deviation of the entries in the specified portion of the input array, using the precomputed mean value.

public double

Returns:

the standard deviation of the values or Double.NaN if length = 0
evaluate
(final double[]
the input array
values
,
final double
the precomputed mean value
mean
)

Returns the Standard Deviation of the entries in the input array, using the precomputed mean value.

public long
getN()

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Returns the number of values that have been added.

public double
public void
increment(final double
the new value.
d
)

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

public boolean

Returns:

Returns the isBiasCorrected.
isBiasCorrected
()

public void
setBiasCorrected(boolean
The isBiasCorrected to set.
isBiasCorrected
)

Inherited from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic:
equalshashCodeincrementAllincrementAll

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

varianceback to summary
private Variance variance

Wrapped Variance instance

Constructor Detail

StandardDeviationback to summary
public StandardDeviation()

Constructs a StandardDeviation. Sets the underlying Variance instance's isBiasCorrected property to true.

StandardDeviationback to summary
public StandardDeviation(final SecondMoment m2)

Constructs a StandardDeviation from an external second moment.

Parameters
m2:SecondMoment

the external moment

StandardDeviationback to summary
public StandardDeviation(StandardDeviation original) throws NullArgumentException

Copy constructor, creates a new StandardDeviation identical to the original

Parameters
original:StandardDeviation

the StandardDeviation instance to copy

Exceptions
NullArgumentException:
if original is null
StandardDeviationback to summary
public StandardDeviation(boolean isBiasCorrected)

Contructs a StandardDeviation with the specified value for the isBiasCorrected property. If this property is set to true, the Variance used in computing results will use the bias-corrected, or "sample" formula. See Variance for details.

Parameters
isBiasCorrected:boolean

whether or not the variance computation will use the bias-corrected formula

StandardDeviationback to summary
public StandardDeviation(boolean isBiasCorrected, SecondMoment m2)

Contructs a StandardDeviation with the specified value for the isBiasCorrected property and the supplied external moment. If isBiasCorrected is set to true, the Variance used in computing results will use the bias-corrected, or "sample" formula. See Variance for details.

Parameters
isBiasCorrected:boolean

whether or not the variance computation will use the bias-corrected formula

m2:SecondMoment

the external moment

Method Detail

clearback to summary
public void clear()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.clear.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.clear.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.clear.

Clears the internal state of the Statistic

Annotations
@Override
copyback to summary
public StandardDeviation copy()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.copy.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy, org.apache.commons.math3.stat.descriptive.UnivariateStatistic.copy.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.copy.

Returns a copy of the statistic with the same internal state.

Returns:StandardDeviation

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy.

a copy of the statistic

Annotations
@Override
copyback to summary
public static void copy(StandardDeviation source, StandardDeviation dest) throws NullArgumentException

Copies source to dest.

Neither source nor dest can be null.

Parameters
source:StandardDeviation

StandardDeviation to copy

dest:StandardDeviation

StandardDeviation to copy to

Exceptions
NullArgumentException:
if either source or dest is null
evaluateback to summary
public double evaluate(final double[] values) throws MathIllegalArgumentException

Overrides org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.evaluate.

Implements org.apache.commons.math3.stat.descriptive.UnivariateStatistic.evaluate.

Returns the Standard Deviation of the entries in the input array, or Double.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.

Parameters
values:double[]

the input array

Returns:double

the standard deviation of the values or Double.NaN if length = 0

Annotations
@Override
Exceptions
MathIllegalArgumentException:
if the array is null
evaluateback to summary
public double evaluate(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Overrides org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.evaluate.

Implements org.apache.commons.math3.stat.descriptive.UnivariateStatistic.evaluate.

Returns the Standard Deviation of the entries in the specified portion of the input array, or Double.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.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the standard deviation of the values or Double.NaN if length = 0

Annotations
@Override
Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
evaluateback to summary
public double evaluate(final double[] values, final double mean, final int begin, final int length) throws MathIllegalArgumentException

Returns the Standard Deviation of the entries in the specified portion of the input array, using the precomputed mean value. Returns Double.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:double[]

the input array

mean:double

the precomputed mean value

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the standard deviation of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
evaluateback to summary
public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException

Returns the Standard Deviation of the entries in the input array, using the precomputed mean value. Returns Double.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:double[]

the input array

mean:double

the precomputed mean value

Returns:double

the standard deviation of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null
getNback to summary
public long getN()

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Returns the number of values that have been added.

Returns:long

the number of values.

getResultback to summary
public double getResult()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.getResult.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.getResult.

Returns the current value of the Statistic.

Returns:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

value of the statistic, Double.NaN if it has been cleared or just instantiated.

Annotations
@Override
incrementback to summary
public void increment(final double d)

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

Parameters
d:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

the new value.

Annotations
@Override
isBiasCorrectedback to summary
public boolean isBiasCorrected()
Returns:boolean

Returns the isBiasCorrected.

setBiasCorrectedback to summary
public void setBiasCorrected(boolean isBiasCorrected)
Parameters
isBiasCorrected:boolean

The isBiasCorrected to set.