pub struct Adam { /* private fields */ }Expand description
Adam optimizer.
Maintains per-parameter adaptive learning rates using first and second moment estimates of gradients.
Update rule:
m_t = beta1 * m_{t-1} + (1 - beta1) * grad
v_t = beta2 * v_{t-1} + (1 - beta2) * grad^2
m_hat = m_t / (1 - beta1^t)
v_hat = v_t / (1 - beta2^t)
param = param - lr * m_hat / (sqrt(v_hat) + eps)Implementations§
Source§impl Adam
impl Adam
Sourcepub fn new(params: Vec<Parameter>, lr: f32) -> Self
pub fn new(params: Vec<Parameter>, lr: f32) -> Self
Creates a new Adam optimizer with default hyperparameters.
Sourcepub fn with_betas(params: Vec<Parameter>, lr: f32, betas: (f32, f32)) -> Self
pub fn with_betas(params: Vec<Parameter>, lr: f32, betas: (f32, f32)) -> Self
Creates Adam with specified betas.
Sourcepub fn with_options(
params: Vec<Parameter>,
lr: f32,
betas: (f32, f32),
eps: f32,
weight_decay: f32,
amsgrad: bool,
) -> Self
pub fn with_options( params: Vec<Parameter>, lr: f32, betas: (f32, f32), eps: f32, weight_decay: f32, amsgrad: bool, ) -> Self
Creates Adam with all options.
Sourcepub fn weight_decay(self, weight_decay: f32) -> Self
pub fn weight_decay(self, weight_decay: f32) -> Self
Builder method to set weight decay.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Adam
impl !RefUnwindSafe for Adam
impl Send for Adam
impl Sync for Adam
impl Unpin for Adam
impl !UnwindSafe for Adam
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