How to efficiently calculate a running standard deviation
The answer is to use Welford’s algorithm, which is very clearly defined after the “naive methods” in: Wikipedia: Algorithms for calculating variance It’s more numerically stable than either the two-pass or online simple sum of squares collectors suggested in other responses. The stability only really matters when you have lots of values that are close … Read more