pub struct ReduceLROnPlateau { /* private fields */ }Expand description
Reduce the learning rate when a monitored metric plateaus.
Unlike the other schedulers which step automatically, this scheduler requires you to report the metric value (e.g., validation loss) and it decides whether to reduce the LR.
§Arguments (builder pattern)
factor: Factor to multiply LR by when reducing (default: 0.1)patience: Number of steps with no improvement before reducing (default: 10)min_lr: Lower bound on the learning rate (default: 1e-6)threshold: Minimum improvement to qualify as improvement (default: 1e-4)
§Example
let mut sched = ReduceLROnPlateau::new(0.01);
// After each epoch:
let new_lr = sched.step_metric(val_loss);
optimizer.set_learning_rate(new_lr);Implementations§
Source§impl ReduceLROnPlateau
impl ReduceLROnPlateau
Sourcepub fn new(initial_lr: f64) -> ReduceLROnPlateau
pub fn new(initial_lr: f64) -> ReduceLROnPlateau
Create a new ReduceLROnPlateau with sensible defaults.
Default: factor=0.1, patience=10, min_lr=1e-6, threshold=1e-4, mode=min
Sourcepub fn factor(self, factor: f64) -> ReduceLROnPlateau
pub fn factor(self, factor: f64) -> ReduceLROnPlateau
Set the factor by which to reduce LR (default: 0.1).
Sourcepub fn patience(self, patience: u64) -> ReduceLROnPlateau
pub fn patience(self, patience: u64) -> ReduceLROnPlateau
Set patience (steps without improvement before reducing, default: 10).
Sourcepub fn min_lr(self, min_lr: f64) -> ReduceLROnPlateau
pub fn min_lr(self, min_lr: f64) -> ReduceLROnPlateau
Set the minimum learning rate (default: 1e-6).
Sourcepub fn threshold(self, threshold: f64) -> ReduceLROnPlateau
pub fn threshold(self, threshold: f64) -> ReduceLROnPlateau
Set the improvement threshold (default: 1e-4).
Sourcepub fn mode_max(self) -> ReduceLROnPlateau
pub fn mode_max(self) -> ReduceLROnPlateau
Set mode to maximize (higher metric = better). Default is minimize (lower metric = better).
Sourcepub fn step_metric(&mut self, metric: f64) -> f64
pub fn step_metric(&mut self, metric: f64) -> f64
Report a metric value and return the (possibly updated) learning rate.
Call this once per epoch/evaluation with the metric value (e.g., val loss).
Sourcepub fn best_metric(&self) -> f64
pub fn best_metric(&self) -> f64
Get the best metric value seen so far.
Auto Trait Implementations§
impl Freeze for ReduceLROnPlateau
impl RefUnwindSafe for ReduceLROnPlateau
impl Send for ReduceLROnPlateau
impl Sync for ReduceLROnPlateau
impl Unpin for ReduceLROnPlateau
impl UnwindSafe for ReduceLROnPlateau
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more