Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-016

SGD Weight Update

Problem

Apply one plain stochastic gradient descent step: w_new = w - lr * grad.

The signature is sgd_update(w, grad, lr). w and grad are lists of the same length.

Hint

Move each parameter opposite to its gradient, scaled by the learning rate.

Test cases

case 1
in: [[1,2],[0.1,0.2],0.5]
expected: [0.95,1.9]
case 2
in: [[0],[-1],0.1]
expected: [0.1]
case 3
in: [[1,-1],[0,0],1]
expected: [1,-1]
case 4
in: [[5,5],[1,-1],2]
expected: [3,7]
Starter codePython
def sgd_update(w, grad, lr):
    # Your code here
    pass

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