All problems
Reduce On Plateau Check
Problem
Simulate a ReduceLROnPlateau scheduler over a sequence of losses.
Start from best_loss and wait. For each loss: if loss < best_loss, set best_loss = loss and wait = 0; otherwise increment wait. Whenever wait > patience, multiply current_lr by factor (never below min_lr), set reduced = True, and reset wait = 0. Return [current_lr, best_loss, wait, reduced].
Hint
A drop happens only when wait becomes strictly greater than patience.
Test cases
case 1
in: [[1,0.9,0.8,0.85,0.86,0.87],0.5,2,0.001,0.1,1,0]
expected: [0.05,0.8,0,true]
case 2
in: [[1,0.99,0.98],0.5,5,0.001,0.1,1,0]
expected: [0.1,0.98,0,false]
case 3
in: [[5,4,3],0.5,1,0.001,0.1,5,0]
expected: [0.1,3,0,false]
case 4
in: [[2,2.1,2.2,2.3],0.5,1,0.01,0.1,2,0]
expected: [0.025,2,0,true]
Starter codePython
def reduce_on_plateau(losses, factor, patience, min_lr, current_lr, best_loss, wait):
# Returns [current_lr, best_loss, wait, reduced]
# Your code here
pass4 test cases · run your code against them in the editor