pub trait LossOptimizer<M: Model>: Sized {
    type Config: Sized;

    // Required methods
    fn new(vs: Vec<Var>, params: Self::Config, model: M) -> CResult<Self>;
    fn backward_step(&mut self, loss: &Tensor) -> CResult<ModelOutcome>;
    fn learning_rate(&self) -> f64;
    fn set_learning_rate(&mut self, lr: f64);
    fn into_inner(self) -> Vec<Var>;

    // Provided method
    fn from_slice(
        vars: &[&Var],
        config: Self::Config,
        model: M
    ) -> CResult<Self> { ... }
}
Expand description

trait for optimisers like LBFGS that need the ability to calculate the loss and its gradient

Required Associated Types§

source

type Config: Sized

type of the optimiser configuration

Required Methods§

source

fn new(vs: Vec<Var>, params: Self::Config, model: M) -> CResult<Self>

create a new optimiser from a Vec of variables, setup parameters and a model

source

fn backward_step(&mut self, loss: &Tensor) -> CResult<ModelOutcome>

take a step of the optimiser

source

fn learning_rate(&self) -> f64

get the current learning rate

source

fn set_learning_rate(&mut self, lr: f64)

set the learning rate

source

fn into_inner(self) -> Vec<Var>

get the a vec of the variables being optimised

Provided Methods§

source

fn from_slice(vars: &[&Var], config: Self::Config, model: M) -> CResult<Self>

create a new optimiser from a slice of variables, setup parameters and a model

Object Safety§

This trait is not object safe.

Implementors§