An overview of gradient descent optimization algorithms.

 Gradient descent variants

    在平时的应用过程中共有三种主流的梯度下降算法:batch gradient decent、stochastic gradient decent、mini-batch gradient decent. 其中第一种和第三种首先分别计算每一个样本的损失函数梯度之后对它们求平均作为更新依据。

Challenges

  • Choosing a proper learning rate can be difficult. 

  • Additionally, the same learning rate applies to all parameter updates. If our data is sparse and our features have very different frequencies, we might not want to update all of them to the same extent, but perform a larger update for rarely occurring features.

  • Another key challenge of minimizing highly non-convex error functions common for neural networks is avoiding getting trapped in their numerous suboptimal local minima. Dauphin et al. [3] argue that the difficulty arises in fact not from local minima but from saddle points, i.e. points where one dimension slopes up and another slopes down. These saddle points are usually surrounded by a plateau of the same error, which makes it notoriously hard for SGD to escape, as the gradient is close to zero in all dimensions.

Gradient descent optimization algorithms

动量(Momentum)

          SGD has trouble navigating ravines, i.e. areas where the surface curves much more steeply in one dimension than in another [4], which are common around local optima. In these scenarios, SGD oscillates across the slopes of the ravine while only making hesitant progress along the bottom towards the local optimum as in Image 2.

Image 2: SGD without momentum
Image 3: SGD with momentum

        Momentum [5] is a method that helps accelerate SGD in the relevant direction and dampens oscillations as can be seen in Image 3. It does this by adding a fraction γ of the update vector of the past time step to the current update vector:

        Note: Some implementations exchange the signs in the equations. The momentum term γ is usually set to 0.9 or a similar value.


Nesterov accelerated gradient(NAG  改进版动量)

    However, a ball that rolls down a hill, blindly following the slope, is highly unsatisfactory. We'd like to have a smarter ball, a ball that has a notion of where it is going so that it knows to slow down before the hill slopes up again.

    Nesterov accelerated gradient (NAG) [6] is a way to give our momentum term this kind of prescience. We know that we will use our momentum term γvt1 to move the parameters θ. Computing θγvt1 thus gives us an approximation of the next position of the parameters (the gradient is missing for the full update), a rough idea where our parameters are going to be. We can now effectively look ahead by calculating the gradient not w.r.t. to our current parameters θ but w.r.t. the approximate future position of our parameters:

vt=γvt1+ηθJ(θγvt1)θ=θvt

    Again, we set the momentum term γ to a value of around 0.9.


Adagrad(自适应学习率,不同参数采用不同学习率)

Adagrad [9] is an algorithm for gradient-based optimization that does just this: It adapts the learning rate to the parameters, performing smaller updates
(i.e. low learning rates) for parameters associated with frequently occurring features, and larger updates (i.e. high learning rates) for parameters associated with infrequent features. For this reason, it is well-suited for dealing with sparse data. Dean et al. [10] have found that Adagrad greatly improved the robustness of SGD and used it for training large-scale neural nets at Google, which -- among other things -- learned to recognize cats in Youtube videos. Moreover, Pennington et al. [11] used Adagrad to train GloVe word embeddings, as infrequent words require much larger updates than frequent ones.

Previously, we performed an update for all parameters θ at once as every parameter θi used the same learning rate η. As Adagrad uses a different learning rate for every parameter θi at every time step t, we first show Adagrad's per-parameter update, which we then vectorize. For brevity, we use gt to denote the gradient at time step tgt,i is then the partial derivative of the objective function w.r.t. to the parameter θi at time step t:

gt,i=θJ(θt,i).

The SGD update for every parameter θi at each time step t then becomes:

θt+1,i=θt,iηgt,i.

In its update rule, Adagrad modifies the general learning rate η at each time step t for every parameter θi based on the past gradients that have been computed for θi:

θt+1,i=θt,iηGt,ii+ϵgt,i.

GtRd×d here is a diagonal matrix where each diagonal element i,i is the sum of the squares of the gradients w.r.t. θi up to time step t [12], while ϵ is a smoothing term that avoids division by zero (usually on the order of 1e8). Interestingly, without the square root operation, the algorithm performs much worse.

As Gt contains the sum of the squares of the past gradients w.r.t. to all parameters θ along its diagonal, we can now vectorize our implementation by performing a matrix-vector product  between Gt and gt:

