-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
c1-quick 🕐Complexity lowComplexity lowp3-enhancement 🔥Much new such featureMuch new such featureto-merge ↰ImminentImminent
Milestone
Description
The current exponential moving average implementation is "naive" and is not correct for the initial iterations. The first value has a disproportionate influence, which makes the result diverge from the true average. The correct implementation initializes with 0 and divides the result by 1 - factor**step
. I'll skip the proof.
Here is a class that I use:
class EMA:
beta: float
ema: float
step: int
def __init__ (self, beta: float):
self.beta = beta
self.ema = 0
self.step = 0
def append(self, value: float):
self.ema = self.beta * self.ema + (1 - self.beta) * value
self.step += 1
def get(self):
return self.ema / (1 - self.beta ** self.step) if self.step > 0 else 'N/A'
Metadata
Metadata
Assignees
Labels
c1-quick 🕐Complexity lowComplexity lowp3-enhancement 🔥Much new such featureMuch new such featureto-merge ↰ImminentImminent