All problems
Online Update Step
Problem
Perform one SGD-with-momentum update: v_new = momentum * velocity + grad, then theta_new = theta - lr * v_new.
Return [theta_new, v_new]. The velocity carries over across updates.
Hint
Momentum smoothly accumulates recent gradients into the step direction.
Test cases
case 1
in: [1,0.5,0.1,0.9,0]
expected: [0.95,0.5]
case 2
in: [0,1,0.01,0,0]
expected: [-0.01,1]
case 3
in: [1,0,0.1,0.9,2]
expected: [0.82,1.8]
case 4
in: [2,1,0.5,0.5,1]
expected: [1.25,1.5]
Starter codePython
def online_update_step(theta, grad, lr, momentum, velocity):
# Your code here
pass4 test cases · run your code against them in the editor