Class GradientDescentMomentumOptimizer
- Namespace
- NeuralNetworks.Optimizers
- Assembly
- NeuralNetworks.dll
Implements the classic "Stochastic" Gradient Descent (SGD) optimizer with momentum for neural network training. Updates parameters by applying momentum to the previous update and subtracting the scaled gradient using a specified learning rate.
public class GradientDescentMomentumOptimizer : Optimizer
- Inheritance
-
GradientDescentMomentumOptimizer
- Inherited Members
Remarks
The momentum term helps accelerate gradients in the relevant direction and dampens oscillations.
Constructors
GradientDescentMomentumOptimizer(LearningRate, float)
Implements the classic "Stochastic" Gradient Descent (SGD) optimizer with momentum for neural network training. Updates parameters by applying momentum to the previous update and subtracting the scaled gradient using a specified learning rate.
public GradientDescentMomentumOptimizer(LearningRate learningRate, float momentum)
Parameters
learningRateLearningRatemomentumfloat
Remarks
The momentum term helps accelerate gradients in the relevant direction and dampens oscillations.
Methods
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
Update(object, Span<float>, ReadOnlySpan<float>)
Updates the parameter values in-place using the provided gradients and the optimizer's momentum and learning rate settings.
protected override void Update(object paramsKey, Span<float> paramsToUpdate, ReadOnlySpan<float> paramGradients)
Parameters
paramsKeyobjectThe key that uniquely identifies the parameter set to update. Used to maintain optimizer state for each parameter group.
paramsToUpdateSpan<float>A span containing the parameter values to be updated. The values are modified in-place based on the computed updates.
paramGradientsReadOnlySpan<float>A read-only span containing the gradients corresponding to each parameter in
paramsToUpdate. Must have the same length asparamsToUpdate.
Remarks
This method applies a momentum-based update to each parameter. The optimizer maintains a
separate velocity vector for each parameter key, which is updated and used to compute the parameter adjustments.
The method modifies the contents of paramsToUpdate directly.