pub struct Sgd {
pub learning_rate: f64,
pub momentum: f64,
pub weight_decay: f64,
pub nesterov: bool,
/* private fields */
}Expand description
Stochastic Gradient Descent with optional momentum, Nesterov lookahead, and L2 weight decay.
Update rule (with momentum): v ← momentum · v + lr · (grad + weight_decay · params) params ← params - v (vanilla momentum) params ← params - (momentum · v + lr · grad) (Nesterov)
Fields§
§learning_rate: f64Base learning rate.
momentum: f64Momentum coefficient (0 = vanilla SGD).
weight_decay: f64L2 weight-decay coefficient.
nesterov: boolUse Nesterov momentum instead of classical momentum.
Implementations§
Source§impl Sgd
impl Sgd
Sourcepub fn step(
&mut self,
params: &mut Vec<f64>,
grad: &[f64],
) -> OptimizeResult<()>
pub fn step( &mut self, params: &mut Vec<f64>, grad: &[f64], ) -> OptimizeResult<()>
Perform one SGD update step.
§Errors
Returns OptimizeError::InvalidInput if params and grad have
different lengths.
Sourcepub fn zero_velocity(&mut self, n: usize)
pub fn zero_velocity(&mut self, n: usize)
Reset velocity buffer to zeros (for new training run).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sgd
impl RefUnwindSafe for Sgd
impl Send for Sgd
impl Sync for Sgd
impl Unpin for Sgd
impl UnsafeUnpin for Sgd
impl UnwindSafe for Sgd
Blanket Implementations§
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
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.