θt+1=θtηGt+ϵgt.

One of Adagrad's main benefits is that it eliminates the need to manually tune the learning rate. Most implementations use a default value of 0.01 and leave it at that.

Adagrad's main weakness is its accumulation of the squared gradients in the denominator: Since every added term is positive, the accumulated sum keeps growing during training. This in turn causes the learning rate to shrink and eventually become infinitesimally small, at which point the algorithm is no longer able to acquire additional knowledge. The following algorithms aim to resolve this flaw.


Adadelta(Adagrad的改进版)

Adadelta [13] is an extension of Adagrad that seeks to reduce its aggressive, monotonically decreasing learning rate. Instead of accumulating all past squared gradients, Adadelta restricts the window of accumulated past gradients to some fixed size w.

Instead of inefficiently storing w previous squared gradients, the sum of gradients is recursively defined as a decaying average of all past squared gradients. The running average E[g2]t at time step t then depends (as a fraction γ similarly to the Momentum term) only on the previous average and the current gradient:

E[g2]t=γE[g2]t1+(1γ)gt2.

We set γ to a similar value as the momentum term, around 0.9. For clarity, we now rewrite our vanilla SGD update in terms of the parameter update vector Δθt:

Δθt=ηgt,iθt+1=θt+Δθt

The parameter update vector of Adagrad that we derived previously thus takes the form:

Δθt=ηGt+ϵgt.

We now simply replace the diagonal matrix Gt with the decaying average over past squared gradients E[g2]t:

Δθt=ηE[g2]t+ϵgt.

As the denominator is just the root mean squared (RMS) error criterion of the gradient, we can replace it with the criterion short-hand:

Δθt=ηRMS[g]tgt.

The authors note that the units in this update (as well as in SGD, Momentum, or Adagrad) do not match, i.e. the update should have the same hypothetical units as the parameter. To realize this, they first define another exponentially decaying average, this time not of squared gradients but of squared parameter updates:

E[Δθ2]t=γE[Δθ2]t1+(1γ)Δθt2.

The root mean squared error of parameter updates is thus:

RMS[Δθ]t=E[Δθ2]t+ϵ.

Since RMS[Δθ]t is unknown, we approximate it with the RMS of parameter updates until the previous time step. Replacing the learning rate η in the previous update rule with RMS[Δθ]t1 finally yields the Adadelta update rule:

Δθt=RMS[Δθ]t1RMS[g]tgtθt+1=θt+Δθt

With Adadelta, we do not even need to set a default learning rate, as it has been eliminated from the update rule.


RMSprop(Adadelta的简化版,在前几次更新与Adadelta相似)

RMSprop is an unpublished, adaptive learning rate method proposed by Geoff Hinton in Lecture 6e of his Coursera Class.

RMSprop and Adadelta have both been developed independently around the same time stemming from the need to resolve Adagrad's radically diminishing learning rates. RMSprop in fact is identical to the first update vector of Adadelta that we derived above:

E[g2]t=0.9E[g2]t1+0.1gt2θt+1=θtηE[g2]t+ϵgt

RMSprop as well divides the learning rate by an exponentially decaying average of squared gradients. Hinton suggests γ to be set to 0.9, while a good default value for the learning rate η is 0.001.


Adam(动量与Adadelta的结合)

Adaptive Moment Estimation (Adam) [14] is another method that computes adaptive learning rates for each parameter. In addition to storing an exponentially decaying average of past squared gradients vt like Adadelta and RMSprop, Adam also keeps an exponentially decaying average of past gradients mt, similar to momentum. Whereas momentum can be seen as a ball running down a slope, Adam behaves like a heavy ball with friction, which thus prefers flat minima in the error surface [15]. We compute the decaying averages of past and past squared gradients mt and vt respectively as follows:

mt=β1mt1+(1β1)gtvt=β2vt1+(1β2)gt2

mt and vt are estimates of the first moment (the mean) and the second moment (the uncentered variance) of the gradients respectively, hence the name of the method. As mt and vt are initialized as vectors of 0's, the authors of Adam observe that they are biased towards zero, especially during the initial time steps, and especially when the decay rates are small (i.e. β1 and β2 are close to 1).

They counteract these biases by computing bias-corrected first and second moment estimates:



