Optimization Algorithm

Optimization Algorithm

Some Source From: deeplearning.ai

GD、SGD和Mini-Batch Gradient Descent

三者关系,

SGDMiniBatch Gradient DescentGD

GD是针对所有样本计算梯度,SGD是随机抽取一个样本计算梯度,Mini-Batch Gradient Descent则是折中地抽取部分样本计算梯度。同时由于SGD是最小化单个样本的损失函数,并不是朝着全局最优方向,因此波动较大,Batch-GD虽然精度高,但是在样本量过大的情况下,计算量会过大。

Mini-Batch Gradient Descent

  1. 从训练集抽取 m 个大小的Batch样本{x(1),...,x(m)}
  2. 梯度估计
    g^1mθiL(f(x(i)),y(i))
  3. 更新
    θθϵg^

    在Mini-Batch Gradient Descent中由于随机采样引入的噪源1,其梯度估计并不会在极小值处小时,而使用全部样本时梯度下降到极小值时,整个代价函数的真实梯度也会变得很小甚至为0,因此Batch-GD下降可以使用固定的学习速率。实践中,一般会线性衰减学习速率到第 τ 次迭代:
    ϵk=(1α)ϵ0+αϵτα=kτ

    其中参数选择为 ϵ0,ϵτ,τ ,通常 τ 被设为反复遍历训练样本所需的迭代次数, ϵτ 设为 1% ϵ0 。主要问题是如何设置 ϵ0 ,若 ϵ0 太大,学习曲线将会剧烈振荡,代价函数会明显增加,如果学习速率太慢,那么学习进程会缓慢。如果初始学习速率太低,那么学习可能会卡在一个相当高的损失值。通常,就总训练时间和最终损失值而言,最优初始学习速率会高于大约迭代100步后输出最好效果的学习速率。因此,通常最好是检测最早的几轮迭代,使用一个高于此时效果最佳学习速率的学习速率,但又不能太高以致严重的不稳定性。在文献2 3中对随机梯度下降有更详细的分析.

mini-batch size

  • Small data set( size < 2000 ) : use batch gradient descent
  • Typical mini-batch size : 64, 128, 256, … ( 2n better )
  • Make sure mini-batch size fits in CPU/GPU memory
  • Search for the much better number about the hyper parameter

Some algorithms faster than gradient descent

Exponentially weighted averages

Original data : θt

Vt=αVt+1+(1α)θt

Means
Vt11αi=t11αtθi

Much better Computarion and memory efficiency, but the effect of the ordinary average is better.

Bias Correction

To correct the preceding value on the warmed up,

Vt=Vt1αt

Gradient descent with momentum

On iteration t :
Compute dw,db on batch(minibatch)

Vdw=αVdw+(1α)dww=wαVdw

Decrease the wave, speed up toward the optimal( could use larger learning rate )

RMSprop

RMSprop(root mean square )

On iteration t :
Compute dw,db on batch(mini-batch)

Sdw=αSdw+(1α)(dw)2w=wαSdwSdw

the effect same as momentum
Avoid dividing by 0

Adam

Adam means adaptive moment estimation

Combine momentum and RMSprop together

On iteration t :
Compute dw,db on batch(mini-batch)

Vdw=α1Vdw+(1α1)dwSdw=α2Sdw+(1α2)(dw)2Vdw=Vdw1αt1Sdw=Sdw1αt2w=wβVdwSdw+ϵ

Hyperparameters choice

β:needs to be tuneα1:0.9α2:0.999ϵ:108

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值