梯度下降優(yōu)化算法綜述

轉(zhuǎn)自http://blog.csdn.net/heyongluoyao8/article/details/52478715

梯度下降優(yōu)化算法綜述

該文翻譯自An overview of gradient descent optimization algorithms。

總所周知,梯度下降算法是機(jī)器學(xué)習(xí)中使用非常廣泛的優(yōu)化算法,也是眾多機(jī)器學(xué)習(xí)算法中最常用的優(yōu)化方法。幾乎當(dāng)前每一個(gè)先進(jìn)的(state-of-the-art)機(jī)器學(xué)習(xí)庫(kù)或者深度學(xué)習(xí)庫(kù)都會(huì)包括梯度下降算法的不同變種實(shí)現(xiàn)。但是,它們就像一個(gè)黑盒優(yōu)化器,很難得到它們優(yōu)缺點(diǎn)的實(shí)際解釋。

這篇文章旨在提供梯度下降算法中的不同變種的介紹,幫助使用者根據(jù)具體需要進(jìn)行使用。

這篇文章首先介紹梯度下降算法的三種框架,然后介紹它們所存在的問(wèn)題與挑戰(zhàn),接著介紹一些如何進(jìn)行改進(jìn)來(lái)解決這些問(wèn)題,隨后,介紹如何在并行環(huán)境中或者分布式環(huán)境中使用梯度下降算法。最后,指出一些有利于梯度下降的策略。

梯度下降算法是通過(guò)沿著目標(biāo)函數(shù)J(θ) 參數(shù)θ∈R的梯度(一階導(dǎo)數(shù))相反方向??θJ(θ) 來(lái)不斷更新模型參數(shù)來(lái)到達(dá)目標(biāo)函數(shù)的極小值點(diǎn)(收斂),更新步長(zhǎng)為 η 。詳細(xì)的介紹參見(jiàn):梯度下降

三種梯度下降優(yōu)化框架

有三種梯度下降算法框架,它們不同之處在于每次學(xué)習(xí)(更新模型參數(shù))使用的樣本個(gè)數(shù),每次更新使用不同的樣本會(huì)導(dǎo)致每次學(xué)習(xí)的準(zhǔn)確性和學(xué)習(xí)時(shí)間不同。

  • 全量梯度下降(Batch gradient descent)

    每次使用全量的訓(xùn)練集樣本來(lái)更新模型參數(shù),即:
    θ=θ?η??θJ(θ)

其代碼如下:

for i in range(epochs):
    params_grad = evaluate_gradient(loss_function,data,params)
    params = params - learning_rate * params_grad

epochs 是用戶輸入的最大迭代次數(shù)。通過(guò)上訴代碼可以看出,每次使用全部訓(xùn)練集樣本計(jì)算損失函數(shù)loss_function的梯度params_grad,然后使用學(xué)習(xí)速率learning_rate朝著梯度相反方向去更新模型的每個(gè)參數(shù)params。一般各現(xiàn)有的一些機(jī)器學(xué)習(xí)庫(kù)都提供了梯度計(jì)算api。如果想自己親手寫代碼計(jì)算,那么需要在程序調(diào)試過(guò)程中驗(yàn)證梯度計(jì)算是否正確,具體驗(yàn)證方法可以參見(jiàn):這里

全量梯度下降每次學(xué)習(xí)都使用整個(gè)訓(xùn)練集,因此其優(yōu)點(diǎn)在于每次更新都會(huì)朝著正確的方向進(jìn)行,最后能夠保證收斂于極值點(diǎn)(凸函數(shù)收斂于全局極值點(diǎn),非凸函數(shù)可能會(huì)收斂于局部極值點(diǎn)),但是其缺點(diǎn)在于每次學(xué)習(xí)時(shí)間過(guò)長(zhǎng),并且如果訓(xùn)練集很大以至于需要消耗大量的內(nèi)存,并且全量梯度下降不能進(jìn)行在線模型參數(shù)更新。

  • 隨機(jī)梯度下降(Stochastic gradient descent)

隨機(jī)梯度下降算法每次從訓(xùn)練集中隨機(jī)選擇一個(gè)樣本來(lái)進(jìn)行學(xué)習(xí),即:
θ=θ?η??θJ(θ;xi;yi)

批量梯度下降算法每次都會(huì)使用全部訓(xùn)練樣本,因此這些計(jì)算是冗余的,因?yàn)槊看味际褂猛耆嗤臉颖炯?。而隨機(jī)梯度下降算法每次只隨機(jī)選擇一個(gè)樣本來(lái)更新模型參數(shù),因此每次的學(xué)習(xí)是非??焖俚?,并且可以進(jìn)行在線更新。

其代碼如下:

for i in range(epochs):
    np.random.shuffle(data)
    for example in data:
        params_grad = evaluate_gradient(loss_function,example,params)
        params = params - learning_rate * params_grad

