Skip to content
DeepForgeby svx
All problems
MediumCalculusca-361

Momentum Velocity and Parameter Update

Problem

One momentum update computes v_new = beta * v - lr * grad and w_new = w + v_new.

Given w, grad, the previous velocity v, the learning rate lr, and beta, return [w_new, v_new].

Hint

Update the velocity from the previous velocity, then move the parameters.

Test cases

case 1
in: [[1,1],[0.1,-0.2],[0,0],0.5,0.9]
expected: [[0.95,1.1],[-0.05,0.1]]
case 2
in: [[0,0],[1,1],[1,1],0.1,0.5]
expected: [[0.4,0.4],[0.4,0.4]]
case 3
in: [[2],[4],[1],0.25,0.8]
expected: [[1.8],[-0.19999999999999996]]
Starter codePython
def momentum_update_step(w, grad, v, lr, beta):
    # Your code here
    pass

3 test cases · run your code against them in the editor