One AdaGrad Update: The Ever-Growing Cache

OptimizationEasy+10 XP+10

One AdaGrad Update: The Ever-Growing Cache

AdaGrad gives every parameter its own learning rate by accumulating the squares of all the gradients it has ever seen:

1cache = cache + grad²
2param = param - learning_rate * grad / (sqrt(cache) + epsilon)

Task: write adagrad_step(params, grads, cache, learning_rate, epsilon) returning [new_params, new_cache], all values rounded to 4 decimal places.

  • Update the cache first, then use the new cache in the parameter update.
  • epsilon sits outside the square root.

The accumulator only ever grows, so the effective learning rate only ever shrinks — and on a long run it eventually reaches zero and training stops making progress. That single flaw is what RMSProp exists to fix, by decaying the accumulator instead of letting it pile up forever.

Examples

params = [1.0, 2.0]
grads = [0.5, -0.5]
cache = [0.0, 0.0]
learning_rate = 0.1
epsilon = 1e-08
returns [[0.9, 2.1], [0.25, 0.25]]
params = [0.0]
grads = [2.0]
cache = [4.0]
learning_rate = 0.1
epsilon = 1e-08
returns [[-0.0707], [8.0]]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run