pub struct Sgd<M> {
    pub cfg: SgdConfig,
    /* private fields */
}
Expand description

Implementation of Stochastic Gradient Descent. Based on pytorch’s implementation

Nesterov Momentum is implemented as described in On the importance of initialization and momentum in deep learning.

Weight decay is implemented as described in Decoupled Weight Decay Regularization Both L2 weight_decay and decoupled weight_decay are available.

Example Usage

Constructing using default:

let mut opt: Sgd<Model> = Default::default();

Constructing using new:

let mut opt: Sgd<Model> = Sgd::new(SgdConfig {
    lr: 1e-3,
    momentum: Some(Momentum::Classic(0.5)),
    weight_decay: Some(WeightDecay::L2(0.01)),
});

See module level documentation at crate::optim for examples of how to actually use an optimizer.

Fields

cfg: SgdConfig

Hyperparameter configuration

Implementations

Constructs using hyperparameters from cfg

Trait Implementations

Formats the value using the given formatter. Read more
Retrieves the data associated with p if there is any. This can modify self, for instance if velocities are calculated based on the associated data! Read more
Updates all of module’s parameters using gradients. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.