Formula Bro

Math and physics formulas, explained like you are new.


Adam Optimizer

In one sentence: Adam keeps a running average of each setting’s slope and of how large those slopes have been, then uses both to choose a step size for every setting separately.

θt=θt−1−ηm̂tv̂t+ϵ\theta_t = \theta_{t-1} - \eta \, \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}

Read it out loud: “theta sub t equals theta sub t minus 1, minus eta times m-hat sub t, divided by the square root of v-hat sub t, plus epsilon. Here theta is the settings of the model, and the subscript t counts steps. Eta, said AY-tuh, is the learning rate. M-hat is the corrected average of the slope, and v-hat is the corrected average of the squared slope. Epsilon, said EP-sih-lon, is a tiny safety number.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Settings, slopes and subscripts

The settings of the model are written θ\theta, the Greek letter theta, said THAY-tuh. The subscript tt counts steps, starting from 1, so θt\theta_t is the settings after step tt and θt−1\theta_{t-1} is the settings one step earlier. The gradient gtg_t is the slope of the loss at the settings before step tt. It says which way the loss rises fastest.

Running averages and decay rates

A running average is an average that is updated after every step, so each new value enters a little and the old values fade. The fraction of the old average that is kept each step is called the decay rate. Adam uses two decay rates, β1\beta_1 (beta one, usually 0.9) for the gradient average and β2\beta_2 (beta two, usually 0.999) for the squared-gradient average. Because β2\beta_2 is closer to 1, its average changes more slowly.

Hats, squares and the bias correction, like m̂t\hat{m}_t

A small hat over a letter, as in m̂t\hat{m}_t (read m-hat), marks a corrected version of a value. The correction adjusts the averages for their slow start. A square such as gt2g_t^{2} means gtg_t times gtg_t. It is never negative, so the average of squares measures how large the slopes have been, while ignoring whether they went up or down.

Square roots, x\sqrt{x}

The square root x\sqrt{x} is the number that, multiplied by itself, gives xx. For example 36=6\sqrt{36} = 6, because 6×6=366 \times 6 = 36. Taking a square root turns a squared quantity back into the same size as the original slopes. That is why Adam divides by the square root of the averaged squares.

Powers of ten, like 10−810^{-8}

Very small numbers are written with a power of ten. The exponent says how many times to divide by 10. So 10−8=1/10810^{-8} = 1 / 10^{8}, which is 0.00000001: a decimal point, then seven zeros, then a 1. Adam’s safety number ϵ\epsilon is set to 10−810^{-8}, so it is tiny, but not zero. Writing it this way keeps the number short and easy to read.

Powers of a decay rate, like β1t\beta_1^{t}

The power β1t\beta_1^{t} means β1\beta_1 multiplied by itself tt times. With β1=0.9\beta_1 = 0.9, after one step it is 0.9, after two steps 0.9×0.9=0.810.9 \times 0.9 = 0.81, and after three steps 0.7290.729. These powers shrink toward zero as tt grows, and they are used in the bias correction.

What each symbol means

SymbolMeaning

θt\theta_t

The settings of the model after step tt. Step counting starts at 1 for the first update. The settings are a list of numbers, and in this toy example they are unitless.

θt−1\theta_{t-1}

The settings before step tt, one update earlier. The gradient is measured at this point, so it is the place where the slope is read.

η\eta

The learning rate, the base size of each step. It is a small positive number, and the Adam paper suggests 0.001 as a starting value. It has no unit in this formula, but it sets how far the settings move per step.

m̂t\hat{m}_t

The bias-corrected average of the gradient, read m-hat sub t. It tracks the direction the slope has been pointing recently. Its unit is the same as the gradient’s unit.

v̂t\hat{v}_t

The bias-corrected average of the squared gradient, read v-hat sub t. Squares are never negative, so this number measures how large the slopes have been. Its unit is the square of the gradient’s unit.

v̂t\sqrt{\hat{v}_t}

The square root of the averaged squared gradient. It gives the typical size of the recent slopes in the same unit as the gradient, so dividing by it makes each step depend on how steady the slopes are.

ϵ\epsilon

A tiny positive number, usually 10−810^{-8}, added to the bottom of the fraction so the step never divides by zero. It is unitless, and it has almost no effect unless the typical slope size is extremely small.