They then use these to update the parameters just as we have seen in Adadelta and RMSprop, which yields the Adam update rule:

The authors propose default values of 0.9 for β1, 0.999 for β2, and 108 for ϵ. They show empirically that Adam works well in practice and compares favorably to other adaptive learning-method algorithms.


AdaMax

The vt factor in the Adam update rule scales the gradient inversely proportionally to the 2 norm of the past gradients (via the vt1 term) and current gradient |gt|2:

vt=β2vt1+(1β2)|gt|2

We can generalize this update to the p norm. Note that Kingma and Ba also parameterize β2 as β2p:

vt=β2pvt1+(1β2p)|gt|p

Norms for large p values generally become numerically unstable, which is why 1 and 2 norms are most common in practice. However,  also generally exhibits stable behavior. For this reason, the authors propose AdaMax (Kingma and Ba, 2015) and show that vt with  converges to the following more stable value. To avoid confusion with Adam, we use ut to denote the infinity norm-constrained vt:

ut=β2vt1+(1β2)|gt|=max(β2vt1,|gt|)

We can now plug this into the Adam update equation by replacing v^t+ϵ with ut to obtain the AdaMax update rule:

θt+1=θtηutm^t

Note that as ut relies on the max operation, it is not as suggestible to bias towards zero as mt and vt in Adam, which is why we do not need to compute a bias correction for ut. Good default values are again η=0.002β1=0.9, and β2=0.999.

Nadam

As we have seen before, Adam can be viewed as a combination of RMSprop and momentum: RMSprop contributes the exponentially decaying average of past squared gradients vt, while momentum accounts for the exponentially decaying average of past gradients mt. We have also seen that Nesterov accelerated gradient (NAG) is superior to vanilla momentum.

Nadam (Nesterov-accelerated Adaptive Moment Estimation) [16] thus combines Adam and NAG. In order to incorporate NAG into Adam, we need to modify its momentum term mt.

First, let us recall the momentum update rule using our current notation :

gt=θtJ(θt)mt=γmt1+ηgtθt+1=θtmt

where J is our objective function, γ is the momentum decay term, and η is our step size. Expanding the third equation above yields:

θt+1=θt(γmt1+ηgt)

This demonstrates again that momentum involves taking a step in the direction of the previous momentum vector and a step in the direction of the current gradient.

NAG then allows us to perform a more accurate step in the gradient direction by updating the parameters with the momentum step before computing the gradient. We thus only need to modify the gradient gt to arrive at NAG:

gt=θtJ(θtγmt1)mt=γmt1+ηgtθt+1=θtmt

Dozat proposes to modify NAG the following way: Rather than applying the momentum step twice -- one time for updating the gradient gt and a second time for updating the parameters θt+1 -- we now apply the look-ahead momentum vector directly to update the current parameters:

gt=θtJ(θt)mt=γmt1+ηgtθt+1=θt(γmt+ηgt)

Notice that rather than utilizing the previous momentum vector mt1 as in the equation of the expanded momentum update rule above, we now use the current momentum vector mt to look ahead. In order to add Nesterov momentum to Adam, we can thus similarly replace the previous momentum vector with the current momentum vector. First, recall that the Adam update rule is the following (note that we do not need to modify v^t):

mt=β1mt1+(1β1)gtm^t=mt1β1tθt+1=θtηv^t+ϵm^t

Expanding the second equation with the definitions of m^t and mt in turn gives us:

θt+1=θtηv^t+ϵ(β1mt11β1t+(1β1)gt1β1t)

Note that β1mt11β1t is just the bias-corrected estimate of the momentum vector of the previous time step. We can thus replace it with m^t1:

θt+1=θtηv^t+ϵ(β1m^t1+(1β1)gt1β1t)

    Note that for simplicity, we ignore that the denominator is 1β1t and not 1β1t1 as we will replace the denominator in the next step anyway. This equation again looks very similar to our expanded momentum update rule above. We can now add Nesterov momentum just as we did previously by simply replacing this bias-corrected estimate of the momentum vector of the previous time step m^t1 with the bias-corrected estimate of the current momentum vector m^t, which gives us the Nadam update rule:

评论

此博客中的热门博文

Visual Mechanisms Inspired Efficient Transformers for Image and Video Quality Assessment

vision transformer