Skip to main content

LambdaLr

Struct LambdaLr 

Source
pub struct LambdaLr { /* private fields */ }
Expand description

Lambda learning-rate scheduler.

Computes lr = base_lr * lr_lambda(step_count) at each step, where lr_lambda is a user-provided closure mapping epoch to a multiplicative factor.

Implementations§

Source§

impl LambdaLr

Source

pub fn new(base_lr: f32, lr_lambda: Box<dyn Fn(usize) -> f32>) -> Self

Creates a lambda scheduler with the given base learning rate and lambda function. The lambda receives the current epoch (after increment) and returns a multiplicative factor applied to base_lr.

Source

pub fn base_lr(&self) -> f32

Returns the base learning rate.

Source

pub fn current_lr(&self) -> f32

Returns the current learning rate.

Source

pub fn step_count(&self) -> usize

Returns the current step count.

Source

pub fn epoch(&self) -> usize

Returns number of already-processed step calls.

Source

pub fn reset(&mut self)

Resets internal state.

Source

pub fn step<O: LearningRate>( &mut self, optimizer: &mut O, ) -> Result<f32, OptimError>

Advances scheduler by one epoch and returns resulting optimizer LR.

Trait Implementations§

Source§

impl LrScheduler for LambdaLr

Source§

fn step<O: LearningRate>( &mut self, optimizer: &mut O, ) -> Result<f32, OptimError>

Advances scheduler by one epoch and returns resulting optimizer LR.
Source§

fn epoch(&self) -> usize

Returns number of already-processed step calls.
Source§

fn reset(&mut self)

Resets scheduler internal 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

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.