Top Description Fields Constructors Methods
org.apache.commons.math3.stat.descriptive.moment

pack-priv Class FirstMoment

extends AbstractStorelessUnivariateStatistic
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.apache.commons.math3.stat.descriptive.moment.SecondMoment
Imports
java.io.Serializable, org.apache.commons.math3.exception.NullArgumentException, org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic, org.apache.commons.math3.util.MathUtils

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 Double.NaN may also be returned if the input includes NaN and / or infinite values.

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.

Field Summary

Modifier and TypeField and Description
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.

private static final long
serialVersionUID

Serializable version identifier

Constructor Summary

AccessConstructor and Description
pack-priv
FirstMoment()

Create a FirstMoment instance

pack-priv
FirstMoment(FirstMoment
the FirstMoment instance to copy
original
)

Copy constructor, creates a new FirstMoment identical to the original

Method Summary

Modifier and TypeMethod and Description
public void
public FirstMoment
public static void
copy(FirstMoment
FirstMoment to copy
source
,
FirstMoment
FirstMoment to copy to
dest
)

Copies source to dest.

public long
getN()

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Returns the number of values that have been added.

public double
public void
increment(final double
the new value.
d
)

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

Inherited from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic:
equalsevaluateevaluatehashCodeincrementAllincrementAll

Field Detail

devback to summary
protected double dev

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

m1back to summary
protected double m1

First moment of values that have been added

nback to summary
protected long n

Count of values that have been added

nDevback to summary
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

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

Constructor Detail

FirstMomentback to summary
pack-priv FirstMoment()

Create a FirstMoment instance

FirstMomentback to summary
pack-priv FirstMoment(FirstMoment original) throws NullArgumentException

Copy constructor, creates a new FirstMoment identical to the original

Parameters
original:FirstMoment

the FirstMoment instance to copy

Exceptions
NullArgumentException:
if original is null

Method Detail

clearback to summary
public void clear()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.clear.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.clear.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.clear.

Clears the internal state of the Statistic

Annotations
@Override
copyback to summary
public FirstMoment copy()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.copy.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy, org.apache.commons.math3.stat.descriptive.UnivariateStatistic.copy.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.copy.

Returns a copy of the statistic with the same internal state.

Returns:FirstMoment

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy.

a copy of the statistic

Annotations
@Override
copyback to summary
public static void copy(FirstMoment source, FirstMoment dest) throws NullArgumentException

Copies source to dest.

Neither source nor dest can be null.

Parameters
source:FirstMoment

FirstMoment to copy

dest:FirstMoment

FirstMoment to copy to

Exceptions
NullArgumentException:
if either source or dest is null
getNback to summary
public long getN()

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getN.

Returns the number of values that have been added.

Returns:long

the number of values.

getResultback to summary
public double getResult()

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.getResult.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.getResult.

Returns the current value of the Statistic.

Returns:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

value of the statistic, Double.NaN if it has been cleared or just instantiated.

Annotations
@Override
incrementback to summary
public void increment(final double d)

Implements abstract org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Doc from org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

Parameters
d:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

the new value.

Annotations
@Override