All problems

When the Learning Rate Blows Up

hardPythonGradient Descent

Before Kestrel Freight commits a learning rate to a real run, it tries the rate on a bowl-shaped test penalty: the penalty at a setting is a fixed multiplier times the square of that setting, so the bottom of the bowl sits at zero and steeper bowls have bigger multipliers. A sensible rate walks the dial down towards the bottom. Too large a rate steps clean over the bottom and lands further up the other side, then does it again, worse each time. The rig runs a fixed number of steps, after which it asks one question: is the dial further from the bottom than it started?

Task: Run the given number of gradient-descent steps on the test penalty and report where the dial ended, or that the rate blew up.

Input

The first line holds three numbers separated by single spaces: the penalty's multiplier, the learning rate, and the starting setting. The second line holds one whole number, the count of steps to run.

Output

One line. If the finishing setting is further from zero than the starting setting was — comparing distances from zero, so signs are ignored — print exactly diverged. Otherwise print the word w_final, a single space, and the finishing setting rounded to 4 decimal places. The comparison is made once, after the last step; a run that lands exactly as far out as it started has not diverged.

Example:

Input:
1 0.1 10
5

Output:
w_final 3.2768

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

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…