隨機(jī)梯度下降最大的缺點(diǎn)在于每次更新可能并不會(huì)按照正確的方向進(jìn)行,因此可以帶來(lái)優(yōu)化波動(dòng)(擾動(dòng)),如下圖:

sgd_fluctuation

圖1 SGD擾動(dòng)來(lái)源

不過(guò)從另一個(gè)方面來(lái)看,隨機(jī)梯度下降所帶來(lái)的波動(dòng)有個(gè)好處就是,對(duì)于類似盆地區(qū)域(即很多局部極小值點(diǎn))那么這個(gè)波動(dòng)的特點(diǎn)可能會(huì)使得優(yōu)化的方向從當(dāng)前的局部極小值點(diǎn)跳到另一個(gè)更好的局部極小值點(diǎn),這樣便可能對(duì)于非凸函數(shù),最終收斂于一個(gè)較好的局部極值點(diǎn),甚至全局極值點(diǎn)。

由于波動(dòng),因此會(huì)使得迭代次數(shù)(學(xué)習(xí)次數(shù))增多,即收斂速度變慢。不過(guò)最終其會(huì)和全量梯度下降算法一樣,具有相同的收斂性,即凸函數(shù)收斂于全局極值點(diǎn),非凸損失函數(shù)收斂于局部極值點(diǎn)。

  • 小批量梯度下降(Mini-batch gradient descent)

Mini-batch梯度下降綜合了batch梯度下降與stochastic梯度下降,在每次更新速度與更新次數(shù)中間取得一個(gè)平衡,其每次更新從訓(xùn)練集中隨機(jī)選擇m,m<n 個(gè)樣本進(jìn)行學(xué)習(xí),即:
θ=θ?η??θJ(θ;xi:i+m;yi:i+m)

其代碼如下:

for i in range(epochs):
    np.random.shuffle(data)
    for batch in get_batches(data, batch_size=50):
        params_grad = evaluate_gradient(loss_function,batch,params)
        params = params - learning_rate * params_grad

相對(duì)于隨機(jī)梯度下降,Mini-batch梯度下降降低了收斂波動(dòng)性,即降低了參數(shù)更新的方差,使得更新更加穩(wěn)定。相對(duì)于全量梯度下降,其提高了每次學(xué)習(xí)的速度。并且其不用擔(dān)心內(nèi)存瓶頸從而可以利用矩陣運(yùn)算進(jìn)行高效計(jì)算。一般而言每次更新隨機(jī)選擇[50,256]個(gè)樣本進(jìn)行學(xué)習(xí),但是也要根據(jù)具體問(wèn)題而選擇,實(shí)踐中可以進(jìn)行多次試驗(yàn),選擇一個(gè)更新速度與更次次數(shù)都較適合的樣本數(shù)。

mini-batch梯度下降雖然可以保證收斂性。mini-batch梯度下降常用于神經(jīng)網(wǎng)絡(luò)中。

問(wèn)題與挑戰(zhàn)

雖然梯度下降算法效果很好,并且廣泛使用,但同時(shí)其也存在一些挑戰(zhàn)與問(wèn)題需要解決:

  • 選擇一個(gè)合理的學(xué)習(xí)速率很難。如果學(xué)習(xí)速率過(guò)小,則會(huì)導(dǎo)致收斂速度很慢。如果學(xué)習(xí)速率過(guò)大,那么其會(huì)阻礙收斂,即在極值點(diǎn)附近會(huì)振蕩。

  • 學(xué)習(xí)速率調(diào)整(又稱學(xué)習(xí)速率調(diào)度,Learning rate schedules)[11]試圖在每次更新過(guò)程中,改變學(xué)習(xí)速率,如退火。一般使用某種事先設(shè)定的策略或者在每次迭代中衰減一個(gè)較小的閾值。無(wú)論哪種調(diào)整方法,都需要事先進(jìn)行固定設(shè)置,這邊便無(wú)法自適應(yīng)每次學(xué)習(xí)的數(shù)據(jù)集特點(diǎn)[10]

  • 模型所有的參數(shù)每次更新都是使用相同的學(xué)習(xí)速率。如果數(shù)據(jù)特征是稀疏的或者每個(gè)特征有著不同的取值統(tǒng)計(jì)特征與空間,那么便不能在每次更新中每個(gè)參數(shù)使用相同的學(xué)習(xí)速率,那些很少出現(xiàn)的特征應(yīng)該使用一個(gè)相對(duì)較大的學(xué)習(xí)速率。

  • 對(duì)于非凸目標(biāo)函數(shù),容易陷入那些次優(yōu)的局部極值點(diǎn)中,如在神經(jīng)網(wǎng)路中。那么如何避免呢。Dauphin[19]指出更嚴(yán)重的問(wèn)題不是局部極值點(diǎn),而是鞍點(diǎn)(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.)。

