Adam Optimizer
Follow first and second moment estimates, then correct their initial bias. This is a scalar teaching implementation with epsilon outside the square root.
beta, gradient = 0.9, 2.0
m = (1-beta)*gradient
print(m, m/(1-beta))From arithmetic to an experiment
Follow first and second moment estimates, then correct their initial bias. This is a scalar teaching implementation with epsilon outside the square root. The trace reads the local variables of your function as it executes. Change one input or parameter, predict the result, then run the checks again. A small deterministic example makes arithmetic mistakes easier to locate than a long training run. State the shape and meaning of the returned value before coding. Keep preprocessing, evaluation and model updates in their proper order, and examine the boundary case in each check. The companion lab lets you replay intermediate values while the same algorithm runs.
Your task
adam_step(w, gradient, m, v, t, lr, beta1, beta2, epsilon) returns (new_w, new_m, new_v). t starts at 1 and epsilon > 0. Apply bias correction to both moments.
The explanation opens here once every check passes.