Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.math.stat.descriptive.moment
Class FirstMoment

    java.lang.Object
      org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic
          org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic
              org.apache.commons.math.stat.descriptive.moment.FirstMoment

All Implemented Interfaces:
  Serializable, StorelessUnivariateStatistic, UnivariateStatistic

Direct Known Subclasses:
  SecondMoment

public class FirstMoment
extends AbstractStorelessUnivariateStatistic
implements 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.1 $ $Date: 2004/10/08 05:08:17 $
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.
`(package private) static long` | `serialVersionUID` Serializable version identifier

Constructor Summary
`FirstMoment()` Create a FirstMoment instance

Method Summary
`void` | `clear()` Clears the internal state of the Statistic
`long` | `getN()` Returns the number of values that have been added.
`double` | `getResult()` Returns the current value of the Statistic.
`void` | `increment(double d)` Updates the internal state of the statistic to reflect the addition of the new value.

Methods inherited from class org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic
`equals, evaluate, evaluate, hashCode, incrementAll, incrementAll`

Methods inherited from class org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic
`test`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### serialVersionUID

    static final long serialVersionUID

  Serializable version identifier

  See Also:
    Constant Field Values

### 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)

  Description copied from interface: `StorelessUnivariateStatistic`
  Updates the internal state of the statistic to reflect the addition of the new value.

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

### clear

    public void clear()

  Description copied from interface: `StorelessUnivariateStatistic`
  Clears the internal state of the Statistic

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

### getResult

    public double getResult()

  Description copied from interface: `StorelessUnivariateStatistic`
  Returns the current value of the Statistic.

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

### getN

    public long getN()

  Description copied from interface: `StorelessUnivariateStatistic`
  Returns the number of values that have been added.

  Specified by:
    `getN` in interface `StorelessUnivariateStatistic`
  Returns:
    the number of values.
  See Also:
    `StorelessUnivariateStatistic.getN()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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