optimization problem
Tip 1: Tuning your Learning rates
- 1 small 如果步伐非常小 训练的时间会非常长。
- 2 large 如果步伐非常大 没有办法走到最低点。会在一个范围震荡
- 3 very large 如果步伐太大 loss很快就飞出去了。
visionlize loss 和 参数更新的关系。
- 1 learning rate 太小 loss下降非常慢
- 2 lerning rate 太大 loss下降非常快 但是很快就卡住。
- 3 learning rate 特别大 loss很快就飞出去了。
在做梯度下降的时候,最好把这个图画出来。否则你不知道这个梯度下降在哪里坏掉了。
Adaptive Learning Rates
Popular & Simple Idea: Reduce the learning rate by some factor every few epochs.
通常leaning rate 随着参数的update会减小。
- At the beginning, we are far from the destination, so we use larger learning rate(刚开始的时候,离最低点比较远,所以你的步伐需要大一点。)
- After several epochs, we are close to the destination, so we reduce the learning rate(经过几次更新之后呢,已经比较靠近目标了,这时候就应该减小learning rate)
- eg
Learning rate cannot be one-size-fits-all
Giving different parameters different learning rates
不同的参数有不同的learning rate)
Adagrad
分母 使参数更新更慢 ,分子使参数更新更快。
最好的step 和一次微分成正比,和二次微分成反比。
“一次微分的平方和开根号代表了二次微分。
Tip2: Stochastic Gradient Descent
如果你现在是在做deep learning 的 case 也就是你的error surface 不是compex 是非常崎岖的。随机取呢是有帮助的。你只算一个example 的loss。
看一个example,就更新一次参数。参数更新的更快。
Tip3 Feature Scaling
Make different features have the same scaling
不同的feature 有不同的范围。要对feature做缩放。
不会向最低点走,而是想着等高线的法线方向去走。
Gradient Descent Theory
在利用梯度下降法(GD)求解损失函数时,参数更新后,Loss不一定下降
Warning of math
Taylor Series (泰勒级数)
when x is close to x0,x-x_0远大于后面的高次项,所以就可以把后面的高次项忽略。
Multivariable Taylor Series
when x is close to x0 y is close to y0
If the red circle is small enough, in the red circle
圆圈足够小。
constant(常量)
做向量乘积。
1 我们可以用这个方法找一个最小值,前提是泰勒展开式成立。理论上学习率要无穷小才能保证Loss越来越小。如果你的learning rate 没有设好,导致泰勒展开不成立,所以loss不一定会变小。
2我们只考虑了泰勒级数里的一次式,如果我们把二次式考虑进来,会多很多运算,而这个运算是无法承受的。用这个运算来换更新参数的效率是不划算的。(eg:deep learning)
在做deep learining的时候 考虑二次项的话,你用对二次项的运算来换取learining rate。这个是不划算的,通常是承受不了的。
More Limitation of Gradient Descent
- stuck at local minima 微分等于0
- stuck at saddle point 比较平滑的地方 微分约等于0
- very slow at the plateau 微分等于0