pub struct SGDOptimizer { /* private fields */ }Expand description
Stochastic gradient descent optimizer with momentum, Nesterov, and weight decay support.
Implementations§
Source§impl SGDOptimizer
impl SGDOptimizer
Sourcepub fn register_parameter(&mut self, name: &str, initial_values: Vec<f64>)
pub fn register_parameter(&mut self, name: &str, initial_values: Vec<f64>)
Register a named parameter vector. The velocity buffer is initialised
to zeros with the same length as initial_values.
Sourcepub fn step(
&mut self,
gradients: &HashMap<String, Vec<f64>>,
) -> Result<(), String>
pub fn step( &mut self, gradients: &HashMap<String, Vec<f64>>, ) -> Result<(), String>
Execute one optimiser step.
gradients must contain exactly the same keys as the registered
parameters, and each gradient vector must match the corresponding
parameter length.
Sourcepub fn get_parameter(&self, name: &str) -> Option<&[f64]>
pub fn get_parameter(&self, name: &str) -> Option<&[f64]>
Return a slice of the current parameter values, if the name exists.
Sourcepub fn get_velocity(&self, name: &str) -> Option<&[f64]>
pub fn get_velocity(&self, name: &str) -> Option<&[f64]>
Return a slice of the velocity buffer, if the name exists.
Sourcepub fn set_learning_rate(&mut self, lr: f64)
pub fn set_learning_rate(&mut self, lr: f64)
Dynamically change the learning rate.
Sourcepub fn parameter_count(&self) -> usize
pub fn parameter_count(&self) -> usize
Total number of registered scalar parameter values.
Sourcepub fn step_count(&self) -> u64
pub fn step_count(&self) -> u64
How many optimiser steps have been performed.
Sourcepub fn zero_velocities(&mut self)
pub fn zero_velocities(&mut self)
Reset all velocity buffers to zero.
Sourcepub fn stats(&self) -> SGDOptimizerStats
pub fn stats(&self) -> SGDOptimizerStats
Return a snapshot of the optimizer statistics.
Trait Implementations§
Source§impl Clone for SGDOptimizer
impl Clone for SGDOptimizer
Source§fn clone(&self) -> SGDOptimizer
fn clone(&self) -> SGDOptimizer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SGDOptimizer
impl RefUnwindSafe for SGDOptimizer
impl Send for SGDOptimizer
impl Sync for SGDOptimizer
impl Unpin for SGDOptimizer
impl UnsafeUnpin for SGDOptimizer
impl UnwindSafe for SGDOptimizer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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