梯度下降優(yōu)化算法

下面將討論一些在深度學(xué)習(xí)社區(qū)中經(jīng)常使用用來(lái)解決上訴問(wèn)題的一些梯度優(yōu)化方法,不過(guò)并不包括在高維數(shù)據(jù)中不可行的算法,如牛頓法。

Momentum

如果在峽谷地區(qū)(某些方向較另一些方向上陡峭得多,常見(jiàn)于局部極值點(diǎn))[1],SGD會(huì)在這些地方附近振蕩,從而導(dǎo)致收斂速度慢。這種情況下,動(dòng)量(Momentum)便可以解決[2]。動(dòng)量在參數(shù)更新項(xiàng)中加上一次更新量(即動(dòng)量項(xiàng)),即:
νt=γνt?1+η ?θJ(θ)

θ=θ?νt
其中動(dòng)量項(xiàng)超參數(shù) γ<1一般是小于等于0.9。

其作用如下圖所示:

圖2 沒(méi)有動(dòng)量
圖3 加上動(dòng)量

加上動(dòng)量項(xiàng)就像從山頂滾下一個(gè)球,求往下滾的時(shí)候累積了前面的動(dòng)量(動(dòng)量不斷增加),因此速度變得越來(lái)越快,直到到達(dá)終點(diǎn)。同理,在更新模型參數(shù)時(shí),對(duì)于那些當(dāng)前的梯度方向與上一次梯度方向相同的參數(shù),那么進(jìn)行加強(qiáng),即這些方向上更快了;對(duì)于那些當(dāng)前的梯度方向與上一次梯度方向不同的參數(shù),那么進(jìn)行削減,即這些方向上減慢了。因此可以獲得更快的收斂速度與減少振蕩。

NAG[7]

從山頂往下滾的球會(huì)盲目地選擇斜坡。更好的方式應(yīng)該是在遇到傾斜向上之前應(yīng)該減慢速度。

Nesterov accelerated gradient(NAG,涅斯捷羅夫梯度加速)不僅增加了動(dòng)量項(xiàng),并且在計(jì)算參數(shù)的梯度時(shí),在損失函數(shù)中減去了動(dòng)量項(xiàng),即計(jì)算
?θJ(θ?γνt?1),這種方式預(yù)估了下一次參數(shù)所在的位置。即:
νt=γνt?1+η??θJ(θ?γνt?1)

θ=θ?νt

如下圖所示:

圖4 NAG更新

詳細(xì)介紹可以參見(jiàn)Ilya Sutskever的PhD論文[9]。假設(shè)動(dòng)量因子參數(shù) γ=0.9,首先計(jì)算當(dāng)前梯度項(xiàng),如上圖小藍(lán)色向量,然后加上動(dòng)量項(xiàng),這樣便得到了大的跳躍,如上圖大藍(lán)色的向量。這便是只包含動(dòng)量項(xiàng)的更新。而NAG首先來(lái)一個(gè)大的跳躍(動(dòng)量項(xiàng)),然后加上一個(gè)小的使用了動(dòng)量計(jì)算的當(dāng)前梯度(上圖紅色向量)進(jìn)行修正得到上圖綠色的向量。這樣可以阻止過(guò)快更新來(lái)提高響應(yīng)性,如在RNNs中[8]。

通過(guò)上面的兩種方法,可以做到每次學(xué)習(xí)過(guò)程中能夠根據(jù)損失函數(shù)的斜率做到自適應(yīng)更新來(lái)加速SGD的收斂。下一步便需要對(duì)每個(gè)參數(shù)根據(jù)參數(shù)的重要性進(jìn)行各自自適應(yīng)更新。

Adagrad

Adagrad[3]也是一種基于梯度的優(yōu)化算法,它能夠?qū)γ總€(gè)參數(shù)自適應(yīng)不同的學(xué)習(xí)速率,對(duì)稀疏特征,得到大的學(xué)習(xí)更新,對(duì)非稀疏特征,得到較小的學(xué)習(xí)更新,因此該優(yōu)化算法適合處理稀疏特征數(shù)據(jù)。Dean等[4]發(fā)現(xiàn)Adagrad能夠很好的提高SGD的魯棒性,google便用起來(lái)訓(xùn)練大規(guī)模神經(jīng)網(wǎng)絡(luò)(看片識(shí)貓:recognize cats in Youtube videos)。Pennington等[5]在GloVe中便使用Adagrad來(lái)訓(xùn)練得到詞向量(Word Embeddings), 頻繁出現(xiàn)的單詞賦予較小的更新,不經(jīng)常出現(xiàn)的單詞則賦予較大的更新。

