Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-003

Momentum Optimizer

Problem

Minimize f(x) = x^2 using gradient descent with momentum.

v starts at 0. For n_iters iterations: grad = 2 * x v = momentum * v - learning_rate * grad x = x + v

Return the final value of x.

Hint

Velocity is a running average of past gradients. x += v, not x -= lr*grad.

Test cases

case 1
in: [10,0.01,0.9,2000]
expected: 0
case 2
in: [5,0.1,0.5,50]
expected: 0
case 3
in: [0,0.1,0.9,100]
expected: 0
Starter codePython
def momentum_gradient_descent(start, learning_rate, momentum, n_iters):
    # Minimize f(x) = x ** 2
    # Your code here
    pass

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