Documentation

Hesper.Optimizer.Adam

Adam Optimizer (Adaptive Moment Estimation) #

Adam optimizer with adaptive learning rates per parameter. Combines ideas from RMSprop and momentum.

Algorithm #

m_t = β₁ * m_{t-1} + (1 - β₁) * g_t          # First moment (momentum)
v_t = β₂ * v_{t-1} + (1 - β₂) * g_t²         # Second moment (uncentered variance)
m̂_t = m_t / (1 - β₁^t)                        # Bias correction
v̂_t = v_t / (1 - β₂^t)                        # Bias correction
θ_t = θ_{t-1} - α * m̂_t / (√v̂_t + ε)       # Parameter update

Typical Hyperparameters #

Usage Example #

-- Create optimizer
let opt := AdamConfig.default.withLearningRate 0.001

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

References #

Adam optimizer configuration

  • learningRate : Float

    Learning rate (typical: 0.001)

  • beta1 : Float

    Exponential decay rate for first moment estimates (typical: 0.9)

  • beta2 : Float

    Exponential decay rate for second moment estimates (typical: 0.999)

  • epsilon : Float

    Small constant for numerical stability (typical: 1e-8)

  • weightDecay : Float

    Weight decay (L2 regularization)

  • amsgrad : Bool

    Use AMSGrad variant (maintains max of v_t)

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

        Default Adam configuration (recommended hyperparameters)

        Equations
        Instances For

          Create Adam with specified learning rate

          Equations
          Instances For

            Create Adam with weight decay (AdamW variant)

            Equations
            Instances For

              Create Adam with custom beta parameters

              Equations
              Instances For

                Enable AMSGrad variant

                Equations
                Instances For

                  Adam optimizer state (moment estimates)

                  • First moment estimates (momentum) for each parameter

                  • Second moment estimates (uncentered variance) for each parameter

                  • vMax : Array (Array Float)

                    Maximum of v_t (for AMSGrad)

                  • step : Nat

                    Number of steps taken

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

                      Initialize Adam state for given parameter shapes

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

                        Initialize Adam state from parameters

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

                          Update a single parameter with Adam

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

                            Perform one optimization step for all parameters

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

                              Helper: Compute effective learning rate at step t

                              Equations
                              Instances For

                                Helper: Compute L2 norm of first moments (momentum magnitude)

                                Equations
                                Instances For

                                  Helper: Compute L2 norm of second moments (variance magnitude)

                                  Equations
                                  Instances For

                                    Helper: Get statistics for monitoring

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