{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"exponentials-decay-and-moving-averages","title":"Exponentials, decay, and the memory of a moving average","url":"https://addaly.com/learn/maths-you-need/exponentials-decay-and-moving-averages","position":40,"of":76,"minutes":9,"answer":"An exponential moving average with factor β remembers roughly 1/(1−β) steps and weights the past geometrically, which is where Adam's 0.9 and 0.999 come from, why it needs a bias correction at the start.","keyIdea":"An exponential moving average with factor β remembers roughly 1/(1−β) steps and weights the past geometrically, which is where Adam's 0.9 and 0.999 come from, why it needs a bias correction at the start, and why a smoothed loss curve shows a spike late and small."},"body":{"format":"markdown","text":"## Repeated multiplication has a shape\n\nMultiply 0.9 by itself and watch what happens.\n\n```\n0.9^1  = 0.900\n0.9^5  = 0.590\n0.9^10 = 0.349\n0.9^22 = 0.098\n0.9^44 = 0.010\n```\n\nEvery ten steps the value falls by roughly the same factor, about 0.35. That is exponential decay, and it has a **half-life**: the number of steps to halve. For a factor `β` the half-life is `ln 0.5 / ln β`. For 0.9 that is `−0.693 / −0.105 = 6.6` steps. For 0.99 it is 69 steps; for 0.999 it is 693. The half-life of `β` close to 1 is approximately `0.693 / (1 − β)`, a rule worth memorising.\n\nGrowth is the mirror image. `1.01^100 = 2.70`, which is `e` to two decimal places, and this is not a coincidence: `(1 + 1/n)^n` approaches `e` as `n` grows, which is why `e` turns up whenever something compounds continuously.\n\n## The exponential moving average\n\nOptimisers, loss smoothers and reinforcement learners all keep a running average that forgets the past gradually rather than all at once:\n\n```\nm_t = β × m_(t−1) + (1 − β) × g_t\n```\n\nUnroll it once and the structure shows. The newest value `g_t` has weight `(1 − β)`. The one before has weight `(1 − β) × β`, the one before that `(1 − β) × β^2`, and a value `k` steps back has weight `(1 − β) × β^k`. The weights are a decaying exponential, and they sum to 1.\n\nHow far back does the average remember? The weights form a geometric series whose mean position is `β / (1 − β)`, and the useful rule is that the **effective window is about `1 / (1 − β)`**. For `β = 0.9` that is ten steps. For `β = 0.999` it is a thousand.\n\nThis is where Adam's two constants come from. Its first moment uses `β1 = 0.9`, a ten-step average of the gradient. Its second moment uses `β2 = 0.999`, a thousand-step average of the squared gradient. The second needs a long memory because it is estimating a variance, and variance estimates from ten samples are noisy in a way that would make the step size lurch.\n\n## The bias at the start, and the correction\n\nStart the average at `m_0 = 0`. After one step, `m_1 = (1 − β) × g_1`. With `β2 = 0.999` that is `0.001 × g_1`: the average claims the squared gradient is a thousand times smaller than it is. Adam divides by the square root of this number to set the step, so an uncorrected first step would be about 30 times too large.\n\nThe correction divides by the total weight that has actually been applied, `1 − β^t`. At `t = 1` that is `1 − 0.999 = 0.001`, so the correction multiplies by a thousand and cancels the bias exactly. At `t = 1000` it is `1 − 0.999^1000 = 1 − 0.368 = 0.632`, still a noticeable 1.6 times. By `t = 5000` it is 0.993 and has faded. If you have ever wondered why Adam's code has two lines called `bias_correction`, that is the entire reason.\n\n## Schedules are exponentials too\n\nAn exponential learning-rate schedule multiplies by a factor `γ` every step. Over 50,000 steps at `γ = 0.9999`:\n\n```\n0.9999^50000 = e^(50000 × ln 0.9999) = e^(−5.0) = 0.0067\n```\n\nSo the final learning rate is 0.67 per cent of the initial one. If that seems too aggressive, the arithmetic tells you the fix: `γ = 0.99995` gives `e^(−2.5) = 0.082`. Working in the exponent is easier than guessing at the factor.\n\nThe same shape is the discount in reinforcement learning. A discount of 0.99 per step gives rewards a horizon of about a hundred steps; beyond that they contribute less than a third of their face value, and beyond 460 steps less than one per cent.\n\n## Where the average misleads\n\nAn exponential average lags. With `β = 0.99` a sudden spike in the loss appears in the smoothed curve about a hundred steps late and a hundred times smaller, and a genuine step change is drawn as a gentle slope. The smoothing slider in TensorBoard is exactly this average, and at its default setting it hides the variance that would tell you the learning rate is too high. Look at the raw curve at least once per run.\n\nThe start is biased as well. Unless the tool applies the correction above, the first hundred points of a smoothed curve are pulled toward zero, which looks like an implausibly good early loss. It is an artefact, not a result.\n\n## Tools\n\nEverything here is arithmetic you can do on a calculator with `ln` and `e^x`, or in three lines of Python:\n\n```python\nimport math\nbeta = 0.999\nprint(1 / (1 - beta), math.log(0.5) / math.log(beta))   # window, half-life\n```"},"check":{"question":"Adam keeps its second-moment estimate with β2 = 0.999. Roughly how far back does that average remember, and how?","options":[{"text":"About a thousand steps, with older gradients fading geometrically.","correct":true},{"text":"Exactly the last 999 gradients, each weighted equally, like a sliding window.","correct":false,"tempting":"Treats an exponential average as a moving window; the weights decay by a factor of β per step and never reach exactly zero."},{"text":"Every gradient since training began, all weighted equally, because β is so close to 1.","correct":false,"tempting":"A β near 1 lengthens the memory but does not make it uniform; a gradient 5,000 steps back carries weight 0.999^5000, under one per cent."},{"text":"About ten steps, the same as the first-moment average.","correct":false,"tempting":"Confuses β2 with β1 = 0.9; the window is 1/(1−β), and 1/(1−0.999) is a thousand, not ten."}]},"prev":{"slug":"logarithms-from-scratch","title":"What a log is, and why the axis got logged","url":"https://addaly.com/learn/maths-you-need/logarithms-from-scratch"},"next":{"slug":"logs-and-loss","title":"Logs, and why losses are logged","url":"https://addaly.com/learn/maths-you-need/logs-and-loss"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Exponentials, decay, and the memory of a moving average', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/exponentials-decay-and-moving-averages (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Exponentials, decay, and the memory of a moving average","courseTitle":"The Maths You Actually Need","module":{"index":5,"slug":"logs-information-and-loss","title":"Logarithms, information and the shape of a loss"},"answer":null,"keyIdea":"An exponential moving average with factor β remembers roughly 1/(1−β) steps and weights the past geometrically, which is where Adam’s 0.9 and 0.999 come from, why it needs a bias correction at the start, and why a smoothed loss curve shows a spike late and small.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"repeated-multiplication-has-a-shape","runs":[{"text":"Repeated multiplication has a shape"}]},{"t":"p","runs":[{"text":"Multiply 0.9 by itself and watch what happens."}]},{"t":"code","lang":"","label":"Text","text":"0.9^1  = 0.900\n0.9^5  = 0.590\n0.9^10 = 0.349\n0.9^22 = 0.098\n0.9^44 = 0.010"},{"t":"p","runs":[{"text":"Every ten steps the value falls by roughly the same factor, about 0.35. That is exponential decay, and it has a "},{"text":"half-life","b":true},{"text":": the number of steps to halve. For a factor "},{"text":"β","code":true},{"text":" the half-life is "},{"text":"ln 0.5 / ln β","code":true},{"text":". For 0.9 that is "},{"text":"−0.693 / −0.105 = 6.6","code":true},{"text":" steps. For 0.99 it is 69 steps; for 0.999 it is 693. The half-life of "},{"text":"β","code":true},{"text":" close to 1 is approximately "},{"text":"0.693 / (1 − β)","code":true},{"text":", a rule worth memorising."}]},{"t":"p","runs":[{"text":"Growth is the mirror image. "},{"text":"1.01^100 = 2.70","code":true},{"text":", which is "},{"text":"e","code":true},{"text":" to two decimal places, and this is not a coincidence: "},{"text":"(1 + 1/n)^n","code":true},{"text":" approaches "},{"text":"e","code":true},{"text":" as "},{"text":"n","code":true},{"text":" grows, which is why "},{"text":"e","code":true},{"text":" turns up whenever something compounds continuously."}]},{"t":"h2","id":"the-exponential-moving-average","runs":[{"text":"The exponential moving average"}]},{"t":"p","runs":[{"text":"Optimisers, loss smoothers and reinforcement learners all keep a running average that forgets the past gradually rather than all at once:"}]},{"t":"code","lang":"","label":"Text","text":"m_t = β × m_(t−1) + (1 − β) × g_t"},{"t":"p","runs":[{"text":"Unroll it once and the structure shows. The newest value "},{"text":"g_t","code":true},{"text":" has weight "},{"text":"(1 − β)","code":true},{"text":". The one before has weight "},{"text":"(1 − β) × β","code":true},{"text":", the one before that "},{"text":"(1 − β) × β^2","code":true},{"text":", and a value "},{"text":"k","code":true},{"text":" steps back has weight "},{"text":"(1 − β) × β^k","code":true},{"text":". The weights are a decaying exponential, and they sum to 1."}]},{"t":"p","runs":[{"text":"How far back does the average remember? The weights form a geometric series whose mean position is "},{"text":"β / (1 − β)","code":true},{"text":", and the useful rule is that the "},{"text":"effective window is about ","b":true},{"text":"1 / (1 − β)","b":true,"code":true},{"text":". For "},{"text":"β = 0.9","code":true},{"text":" that is ten steps. For "},{"text":"β = 0.999","code":true},{"text":" it is a thousand."}]},{"t":"p","runs":[{"text":"This is where Adam’s two constants come from. Its first moment uses "},{"text":"β1 = 0.9","code":true},{"text":", a ten-step average of the gradient. Its second moment uses "},{"text":"β2 = 0.999","code":true},{"text":", a thousand-step average of the squared gradient. The second needs a long memory because it is estimating a variance, and variance estimates from ten samples are noisy in a way that would make the step size lurch."}]},{"t":"h2","id":"the-bias-at-the-start-and-the-correction","runs":[{"text":"The bias at the start, and the correction"}]},{"t":"p","runs":[{"text":"Start the average at "},{"text":"m_0 = 0","code":true},{"text":". After one step, "},{"text":"m_1 = (1 − β) × g_1","code":true},{"text":". With "},{"text":"β2 = 0.999","code":true},{"text":" that is "},{"text":"0.001 × g_1","code":true},{"text":": the average claims the squared gradient is a thousand times smaller than it is. Adam divides by the square root of this number to set the step, so an uncorrected first step would be about 30 times too large."}]},{"t":"p","runs":[{"text":"The correction divides by the total weight that has actually been applied, "},{"text":"1 − β^t","code":true},{"text":". At "},{"text":"t = 1","code":true},{"text":" that is "},{"text":"1 − 0.999 = 0.001","code":true},{"text":", so the correction multiplies by a thousand and cancels the bias exactly. At "},{"text":"t = 1000","code":true},{"text":" it is "},{"text":"1 − 0.999^1000 = 1 − 0.368 = 0.632","code":true},{"text":", still a noticeable 1.6 times. By "},{"text":"t = 5000","code":true},{"text":" it is 0.993 and has faded. If you have ever wondered why Adam’s code has two lines called "},{"text":"bias_correction","code":true},{"text":", that is the entire reason."}]},{"t":"h2","id":"schedules-are-exponentials-too","runs":[{"text":"Schedules are exponentials too"}]},{"t":"p","runs":[{"text":"An exponential learning-rate schedule multiplies by a factor "},{"text":"γ","code":true},{"text":" every step. Over 50,000 steps at "},{"text":"γ = 0.9999","code":true},{"text":":"}]},{"t":"code","lang":"","label":"Text","text":"0.9999^50000 = e^(50000 × ln 0.9999) = e^(−5.0) = 0.0067"},{"t":"p","runs":[{"text":"So the final learning rate is 0.67 per cent of the initial one. If that seems too aggressive, the arithmetic tells you the fix: "},{"text":"γ = 0.99995","code":true},{"text":" gives "},{"text":"e^(−2.5) = 0.082","code":true},{"text":". Working in the exponent is easier than guessing at the factor."}]},{"t":"p","runs":[{"text":"The same shape is the discount in reinforcement learning. A discount of 0.99 per step gives rewards a horizon of about a hundred steps; beyond that they contribute less than a third of their face value, and beyond 460 steps less than one per cent."}]},{"t":"h2","id":"where-the-average-misleads","runs":[{"text":"Where the average misleads"}]},{"t":"p","runs":[{"text":"An exponential average lags. With "},{"text":"β = 0.99","code":true},{"text":" a sudden spike in the loss appears in the smoothed curve about a hundred steps late and a hundred times smaller, and a genuine step change is drawn as a gentle slope. The smoothing slider in TensorBoard is exactly this average, and at its default setting it hides the variance that would tell you the learning rate is too high. Look at the raw curve at least once per run."}]},{"t":"p","runs":[{"text":"The start is biased as well. Unless the tool applies the correction above, the first hundred points of a smoothed curve are pulled toward zero, which looks like an implausibly good early loss. It is an artefact, not a result."}]},{"t":"h2","id":"tools","runs":[{"text":"Tools"}]},{"t":"p","runs":[{"text":"Everything here is arithmetic you can do on a calculator with "},{"text":"ln","code":true},{"text":" and "},{"text":"e^x","code":true},{"text":", or in three lines of Python:"}]},{"t":"code","lang":"python","label":"Python","text":"import math\nbeta = 0.999\nprint(1 / (1 - beta), math.log(0.5) / math.log(beta))   # window, half-life"}],"check":{"question":[{"text":"Adam keeps its second-moment estimate with β2 = 0.999. Roughly how far back does that average remember, and how?"}],"options":[{"text":[{"text":"About a thousand steps, with older gradients fading geometrically."}],"correct":true,"tempting":null},{"text":[{"text":"Exactly the last 999 gradients, each weighted equally, like a sliding window."}],"correct":false,"tempting":[{"text":"Treats an exponential average as a moving window; the weights decay by a factor of β per step and never reach exactly zero."}]},{"text":[{"text":"Every gradient since training began, all weighted equally, because β is so close to 1."}],"correct":false,"tempting":[{"text":"A β near 1 lengthens the memory but does not make it uniform; a gradient 5,000 steps back carries weight 0.999^5000, under one per cent."}]},{"text":[{"text":"About ten steps, the same as the first-moment average."}],"correct":false,"tempting":[{"text":"Confuses β2 with β1 = 0.9; the window is 1/(1−β), and 1/(1−0.999) is a thousand, not ten."}]}],"order":[3,0,2,1],"why":null},"prev":{"slug":"logarithms-from-scratch","title":"What a log is, and why the axis got logged","minutes":8},"next":{"slug":"logs-and-loss","title":"Logs, and why losses are logged","minutes":8}}}