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: 1006299 $ $Date: 2010-10-10 16:47:17 +0200 (dim. 10 oct. 2010) $
See Also:
  • Field Details

    • 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 Details

    • FirstMoment

      public FirstMoment()
      Create a FirstMoment instance
    • FirstMoment

      public FirstMoment(FirstMoment original)
      Copy constructor, creates a new FirstMoment identical to the original
      Parameters:
      original - the FirstMoment instance to copy
  • Method Details