FunctionRacerProblemsRace

Keep Rolling

HardPyTorchPython

Minimize the sum of (w - target)² over the elements, starting from w = start, with torch.optim.SGD given the learning rate lr and the momentum mu. Take steps steps and return w.

Example 1

start [0.0]
target [1.0]
lr 0.1
mu 0.9
steps 2
returns [0.54]

The first step moves by 0.1 times the gradient, to 0.2. The second adds 0.9 of the old velocity to the new gradient and moves further, to 0.54.

Example 2

start [0.0]
target [1.0]
lr 0.1
mu 0.9
steps 1
returns [0.2]

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