Run Adagrad on a quadratic with uneven curvature
Why it matters Adagrad is still used for sparse embedding tables in recommendation models.
Adagrad gives each parameter its own learning rate, shrinking it where gradients have been large.
Write adagrad(w0, a, lr, steps, eps=1e-8). The loss is f(w) = 0.5 * sum(a * w^2), so the gradient is a * w. Keep G = 0 per parameter. Each step: g = a * w, G = G + g^2, w = w - lr * g / (sqrt(G) + eps). Return (w, G) as float arrays after the given number of steps.
def adagrad(w0, a, lr, steps, eps=1e-8)Example
adagrad([1, 1], [1, 100], 0.5, 1) gives w [0.5, 0.5] and G [1, 10000]: both coordinates move the same amount on the first step despite 100x different curvature.
Understand the idea
Adagrad keeps a tally of how big each parameter's gradients have been so far. Parameters that get big gradients all the time get smaller steps; rarely updated ones keep larger steps. Like a teacher who gives more attention to a quiet student than to one who answers every question.
Tiny example: two coordinates with curvature 1 and 100, both at w = 1, lr = 0.5. Gradients 1 and 100. G = 1 and 10000, sqrt = 1 and 100. Steps 0.5 * 1/1 and 0.5 * 100/100: both 0.5. The scaling cancels the curvature difference.
Rules: G += g^2, w -= lr * g / (sqrt(G) + eps).
It suits sparse features such as word or item embeddings, but the ever-growing G makes it stall on long dense training runs, which motivated RMSProp, Adadelta and Adam.