在前述中,每個(gè)模型參數(shù) θi 使用相同的學(xué)習(xí)速率 η 而Adagrad在每一個(gè)更新步驟中對(duì)于每一個(gè)模型參數(shù)θi使用不同的學(xué)習(xí)速率ηi,設(shè)第 t 次更新步驟中,目標(biāo)函數(shù)的參數(shù) θi梯度為gt,i,即:
gt,i=?θJ(θi)

那么SGD更新方程為:
θt+1,i=θt,i?η?gt,i
而Adagrad對(duì)每一個(gè)參數(shù)使用不同的學(xué)習(xí)速率,其更新方程為:
\theta_{t+1,i}=\theta_{t,i} - \frac{\eta}{\sqrt{G_{t,ii}+\epsilon}} \cdot g_{t,i}

其中,Gt∈Rd×d是一個(gè)對(duì)角矩陣,其中第 i行的對(duì)角元素 eii為過(guò)去到當(dāng)前第 i個(gè)參數(shù)θi的梯度的平方和, epsilon是一個(gè)平滑參數(shù),為了使得分母不為0(通常?=1e?8) ,另外如果分母不開(kāi)根號(hào),算法性能會(huì)很糟糕。

進(jìn)一步,將所有Gt,ii,gt,i

的元素寫成向量

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">G

t

,

g

t</nobr>

,這樣便可以使用向量點(diǎn)乘操作:

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">θ

t

1

=

θ

t

?

η

G

t

?

?

?

?

?

?

?

g

t</nobr>

Adagrad主要優(yōu)勢(shì)在于它能夠?yàn)槊總€(gè)參數(shù)自適應(yīng)不同的學(xué)習(xí)速率,而一般的人工都是設(shè)定為0.01。同時(shí)其缺點(diǎn)在于需要計(jì)算參數(shù)梯度序列平方和,并且學(xué)習(xí)速率趨勢(shì)是不斷衰減最終達(dá)到一個(gè)非常小的值。下文中的Adadelta便是用來(lái)解決該問(wèn)題的。

Adadelta ?? Adadelta[6]是Adagrad的一種擴(kuò)展,為了降低Adagrad中學(xué)習(xí)速率衰減過(guò)快問(wèn)題,其改進(jìn)了三處,一是使用了窗口

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">w</nobr>

;二是對(duì)于參數(shù)梯度歷史窗口序列(不包括當(dāng)前)不再使用平方和,而是使用均值代替;三是最終的均值是歷史窗口序列均值與當(dāng)前梯度的時(shí)間衰減加權(quán)平均。即:

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">E

[

g

2

]

t

=

γ

E

[

g

2

]

t

?

1

(

1

?

γ

)

g

2

t</nobr>

其中

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">γ</nobr>

與動(dòng)量項(xiàng)中的一樣,都是

<a name="t7" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>RMSprop

其實(shí)RMSprop是Adadelta的中間形式,也是為了降低Adagrad中學(xué)習(xí)速率衰減過(guò)快問(wèn)題,即:

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">E

[

g

2

]

t

=

γ

E

[

g

2

]

t

?

1

(

1

?

γ

)

g

2

t</nobr>

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">θ

t

1

=

θ

t

?

η

E

[

g

2

]

t

?

?

?

?

?

?

?

?

?

g

t</nobr>

Hinton建議

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">γ

=

0.9

,

η

=

0.001</nobr>

<a name="t8" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>Adam

Adaptive Moment Estimation(Adam) 也是一種不同參數(shù)自適應(yīng)不同學(xué)習(xí)速率方法,與Adadelta與RMSprop區(qū)別在于,它計(jì)算歷史梯度衰減方式不同,不使用歷史平方衰減,其衰減方式類似動(dòng)量,如下:

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">m

t

=

β

1

m

t

?

1

(

1

?

β

1

)

g

t</nobr>

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">v

t

=

β

2

v

t

?

1

(

1

?

b

e

t

a

2

)

g

2

t</nobr>

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">m

t</nobr>

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">v

t</nobr>

分別是梯度的帶權(quán)平均和帶權(quán)有偏方差,初始為0向量,Adam的作者發(fā)現(xiàn)他們傾向于0向量(接近于0向量),特別是在衰減因子(衰減率)

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">β

1</nobr>

,

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">β

2</nobr>

接近于1時(shí)。為了改進(jìn)這個(gè)問(wèn)題,對(duì)

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">m

t</nobr>

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">v

t</nobr>

進(jìn)行偏差修正(bias-corrected):

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">m

t

^

=

m

t

1

?

b

e

t

a

t

1</nobr>

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">v

t

^

=

v

t

1

?

b

e

t

a

t

2</nobr>

最終,Adam的更新方程為:

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">θ

t

1

=

θ

t

?

η

v

t

^

?

?

?

m

t

^</nobr>

論文中建議默認(rèn)值:

<nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">β

1

=

0.9

,

β

2

=

0.999

?

=

10

?

8</nobr>

。論文中將Adam與其它的幾個(gè)自適應(yīng)學(xué)習(xí)速率進(jìn)行了比較,效果均要好。

<a name="t9" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>各優(yōu)化方法比較

下面兩幅圖可視化形象地比較上述各優(yōu)化方法,詳細(xì)參見(jiàn)這里,如圖:

contours_evaluation_optimizers

圖5 SGD各優(yōu)化方法在損失曲面上的表現(xiàn)

從上圖可以看出, Adagrad、Adadelta與RMSprop在損失曲面上能夠立即轉(zhuǎn)移到正確的移動(dòng)方向上達(dá)到快速的收斂。而Momentum 與NAG會(huì)導(dǎo)致偏離(off-track)。同時(shí)NAG能夠在偏離之后快速修正其路線,因?yàn)槠涓鶕?jù)梯度修正來(lái)提高響應(yīng)性。

saddle_point_evaluation_optimizers

圖6 SGD各優(yōu)化方法在損失曲面鞍點(diǎn)處上的表現(xiàn)

從上圖可以看出,在鞍點(diǎn)(saddle points)處(即某些維度上梯度為零,某些維度上梯度不為零),SGD、Momentum與NAG一直在鞍點(diǎn)梯度為零的方向上振蕩,很難打破鞍點(diǎn)位置的對(duì)稱性;Adagrad、RMSprop與Adadelta能夠很快地向梯度不為零的方向上轉(zhuǎn)移。

從上面兩幅圖可以看出,自適應(yīng)學(xué)習(xí)速率方法(Adagrad、Adadelta、RMSprop與Adam)在這些場(chǎng)景下具有更好的收斂速度與收斂性。

<a name="t10" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>如何選擇SGD優(yōu)化器

如果你的數(shù)據(jù)特征是稀疏的,那么你最好使用自適應(yīng)學(xué)習(xí)速率SGD優(yōu)化方法(Adagrad、Adadelta、RMSprop與Adam),因?yàn)槟悴恍枰诘^(guò)程中對(duì)學(xué)習(xí)速率進(jìn)行人工調(diào)整。

RMSprop是Adagrad的一種擴(kuò)展,與Adadelta類似,但是改進(jìn)版的Adadelta使用RMS去自動(dòng)更新學(xué)習(xí)速率,并且不需要設(shè)置初始學(xué)習(xí)速率。而Adam是在RMSprop基礎(chǔ)上使用動(dòng)量與偏差修正。RMSprop、Adadelta與Adam在類似的情形下的表現(xiàn)差不多。Kingma[15]指出收益于偏差修正,Adam略優(yōu)于RMSprop,因?yàn)槠湓诮咏諗繒r(shí)梯度變得更加稀疏。因此,Adam可能是目前最好的SGD優(yōu)化方法。

有趣的是,最近很多論文都是使用原始的SGD梯度下降算法,并且使用簡(jiǎn)單的學(xué)習(xí)速率退火調(diào)整(無(wú)動(dòng)量項(xiàng))?,F(xiàn)有的已經(jīng)表明:SGD能夠收斂于最小值點(diǎn),但是相對(duì)于其他的SGD,它可能花費(fèi)的時(shí)間更長(zhǎng),并且依賴于魯棒的初始值以及學(xué)習(xí)速率退火調(diào)整策略,并且容易陷入局部極小值點(diǎn),甚至鞍點(diǎn)。因此,如果你在意收斂速度或者訓(xùn)練一個(gè)深度或者復(fù)雜的網(wǎng)絡(luò),你應(yīng)該選擇一個(gè)自適應(yīng)學(xué)習(xí)速率的SGD優(yōu)化方法。

<a name="t11" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>并行與分布式SGD

