commonSense.stat.basic
Class FirstMoment

java.lang.Object
  extended byorg.apache.commons.math.stat.univariate.AbstractUnivariateStatistic
      extended byorg.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic
          extended bycommonSense.stat.basic.FirstMoment
All Implemented Interfaces:
java.io.Serializable, org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic, org.apache.commons.math.stat.univariate.UnivariateStatistic
Direct Known Subclasses:
SecondMoment

public class FirstMoment
extends org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic
implements java.io.Serializable

Computes the first moment (arithmetic mean). Uses the definitional formula:

mean = sum(x_i) / n

where n is the number of observations.

To limit numeric errors, the value of the statistic is computed using the following recursive updating algorithm:

  1. Initialize m = the first value
  2. For each additional value, update using
    m = m + (new value - m) / (number of observations)

Returns Double.NaN if the dataset is empty.

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: 1.20 $ $Date: 2004/07/18 05:39:30 $
See Also:
Serialized Form

Field Summary
protected  double dev
          Deviation of most recently added value from previous first moment.
protected  double m1
          First moment of values that have been added
protected  long n
          Count of values that have been added
protected  double nDev
          Deviation of most recently added value from previous first moment, normalized by previous sample size.
 
Constructor Summary
FirstMoment()
          Create a FirstMoment instance
 
Method Summary
 void clear()
           
 long getN()
           
 double getResult()
           
 void increment(double d)
           
 
Methods inherited from class org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic
equals, evaluate, evaluate, hashCode, incrementAll, incrementAll
 
Methods inherited from class org.apache.commons.math.stat.univariate.AbstractUnivariateStatistic
test
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

n

protected long n
Count of values that have been added


m1

protected double m1
First moment of values that have been added


dev

protected double dev
Deviation of most recently added value from previous first moment. Retained to prevent repeated computation in higher order moments.


nDev

protected double nDev
Deviation of most recently added value from previous first moment, normalized by previous sample size. Retained to prevent repeated computation in higher order moments

Constructor Detail

FirstMoment

public FirstMoment()
Create a FirstMoment instance

Method Detail

increment

public void increment(double d)
Specified by:
increment in interface org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic
See Also:
StorelessUnivariateStatistic.increment(double)

clear

public void clear()
Specified by:
clear in interface org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic
See Also:
StorelessUnivariateStatistic.clear()

getResult

public double getResult()
Specified by:
getResult in interface org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic
See Also:
StorelessUnivariateStatistic.getResult()

getN

public long getN()
Specified by:
getN in interface org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic
See Also:
StorelessUnivariateStatistic.getN()


RealJ version 3.5 2001. www.realj.com