1. The Optimization Problem¶
Neural network training is formulated as empirical risk minimization:
Finite-sum structure: The objective decomposes over training samples.
Non-convexity: Due to nonlinear activation functions, the loss landscape is generally non-convex.
Gradient computation: Training requires computing , done efficiently via backpropagation.
2. Gradient Descent and Stochastic Gradient Descent¶
Gradient Descent (GD)¶
Each iteration requires computing gradients for all training samples.
Stochastic Gradient Descent (SGD)¶
When is large, computing the full gradient is expensive. Instead, sample an index uniformly and use the stochastic gradient :
Since , SGD uses an unbiased estimate of the full gradient.
Mini-batch SGD¶
In practice, we use mini-batches of size :
Epoch: One complete pass through the entire dataset.
Iterations per epoch: .
Random reshuffling: Before each epoch, the dataset is often shuffled and divided into consecutive mini-batches. Empirically, this converges faster than independent sampling.
3. SGD with Momentum¶
Heavy-ball Momentum¶
where is the momentum parameter (typically ).
accumulates information from previous gradients.
Momentum acts like a ball rolling downhill, keeping movement in directions that consistently decrease the loss.
Expanding the recursion: , so recent gradients receive larger weight.
Exponential Averaging Form¶
Sometimes written as:
Since , this is an exponentially weighted average of past gradients.
Nesterov Accelerated Gradient (NAG)¶
A variant that evaluates the gradient at a look-ahead point:
Uses gradient information from a look-ahead point.
Less commonly used in nonconvex optimization.
4. Gradient Normalization and Clipping¶
Why Normalize or Clip?¶
In deep networks, gradients can become very large (exploding gradients), causing unstable updates. A single large gradient can produce an excessively large step, slowing training or causing divergence.
Gradient Normalization¶
The update depends only on the direction of the gradient; step length is controlled by the learning rate.
Gradient Clipping¶
More commonly used than normalization:
If the gradient is small, the update is unchanged. If large, its magnitude is capped at (typically or 0.5).
Can be viewed as projecting the gradient onto a ball of radius .
Two hyperparameters: learning rate and clipping threshold .
5. Adaptive Optimizers¶
Different parameters may have gradients of very different magnitudes. Adaptive methods use a different effective step size for each coordinate based on historical gradients:
Smaller steps for coordinates with large historical gradients.
Larger steps for coordinates with small historical gradients.
AdaGrad¶
Accumulates squared gradients:
where denotes element-wise multiplication and operations are element-wise.
Each coordinate has its own adaptive step size.
Coordinates with large past gradients receive smaller future updates.
Works well for sparse features.
Drawback: The accumulated sum keeps growing, so the effective learning rate may become too small.
RMSProp¶
Improves AdaGrad by using an exponentially weighted average instead of a cumulative sum:
where (typically ) and for numerical stability.
The denominator does not grow monotonically.
Adapts the learning rate based on recent gradients.
Works well in practice for training neural networks.
Adam (Adaptive Moment Estimation)¶
Combines momentum and RMSProp-style scaling:
First moment estimate:
Second moment estimate:
Since , the estimates are biased toward zero in early iterations. Apply bias correction:
Typical defaults: , , .
The correction mainly affects the first few iterations and becomes negligible later.
6. Weight Decay and AdamW¶
L2 Regularization (Weight Decay)¶
To reduce overfitting, add a regularization term:
The gradient becomes , so the SGD update is:
This is often called weight decay as it encourages smaller parameter values and can improve generalization.
AdamW: Decoupled Weight Decay¶
For SGD, L2 regularization and weight decay are equivalent. However, for Adam they are not, because the adaptive scaling affects the regularization term. AdamW applies weight decay separately from the gradient update:
Weight decay is decoupled from the gradient update.
Works better with adaptive methods like Adam.
Widely used in modern deep learning.
7. Learning Rate Schedules¶
| Schedule | Formula |
|---|---|
| Constant | |
| Exponential decay | for some |
| Linear decay | where is total epochs |
| Cosine | |
| Reduce on plateau | Decrease when validation loss improvement stalls |
| Warmup | Start with small , increase over a few epochs to , then apply main schedule |
8. Practical Recommendations¶
Start simple: Adam/AdamW is often a good default choice.
Tune the learning rate first: it usually matters more than other hyperparameters.
Monitor both training and validation performance.
If training is unstable: try a smaller learning rate.
If progress is too slow: try a different optimizer or learning rate schedule.