【吴恩达深度学习】测试2-2总结:优化算法

Mini-batch

  1. [i] {j} (k)上标分别表示 第i层,第j小块,第k个示例

  2. 优点:

  • 能够进行向量化。
  • 不用等整个数据集都计算后再梯度下降,单次迭代耗时短。

指数加权平均

  1. V t = β V t − 1 + ( 1 − β ) θ t V_t=\beta V_{t-1}+(1-\beta)\theta_t Vt=βVt1+(1β)θt (平均过去 1 1 − β \frac{1}{1-\beta} 1β1天的数据)
  2. β \beta β越大,曲线越平稳,也会稍微右移。
  3. 优点:占用极少内存,只用一行代码,不断更新 V V V值。
  4. 偏差修正: V t c o r r e c t e d = V t 1 − β t V_t^{corrected}=\frac{V_t}{1-\beta^t} Vtcorrected=1βtVt
    早期需要好的估测来修正,随着 t t t的增大, β t \beta^t βt逐渐趋于 0 0 0,修正也不再起作用。

Momentum

(Gradient descent with momentum)动量梯度下降法

  1. 基本思路:计算梯度的指数加权平均值,更新权重,加速梯度下降。
    上下摆动正负抵消,摆动变小,横轴平均值还很大,因此运动更快。
  2. V d θ = β V d θ = + ( 1 − β ) d θ V_{d\theta}=\beta V_{d\theta}=+(1-\beta)d\theta Vdθ=βVdθ=+(1β)dθ
    θ = θ − α V d θ \theta=\theta-\alpha V_{d\theta} θ=θαVdθ
    β = 0.9 \beta=0.9 β=0.9 (一般固定,平均前十次迭代)
    β \beta β越大,上下摆动越小。
  3. 不用偏差修正,10次迭代后已经过了初始阶段,基本无偏差。
  4. 想象成小球从坡上往下滚。小球的动量越来越大,过最低点后仍然会往前冲。

RMSprop

(root mean square propagation) 均方根反向传播

  1. S d θ = β S d θ = + ( 1 − β ) d 2 θ S_{d\theta}=\beta S_{d\theta}=+(1-\beta)d^2\theta Sdθ=βSdθ=+(1β)d2θ

    θ = θ − α d θ S d θ + ϵ \theta=\theta-\alpha\frac{d\theta}{\sqrt{S_{d\theta}}+\epsilon} θ=θαSdθ +ϵdθ

    ϵ = 1 0 − 8 \epsilon=10^{-8} ϵ=108 (使稳定,不为0)

  2. 纵轴斜率大,因此除以一个大的数,会减缓纵轴摆动;
    横轴斜率小,因此除以一个小的数,会加速梯度下降。

Adam 优化算法

Adaptive Moment Estimation 自适应矩估计

  1. 结合Momentum and RMSprop

  2. V d θ = β 1 V d θ = + ( 1 − β 1 ) d θ V_{d\theta}=\beta_1 V_{d\theta}=+(1-\beta_1)d\theta Vdθ=β1Vdθ=+(1β1)dθ
    S d θ = β 2 S d θ = + ( 1 − β 2 ) d 2 θ S_{d\theta}=\beta_2 S_{d\theta}=+(1-\beta_2)d^2\theta Sdθ=β2Sdθ=+(1β2)d2θ

    V d θ c o r r e c t e d = V d θ 1 − β 1 t V_{d\theta}^{corrected}=\frac{V_{d\theta}}{1-\beta_1^t} Vdθcorrected=1β1tVdθ

    S d θ c o r r e c t e d = S d θ 1 − β 2 t S_{d\theta}^{corrected}=\frac{S_{d\theta}}{1-\beta_2^t} Sdθcorrected=1β2tSdθ

    θ = θ − α V d θ c o r r e c t e d S d θ c o r r e c t e d + ϵ \theta=\theta-\alpha\frac{V_{d\theta}^{corrected}}{\sqrt{S_{d\theta}^{corrected}}+\epsilon} θ=θαSdθcorrected +ϵVdθcorrected

    β 1 = 0.9 \beta_1=0.9 β1=0.9, β 2 = 0.999 \beta_2=0.999 β2=0.999, ϵ = 1 0 − 8 \epsilon=10^{-8} ϵ=108

学习率衰减

1 epoch:遍历一次整个数据集
1 iteration:遍历batchsize的数据,进行一次梯度下降
学习开始可以承受较大的步伐,但开始收敛时,要减小步伐,因此需要学习率衰减。

α = 1 1 + d e c a y − r a t e ∗ e p o c h − n u m α 0 \alpha=\frac{1}{1+decay-rate*epoch-num}\alpha_0 α=1+decayrateepochnum1α0

α = 0.9 5 e p o c h − n u m α 0 \alpha=0.95^{epoch-num}\alpha_0 α=0.95epochnumα0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值