The running average a_n of a series R_n
a_n =\frac{a\_{n-1}\times u+R_n\times v}{u+v}
The larger u and the smaller v, the longer the period over which the running average is taken.
We don’t want to do floating point arithmetic, because different peers might get different answers. And with integer arithmetic, kind of like to make u+v=2^n
It is probably harmless if they get different answers, provided that this happens rarely, but easier to ensure that this never happens than to try to think about all the possible circumstances where this could become a problem, where malicious people could contrive inputs to make sure it becomes a problem.
Unsigned integer arithmetic is guaranteed to give the same answers on all hardware under all compilers. So, when we can, use unsigned integers.
Taking the running average of the running average repeatedly gives you higher order smoothing behavior.
To calculate the running variance, calculate the running average of the squares.
Standard deviation over a finite set of N elements is:
\displaystyle\frac{\Large{\sum\limits^N_{j} \bigg({R_j-\sum\limits^N_{i} \frac{R_i}{N}}\bigg)^2}}{\LARGE{N-1}} \displaystyle\large{\approx\sum\limits^N_{j} \frac{R^2_j}{N-1} - \bigg({\sum\limits^N_{i} \frac{R_i}{N}}\bigg)^2}
Presumably the same trick will work over running averages.
reaction.la gpg key 154588427F2709CD9D7146B01C99BB982002C39F
This work is licensed under the Creative Commons Attribution 4.0 International License.