【深度学习基础】第十九课:Adam优化算法
【深度学习基础】系列博客为学习Coursera上吴恩达深度学习课程所做的课程笔记。
【深度学习基础】系列博客为学习Coursera上吴恩达深度学习课程所做的课程笔记。
1.Adam优化算法
Adam优化算法(Adaptive Moment Estimation)和RMSprop、Momentum梯度下降法是被广泛应用并且经受了大量考验的优化算法,适用于不同的深度学习结构。
Adam优化算法实际上就是将RMSprop和Momentum结合在一起。
接下来看下Adam优化算法的详细步骤:
- 初始化: V d w = 0 , S d w = 0 , V d b = 0 , S d b = 0 V_{dw}=0,S_{dw}=0,V_{db}=0,S_{db}=0 Vdw=0,Sdw=0,Vdb=0,Sdb=0
- On iteration t:
- Compute d w , d b dw,db dw,db using current mini-batch
- V d w = β 1 V d w + ( 1 − β 1 ) d w ; V d b = β 1 V d b + ( 1 − β 1 ) d b V_{dw}=\beta _1 V_{dw}+(1-\beta_1)dw;V_{db}=\beta _1 V_{db}+(1-\beta_1)db Vdw=β1Vdw+(1−β1)dw;Vdb=β1Vdb+(1−β1)db
- S d w = β 2 S d w + ( 1 − β 2 ) ( d w ) 2 ; S d b = β 2 S d b + ( 1 − β 2 ) ( d b ) 2 S_{dw}=\beta_2 S_{dw}+(1-\beta_2)(dw)^2;S_{db}=\beta_2 S_{db}+(1-\beta_2)(db)^2 Sdw=β2Sdw+(1−β2)(dw)2;Sdb=β2Sdb+(1−β2)(db)2
- V d w c o r r e c t e d = V d w / ( 1 − β 1 t ) ; V d b c o r r e c t e d = V d b / ( 1 − β 1 t ) V^{corrected}_{dw}=V_{dw}/(1-\beta _1^t);V^{corrected}_{db}=V_{db}/(1-\beta_1 ^t) Vdwcorrected=Vdw/(1−β1t);Vdbcorrected=Vdb/(1−β1t)
- S d w c o r r e c t e d = S d w / ( 1 − β 2 t ) ; S d b c o r r e c t e d = S d b / ( 1 − β 2 t ) S^{corrected}_{dw}=S_{dw}/(1-\beta _2^t);S^{corrected}_{db}=S_{db}/(1-\beta_2 ^t) Sdwcorrected=Sdw/(1−β2t);Sdbcorrected=Sdb/(1−β2t)
- w : = w − α V d w c o r r e c t e d S d w c o r r e c t e d + ϵ ; b : = b − α V d b c o r r e c t e d S d b c o r r e c t e d + ϵ w:=w-\alpha \frac{V^{corrected}_{dw}}{\sqrt{S^{corrected}_{dw}}+\epsilon};b:=b-\alpha \frac{V^{corrected}_{db}}{\sqrt{S^{corrected}_{db}}+\epsilon} w:=w−αSdwcorrected+ϵVdwcorrected;b:=b−αSdbcorrected+ϵVdbcorrected
Adam算法涉及很多超参数:
- α \alpha α:学习率,需要自行尝试得到合适的值。
- β 1 \beta_1 β1:常用的值是0.9。
- β 2 \beta_2 β2:Adam算法的发明者推荐使用0.999。
- ϵ \epsilon ϵ:Adam算法的发明者建议为 1 0 − 8 10^{-8} 10−8。
其中超参数 β 1 , β 2 , ϵ \beta_1,\beta_2,\epsilon β1,β2,ϵ通常使用推荐值即可,没有调整的必要,对结果影响不大。
后续提出的AdamW则可用来解决Adam优化器中L2正则化失效的问题。Adam算法参数更新的计算公式如下(和上面是一样的,只是换了种表示方式):
t = t + 1 t=t+1 t=t+1
m o m e n t _ 1 _ o u t = β 1 ∗ m o m e n t _ 1 + ( 1 − β 1 ) ∗ g r a d moment\_1\_out = \beta _1 * moment\_1 + (1-\beta _1) * grad moment_1_out=β1∗moment_1+(1−β1)∗grad
m o m e n t _ 2 _ o u t = β 2 ∗ m o m e n t _ 2 + ( 1 − β 2 ) ∗ g r a d ∗ g r a d moment\_2\_out = \beta_2 * moment\_2 + (1-\beta_2) * grad * grad moment_2_out=β2∗moment_2+(1−β2)∗grad∗grad
l e a r n i n g _ r a t e = l e a r n i n g _ r a t e ∗ 1 − β 2 t 1 − β 1 t learning\_rate = learning\_rate * \frac{\sqrt{1-\beta_2^t}}{1-\beta_1^t} learning_rate=learning_rate∗1−β1t1−β2t
p a r a m _ o u t = p a r a m − l e a r n i n g _ r a t e ∗ m o m e n t _ 1 m o m e n t _ 2 + ϵ param\_out = param - learning\_rate * \frac{moment\_1}{\sqrt{moment\_2} + \epsilon} param_out=param−learning_rate∗moment_2+ϵmoment_1
AdamW算法参数更新的计算公式如下:
t = t + 1 t =t +1 t=t+1
m o m e n t _ 1 _ o u t = β 1 ∗ m o m e n t _ 1 + ( 1 − β 1 ) ∗ g r a d moment\_1\_out = \beta_1 * moment\_1 + (1 - \beta_1) * grad moment_1_out=β1∗moment_1+(1−β1)∗grad
m o m e n t _ 2 _ o u t = β 2 ∗ m o m e n t _ 2 + ( 1 − β 2 ) ∗ g r a d ∗ g r a d moment\_2\_out = \beta_2 * moment\_2 + (1-\beta_2) * grad * grad moment_2_out=β2∗moment_2+(1−β2)∗grad∗grad
l e a r n i n g _ r a t e = l e a r n i n g _ r a t e ∗ 1 − β 2 t 1 − β 1 t learning\_rate = learning\_rate * \frac{\sqrt{1-\beta_2^t}}{1-\beta_1^t} learning_rate=learning_rate∗1−β1t1−β2t
p a r a m _ o u t = p a r a m − l e a r n i n g _ r a t e ∗ ( m o m e n t _ 1 m o m e n t _ 2 + ϵ + λ ∗ p a r a m ) param\_out = param - learning\_rate * ( \frac{moment\_1}{\sqrt{moment\_2} + \epsilon} + \lambda * param ) param_out=param−learning_rate∗(moment_2+ϵmoment_1+λ∗param)
2.参考资料
想要获取最新文章推送或者私聊谈人生,请关注我的个人微信公众号:⬇️x-jeff的AI工坊⬇️
个人博客网站:https://shichaoxin.com
GitHub:https://github.com/x-jeff
更多推荐
所有评论(0)