gtg_t

The gradient at step tt, the slope of the loss at the settings before that step. It has the unit of the loss divided by the unit of the settings. It is the raw input to both running averages.

β1\beta_1

The decay rate for the gradient average, the Greek letter beta with subscript 1. Usually 0.9, so the old average keeps 90 percent of its weight each step.

β2\beta_2

The decay rate for the squared-gradient average, the Greek letter beta with subscript 2. Usually 0.999, so the old squared average keeps 99.9 percent of its weight each step, which makes it change slowly.

The formula piece by piece

m̂t\hat{m}_t

The averaged slope, corrected for the early steps. It points in the direction the loss has been falling, averaged over recent steps, so one noisy slope cannot decide the whole move.

v̂t+ϵ\sqrt{\hat{v}_t} + \epsilon

The typical size of recent slopes, with the tiny safety number ϵ\epsilon added so that nothing divides by zero. Taking the square root returns the squared average to the original size of the slopes.

m̂tv̂t+ϵ\frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}

The direction divided by the typical size. When the slopes have been steady, this ratio is close to plus or minus 1, so each step is about the learning rate. When the slopes flip sign, the average shrinks and the step gets smaller.

ηm̂tv̂t+ϵ\eta \, \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}

The learning rate times that ratio: the size of one step, in the units of the settings. Each setting gets its own ratio, so each setting moves at its own pace.

θt=θt−1−ηm̂tv̂t+ϵ\theta_t = \theta_{t-1} - \eta \, \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}

The whole rule in one sentence: the new settings equal the old settings minus the learning rate times the averaged slope divided by its typical size, with a tiny safety number to keep the division safe.

What the formula is doing, and why

What goes in and what comes out. Adam takes the current slope for each setting and returns a new value for that setting. Inside, it keeps two running averages for every setting. The first, mtm_t, is an average of the slopes gtg_t, so it shows which way the slope has been pointing. The second, vtv_t, is an average of the squared slopes, so it shows how large the slopes have been. They update as mt=β1mt−1+(1−β1)gtm_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t and vt=β2vt−1+(1−β2)gt2v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^{2}. Each new slope takes a small share, and the old average keeps most of its weight.

Why correct the early steps? Both averages start at zero, so the first few values are too small, because they have not yet collected enough slopes. The bias correction fixes this: m̂t=mt/(1−β1t)\hat m_t = m_t / (1 - \beta_1^{t}) and v̂t=vt/(1−β2t)\hat v_t = v_t / (1 - \beta_2^{t}). The denominators are small early on, which makes the division bigger, and they approach 1 as tt grows. So the correction matters mostly for the first steps.

Why divide by the typical slope size? The update divides the averaged slope m̂t\hat m_t by the square root of the averaged squared slope, v̂t\sqrt{\hat v_t}. Dividing by the typical size means that each setting moves by roughly η\eta, whatever the raw size of its slopes was. Settings with steady, large slopes do not take huge steps, and settings with small slopes still move. The tiny ϵ\epsilon only keeps the division safe when the typical slope size is almost zero.

Defaults and their limits. The Adam paper by Kingma and Ba reports β1=0.9\beta_1 = 0.9, β2=0.999\beta_2 = 0.999 and ϵ=10−8\epsilon = 10^{-8}, with the learning rate η=0.001\eta = 0.001, as settings that worked well on the problems it tested. Many libraries use the same defaults. They are a starting point, not a guarantee of the best result on a new problem.

An everyday picture

Picture a driver who remembers two things about the road: which way it has been bending, and how bumpy the ride has been. On a smooth stretch the driver steers firmly. On a rough, jerky stretch the driver takes smaller, careful steps. Adam gives each setting in the model its own memory of how bumpy its road has been.

Worked example: Two steps of Adam on one setting

