Search Knowledge

© 2026 LIBREUNI PROJECT

Machine Learning / Deep Learning

Numerical Optimization

Optimization

Training models requires finding parameters θ\theta that minimize a cost function J(θ)J(\theta) by updating them iteratively.

Stochastic Gradient Descent (SGD)

SGD updates parameters using the gradient calculated from a single random instance (or a mini-batch) at each step:

θ←θ−η∇θJ(θ;x(i),y(i))\theta \leftarrow \theta - \eta \nabla_{\theta} J(\theta; x^{(i)}, y^{(i)})

While computationally efficient, SGD’s updates can oscillate, slowing convergence.

Momentum and Nesterov Accelerated Gradient

Momentum accelerates SGD by adding a fraction β\beta of the previous update vector mm, acting like a physical ball rolling down a hill:

m←βm+η∇θJ(θ)m \leftarrow \beta m + \eta \nabla_{\theta} J(\theta) θ←θ−m\theta \leftarrow \theta - m

NAG calculates the gradient ahead of the current position (J(θ−βm)J(\theta - \beta m)) to stabilize convergence.

Adaptive Learning Rates

Adaptive algorithms adjust the learning rate per parameter based on historical gradients:

  • RMSProp: Decays past squared gradients to focus on recent updates. s←βs+(1−β)(∇θJ(θ))2s \leftarrow \beta s + (1 - \beta) (\nabla_{\theta} J(\theta))^2 θ←θ−ηs+ϵ∇θJ(θ)\theta \leftarrow \theta - \frac{\eta}{\sqrt{s + \epsilon}} \nabla_{\theta} J(\theta)
  • Adam (Adaptive Moment Estimation): Tracks first (mean) and second (variance) moments of the gradients: m←β1m+(1−β1)∇θJ(θ)m \leftarrow \beta_1 m + (1 - \beta_1) \nabla_{\theta} J(\theta) s←β2s+(1−β2)(∇θJ(θ))2s \leftarrow \beta_2 s + (1 - \beta_2) (\nabla_{\theta} J(\theta))^2

Bias correction is applied: m^=m/(1−β1t)\hat{m} = m/(1-\beta_1^t) and s^=s/(1−β2t)\hat{s} = s/(1-\beta_2^t).

AdamW (Weight Decay)

AdamW improves on Adam by applying weight decay directly to the parameters rather than incorporating it into the gradient update step.

Example: Optimizing Parameters

The following example demonstrates parameter optimization using Adam in PyTorch:

python

Interactive Lab

Minimize a quadratic function using the Adam optimizer in PyTorch. Observe how w converges toward zero over 5 gradient update steps.

Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare

Exercise

Test your understanding of adaptive optimization updates:

Why is bias correction necessary in the Adam optimizer?

References & Further Reading

Previous Module Clustering Algorithms