Answer:
Explanation with Numerical Example:
First, let's understand the concepts of sharp minima and flat minima:
-
Sharp Minimum: A point in the parameter space where the loss function has a high curvature. Small changes in the parameters result in large increases in the loss. This means the second derivative (curvature) at this point is large.
-
Flat Minimum: A region where the loss function has a low curvature. Small changes in the parameters result in small changes in the loss. The second derivative at this point is small or zero.
Why Does SGD Tend to Find Flat Minima?
Stochastic Gradient Descent (SGD) introduces noise in the gradient estimation because it uses a subset (mini-batch) of the data to compute the gradient at each step. This noise can cause the optimizer to "jump around" in the parameter space. Sharp minima are sensitive to such perturbations because the loss increases rapidly away from the minimum. Therefore, SGD is more likely to escape sharp minima due to the noise. On the other hand, flat minima are more robust to noise because the loss changes slowly with parameter changes, making SGD more likely to converge to and stay in flat regions.
In contrast, Full Batch Gradient Descent computes the exact gradient over the entire dataset at each step, without introducing noise. Therefore, it can converge to sharp minima because there's no stochastic perturbation to push it away.
Numerical Example:
Let's consider two simple loss functions, both having a global minimum at ( w = 0 ), but differing in curvature.
-
Sharp Minimum Loss Function:
[
L_s(w) = w^2
]
- First derivative (gradient): ( \frac{dL_s}{dw} = 2w )
- Second derivative (curvature): ( \frac{d^2L_s}{dw^2} = 2 ) (constant, high curvature)
-
Flat Minimum Loss Function:
[
L_f(w) = w^4
]
- First derivative (gradient): ( \frac{dL_f}{dw} = 4w^3 )
- Second derivative (curvature): ( \frac{d^2L_f}{dw^2} = 12w^2 )
- At ( w = 0 ), ( \frac{d^2L_f}{dw^2} = 0 ) (zero curvature)
Simulation of Gradient Descent (GD) and Stochastic Gradient Descent (SGD):
Initial Conditions:
- Starting point: ( w = 0.1 )
- Learning rate: ( \eta = 0.1 )
- Gradient noise for SGD: ( \epsilon \sim \mathcal{N}(0, \sigma^2) ), with ( \sigma = 0.02 )
Full Batch Gradient Descent (GD):
For Sharp Minimum ( L_s(w) ):
- Compute gradient: ( \frac{dL_s}{dw} = 2w = 2 \times 0.1 = 0.2 )
- Update parameter: ( w_{\text{new}} = w - \eta \times \frac{dL_s}{dw} = 0.1 - 0.1 \times 0.2 = 0.08 )
- The parameter moves significantly towards the minimum at ( w = 0 ).
For Flat Minimum ( L_f(w) ):
- Compute gradient: ( \frac{dL_f}{dw} = 4w^3 = 4 \times (0.1)^3 = 0.004 )
- Update parameter: ( w_{\text{new}} = w - \eta \times \frac{dL_f}{dw} = 0.1 - 0.1 \times 0.004 = 0.0996 )
- The parameter moves very little towards the minimum.
Observation: Gradient Descent moves faster towards the sharp minimum due to the larger gradient.
Stochastic Gradient Descent (SGD) with Noisy Gradients:
For Sharp Minimum ( L_s(w) ):
-
Compute gradient with noise: ( \frac{dL_s}{dw} + \epsilon = 0.2 + \epsilon )
- Suppose ( \epsilon = 0.02 ), so gradient is ( 0.22 )
-
Update parameter: ( w_{\text{new}} = 0.1 - 0.1 \times 0.22 = 0.078 )
-
The parameter update is larger due to noise, potentially overshooting the minimum.
-
Near the minimum (( w \approx 0 )):
- Gradient: ( \frac{dL_s}{dw} \approx 0 )
- Noise dominates, causing the parameter to oscillate and not settle at the minimum.
For Flat Minimum ( L_f(w) ):
-
Compute gradient with noise: ( \frac{dL_f}{dw} + \epsilon = 0.004 + \epsilon )
- Suppose ( \epsilon = 0.02 ), so gradient is ( 0.024 )
-
Update parameter: ( w_{\text{new}} = 0.1 - 0.1 \times 0.024 = 0.0976 )
-
The parameter update is affected by noise, but the flatness of the minimum makes the optimization less sensitive to parameter changes.
-
Near the minimum (( w \approx 0 )):
- Gradient: ( \frac{dL_f}{dw} \approx 0 )
- Noise still affects updates, but the loss increases slowly away from the minimum.
Observation: In SGD, the noise in the gradient causes difficulty in converging to the sharp minimum because the optimizer can be easily pushed away. For the flat minimum, the optimizer is less sensitive to noise due to the low curvature, making it more likely for SGD to find and stay near the flat minimum.
Conclusion:
- SGD tends to find flat minima because the noise in gradient estimation can prevent convergence to sharp minima by pushing the optimizer out of narrow valleys where the loss increases rapidly.
- Full Batch GD can converge to sharp minima because it uses the exact gradient without noise, allowing it to settle in regions of high curvature.
This numerical example illustrates why, even when the loss values at the minima are equal, SGD tends to find flat minima due to its stochastic nature, while full batch GD can find sharp minima.