org.apache.commons.math.stat.univariate.moment
Class Variance

java.lang.Object
  extended byorg.apache.commons.math.stat.univariate.AbstractUnivariateStatistic
      extended byorg.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic
          extended byorg.apache.commons.math.stat.univariate.moment.Variance
All Implemented Interfaces:
Serializable, StorelessUnivariateStatistic, UnivariateStatistic
Direct Known Subclasses:
StandardDeviation

public class Variance
extends AbstractStorelessUnivariateStatistic
implements Serializable

Version:
$Revision: 1.14 $ $Date: 2003/11/19 03:28:24 $
See Also:
Serialized Form

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  Mean mean
          Mean to be used in UnvariateStatistic evaluation approach.
protected  SecondMoment moment
          SecondMoment is used in incremental calculation of Variance
protected  int n
          Maintains the current count of inrementations that have occured.
protected  double variance
          This property maintains the latest calculated variance for efficiency when getResult() is called many times between increments.
 
Constructor Summary
Variance()
          Constructs a Variance.
Variance(SecondMoment m2)
          Constructs a Variance based on an externalized second moment.
 
Method Summary
 void clear()
          Clears all the internal state of the Statistic
 double evaluate(double[] values, int begin, int length)
          Returns the variance of the available values.
 double getN()
          Returns the current state of the statistic after the last increment.
 double getResult()
          Returns the current state of the statistic after the last increment.
 void increment(double d)
          Increments the internal state of the Storagless Implementation.
 
Methods inherited from class org.apache.commons.math.stat.univariate.AbstractUnivariateStatistic
evaluate, test
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.math.stat.univariate.UnivariateStatistic
evaluate
 

Field Detail

moment

protected SecondMoment moment
SecondMoment is used in incremental calculation of Variance


incMoment

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.


variance

protected double variance
This property maintains the latest calculated variance for efficiency when getResult() is called many times between increments.


n

protected int n
Maintains the current count of inrementations that have occured. If the external SecondMoment is used, the this is updated from that moments counter


mean

protected Mean mean
Mean to be used in UnvariateStatistic evaluation approach.

Constructor Detail

Variance

public Variance()
Constructs a Variance.


Variance

public Variance(SecondMoment m2)
Constructs a Variance based on an externalized second moment.

Parameters:
m2 - the SecondMoment (Thrid or Fourth moments work here as well.)
Method Detail

increment

public void increment(double d)
Description copied from interface: StorelessUnivariateStatistic
Increments the internal state of the Storagless Implementation.

Specified by:
increment in interface StorelessUnivariateStatistic
Specified by:
increment in class AbstractStorelessUnivariateStatistic
See Also:
StorelessUnivariateStatistic.increment(double)

getResult

public double getResult()
Description copied from interface: StorelessUnivariateStatistic
Returns the current state of the statistic after the last increment.

Specified by:
getResult in interface StorelessUnivariateStatistic
Specified by:
getResult in class AbstractStorelessUnivariateStatistic
See Also:
StorelessUnivariateStatistic.getResult()

getN

public double getN()
Description copied from interface: StorelessUnivariateStatistic
Returns the current state of the statistic after the last increment.

Specified by:
getN in interface StorelessUnivariateStatistic
Returns:
value of the statistic, Double.NaN if it has been cleared or just instantiated.
See Also:
StorelessUnivariateStatistic.getN()

clear

public void clear()
Description copied from interface: StorelessUnivariateStatistic
Clears all the internal state of the Statistic

Specified by:
clear in interface StorelessUnivariateStatistic
Specified by:
clear in class AbstractStorelessUnivariateStatistic
See Also:
StorelessUnivariateStatistic.clear()

evaluate

public double evaluate(double[] values,
                       int begin,
                       int length)
Returns the variance of the available values. This uses a corrected two pass algorithm of the following corrected two pass formula (14.1.8), and also referenced in:

"Algorithms for Computing the Sample Variance: Analysis and Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J. 1983, American Statistician, vol. 37, pp. 242?247.

Specified by:
evaluate in interface UnivariateStatistic
Overrides:
evaluate in class AbstractStorelessUnivariateStatistic
Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the result, Double.NaN if no values for an empty array or 0.0 for a single value set.
See Also:
UnivariateStatistic.evaluate(double[], int, int)


Copyright © 2003-2004 Apache Software Foundation. All Rights Reserved.