stochastic_optimization_techniques

**This is an old revision of the document!**

Neural networks are often trained stochastically, i.e. using a method where the objective function changes at each iteration. This stochastic variation is due to the model being trained on different data during each iteration. This is motivated by (at least) two factors: First, the dataset used as training data is often too large to fit in memory and/or be optimized over efficiently. Second, the objective function is typically nonconvex, so using different data at each iteration can help prevent the model from settling in a local minimum. Furthermore, training neural networks is usually done using only the first-order gradient of the parameters with respect to the loss function. This is due to the large number of parameters present in a neural network, which for practical purposes prevents the computation of the Hessian matrix. Because vanilla gradient descent can diverge or converge incredibly slowly if its learning rate hyperparameter is set inappropriately, many alternative methods have been proposed which are intended to produce desirable convergence with less dependence on hyperparameter settings. These methods often effectively compute and utilize a preconditioner on the gradient, adaptively change the learning rate over time or approximate the Hessian matrix.

In the following, we will use $p_t$ to denote some generic parameter of the model at iteration $t$, to be optimized according to some loss function $\mathcal{L}$ which is to be minimized. For another brief overview of many of these methods with code examples in Theano, see ^{1)}.

Stochastic gradient descent (SGD) simply updates each parameter by subtracting the gradient of the loss with respect to the parameter, scaled by the learning rate $\lambda$, a hyperparameter. If $lambda$ is too large, SGD will diverge; if it's too small, it will converge slowly. The update rule is simply $$ p_{t + 1} = p_t - \lambda \nabla \mathcal{L}(p_t) $$

In SGD, the gradient $\nabla \mathcal{L}(p_t)$ often changes rapidly at each iteration $t$ due to the fact that the loss is being computed over different data. This is often partially mitigated by re-using the gradient value from the previous iteration, scaled by a momentum hyperparameter $\mu$, as follows:

\begin{align*} v_{t + 1} &= \mu v_t - \lambda \nabla \mathcal{L}(p_t) \\ p_{t + 1} &= p_t + v_{t+1} \end{align*}

It has been argued that including the previous gradient step has the effect of approximating some second-order information about the gradient.

In Nesterov's Accelerated Gradient (NAG), the gradient of the loss at each step is computed at $p_t + \mu v_t$ instead of $p_t$. In momentum, the parameter update could be written $p_{t + 1} = p_t + \mu v_t - \lambda \nabla \mathcal{L}(p_t)$, so NAG effectively computes the gradient at the new parameter location but without considering the gradient term. In practice, this causes NAG to behave more stably than regular momentum in many situations. A more thorough analysis can be found in ^{2)}. The update rules are then as follows:

\begin{align*} v_{t + 1} &= \mu v_t - \lambda \nabla\mathcal{L}(p_t + \mu v_t) \\ p_{t + 1} &= p_t + v_{t+1} \end{align*}

Adagrad effectively rescales the learning rate for each parameter according to the history of the gradients for that parameter. This is done by dividing each term in $\nabla \mathcal{L}$ by the square root of the sum of squares of its historical gradient. Rescaling in this way effectively lowers the learning rate for parameters which consistently have large gradient values. It also effectively decreases the learning rate over time, because the sum of squares will continue to grow with the iteration. After setting the rescaling term $g = 0$, the updates are as follows:
\begin{align*}
g_{t + 1} &= g_t + \nabla \mathcal{L}(p_t)^2 \\
p_{t + 1} &= p_t - \frac{\lambda\nabla \mathcal{L}(p_t)}{\sqrt{g_{t + 1}} + \epsilon}
\end{align*}
where division is elementwise and $\epsilon$ is a small constant included for numerical stability. It has nice theoretical guarantees and empirical results ^{3)} ^{4)}.

\begin{align*} g_{t+1} &= \gamma g_t + (1 - \gamma) \nabla \mathcal{L}(p_t)^2 \\ p_{t+1} &= p_t - \frac{\lambda\nabla \mathcal{L}(p_t)}{\sqrt{g_{t + 1}} + \epsilon} \end{align*}

\begin{align*} g_{t + 1} &= \gamma g_t + (1 - \gamma) \nabla \mathcal{L}(p_t)^2 \\ v_{t + 1} &= -\frac{\sqrt{x_t + \epsilon} \nabla \mathcal{L}(p_t)}{\sqrt{g_{t+1} + \epsilon}} \\ x_{t + 1} &= \gamma x_t + (1 - \gamma) v_{t + 1}^2 \\ p_{t + 1} &= p_t + v_{t + 1} \end{align*}

stochastic_optimization_techniques.1425434885.txt.gz · Last modified: 2015/12/17 22:00 (external edit)