pub struct Sgd {
pub lr: f32,
pub momentum: f32,
pub weight_decay: f32,
pub dampening: f32,
pub nesterov: bool,
pub state: State,
}Expand description
Stochastic gradient descent optimizer.
Fields§
§lr: f32Learning rate
momentum: f32Momentum strength. Default to Sgd::DEFAULT_MOMENTUM if not specified.
weight_decay: f32Weight decay (L2 penalty). Default to Sgd::DEFAULT_WEIGHT_DECAY if not specified.
dampening: f32Dampening for momentum. Default to Sgd::DEFAULT_DAMPENING if not specified.
nesterov: boolEnables nesterov momentum. Default to Sgd::DEFAULT_NESTEROV if not specified.
state: StateInner state
Implementations§
Source§impl Sgd
impl Sgd
Sourcepub const DEFAULT_MOMENTUM: f32 = 0.0
pub const DEFAULT_MOMENTUM: f32 = 0.0
Default momentum if not specified.
Sourcepub const DEFAULT_WEIGHT_DECAY: f32 = 0.0
pub const DEFAULT_WEIGHT_DECAY: f32 = 0.0
Default weight decay if not specified.
Sourcepub const DEFAULT_DAMPENING: f32 = 0.0
pub const DEFAULT_DAMPENING: f32 = 0.0
Default dampening if not specified.
Sourcepub const DEFAULT_NESTEROV: bool = false
pub const DEFAULT_NESTEROV: bool = false
Default nesterov if not specified.
Trait Implementations§
Source§impl Buildable for Sgd
impl Buildable for Sgd
Source§type Builder = SgdBuilder
type Builder = SgdBuilder
The builder type for this buildable type
Source§impl Builder<Sgd> for SgdBuilder
impl Builder<Sgd> for SgdBuilder
Source§impl Optimizer for Sgd
impl Optimizer for Sgd
Source§fn update_single(
&mut self,
key: &Rc<str>,
gradient: &Array,
parameter: &mut Array,
) -> Result<()>
fn update_single( &mut self, key: &Rc<str>, gradient: &Array, parameter: &mut Array, ) -> Result<()>
Apply SGD to a single parameter. Returns the updated parameter and the updated state.
Source§fn update<M>(
&mut self,
model: &mut M,
gradients: impl Borrow<FlattenedModuleParam>,
) -> Result<()>where
M: ModuleParameters,
fn update<M>(
&mut self,
model: &mut M,
gradients: impl Borrow<FlattenedModuleParam>,
) -> Result<()>where
M: ModuleParameters,
Apply the gradients to the parameters of the model and update the model with the new
parameters.
Source§impl Updatable for Sgd
impl Updatable for Sgd
Source§fn state_projection(
&mut self,
) -> Result<StateProjection<'_>, StateProjectionError>
fn state_projection( &mut self, ) -> Result<StateProjection<'_>, StateProjectionError>
Declare all required and optional state slots.
Source§impl Updatable for &mut Sgd
impl Updatable for &mut Sgd
Source§fn state_projection(
&mut self,
) -> Result<StateProjection<'_>, StateProjectionError>
fn state_projection( &mut self, ) -> Result<StateProjection<'_>, StateProjectionError>
Declare all required and optional state slots.
Auto Trait Implementations§
impl !Send for Sgd
impl !Sync for Sgd
impl Freeze for Sgd
impl RefUnwindSafe 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
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> 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> IntoOption<T> for T
impl<T> IntoOption<T> for T
Source§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
Convert into an
Option.