如果你處理的數(shù)據(jù)集非常大,并且有機(jī)器集群可以利用,那么并行或分布式SGD是一個(gè)非常好的選擇,因?yàn)榭梢源蟠蟮靥岣咚俣?。SGD算法的本質(zhì)決定其是串行的(step-by-step)。因此如何進(jìn)行異步處理便是一個(gè)問(wèn)題。雖然串行能夠保證收斂,但是如果訓(xùn)練集大,速度便是一個(gè)瓶頸。如果進(jìn)行異步更新,那么可能會(huì)導(dǎo)致不收斂。下面將討論如何進(jìn)行并行或分布式SGD,并行一般是指在同一機(jī)器上進(jìn)行多核并行,分布式是指集群處理。

  • Hogwild

    Niu[23]提出了被稱為Hogwild的并行SGD方法。該方法在多個(gè)CPU時(shí)間進(jìn)行并行。處理器通過(guò)共享內(nèi)存來(lái)訪問(wèn)參數(shù),并且這些參數(shù)不進(jìn)行加鎖。它為每一個(gè)cpu分配不重疊的一部分參數(shù)(分配互斥),每個(gè)cpu只更新其負(fù)責(zé)的參數(shù)。該方法只適合處理數(shù)據(jù)特征是稀疏的。該方法幾乎可以達(dá)到一個(gè)最優(yōu)的收斂速度,因?yàn)閏pu之間不會(huì)進(jìn)行相同信息重寫。

  • Downpour SGD

    Downpour SGD是Dean[4]提出的在DistBelief(Google TensorFlow的前身)使用的SGD的一個(gè)異步變種。它在訓(xùn)練子集上訓(xùn)練同時(shí)多個(gè)模型副本。這些副本將各自的更新發(fā)送到參數(shù)服務(wù)器(PS,parameter server),每個(gè)參數(shù)服務(wù)器只更新互斥的一部分參數(shù),副本之間不會(huì)進(jìn)行通信。因此可能會(huì)導(dǎo)致參數(shù)發(fā)散而不利于收斂。

  • Delay-tolerant Algorithms for SGD

    McMahan與Streeter[12]擴(kuò)展AdaGrad,通過(guò)開(kāi)發(fā)延遲容忍算法(delay-tolerant algorithms),該算法不僅自適應(yīng)過(guò)去梯度,并且會(huì)更新延遲。該方法已經(jīng)在實(shí)踐中表明是有效的。

  • TensorFlow

    TensorFlow[13]是Google開(kāi)源的一個(gè)大規(guī)模機(jī)器學(xué)習(xí)庫(kù),它的前身是DistBelief。它已經(jīng)在大量移動(dòng)設(shè)備上或者大規(guī)模分布式集群中使用了,已經(jīng)經(jīng)過(guò)了實(shí)踐檢驗(yàn)。其分布式實(shí)現(xiàn)是基于圖計(jì)算,它將圖分割成多個(gè)子圖,每個(gè)計(jì)算實(shí)體作為圖中的一個(gè)計(jì)算節(jié)點(diǎn),他們通過(guò)Rend/Receive來(lái)進(jìn)行通信。具體參見(jiàn)這里。

  • Elastic Averaging SGD

    Zhang等[14]提出Elastic Averaging SGD(EASGD),它通過(guò)一個(gè)elastic force(存儲(chǔ)參數(shù)的參數(shù)服務(wù)器中心)來(lái)連接每個(gè)work來(lái)進(jìn)行參數(shù)異步更新。This allows the local variables to fluctuate further from the center variable, which in theory allows for more exploration of the parameter space. They show empirically that this increased capacity for exploration leads to improved performance by finding new local optima. 這句話不太懂,需要去看論文。

<a name="t12" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>更多的SGD優(yōu)化策略

接下來(lái)介紹更多的SGD優(yōu)化策略來(lái)進(jìn)一步提高SGD的性能。另外還有眾多其它的優(yōu)化策略,可以參見(jiàn)[22]

  • Shuffling and Curriculum Learning

    為了使得學(xué)習(xí)過(guò)程更加無(wú)偏,應(yīng)該在每次迭代中隨機(jī)打亂訓(xùn)練集中的樣本。

    另一方面,在很多情況下,我們是逐步解決問(wèn)題的,而將訓(xùn)練集按照某個(gè)有意義的順序排列會(huì)提高模型的性能和SGD的收斂性,如何將訓(xùn)練集建立一個(gè)有意義的排列被稱為Curriculum Learning[16]。

    Zaremba與Sutskever[17]在使用Curriculum Learning來(lái)訓(xùn)練LSTMs以解決一些簡(jiǎn)單的問(wèn)題中,表明一個(gè)相結(jié)合的策略或者混合策略比對(duì)訓(xùn)練集按照按照訓(xùn)練難度進(jìn)行遞增排序要好。(表示不懂,衰)

  • Batch normalization

    為了方便訓(xùn)練,我們通常會(huì)對(duì)參數(shù)按照0均值1方差進(jìn)行初始化,隨著不斷訓(xùn)練,參數(shù)得到不同程度的更新,這樣這些參數(shù)會(huì)失去0均值1方差的分布屬性,這樣會(huì)降低訓(xùn)練速度和放大參數(shù)變化隨著網(wǎng)絡(luò)結(jié)構(gòu)的加深。

    Batch normalization[18]在每次mini-batch反向傳播之后重新對(duì)參數(shù)進(jìn)行0均值1方差標(biāo)準(zhǔn)化。這樣可以使用更大的學(xué)習(xí)速率,以及花費(fèi)更少的精力在參數(shù)初始化點(diǎn)上。Batch normalization充當(dāng)著正則化、減少甚至消除掉Dropout的必要性。

  • Early stopping

    在驗(yàn)證集上如果連續(xù)的多次迭代過(guò)程中損失函數(shù)不再顯著地降低,那么應(yīng)該提前結(jié)束訓(xùn)練,詳細(xì)參見(jiàn)NIPS 2015 Tutorial slides,或者參見(jiàn)防止過(guò)擬合的一些方法。

  • Gradient noise

    Gradient noise[21]即在每次迭代計(jì)算梯度中加上一個(gè)高斯分布

    <nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">N

    (

    0

    ,

    σ

    2

    t

    )</nobr>

    的隨機(jī)誤差,即

    <nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">g

    t

    ,

    i

    =

    g

    t

    ,

    i

    N

    (

    0

    ,

    σ

    2

    t

    )</nobr>

    高斯誤差的方差需要進(jìn)行退火:

    <nobr style="box-sizing: border-box; transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px; line-height: normal; text-decoration: none; white-space: nowrap !important;">σ

    2

    t

    =

    η

    (

    1

    t

    )

    γ</nobr>

    對(duì)梯度增加隨機(jī)誤差會(huì)增加模型的魯棒性,即使初始參數(shù)值選擇地不好,并適合對(duì)特別深層次的負(fù)責(zé)的網(wǎng)絡(luò)進(jìn)行訓(xùn)練。其原因在于增加隨機(jī)噪聲會(huì)有更多的可能性跳過(guò)局部極值點(diǎn)并去尋找一個(gè)更好的局部極值點(diǎn),這種可能性在深層次的網(wǎng)絡(luò)中更常見(jiàn)。

