Struct ScheduledOptimizer

Source
pub struct ScheduledOptimizer<O: Optimizer, S: LearningRateScheduler> { /* private fields */ }
Expand description

Wrapper that combines an optimizer with a learning rate scheduler

Implementations§

Source§

impl<O: Optimizer, S: LearningRateScheduler> ScheduledOptimizer<O, S>

Source

pub fn new(optimizer: O, scheduler: S, base_lr: f64) -> Self

Source

pub fn step(&mut self)

Step the scheduler (should be called at the end of each epoch)

Source

pub fn step_with_val_loss(&mut self, val_loss: f64)

Step with validation loss (for ReduceLROnPlateau)

Source

pub fn get_current_lr(&self) -> f64

Get the current learning rate

Source

pub fn get_current_epoch(&self) -> usize

Get the current epoch

Source

pub fn reset(&mut self)

Reset both optimizer and scheduler

Source

pub fn scheduler_name(&self) -> &'static str

Get the scheduler name for logging

Source§

impl<O: Optimizer> ScheduledOptimizer<O, ConstantLR>

Helper functions to create common optimizer-scheduler combinations

Source

pub fn constant(optimizer: O, lr: f64) -> Self

Source§

impl<O: Optimizer> ScheduledOptimizer<O, StepLR>

Source

pub fn step_lr(optimizer: O, lr: f64, step_size: usize, gamma: f64) -> Self

Source§

impl<O: Optimizer> ScheduledOptimizer<O, ExponentialLR>

Source

pub fn exponential(optimizer: O, lr: f64, gamma: f64) -> Self

Source§

impl<O: Optimizer> ScheduledOptimizer<O, CosineAnnealingLR>

Source

pub fn cosine_annealing( optimizer: O, lr: f64, t_max: usize, eta_min: f64, ) -> Self

Source§

impl<O: Optimizer> ScheduledOptimizer<O, PolynomialLR>

Source

pub fn polynomial( optimizer: O, lr: f64, total_iters: usize, power: f64, end_lr: f64, ) -> Self

Source§

impl<O: Optimizer> ScheduledOptimizer<O, CyclicalLR>

Source

pub fn cyclical( optimizer: O, base_lr: f64, max_lr: f64, step_size: usize, ) -> Self

Source

pub fn cyclical_triangular2( optimizer: O, base_lr: f64, max_lr: f64, step_size: usize, ) -> Self

Source

pub fn cyclical_exp_range( optimizer: O, base_lr: f64, max_lr: f64, step_size: usize, gamma: f64, ) -> Self

Source§

impl<O: Optimizer> ScheduledOptimizer<O, OneCycleLR>

Source

pub fn one_cycle(optimizer: O, max_lr: f64, total_steps: usize) -> Self

Trait Implementations§

Source§

impl<O: Optimizer, S: LearningRateScheduler> Optimizer for ScheduledOptimizer<O, S>

Source§

fn update( &mut self, param_id: &str, param: &mut Array2<f64>, gradient: &Array2<f64>, )

Source§

fn reset(&mut self)

Source§

fn set_learning_rate(&mut self, lr: f64)

Set the learning rate dynamically (for compatibility with schedulers)
Source§

fn get_learning_rate(&self) -> f64

Get the current learning rate

Auto Trait Implementations§

§

impl<O, S> Freeze for ScheduledOptimizer<O, S>
where O: Freeze, S: Freeze,

§

impl<O, S> RefUnwindSafe for ScheduledOptimizer<O, S>

§

impl<O, S> Send for ScheduledOptimizer<O, S>
where O: Send, S: Send,

§

impl<O, S> Sync for ScheduledOptimizer<O, S>
where O: Sync, S: Sync,

§

impl<O, S> Unpin for ScheduledOptimizer<O, S>
where O: Unpin, S: Unpin,

§

impl<O, S> UnwindSafe for ScheduledOptimizer<O, S>
where O: UnwindSafe, S: UnwindSafe,

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, 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.
Source§

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

Source§

fn vzip(self) -> V