Maintain the variance in a stream

275 Views Asked by At

I am trying to understand how to compute the variance online. If I have the value 23 ten times, the value 10 five times and the value 4 three times, what is the variance?

We know the mean is $(230+50+12)/18 \approx 16.22$ and the variance is approx $61.17$ .

It is easy to maintain the mean online by just storing the sum and the number of numbers we have seen.

However, if the numbers arrived one at a time, how can we maintain the variance as the numbers arrive? That is without just storing all the numbers and recalculating each time a new number arrives.

1

There are 1 best solutions below

0
On BEST ANSWER

There are good number of algorithms for this.

Try this algorithm from Knuth: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm