- All Implemented Interfaces:
- Serializable, StorelessUnivariateStatistic, UnivariateStatistic, WeightedEvaluation, MathArrays.Function
public class Meanextends AbstractStorelessUnivariateStatisticimplements Serializable, WeightedEvaluation
Computes the arithmetic mean of a set of values. Uses the definitional formula:
mean = sum(x_i) / n
nis the number of observations.
increment(double)is used to add data incrementally from a stream of (unstored) values, the value of the statistic that
getResult()returns is computed using the following recursive updating algorithm:
m =the first value
- For each additional value, update using
m = m + (new value - m) / (number of observations)
AbstractStorelessUnivariateStatistic.evaluate(double)is used to compute the mean of an array of stored values, a two-pass, corrected algorithm is used, starting with the definitional formula computed using the array of stored values and then correcting this by adding the mean deviation of the data values from the arithmetic mean. See, e.g. "Comparison of Several Algorithms for Computing Sample Means and Variances," Robert F. Ling, Journal of the American Statistical Association, Vol. 69, No. 348 (Dec., 1974), pp. 859-866.
ReturnsNote 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
Double.NaNif the dataset is empty.
clear()method, it must be synchronized externally.
- See Also:
- Serialized Form