Documentation

Hesper.Optimizer.SGD

Stochastic Gradient Descent (SGD) Optimizer #

Classical SGD optimizer with optional momentum and weight decay.

Variants #

Usage Example #

-- Create optimizer
let opt := SGDConfig.default.withLearningRate 0.01 |>.withMomentum 0.9

-- Optimization step
let (newParams, newState) := opt.step params grads state

SGD optimizer configuration

  • learningRate : Float

    Learning rate (step size)

  • momentum : Float

    Momentum coefficient (0 = no momentum, typical: 0.9)

  • weightDecay : Float

    Weight decay (L2 regularization coefficient)

  • nesterov : Bool

    Use Nesterov momentum

  • dampening : Float

    Dampening for momentum (typical: 0 for standard momentum)

Instances For
    Equations
    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Default SGD configuration (no momentum, lr=0.01)

        Equations
        Instances For

          Create SGD with specified learning rate

          Equations
          Instances For

            Create SGD with momentum

            Equations
            Instances For

              Create SGD with weight decay (L2 regularization)

              Equations
              Instances For

                Enable Nesterov momentum

                Equations
                Instances For

                  SGD optimizer state (momentum buffers)

                  • momentumBuffers : Array (Array Float)

                    Momentum buffers for each parameter

                  • step : Nat

                    Number of steps taken

                  Instances For
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Initialize SGD state for given parameter shapes

                      Equations
                      Instances For

                        Initialize SGD state from parameters

                        Equations
                        Instances For
                          def Hesper.Optimizer.SGD.updateParam (config : SGDConfig) (param grad momentumBuffer : Array Float) :

                          Update a single parameter with SGD

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            def Hesper.Optimizer.SGD.step (config : SGDConfig) (params grads : Array (Array Float)) (state : SGDState) :

                            Perform one optimization step for all parameters

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              Perform optimization step with proper indexing

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                Helper: Compute L2 norm of gradients (for monitoring)

                                Equations
                                Instances For

                                  Helper: Compute parameter L2 norm

                                  Equations
                                  Instances For