Metric-driven plateau detector — reduce lr when progress stalls.
Not a LRScheduler subclass: step takes a scalar
metric instead of an epoch index. Tracks the best metric seen so
far and counts consecutive epochs that fail to improve beyond a
threshold. Once patience bad epochs accumulate the optimiser's
lr is multiplied by factor (subject to min_lr), after which
a cooldown-step grace period suppresses further reductions to
let the model settle into the new regime.
See Also
CosineAnnealingLR — deterministic alternative when the loss
curve is too noisy to drive a plateau heuristic.
Parameters
optOptimizermodeMode, default Mode::MinMin to minimise the metric, Max to maximise.factorfloat, default 0.1patienceint, default 10thresholdfloat, default 1e-4threshold_mode).threshold_modeThresholdMode, default ThresholdMode::RelRel — improvement measured as a fraction of best_; Abs — improvement measured in raw units.cooldownint, default 0min_lrfloat, default 0.0epsfloat, default 1e-8Attributes
best_floatnum_bad_epochs_intcooldown_counter_intlast_lr_floatstep.Notes
The improvement test is implemented via is_better which
branches on mode_ and threshold_mode_.
Constructors
1ReduceLROnPlateau
void ReduceLROnPlateau(Optimizer & opt, Mode mode, double factor, int patience, double threshold, ThresholdMode threshold_mode, int cooldown, double min_lr, double eps)Construct the plateau detector.
Parameters
optOptimizermodeMode, default Mode::Minfactorfloat, default 0.1patienceint, default 10thresholdfloat, default 1e-4threshold_modeThresholdMode, default ThresholdMode::Relthreshold.cooldownint, default 0min_lrfloat, default 0.0epsfloat, default 1e-8Methods
4Test whether metric improves over best_.
Parameters
metricfloatReturns
boolTrue when metric beats best_ by at least threshold_, interpreted according to threshold_mode_.
Return the lr applied at the most recent step.
Returns
floatlast_lr_.
Return the running count of consecutive non-improving epochs.
Returns
intnum_bad_epochs_.
Evaluate metric, update counters, and reduce lr if needed.
Parameters
metricfloatNotes
No-op while the cooldown counter is positive. Once patience
bad epochs accumulate, the optimiser's lr is multiplied by
factor_ (clamped at min_lr_) and the cooldown begins.