commonSense.stat.basic
Class Mean

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

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

Returns the arithmetic mean of the available values. Uses the definitional formula:

mean = sum(x_i) / n

where n is the number of observations.

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.22 $ $Date: 2004/07/18 05:34:26 $
See Also:
Serialized Form

Field Summary
protected  boolean incMoment
          Determines whether or not this statistic can be incremented or cleared.
protected  FirstMoment moment
          First moment on which this statistic is based.
 
Constructor Summary
Mean()
          Constructs a Mean.
Mean(FirstMoment m1)
          Constructs a Mean with an External Moment.
 
Method Summary
 void clear()
           
 double evaluate(double[] values, int begin, int length)
          Returns the arithmetic mean of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.
 long getN()
           
 double getResult()
           
 void increment(double d)
           
 
Methods inherited from class org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic
equals, 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

moment

protected FirstMoment moment
First moment on which this statistic is based.


incMoment

protected boolean incMoment
Determines whether or not this statistic can be incremented or cleared.

Statistics based on (constructed from) external moments cannot be incremented or cleared.

Constructor Detail

Mean

public Mean()
Constructs a Mean.


Mean

public Mean(FirstMoment m1)
Constructs a Mean with an External Moment.

Parameters:
m1 - the moment
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()

evaluate

public double evaluate(double[] values,
                       int begin,
                       int length)
Returns the arithmetic mean of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws IllegalArgumentException if the array is null.

See Mean for details on the computing algorithm.

Specified by:
evaluate in interface org.apache.commons.math.stat.univariate.UnivariateStatistic
Parameters:
values - the input array
begin - index of the first array element to include
length - the number of elements to include
Returns:
the mean of the values or Double.NaN if length = 0
Throws:
java.lang.IllegalArgumentException - if the array is null or the array index parameters are not valid


RealJ version 3.5 2001. www.realj.com