v9.1.1
Menu

SGD Parameter Update

easyFREEOptimization & TrainingDeep LearningDeep Learning 1

Problem Statement

Perform a single Stochastic Gradient Descent update step.

Background

In SGD, parameters are updated using gradients and a learning rate α\alpha (alpha):

W=W−α⋅dWW = W - \alpha \cdot dW

This simple rule moves parameters in the direction that reduces the loss.

Your Task

Write a function sgd_update(weights, gradients, learning_rate) that performs a single SGD update on a list of weights.

Output Format

Return a list of updated weights. Round each value to 4 decimal places.

Example

Input
weights=[1.0], gradients=[0.5], learning_rate=0.1
Output
[0.95]
Reasoning
  • Inputs: weights holds the current parameter values WW (here a single weight, W=1.0W = 1.0); gradients holds dWdW, the slope of the loss with respect to each weight (here 0.50.5); learning_rate is the step size α=0.1\alpha = 0.1. The two lists line up position by position.
  • Step size: the gradient says the loss rises as WW grows, so the update moves WW the other way by α⋅dW=0.1×0.5=0.05\alpha \cdot dW = 0.1 \times 0.5 = 0.05.
  • Update: Wnew=1.0−0.05=0.95W_{\text{new}} = 1.0 - 0.05 = 0.95, rounded to 4 decimal places it stays 0.950.95, giving the output [0.95].
  • Output: a list the same length as the input, one updated value per weight, each depending only on its own gradient.
  • Notice that the sign of dWdW decides the direction: a negative gradient makes the weight grow. With W=0W = 0, dW=−1dW = -1 and α=0.01\alpha = 0.01 the new weight is 0−0.01×(−1)=0.010 - 0.01 \times (-1) = 0.01. A smaller α\alpha means a smaller, more cautious step.

Constraints

  • -1000 <= weights[i], gradients[i] <= 1000
  • 0 < learning_rate <= 1
  • List length: 1 to 100 elements

Learn this in

More from Deep Learning 1

solution.py

Test results

Sign in to run your code against the test cases.