Repeating the Update
One move is rarely enough, so Kestrel Freight's trainer repeats it. The rig is the same: the penalty for a setting is the square of its distance from the ideal setting, the dial moves downhill from wherever it currently stands, and the learning rate fixes how far one move travels per unit of steepness. What changes is that the run is now a fixed number of moves long, and each move starts from where the last one finished — including the steepness, which is read afresh at the new setting every time.
Task: Run the given number of gradient-descent steps and print the setting the run finishes on.
Input
The first line holds three numbers separated by single spaces: the starting setting, the ideal setting, and the learning rate. The second line holds one whole number, the number of steps to run, which may be 0.
Output
One line: the word w_final, a single space, and the setting after all the steps have been run, rounded to 4 decimal places. Print nothing for the settings in between.
Example:
Input:
0 4 0.1
2
Output:
w_final 1.4400
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in