Gradient Descent

  • Epoch: the time that we iterative through all the training data.
  • Batch Size: the number of data points that we feed to the algorithm every iteration.
  • An Iteration: the time that the weights update.

Given the steps of gradient descent algorithm,

  • Algorithm:
    1. Initialize the weights.
    2. For all the training data: forward pass and calculate the output(s) $Y$.
    3. Update the weights (gradient descent):
    4. Repeat from step 1.

Batch Gradient Descent

We can use GPU to accelerate the computations, but we cannot fit all the data into the GPU memory as the GPU is small. Therefore, we consider feeding a batch of data each time.

  • Min-Batch Gradient Descent
    This algorithm uses a batch of samples to update the weights every iteration.

  • Stochastic Gradient Descent
    This algorithm uses 1 sample to update the weights every iteration.

However, if the model is too large while the batch is too small, the training can be very unstable.

Any solutions can make the convergence more stable?

Accumulate Gradient

We can accumulate the gradient for like 10 iterations to update the weights.

  • Algorithm:
    For t=1:10
Any solutions can make the convergence faster and better?

Momentum Optimization

Momentum

  • Learning Rate: It is hard to set the learning rate, if too small will take more steps to converge, while too large may lead to oscillation which slows down the convergence. Momentum extension focuses on improving the selection of the learning rate.
  • Idea: By remembering the update of the previous step, the learning rate $\alpha$ is affected by the sign of both previous and current gradients. If they have the same gradient sign, the update step is longer in directions; otherwise, the update step is shorter in directions.

  • Algorithm:
    For each iteration

    1. Compute the gradient at the current location
    2. Add the scaled previous step
    • $\Delta w^{\,t-1} = w^{\,t-1} - w^{\,t-2}$
    • Typical $\alpha = 0.001$, $\beta = 0.9$
  • Why momentum can conduct a smoother and faster convergence?
    It actually maintains a moving average of the gradient, which can amplify the learning rate in the correct direction, which smoothes the updates and enlarges the learning rate if the gradient signs are the same.

Nestorov’s Momentum

The difference between Momentum and Nesterov’s Momentum is in the gradient computation phase. The Nesterov’s Momentum will take an extension of the previous step first, then compute the gradient at the location (after extension).

  • Algorithm:
    For each iteration

    1. Extend the previous step
    2. Compute the gradient at the current location
    3. Sum them upMomentum Method (Left), Nestorov's Momentum (Right)
  • Any further improvement?

    • Observation: The steps in the oscillatory direction still show a large total movement.
    • Improvement: We want to reduce the step size in directions with high motion and increase it in directions with slow motion.
    • Methodology: We can scale the updates in every component in inverse proportion to the total movement of that component in recent past.

Scaling

Inverse mean square derivative

Recall the update of weights: $w^{\,t} = w^{\,t-1} - \alpha \frac{\partial Loss}{\partial w^{\,t-1}}$.
Let $\partial_{w^{\,t-1}}L = \frac{\partial Loss}{\partial w^{\,t-1}}$ be the derivative of loss with respect to the parameter $w^{\,t-1}$ (i.e., the gradient).

  • $(\partial_{w^{\,t-1}}L)^2$ denotes the squared derivative, not the second derivative
  • $E[(\partial_{w}L)^2]$ denotes the expectation of the square derivative.
  • $E[(\partial_{w}L)^2]_{t-1}$ denotes the expectation of the square derivative until step $t-1$

Now the step is scaled by the inverse mean square derivative,

Since the number of iterations may be very large, it is expensive to store all previous squared derivative. Instead of accurately compute the expectation of the square derivative until the step, we apply a running average to estimate it,

To prevent the divide by 0 problem, we add $\epsilon$ to $E[(\partial_{w}L)^2]_{t-1}$,

Root Mean Squared Propagation

  • $E[(\partial_{w}L)^2]_{t-1} = \gamma\, E[(\partial_{w}L)^2]_{t-2} + (1-\gamma)(\partial_{w^{\,t-1}}L)^2$
  • $E[(\partial_{w}L)^2]_0 = 0$
  • Typical $\gamma = 0.9$, $\alpha = 0.001$, $\epsilon = 10^{-7}$

Adaptive moment estimation

RMS Prop + Momentum

Recall the update of momentum method: $w^{\,t} = w^{\,t-1} - \alpha \frac{\partial Loss}{\partial w^{\,t-1}} + \beta \Delta w^{\,t-1}$, where $\Delta w^{\,t-1} = w^{\,t-1} - w^{\,t-2}$.

We can determine $w^{\,t}$ as following,

We find the recursive structure,

We can determine the $w^{\,t}$ by apply the recursive structure,

Note that the terms $\frac{\partial Loss}{\partial w^{\,t-1}} + \beta \frac{\partial Loss}{\partial w^{\,t-2}} + \cdots + \beta^{\,t-1} \frac{\partial Loss}{\partial w^{\,0}} + 0$ related to ALL previous derivatives, which is the running average. Therefore, we can unify the expression,

  • $E[(\partial_{w}L)^2]_{t-1} = \gamma\, E[(\partial_{w}L)^2]_{t-2} + (1-\gamma)(\partial_{w^{\,t-1}}L)^2$.
  • $E[\partial_wL]_{t-1} = \delta E[\partial_wL]_{t-2} + (1-\delta)\partial_{w^{\,t-1}}L$, which is similar to the RMS Prop.
  • The boundary cases: $E[(\partial_{w}L)^2]_0 = 0$ and $E[\partial_wL]_0 = 0$.
  • Typical $\gamma = 0.9$, $\alpha = 0.001$, $\epsilon = 10^{-7}$

Expected running average

Let $m_t$ be the running average until step t.
Let $g_t$ be the value of each observation at step t.

Take the expectation on both sides,

We believe that the observation of $g_i$ is around $g_t$, so we let $g_i = g_t + \varsigma$,

If the running average is good, $E[m_t] = E[g_t]$.

Running average correction

Since running average is not an unbiased estimator, we need to add a correction term.

If $t$ is small, $1-\gamma^{\,\,t-1}$ is small, which means not correlate.

Adam formula

  • $\hat{E}[(\partial_wL)^2]_{t-1} = \frac{E[(\partial_wL)^2]_{t-1}}{1-\gamma^{\,\,t-1}}$ where $E[(\partial_{w}L)^2]_{t-1} = \gamma\, E[(\partial_{w}L)^2]_{t-2} + (1-\gamma)(\partial_{w^{\,t-1}}L)^2$.
  • $\hat{E}[\partial_wL]_{t-1}\frac{E[\partial_wL]_{t-1}}{1-\delta^{\,t-1}}$ where $E[\partial_wL]_{t-1} = \delta E[\partial_wL]_{t-2} + (1-\delta)\partial_{w^{\,t-1}}L$.
  • The boundary cases: $E[(\partial_{w}L)^2]_0 = 0$ and $E[\partial_wL]_0 = 0$.
  • Typical $\alpha = 0.001$, $\gamma = 0.999$, $\delta = 0.9$, $\epsilon = 10^{-7}$

Scribing Note