Created
January 13, 2021 23:06
-
-
Save philipperemy/0011d612031299787b17b2a58066579c to your computer and use it in GitHub Desktop.
Revisions
-
philipperemy created this gist
Jan 13, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import numpy as np # online computation of the mean and the variance. class RollingMean: def __init__(self): self.st = 0.0 self.n = 0 def update(self, x): self.st += x self.n += 1 return self.st / self.n class RollingStd: def __init__(self): self.sst = 0.0 self.st = 0.0 self.n = 0 def update(self, x): self.sst += x ** 2 self.st += x self.n += 1 return np.sqrt((self.sst - (self.st ** 2) / self.n) / self.n)