FunctionRacerProblemsRace

One Step Downhill

MediumPyTorchPython

A line predicts w * x + b for every element of x. Its loss is the mean of the squared differences from y. Take one step of gradient descent: move w and b against their gradients, each by lr times its gradient. Return the new [w, b].

Example 1

x [1.0,2.0,3.0]
y [2.0,4.0,6.0]
w 0.0
b 0.0
lr 0.1
returns [1.8666667,0.8]

From 0 and 0 every prediction is too low, so both gradients are negative and the step moves w and b up.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More PyTorch problems