Parameter Update Step

Easy
~10 min
code completion

The Gradient Descent Update

At its core, gradient descent is a single rule applied repeatedly:

where:

  • is the current parameter vector (weights)
  • is the learning rate (step size)
  • is the gradient of the loss w.r.t. the parameters
  • Subtracting the gradient moves parameters in the direction that decreases the loss.

    Your task:

    Implement gradient_step(weights, gradient, learning_rate) that returns the updated weights after one gradient descent step.

    Example Tests

    Standard update reduces weights

    Input: {"weights":[1,2],"gradient":[0.5,-1],"learning_rate":0.1}

    Expected: [0.95,2.1]

    All-zero gradient: weights unchanged

    Input: {"weights":[5,5],"gradient":[0,0],"learning_rate":0.5}

    Expected: [5,5]

    Large learning rate scales gradient

    Input: {"weights":[0,0,0],"gradient":[1,2,3],"learning_rate":0.01}

    Expected: [-0.01,-0.02,-0.03]

    Sign in to solve this problem

    You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.