Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-026

Early Stopping Patience Check

Problem

Scan a list of validation losses with early stopping logic.

Start with best = losses[0] and wait = 0. For each later loss, if loss < best - min_delta treat it as an improvement and reset wait to 0; otherwise increment wait. Stop at the first non-improvement that makes wait >= patience. Return [stop, best, wait], where stop is a boolean; an empty list returns [False, 0.0, 0].

Hint

An improvement must beat the best by strictly more than min_delta.

Test cases

case 1
in: [[1,0.9,0.905,0.91],2,0]
expected: [true,0.9,2]
case 2
in: [[1,0.8,0.7,0.6],3,0]
expected: [false,0.6,0]
case 3
in: [[1,1.1],1,0.05]
expected: [true,1,1]
case 4
in: [[],3,0]
expected: [false,0,0]
case 5
in: [[2,1.97],0,0.01]
expected: [false,1.97,0]
Starter codePython
def early_stopping_patience(losses, patience, min_delta):
    # Returns [stop, best, wait]
    # Your code here
    pass

5 test cases · run your code against them in the editor