Using the algorithm described here to calculate the variance while data streams, I want to compute a moving variance, which like in the case of moving average will consider older data less important.
for convinence here the algorithm from the wiki page :
def weighted_incremental_variance(dataWeightPairs):
wSum = 0
mean = 0
S = 0
for x, w in dataWeightPairs: # Alternatively "for x, w in zip(data, weights):"
wSum = wSum + w
meanOld = mean
mean = meanOld + (w / wSum) * (x - meanOld)
S = S + w * (x - meanOld) * (x - mean)
variance = S / wSum
altering this algorithm for moving mean is easy (i think) just divide wSum by some factor>1 (the larger the more forgetfull it becomes). but given this factor, how would i fix S to act accordingly?
I could divide it by the same factor as well but that doesnt feel right...