Compute an exponentially weighted average with bias correction
Why it matters Adam, AdamW and most training-loss smoothers rely on exactly this correction.
Adam's moment estimates are exponentially weighted averages that start at 0, so early values are too small. Bias correction fixes that.
Write ewma(values, beta). Start with v = 0. For t = 1, 2, ..., n set v_t = beta * v_{t-1} + (1 - beta) * x_t. Return (raw, corrected), two float arrays of length n, where corrected_t = v_t / (1 - beta^t).
def ewma(values, beta)Example
ewma([10, 10], 0.9) gives raw [1.0, 1.9] and corrected [10.0, 10.0].
Understand the idea
An exponentially weighted average keeps a running summary where recent values count more and old ones fade. Because it starts at 0, the first few averages are dragged toward 0, like a new restaurant whose rating starts at zero stars before any review.
Tiny example: beta = 0.9, two readings of 10. Step 1: v = 0.1 * 10 = 1, though the true level is 10. Divide by 1 - 0.9 = 0.1 to get 10. Step 2: v = 0.9 * 1 + 1 = 1.9; divide by 1 - 0.81 = 0.19 to get 10 again.
Rules: v_t = beta * v_{t-1} + (1 - beta) * x_t, corrected_t = v_t / (1 - beta^t).
Adam applies this to both its first and second moment, which is why its first steps are not tiny.