One setting, θ\theta, has a bowl-shaped loss L(θ)=(θ−3)2L(\theta) = (\theta - 3)^{2}, with its lowest point at 3. Its slope is g=2(θ−3)g = 2(\theta - 3). We start at θ0=0\theta_0 = 0 with both averages at zero, m0=0m_0 = 0 and v0=0v_0 = 0. We use the defaults β1=0.9\beta_1 = 0.9, β2=0.999\beta_2 = 0.999 and ϵ=10−8\epsilon = 10^{-8}. For easy numbers, the learning rate is η=0.1\eta = 0.1. All values are unitless.

  1. Step 1: find the slope. At θ0=0\theta_0 = 0 the slope is g1=2(0−3)=−6g_1 = 2(0 - 3) = -6. The slope is negative, which means the loss falls as the setting goes up, so the step should move the setting upward.
  2. Step 1: update the two averages. The gradient average becomes m1=0.9×0+0.1×(−6)=−0.6m_1 = 0.9 \times 0 + 0.1 \times (-6) = -0.6. The squared average becomes v1=0.999×0+0.001×36=0.036v_1 = 0.999 \times 0 + 0.001 \times 36 = 0.036. Each average takes only a small share of the new value, because the decay rates keep most of the old average.
  3. Step 1: correct the early averages. Both averages are still small, because they started at zero. We divide by 1−β11=0.11 - \beta_1^{1} = 0.1 and by 1−β21=0.0011 - \beta_2^{1} = 0.001. That gives m̂1=−0.6/0.1=−6\hat m_1 = -0.6 / 0.1 = -6 and v̂1=0.036/0.001=36\hat v_1 = 0.036 / 0.001 = 36, which match the slope we actually measured.
  4. Step 1: move the setting. The ratio m̂1/v̂1=−6/6=−1\hat m_1 / \sqrt{\hat v_1} = -6 / 6 = -1. So the step is the learning rate times that ratio: θ1=0−0.1×(−1)=0.1\theta_1 = 0 - 0.1 \times (-1) = 0.1, approximately. The first step moves by exactly the learning rate, which is what this ratio is designed to do when the slopes are steady.
  5. Step 2: find the new slope and update the averages. At θ1=0.1\theta_1 = 0.1 the slope is g2=2(0.1−3)=−5.8g_2 = 2(0.1 - 3) = -5.8. The gradient average is m2=0.9×(−0.6)+0.1×(−5.8)=−1.12m_2 = 0.9 \times (-0.6) + 0.1 \times (-5.8) = -1.12. The squared average is v2=0.999×0.036+0.001×33.64=0.069604v_2 = 0.999 \times 0.036 + 0.001 \times 33.64 = 0.069604.
  6. Step 2: correct the averages and move. Dividing by 1−0.92=0.191 - 0.9^{2} = 0.19 gives m̂2≈−5.8947\hat m_2 \approx -5.8947. Dividing by 1−0.9992≈0.0019991 - 0.999^{2} \approx 0.001999 gives v̂2≈34.8194\hat v_2 \approx 34.8194. The ratio is −5.8947/34.8194≈−0.9989-5.8947 / \sqrt{34.8194} \approx -0.9989, so θ2=0.1−0.1×(−0.9989)≈0.1999\theta_2 = 0.1 - 0.1 \times (-0.9989) \approx 0.1999. The second step is again close to the learning rate, even though the raw slope was 5.8.

Answer: After two steps the setting is θ2≈0.1999\theta_2 \approx 0.1999. Both steps are almost exactly the learning rate of 0.1, even though the raw slope was 6 at step 1 and 5.8 at step 2. Adam sets the step size from the ratio of the averaged slope to its typical size, not from the raw slope alone.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

Why is it called Adam?

The name comes from adaptive moment estimation. The first moment is the averaged slope and the second moment is the averaged squared slope, so the name describes the two running averages that Adam keeps.

Does Adam always beat plain gradient descent?

No. Adam often trains quickly with little tuning, but on some problems gradient descent with momentum on small batches reaches a better final result. Trying both is sensible when the model matters.

What is the difference between m and v?

mtm_t is the average of the slope itself, which carries the direction. vtv_t is the average of the squared slope, which carries the size. Adam uses both to decide how far each setting moves.

Do I need to change beta 1 and beta 2?

Usually not at first. The defaults 0.9 and 0.999 are the starting point in most libraries.

Sources

  1. Adam: A Method for Stochastic Optimization, Kingma and Ba (arXiv:1412.6980)
  2. Stochastic gradient descent, Wikipedia

| All AI & ML formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: ai-ml/adam-optimizer.md.