All problems
AMSGrad Update
Problem
Perform one AMSGrad update on a scalar parameter.
Update m and v as in Adam, then set v_max_new = max(v_max, v). Bias-correct with m_hat = m / (1 - beta1^t) and v_hat = v_max_new / (1 - beta2^t), and update x_new = x - lr * m_hat / (sqrt(v_hat) + eps). Return [x_new, m_new, v_new, v_max_new].
Hint
The denominator always uses the running maximum of v, never letting it decrease.
Test cases
case 1
in: [1,0,0,0,0.5,1,0.1,0.9,0.999,1e-8]
expected: [0.900000002,0.04999999999999999,0.0002500000000000002,0.0002500000000000002]
case 2
in: [1,0.1,0.01,0.02,0.5,5,0.01,0.9,0.999,1e-8]
expected: [0.998292348547027,0.14,0.01024,0.02]
case 3
in: [-2,-0.3,0.4,1,1.2,10,0.05,0.8,0.99,1e-8]
expected: [-2,-5.551115123125783e-17,0.41040000000000004,1]
Starter codePython
def amsgrad_update(x, m, v, v_max, g, t, lr, beta1, beta2, eps):
# Returns [x_new, m_new, v_new, v_max_new]
# Your code here
pass3 test cases · run your code against them in the editor