| org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic org.apache.commons.math.stat.descriptive.moment.Variance
Variance | public class Variance extends AbstractStorelessUnivariateStatistic implements Serializable(Code) | | Computes the variance of the available values. By default, the unbiased
"sample variance" definitional formula is used:
variance = sum((x_i - mean)^2) / (n - 1)
where mean is the
Mean and n is the number
of sample observations.
The definitional formula does not have good numerical properties, so
this implementation uses updating formulas based on West's algorithm
as described in
Chan, T. F. andJ. G. Lewis 1979, Communications of the ACM,
vol. 22 no. 9, pp. 526-531..
The "population variance" ( sum((x_i - mean)^2) / n ) can also
be computed using this statistic. The isBiasCorrected
property determines whether the "population" or "sample" value is
returned by the evaluate and getResult methods.
To compute population variances, set this property to false.
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.
version: $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $ |
Field Summary | |
protected boolean | incMoment Boolean test to determine if this Variance should also increment
the second moment, this evaluates to false when this Variance is
constructed with an external SecondMoment as a parameter. | protected SecondMoment | moment |
Constructor Summary | |
public | Variance() Constructs a Variance with default (true) isBiasCorrected
property. | public | Variance(SecondMoment m2) Constructs a Variance based on an external second moment. | public | Variance(boolean isBiasCorrected) | public | Variance(boolean isBiasCorrected, SecondMoment m2) Constructs a Variance with the specified isBiasCorrected
property and the supplied external second moment. |
Method Summary | |
public void | clear() | public double | evaluate(double[] values) Returns the variance of the entries in the input array, or
Double.NaN if the array is empty.
See
Variance for details on the computing algorithm.
Returns 0 for a single-value (i.e. | public double | evaluate(double[] values, int begin, int length) Returns the variance of the entries in the specified portion of
the input array, or Double.NaN if the designated subarray
is empty.
See
Variance for details on the computing algorithm.
Returns 0 for a single-value (i.e. | public double | evaluate(double[] values, double mean, int begin, int length) Returns the variance of the entries in the specified portion of
the input array, using the precomputed mean value. | public double | evaluate(double[] values, double mean) Returns the variance of the entries in the input array, using the
precomputed mean value. | public long | getN() | public double | getResult() | public void | increment(double d) | public boolean | isBiasCorrected() | public void | setBiasCorrected(boolean isBiasCorrected) |
incMoment | protected boolean incMoment(Code) | | Boolean test to determine if this Variance should also increment
the second moment, this evaluates to false when this Variance is
constructed with an external SecondMoment as a parameter.
|
moment | protected SecondMoment moment(Code) | | SecondMoment is used in incremental calculation of Variance
|
Variance | public Variance()(Code) | | Constructs a Variance with default (true) isBiasCorrected
property.
|
Variance | public Variance(SecondMoment m2)(Code) | | Constructs a Variance based on an external second moment.
Parameters: m2 - the SecondMoment (Thrid or Fourth moments workhere as well.) |
Variance | public Variance(boolean isBiasCorrected)(Code) | | Constructs a Variance with the specified isBiasCorrected
property
Parameters: isBiasCorrected - setting for bias correction - true meansbias will be corrected and is equivalent to using the argumentlessconstructor |
Variance | public Variance(boolean isBiasCorrected, SecondMoment m2)(Code) | | Constructs a Variance with the specified isBiasCorrected
property and the supplied external second moment.
Parameters: isBiasCorrected - setting for bias correction - true meansbias will be corrected Parameters: m2 - the SecondMoment (Thrid or Fourth moments workhere as well.) |
evaluate | public double evaluate(double[] values)(Code) | | Returns the variance of the entries in the input array, or
Double.NaN if the array is empty.
See
Variance for details on the computing algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws IllegalArgumentException if the array is null.
Does not change the internal state of the statistic.
Parameters: values - the input array the variance of the values or Double.NaN if length = 0 throws: IllegalArgumentException - if the array is null |
evaluate | public double evaluate(double[] values, int begin, int length)(Code) | | Returns the variance of the entries in the specified portion of
the input array, or Double.NaN if the designated subarray
is empty.
See
Variance for details on the computing algorithm.
Returns 0 for a single-value (i.e. length = 1) sample.
Does not change the internal state of the statistic.
Throws IllegalArgumentException if the array is null.
Parameters: values - the input array Parameters: begin - index of the first array element to include Parameters: length - the number of elements to include the variance of the values or Double.NaN if length = 0 throws: IllegalArgumentException - if the array is null or the array indexparameters are not valid |
evaluate | public double evaluate(double[] values, double mean, int begin, int length)(Code) | | Returns the variance 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.
See
Variance for details on the computing algorithm.
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.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws IllegalArgumentException if the array is null.
Does not change the internal state of the statistic.
Parameters: values - the input array Parameters: mean - the precomputed mean value Parameters: begin - index of the first array element to include Parameters: length - the number of elements to include the variance of the values or Double.NaN if length = 0 throws: IllegalArgumentException - if the array is null or the array indexparameters are not valid |
evaluate | public double evaluate(double[] values, double mean)(Code) | | Returns the variance of the entries in the input array, using the
precomputed mean value. Returns Double.NaN if the array
is empty.
See
Variance for details on the computing algorithm.
If isBiasCorrected is true the formula used
assumes that the supplied mean value is the arithmetic mean of the
sample data, not a known population parameter. If the mean is a known
population parameter, or if the "population" version of the variance is
desired, set isBiasCorrected to false before
invoking this method.
Returns 0 for a single-value (i.e. length = 1) sample.
Throws IllegalArgumentException if the array is null.
Does not change the internal state of the statistic.
Parameters: values - the input array Parameters: mean - the precomputed mean value the variance of the values or Double.NaN if the array is empty throws: IllegalArgumentException - if the array is null |
isBiasCorrected | public boolean isBiasCorrected()(Code) | | Returns the isBiasCorrected. |
setBiasCorrected | public void setBiasCorrected(boolean isBiasCorrected)(Code) | | Parameters: isBiasCorrected - The isBiasCorrected to set. |
|
|