Implement the Gradient Descent Update

Easy
~10 min
code completion

Gradient Descent Parameter Update

Gradient descent is the core optimization algorithm in machine learning. In each step, we move parameters in the direction that reduces the loss.

The update rule for a single parameter is:

where:

  • is the learning rate (step size)
  • is the gradient of the loss with respect to
  • Your task:

    Implement gradient_step that applies one gradient descent update to an array of parameters.

    Watch out for:

  • The sign: we *subtract* the gradient (going downhill)
  • Modifying the original array vs. returning a new one
  • Example Tests

    Correct update with lr=0.1

    Input: {"params":[2,-1],"gradients":[4,-2],"learning_rate":0.1}

    Expected: [1.6,-0.8]

    Zero gradients leave params unchanged

    Input: {"params":[5,3],"gradients":[0,0],"learning_rate":0.5}

    Expected: [5,3]

    Gradient sign error detection

    Input: {"params":[1],"gradients":[1],"learning_rate":0.1}

    Expected: [0.9]

    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.