Trait Optimizer

Source
pub trait Optimizer<F: Float + Debug + ScalarOperand> {
    // Required methods
    fn update(
        &mut self,
        params: &mut [Array<F, IxDyn>],
        grads: &[Array<F, IxDyn>],
    ) -> Result<()>;
    fn get_learning_rate(&self) -> F;
    fn set_learning_rate(&mut self, lr: F);

    // Provided methods
    fn step_model(&mut self, model: &mut dyn ParamLayer<F>) -> Result<()> { ... }
    fn reset(&mut self) { ... }
    fn name(&self) -> &'static str { ... }
}
Expand description

Trait for neural network optimizers

Required Methods§

Source

fn update( &mut self, params: &mut [Array<F, IxDyn>], grads: &[Array<F, IxDyn>], ) -> Result<()>

Update parameters based on gradients

Source

fn get_learning_rate(&self) -> F

Get the current learning rate

Source

fn set_learning_rate(&mut self, lr: F)

Set the learning rate

Provided Methods§

Source

fn step_model(&mut self, model: &mut dyn ParamLayer<F>) -> Result<()>

Update model parameters using the optimizer (non-generic version for trait objects)

Source

fn reset(&mut self)

Reset the optimizer’s internal state

Source

fn name(&self) -> &'static str

Get the optimizer’s name

Trait Implementations§

Source§

impl<F: Float + Debug + ScalarOperand> OptimizerStep<F> for dyn Optimizer<F> + Send + Sync

Implementation for trait objects

Source§

fn step<L: ParamLayer<F> + ?Sized>(&mut self, model: &mut L) -> Result<()>

Update model parameters using the optimizer

Implementors§