All problems

Simulating Early-Stopping Patience

hardPythonModel Validation

Training at Halewood Analytics runs in rounds called epochs. After each epoch the model is scored on a validation set it never learns from, and that score is a loss, so lower is better. Left to itself the run keeps going long after the loss has stopped falling, burning machine time and steadily making the model worse. So the run is watched, and once it has gone an agreed number of epochs without beating the lowest loss seen so far, it is cut off. That allowance is called the patience.

Task: Print the epoch the run is cut off at, or report that it was never cut off.

Input

The first line holds two integers separated by a single space: n, the number of epochs, then the patience. The second line holds n losses separated by single spaces, one per epoch, in epoch order.

Output

One line. Print the number of the epoch where the run is cut off, counting epochs from 1: that is the epoch at which the unbroken run of non-beating epochs reaches the patience. Epoch 1 sets the standard and is never counted against it. Beating means strictly lower than the lowest loss seen so far — matching it exactly does not count. Print no early stop if the patience is never used up.

Example:

Input:
5 2
0.9 0.8 0.85 0.86 0.87

Output:
4

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…