<a name="t13" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>總結(jié)

在上文中,對(duì)梯度下降算法的三種框架進(jìn)行了介紹,并且mini-batch梯度下降是使用最廣泛的。隨后,我們重點(diǎn)介紹了SGD的一些優(yōu)化方法:Momentum、NAG、Adagrad、Adadelta、RMSprop與Adam,以及一些異步SGD方法。最后,介紹了一些提高SGD性能的其它優(yōu)化建議,如:訓(xùn)練集隨機(jī)洗牌與課程學(xué)習(xí)(shuffling and curriculum learning)、batch normalization,、early stopping與Gradient noise。

希望這篇文章能給你提供一些關(guān)于如何使用不同的梯度優(yōu)化算法方面的指導(dǎo)。如果還有更多的優(yōu)化建議或方法還望大家提出來(lái)?或者你使用什么技巧和方法來(lái)更好地訓(xùn)練SGD可以一起交流?Thanks。

<a name="t14" style="box-sizing: border-box; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: normal; outline: none; background: transparent;"></a>引用

[1] Sutton, R. S. (1986). Two problems with backpropagation and other steepest-descent learning procedures for networks. Proc. 8th Annual Conf. Cognitive Science Society.

[2] Qian, N. (1999). On the momentum term in gradient descent learning algorithms. Neural Networks : The Official Journal of the International Neural Network Society, 12(1), 145–151.

http://doi.org/10.1016/S0893-6080(98)00116-6.

[3] Duchi, J., Hazan, E., & Singer, Y. (2011). Adaptive Subgradient Methods for Online Learning and Stochastic Optimization. Journal of Machine Learning Research, 12, 2121–2159. Retrieved fromhttp://jmlr.org/papers/v12/duchi11a.html.

[4] Dean, J., Corrado, G. S., Monga, R., Chen, K., Devin, M., Le, Q. V, … Ng, A. Y. (2012). Large Scale Distributed Deep Networks. NIPS 2012: Neural Information Processing Systems, 1–11.

http://doi.org/10.1109/ICDAR.2011.95.

[5] Pennington, J., Socher, R., & Manning, C. D. (2014). Glove: Global Vectors for Word Representation. Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing, 1532–1543.http://doi.org/10.3115/v1/D14-1162.

[6] Zeiler, M. D. (2012). ADADELTA: An Adaptive Learning Rate Method. Retrieved fromhttp://arxiv.org/abs/1212.5701.

[7] Nesterov, Y. (1983). A method for unconstrained convex minimization problem with the rate of convergence o(1/k2). Doklady ANSSSR (translated as Soviet.Math.Docl.), vol. 269, pp. 543– 547.

[8] Bengio, Y., Boulanger-Lewandowski, N., & Pascanu, R. (2012). Advances in Optimizing Recurrent Networks. Retrieved from

http://arxiv.org/abs/1212.0901.

[9] Sutskever, I. (2013). Training Recurrent neural Networks. PhD Thesis.

[10] Darken, C., Chang, J., & Moody, J. (1992). Learning rate schedules for faster stochastic gradient search. Neural Networks for Signal Processing II Proceedings of the 1992 IEEE Workshop, (September), 1–11.http://doi.org/10.1109/NNSP.1992.253713.

