Tuesday, July 03, 2012

Mean calculation based on previous mean value

mean_n(a) = ( 1/n ) * ( (n-1) * mean_n_1 + a )

where mean_n is mean of all numbers till a.
           mean_n_1 is mean of all numbers except a.

Now if the n is big then it can be approximated to: mean_n_1 + a/n.

The interesting part is (a/n). If a wants to participate in the mean calculation then it just needs to be divided into n portions and added to the previous mean(for n-1).

No comments: