I am trying to calculate a windowed average where the newest value replaces the oldest value in a set of size 10. In this case, I have a real-time number stream and have access to current value, current average and the previous value.
Is there any way to calculate this value incrementally storing minimal amount of historical state? I have tried formulas in this question but they don't seem to be suitable for window situation
To do this you need to store all values currently in the window. This is best done using a double-linked list. So for each new value you append the value to the list and pop of the first (oldest) number in the list. Then you can subtract oldest/10 and add new/10 to the average value.
So the algorithm is (for maximal window size $\lambda$):