[11] H. Robinds and S. Monro, “A stochastic approximation method,” Annals of Mathematical Statistics, vol. 22, pp. 400–407, 1951.

[12] Mcmahan, H. B., & Streeter, M. (2014). Delay-Tolerant Algorithms for Asynchronous Distributed Online Learning. Advances in Neural Information Processing Systems (Proceedings of NIPS), 1–9. Retrieved fromhttp://papers.nips.cc/paper/5242-delay-tolerant-algorithms-for-asynchronous-distributed-online-learning.pdf.

[13] Abadi, M., Agarwal, A., Barham, P., Brevdo, E., Chen, Z., Citro, C., … Zheng, X. (2015). TensorFlow : Large-Scale Machine Learning on Heterogeneous Distributed Systems.

[14] Zhang, S., Choromanska, A., & LeCun, Y. (2015). Deep learning with Elastic Averaging SGD. Neural Information Processing Systems Conference (NIPS 2015), 1–24. Retrieved from

http://arxiv.org/abs/1412.6651.

[15] Kingma, D. P., & Ba, J. L. (2015). Adam: a Method for Stochastic Optimization. International Conference on Learning Representations, 1–13

[16] Bengio, Y., Louradour, J., Collobert, R., & Weston, J. (2009). Curriculum learning. Proceedings of the 26th Annual International Conference on Machine Learning, 41–48.

http://doi.org/10.1145/1553374.1553380.

[17] Zaremba, W., & Sutskever, I. (2014). Learning to Execute, 1–25. Retrieved fromhttp://arxiv.org/abs/1410.4615.

[18] Ioffe, S., & Szegedy, C. (2015). Batch Normalization : Accelerating Deep Network Training by Reducing Internal Covariate Shift. arXiv Preprint arXiv:1502.03167v3.

[19] Dauphin, Y., Pascanu, R., Gulcehre, C., Cho, K., Ganguli, S., & Bengio, Y. (2014). Identifying and attacking the saddle point problem in high-dimensional non-convex optimization. arXiv, 1–14. Retrieved fromhttp://arxiv.org/abs/1406.2572.

[20] Sutskever, I., & Martens, J. (2013). On the importance of initialization and momentum in deep learning.http://doi.org/10.1109/ICASSP.2013.6639346.

[21] Neelakantan, A., Vilnis, L., Le, Q. V., Sutskever, I., Kaiser, L., Kurach, K., & Martens, J. (2015). Adding Gradient Noise Improves Learning for Very Deep Networks, 1–11. Retrieved from

http://arxiv.org/abs/1511.06807.

[22] LeCun, Y., Bottou, L., Orr, G. B., & Müller, K. R. (1998). Efficient BackProp. Neural Networks: Tricks of the Trade, 1524, 9–50.

http://doi.org/10.1007/3-540-49430-8_2.

[23] Niu, F., Recht, B., Christopher, R., & Wright, S. J. (2011). Hogwild ! : A Lock-Free Approach to Parallelizing Stochastic Gradient Descent, 1–22.

[24] Duchi et al. [3] give this matrix as an alternative to the full matrix containing the outer products of all previous gradients, as the computation of the matrix square root is infeasible even for a moderate number of parameters dd.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 轉(zhuǎn)載-劉建平Pinard-www.cnblogs.com/pinard/p/5970503.html 在求解機(jī)器學(xué)...
    商三郎閱讀 3,609評(píng)論 0 2
  • AI人工智能時(shí)代,機(jī)器學(xué)習(xí),深度學(xué)習(xí)作為其核心,本文主要介紹機(jī)器學(xué)習(xí)的基礎(chǔ)算法,以詳細(xì)線介紹 線性回歸算法 及其 ...
    erixhao閱讀 14,194評(píng)論 0 36
  • 梯度下降法或最速下降法是求解無(wú)約束最優(yōu)化問(wèn)題的一種最常用的方法,梯度下降法是迭代算法,每一步需要求解目標(biāo)函數(shù)的梯度...
    文哥的學(xué)習(xí)日記閱讀 2,551評(píng)論 0 4
  • 前言 梯度下降算法現(xiàn)在變的越來(lái)越流行,但是對(duì)于使用者來(lái)說(shuō),它的優(yōu)化過(guò)程變的越來(lái)越黑盒。本文我們介紹下不通梯度下降算...
    wendaJ閱讀 1,645評(píng)論 0 1
  • 什么是優(yōu)化算法 優(yōu)化算法要求解的,是一個(gè)問(wèn)題的最優(yōu)解或者近似最優(yōu)解。在機(jī)器學(xué)習(xí)中,有很多問(wèn)題都是優(yōu)化問(wèn)題,即我們要...
    刺猬ciwei_532a閱讀 2,238評(píng)論 0 7

友情鏈接更多精彩內(nèi)容