Improving Deep Neural Networks学习笔记(二)

来源:互联网 发布:合泰触摸单片机芯片 编辑:程序博客网 时间:2024/05/16 12:10

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

4. Optimization algorithms

4.1 Mini-batch gradient descent

xtyt is used to index into different mini batches. x[t]y[t] is used to index into different layer. x(t)y(t) is used to index into different examples.

Batch gradient descent is to process entire training set at the same time. Mini-batch gradient descent is to process single mini batch xtyt at the same time.

Run forward propagation and back propagation once on mini batch is called one iteration.

Mini-batch gradient descent runs much faster than batch gradient descent.

4.2 Understanding mini-batch gradient descent

If mini-batch size = m, it’s batch gradient descend.
If mini-batch size = 1, it’s stochastic gradient descend.
In pracice, mini-batch size between 1 and m.

Batch gradient descend: too long per iteration.
Stochastic gradient descend: lose speed up from vectorization.
Mini-batch gradient descend: Faster learning, 1. vectorization 2. Make progress without needing to wait.

Choosing mini-batch size:

If small training set(m <= 2000), use batch gradient descend.
Typical mini-batch size: 64, 128, 256, 512, 1024(rare).

4.3 Exponentially weighted averages

Vt=βVt1+(1β)θt

View Vt as approximately averaging over 11β.

It’s called moving average in the statistics literature.

β=0.9

Figure 1

β=0.9(red)β=0.98(green)β=0.5(yellow)

Figure 2

4.4 Understanding exponentially weighted averages

θ is the temperature of the day.

v100=0.9v99+0.1θ100
v99=0.9v98+0.1θ99
...

So

v100=0.1\*θ100+0.1\*0.9\*θ99+...+0.1\*0.9i\*θ100i+...

Th coefficients is

0.1+0.1\*0.9+0.1\*0.92+...

All of these coefficients, add up to one or add up to very close to one. It is called bias correction.

(1ϵ)1ϵ1e
1e0.3679

Implement exponentially weighted average:

v0=0
v1=βv0+(1β)θ1
v2=βv1+(1β)θ2
...

Exponentially weighted average takes very low memory.

4.5 Bias correction in exponentially weighted averages

It’s not a very good estimate of the first several day’s temperature. Bias correction is used to mofity this estimate that makes it much better. The formula is:

vt1βt=βvt1+(1β)θt.

4.6 Gradient descent with momentum

Gradient descent with momentum almost always works faster than the standard gradient descent algorithm. The basic idea is to compute an exponentially weighted average of gradients, and then use that gradient to update weights instead.

On iteration t:

  1. compute dw, db on current mini-batch.
  2. compute vdw, vdb
    vdw=βvdw+(1β)dw
    vdb=βvdb+(1β)db
  3. update dw, db
    w=wαvdw
    b=bαvdb

There are two hyperparameters, the most common value for β is 0.9.

Another formula is vdw=βvdw+dw, you need to modify corresponding α.

4.7 RMSprop

RMSprop stands for root mean square prop, that can also speed up gradient descent.

On iteration t:

  1. compute dw, db on current mini-batch.
  2. compute sdw, sdb
    sdw=βsdw+(1β)dw2
    sdb=βsdb+(1β)db2
  3. update dw, db
    w=wαdwsdw
    b=bαdbsdb

In practice, in order to avoid sdw being very close zero:

w=wαdwsdw+ϵ
b=bαdbsdb+ϵ

Usually

ϵ=108

4.8 Adam optimization algorithm

vdw=0,sdw=0,vdb,sdb=0

On iteration t:

vdw=β1vdw+(1β1)dw
vdb=β1vdb+(1β1)db

sdw=β2sdw+(1β2)dw2
sdb=β2sdb+(1β2)db2

Bias correction:

vbcdw=vdw1βt1,vbcdb=vdb1βt1
sbcdw=sdw1βt2,sbcdb=sdb1βt2

Update weight:

w=wαvbcdwsbcdw+ϵ
b=bαvbcdbsbcdb+ϵ

Adam combines the effect of gradient descent with momentum together with gradient descent with RMSprop. It’s a commonly used learning algorithm that is proven to be very effective for many different neural networks of a very wide variety of architectures.\

α needs to be tuned. β1=0.9, β2=0.999, ϵ=108.

Adam stands for Adaptive Moment Estimation.

4.9 Learning rate decay

Learning rate decay is slowly reduce the learning rate.

α=11+decayrate\*epochsα0

α0 is the initial learning rate.

Other learning rate decay methods:

α=0.95epochsα0, this is called exponentially decay.

α=kepochsα0, α=ktα0.

α=12epochsα0, this is called a discrete staircase.

4.10 The problem of local optima

In very high-dimensional spaces you’re actually much more likely to run into a saddle point, rather than local optimum.

  • Unlikely to get stuck in a bad local optima.
  • Plateaus can make learning slow.
阅读全文
0 0
原创粉丝点击