Class AdagradGpuConfig
- Namespace
- AiDotNet.Interfaces
- Assembly
- AiDotNet.dll
Configuration for Adagrad optimizer on GPU.
public class AdagradGpuConfig : IGpuOptimizerConfig
- Inheritance
-
AdagradGpuConfig
- Implements
- Inherited Members
Remarks
Adagrad accumulates squared gradients over all time, providing automatic learning rate adaptation. Parameters with frequently occurring features get smaller learning rates.
For Beginners: Adagrad is good for sparse data because it gives larger updates to infrequent parameters and smaller updates to frequent ones. However, the accumulated squared gradients can make learning rate too small eventually.
Constructors
AdagradGpuConfig(float, float, float, int)
Creates a new Adagrad GPU configuration.
public AdagradGpuConfig(float learningRate, float epsilon = 1E-08, float weightDecay = 0, int step = 0)
Parameters
learningRatefloatLearning rate for parameter updates.
epsilonfloatNumerical stability constant (default 1e-8).
weightDecayfloatWeight decay coefficient (default 0).
stepintCurrent optimization step.
Properties
Epsilon
Gets the small constant for numerical stability (typically 1e-8).
public float Epsilon { get; init; }
Property Value
LearningRate
Gets the learning rate for parameter updates.
public float LearningRate { get; init; }
Property Value
OptimizerType
Gets the type of optimizer (SGD, Adam, AdamW, etc.).
public GpuOptimizerType OptimizerType { get; }
Property Value
Step
Gets the current optimization step (used for bias correction in Adam-family optimizers).
public int Step { get; init; }
Property Value
WeightDecay
Gets the weight decay (L2 regularization) coefficient.
public float WeightDecay { get; init; }
Property Value
Methods
ApplyUpdate(IDirectGpuBackend, IGpuBuffer, IGpuBuffer, GpuOptimizerState, int)
Applies the optimizer update to the given parameter buffer using its gradient.
public void ApplyUpdate(IDirectGpuBackend backend, IGpuBuffer param, IGpuBuffer gradient, GpuOptimizerState state, int size)
Parameters
backendIDirectGpuBackendThe GPU backend to execute the update.
paramIGpuBufferBuffer containing the parameters to update (modified in-place).
gradientIGpuBufferBuffer containing the gradients.
stateGpuOptimizerStateOptimizer state buffers (momentum, squared gradients, etc.).
sizeintNumber of parameters to update.
Remarks
For Beginners: This method applies the optimizer's update rule directly on the GPU. Each optimizer type (SGD, Adam, etc.) implements its own update logic using GPU kernels. The state parameter contains any auxiliary buffers needed (like velocity for SGD with momentum, or m/v buffers for Adam).
Design Note: Following the Open/Closed Principle, each optimizer config knows how to apply its own update, so adding new optimizers doesn't require modifying layer code.