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: f32
Learning rate
momentum: f32
Momentum strength. Default to Sgd::DEFAULT_MOMENTUM
if not specified.
weight_decay: f32
Weight decay (L2 penalty). Default to Sgd::DEFAULT_WEIGHT_DECAY
if not specified.
dampening: f32
Dampening for momentum. Default to Sgd::DEFAULT_DAMPENING
if not specified.
nesterov: bool
Enables nesterov momentum. Default to Sgd::DEFAULT_NESTEROV
if not specified.
state: State
Inner state
Implementations§
Source§impl Sgd
impl Sgd
Sourcepub const DEFAULT_MOMENTUM: f32 = 0f32
pub const DEFAULT_MOMENTUM: f32 = 0f32
Default momentum if not specified.
Sourcepub const DEFAULT_WEIGHT_DECAY: f32 = 0f32
pub const DEFAULT_WEIGHT_DECAY: f32 = 0f32
Default weight decay if not specified.
Sourcepub const DEFAULT_DAMPENING: f32 = 0f32
pub const DEFAULT_DAMPENING: f32 = 0f32
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 &mut Sgd
impl Updatable for &mut Sgd
Source§fn updatable_states(&self) -> impl IntoIterator<Item = &Array>
fn updatable_states(&self) -> impl IntoIterator<Item = &Array>
Returns a list of references to the updatable states. Read more
Source§fn updatable_states_mut(&mut self) -> impl IntoIterator<Item = &mut Array>
fn updatable_states_mut(&mut self) -> impl IntoIterator<Item = &mut Array>
Returns a list of mutable references to the updatable states. Read more
Source§impl Updatable for Sgd
impl Updatable for Sgd
Source§fn updatable_states(&self) -> impl IntoIterator<Item = &Array>
fn updatable_states(&self) -> impl IntoIterator<Item = &Array>
Returns a list of references to the updatable states. Read more
Source§fn updatable_states_mut(&mut self) -> impl IntoIterator<Item = &mut Array>
fn updatable_states_mut(&mut self) -> impl IntoIterator<Item = &mut Array>
Returns a list of mutable references to the updatable states. Read more
Auto Trait Implementations§
impl Freeze for Sgd
impl RefUnwindSafe for Sgd
impl !Send for Sgd
impl !Sync for Sgd
impl Unpin 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> 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
.