Computes the arithmetic mean of a set of values. Uses the definitional formula:
mean = sum(x_i) / n
where n
is the number of observations.
When {@link #increment(double)} is used to add data incrementally from astream of (unstored) values, the value of the statistic that {@link #getResult()} returns is computed using the following recursiveupdating algorithm:
- Initialize
m =
the first value - For each additional value, update using
m = m + (new value - m) / (number of observations)
If {@link #evaluate(double[])} is used to compute the mean of an arrayof 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.
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.