pub struct SGD { /* private fields */ }Expand description
Stochastic Gradient Descent optimizer with momentum.
Update rule:
v_t = momentum * v_{t-1} + grad
param = param - lr * v_tWith Nesterov momentum:
v_t = momentum * v_{t-1} + grad
param = param - lr * (momentum * v_t + grad)Implementations§
Source§impl SGD
impl SGD
Sourcepub fn new(params: Vec<&mut Tensor>, lr: f32) -> Self
pub fn new(params: Vec<&mut Tensor>, lr: f32) -> Self
Create a new SGD optimizer.
§Arguments
params- Mutable references to parameter tensorslr- Learning rate
Sourcepub fn with_momentum(params: Vec<&mut Tensor>, lr: f32, momentum: f32) -> Self
pub fn with_momentum(params: Vec<&mut Tensor>, lr: f32, momentum: f32) -> Self
Create SGD with momentum.
Sourcepub fn weight_decay(self, wd: f32) -> Self
pub fn weight_decay(self, wd: f32) -> Self
Set weight decay (L2 regularization).
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> 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