Skip to content
class

ReduceLROnPlateau

ReduceLROnPlateau

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

Target optimiser.
modeMode, default Mode::Min
Min to minimise the metric, Max to maximise.
factorfloat, default 0.1
Multiplicative lr reduction.
patienceint, default 10
Bad-epoch tolerance before reducing.
thresholdfloat, default 1e-4
Minimum improvement to count as progress (interpretation depends on threshold_mode).
threshold_modeThresholdMode, default ThresholdMode::Rel
Rel — improvement measured as a fraction of best_; Abs — improvement measured in raw units.
cooldownint, default 0
Steps to wait after each reduction before resuming bad-epoch counting.
min_lrfloat, default 0.0
Floor of the lr — reductions saturate here.
epsfloat, default 1e-8
Guard against reductions whose absolute lr change is below this.

Attributes

best_float
Best metric value observed so far.
num_bad_epochs_int
Consecutive non-improving epochs.
cooldown_counter_int
Remaining grace steps after the most recent reduction.
last_lr_float
lr applied at the last call to step.

Notes

The improvement test is implemented via is_better which branches on mode_ and threshold_mode_.

Constructors

1
ctor

ReduceLROnPlateau

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

Target optimiser.
modeMode, default Mode::Min
Whether to minimise or maximise the metric.
factorfloat, default 0.1
Multiplicative lr reduction.
patienceint, default 10
Bad-epoch tolerance.
thresholdfloat, default 1e-4
Improvement threshold.
threshold_modeThresholdMode, default ThresholdMode::Rel
Relative vs absolute interpretation of threshold.
cooldownint, default 0
Grace period after a reduction.
min_lrfloat, default 0.0
Floor of the lr.
epsfloat, default 1e-8
Minimum lr delta to actually apply a reduction.

Methods

4
fnconst

is_better

→bool
bool is_better(double metric)

Test whether metric improves over best_.

Parameters

metricfloat
Candidate metric value.

Returns

bool

True when metric beats best_ by at least threshold_, interpreted according to threshold_mode_.

fnconst

last_lr

→float
double last_lr()

Return the lr applied at the most recent step.

Returns

float

last_lr_.

fnconst

num_bad_epochs

→int
int num_bad_epochs()

Return the running count of consecutive non-improving epochs.

Returns

int

num_bad_epochs_.

fn

step

void step(double metric)

Evaluate metric, update counters, and reduce lr if needed.

Parameters

metricfloat
Latest value of the watched metric (e.g. validation loss).

Notes

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.