Is there a way to incrementally calculate (or estimate) the average of a vector (a set of numbers) without knowing their count in advance?
For example you have
a = [4 6 3 9 4 12 4 18]and you want to get an estimate of the average but you don’t have all the values at hand so you want to have a running average without keeping all the previous values available.
You need to keep at least two pieces of information: the number of terms so far and the running mean (or something equivalent to it).
Let’s suppose the nth component of the vector is an and the running mean up to this is mn so mn=1nn∑i=1ai.
Starting with m0=0, you can use the obvious single pass mn=(n−1)mn−1+ann but precision errors are likely to be smaller if you use the equivalent mn=mn−1+an−mn−1n.