Created
June 27, 2018 09:57
-
-
Save vsmelov/4181ebd320c653e6d3a274d3c43188e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RollingStatistic(object): | |
def __init__(self, window_size, average, variance): | |
self.N = window_size | |
self.average = average | |
self.variance = variance | |
self.stddev = sqrt(variance) | |
def update(new, old): | |
oldavg = self.average | |
newavg = oldavg + (new - old)/self.N | |
self.average = newavg | |
self.variance += (new-old)*(new-newavg+old-oldavg)/(self.N-1) | |
self.stddev = sqrt(variance) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment