All problems

Picking the Early-Stopping Checkpoint

easyPythonGradient Descent

Kestrel Freight keeps a set of deliveries out of training entirely and scores the model against them after every epoch — an epoch being one full pass over the training data. That held-out score is the validation loss, and it is the only honest signal the team has: the training loss falls whatever happens, while the validation loss falls for a while before it starts climbing, as the model begins memorising the deliveries it was shown. The trainer saves a copy of the model at the end of every epoch, so the release is not the last copy but the best one. If two epochs tie on the best score, the depot ships the earlier one, since it took less compute to reach.

Task: Print which saved epoch should be released, and its score.

Input

The first line holds one integer n, the number of epochs, where 1 <= n <= 1000. The second line holds n numbers separated by single spaces: the validation loss after each epoch, in epoch order.

Output

Two lines. First the word epoch, a single space, and the number of the epoch to release, counting the first epoch as 1 and printed as a plain whole number with no decimal point. Then the word loss, a single space, and that epoch's validation loss rounded to 4 decimal places. Lower loss is better; on a tie, print the earlier epoch.

Example:

Input:
5
0.9 0.5 0.3 0.35 0.4

Output:
epoch 3
loss 0.3000

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…