ReduceLROnPlateau

Struct ReduceLROnPlateau 

Source
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

Source

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

Source

pub fn factor(self, factor: f64) -> ReduceLROnPlateau

Set the factor by which to reduce LR (default: 0.1).

Source

pub fn patience(self, patience: u64) -> ReduceLROnPlateau

Set patience (steps without improvement before reducing, default: 10).

Source

pub fn min_lr(self, min_lr: f64) -> ReduceLROnPlateau

Set the minimum learning rate (default: 1e-6).

Source

pub fn threshold(self, threshold: f64) -> ReduceLROnPlateau

Set the improvement threshold (default: 1e-4).

Source

pub fn mode_max(self) -> ReduceLROnPlateau

Set mode to maximize (higher metric = better). Default is minimize (lower metric = better).

Source

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).

Source

pub fn lr(&self) -> f64

Get the current learning rate.

Source

pub fn best_metric(&self) -> f64

Get the best metric value seen so far.

Source

pub fn bad_steps(&self) -> u64

Get number of steps without improvement.

Source

pub fn reset(&mut self)

Reset state.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V