梯度下降法推导与改进
符号说明
x
,
x
0
,
x
t
,
△
x
\textbf{x},\textbf{x}_0,\textbf{x}_t,\triangle\textbf{x}
x,x0,xt,△x都是nx1的列向量。
x
t
,
i
\textbf{x}_{t,i}
xt,i代表向量
x
t
\textbf{x}_t
xt的第i个元素,是个常量。
f
(
x
)
f(\textbf{x})
f(x)为
x
\textbf{x}
x的函数,是一个常量。
基本思想
梯度下降法的基本思想非常简单,想象一下自己在一个盆地中,现在需要进入到盆地最底部,那么最简单的方式就是一直往下走,直到不能再向下走为止,此时就到达了盆地最底部。那么对于一个复杂的函数而言,找到一个合适的公式去描述这一简单的思想,就可以求出函数的极小值位置了。
算法推导
高维函数带有佩亚诺余项的一阶泰勒展开式如下
f
(
x
)
=
f
(
x
0
)
+
▽
f
(
x
0
)
T
(
x
−
x
0
)
+
o
(
∣
∣
x
−
x
0
∣
∣
)
f(\textbf{x})=f(\textbf{x}_0)+\triangledown{f(\textbf{x}_0)}^T(\textbf{x}-\textbf{x}_0)+o(||\textbf{x}-\textbf{x}_0||)
f(x)=f(x0)+▽f(x0)T(x−x0)+o(∣∣x−x0∣∣)
令
x
=
x
0
+
△
x
\textbf{x}=\textbf{x}_0+\triangle{\textbf{x}}
x=x0+△x
f
(
x
0
+
△
x
)
−
f
(
x
0
)
=
▽
f
(
x
0
)
T
△
x
+
o
(
∣
∣
△
x
∣
∣
)
f(\textbf{x}_0+\triangle{\textbf{x}})-f(\textbf{x}_0)=\triangledown{f(\textbf{x}_0)}^T\triangle{}\textbf{x}+o(||\triangle{}\textbf{x}||)
f(x0+△x)−f(x0)=▽f(x0)T△x+o(∣∣△x∣∣)
假设
x
0
\textbf{x}_0
x0处是极小值位置
那么下式成立
lim
∣
∣
△
x
∣
∣
→
0
f
(
x
0
+
△
x
)
−
f
(
x
0
)
>
0
(1.1)
\lim_{||\triangle{}\textbf{x}||\to 0}f(\textbf{x}_0+\triangle{\textbf{x}})-f(\textbf{x}_0)>0\tag{1.1}
∣∣△x∣∣→0limf(x0+△x)−f(x0)>0(1.1)
⟺
\iff
⟺
lim
∣
∣
△
x
∣
∣
→
0
▽
f
(
x
0
)
T
△
x
∣
∣
△
x
∣
∣
+
lim
△
x
→
0
o
(
∣
∣
△
x
∣
∣
)
∣
∣
△
x
∣
∣
>
0
(1.2)
\lim_{||\triangle{x}|| \to 0}\frac{\triangledown{f(\textbf{x}_0)}^T\triangle{}\textbf{x}}{||\triangle{\textbf{x}}||}+\lim_{\triangle{\textbf{x}}\to 0}\frac{o(||\triangle{\textbf{x}}||)}{||\triangle{\textbf{x}}||}>0\tag{1.2}
∣∣△x∣∣→0lim∣∣△x∣∣▽f(x0)T△x+△x→0lim∣∣△x∣∣o(∣∣△x∣∣)>0(1.2)
⟺
\iff
⟺
lim
∣
∣
△
x
∣
∣
→
0
▽
f
(
x
0
)
T
△
x
∣
∣
△
x
∣
∣
>
0
(1.3)
\lim_{||\triangle{x}|| \to 0}\frac{\triangledown{f(\textbf{x}_0)}^T\triangle{}\textbf{x}}{||\triangle{\textbf{x}}||}>0\tag{1.3}
∣∣△x∣∣→0lim∣∣△x∣∣▽f(x0)T△x>0(1.3)
⟺
\iff
⟺
lim
∣
∣
△
x
∣
∣
→
0
▽
f
(
x
0
)
T
△
x
>
0
(1.4)
\lim_{||\triangle{x}|| \to 0}\triangledown{f(\textbf{x}_0)}^T\triangle{}\textbf{x}>0\tag{1.4}
∣∣△x∣∣→0lim▽f(x0)T△x>0(1.4)
可以得到如果两个向量
▽
f
(
x
0
)
\triangledown{f{(\textbf{x}_0)}}
▽f(x0)与
△
x
\triangle{\textbf{x}}
△x同向那么满足推导(4),同样也满足公式(1)
lim
∣
∣
△
x
∣
∣
→
0
△
x
=
α
▽
f
(
x
0
)
,
α
>
0
\lim_{||\triangle{\textbf{x}||\to0}}\triangle{\textbf{x}}=\alpha{\triangledown{f(\textbf{x}_0)}},\alpha>{0}
∣∣△x∣∣→0lim△x=α▽f(x0),α>0
令
△
x
=
x
t
−
x
t
+
1
\triangle{\textbf{x}}=\textbf{x}_{t}-\textbf{x}_{t+1}
△x=xt−xt+1,若要使
▽
f
(
x
t
)
\triangledown{f(\textbf{x}_t)}
▽f(xt)与其同向,只需要一个可收敛的递推式(可收敛很重要)
x
t
−
x
t
+
1
=
α
▽
f
(
x
t
)
,
α
>
0
\textbf{x}_{t}-\textbf{x}_{t+1}=\alpha{\triangledown{f(\textbf{x}_t)}},\alpha>{0}
xt−xt+1=α▽f(xt),α>0
得到最终的梯度下降递推式如下
x
t
+
1
=
x
t
−
α
▽
f
(
x
t
)
,
α
>
0
,
t
=
1
,
2
,
3
,
⋯
(1.5)
\textbf{x}_{t+1}=\textbf{x}_{t}-\alpha{\triangledown{f(\textbf{x}_t)}},\alpha>{0},t=1,2,3,\cdots\tag{1.5}
xt+1=xt−α▽f(xt),α>0,t=1,2,3,⋯(1.5)
推导过程中假设条件为极小值,那么对于求极大值的情况常常在函数前面加一个负号,转换成求极小值的情况。
在应用中也会发现,有些存在极值的函数利用梯度下降无法求出极值,一般是
α
\alpha
α取值或者函数本身的问题导致递推式无法收敛。从推导过程中可以看出,如果这个递推式不收敛,那么就不会满足推导(4)从而无法利用这个方法求极值。
算法改进
Polysk’s Classical Momentum算法
简称为CM算法,可以加速梯度下降法,递推公式如下
x
t
+
1
=
x
t
+
v
t
+
1
(2.1)
\textbf{x}_{t+1}=\textbf{x}_t+\textbf{v}_{t+1}\tag{2.1}
xt+1=xt+vt+1(2.1)
v
t
+
1
=
u
v
t
−
α
▽
x
t
f
,
u
∈
[
0
,
1
)
(2.2)
\textbf{v}_{t+1}=u\textbf{v}_t-\alpha{\triangledown_{\textbf{x}_t}{f}},u\in{[0,1)}\tag{2.2}
vt+1=uvt−α▽xtf,u∈[0,1)(2.2)
利用公式(2.2)对公式(2,1)展开,
v
t
+
1
=
u
t
+
1
v
0
−
α
u
t
▽
x
0
f
−
α
u
t
−
1
▽
x
1
f
⋯
−
α
▽
x
t
f
(2.3)
\textbf{v}_{t+1}=\textbf{u}^{t+1}\textbf{v}_0-\alpha{\textbf{u}^{t}}{\triangledown_{\textbf{x}_0}{f}}-\alpha{\textbf{u}^{t-1}}{\triangledown_{\textbf{x}_1}{f}}\cdots-\alpha{{\triangledown_{\textbf{x}_t}{f}}}\tag{2.3}
vt+1=ut+1v0−αut▽x0f−αut−1▽x1f⋯−α▽xtf(2.3)
x
t
+
1
=
x
t
+
v
t
+
1
(2.4)
\textbf{x}_{t+1}=\textbf{x}_t+\textbf{v}_{t+1}\tag{2.4}
xt+1=xt+vt+1(2.4)
一般而言,
u
t
+
1
v
0
\textbf{u}^{t+1}\textbf{v}_0
ut+1v0(一般为0向量)对
v
t
+
1
\textbf{v}_{t+1}
vt+1的方向影响几乎可以忽略,若该递推式是收敛的,那么该公式满足递推(1.4),那么该递推式可以求出极值点,而且
v
t
+
1
\textbf{v}_{t+1}
vt+1变化量明显大于
−
α
▽
x
t
f
-\alpha{{\triangledown_{\textbf{x}_t}{f}}}
−α▽xtf所以当选取的初始迭代点
x
0
\textbf{x}_0
x0距离极值点较远时能够较快地达到收敛位置。但是缺点是会在即将到达收敛的时候在极值点附近来回震荡,所以也有可能导致更多的迭代步骤。

左侧为梯度下降法的迭代示例,右侧为CM算法迭代步骤。与之前的分析一致。
Nesterov’s Accelerated Gradient算法
简称为NAG算法,也可以对对梯度下降法进行加速,其递推式如下
x
t
+
1
=
x
t
+
v
t
+
1
(2.5)
\textbf{x}_{t+1}=\textbf{x}_t+\textbf{v}_{t+1}\tag{2.5}
xt+1=xt+vt+1(2.5)
v
t
+
1
=
u
v
t
−
α
▽
x
t
+
v
t
f
,
u
∈
[
0
,
1
)
(2.6)
\textbf{v}_{t+1}=u\textbf{v}_t-\alpha{\triangledown_{\textbf{x}_t+\textbf{v}_t}{f}},u\in{[0,1)}\tag{2.6}
vt+1=uvt−α▽xt+vtf,u∈[0,1)(2.6)
与CM算法相比,求梯度的位置不一样,CM算法是对当前的位置
x
t
\textbf{x}_t
xt的求梯度,NAG算法是对即将到达的下一个位置
x
t
+
v
t
\textbf{x}_t+\textbf{v}_t
xt+vt求梯度,仅仅这一点的改变就可能会使其迭代步骤低于CM算法。
Adgard算法
迭代公式如下
x
t
+
1
,
i
=
x
t
,
i
−
α
G
t
,
i
+
ϵ
▽
x
t
,
i
f
(2.7)
\textbf{x}_{t+1,i}=\textbf{x}_{t,i}-\frac{\alpha}{\sqrt{G_{t,i}+\epsilon}}\triangledown_{\textbf{x}_{t,i}}{f}\tag{2.7}
xt+1,i=xt,i−Gt,i+ϵα▽xt,if(2.7)
G
t
,
i
=
∑
i
=
0
i
=
t
▽
x
t
,
i
2
f
(2.8)
G_{t,i}=\sum_{i=0}^{i=t}\triangledown_{\textbf{x}_{t,i}^2}{f}\tag{2.8}
Gt,i=i=0∑i=t▽xt,i2f(2.8)
随着迭代步骤t的增加,与梯度下降法中的
α
\alpha
α相比,Adgard算法中的系数
α
G
t
,
i
+
ϵ
\frac{\alpha}{\sqrt{G_{t,i}+\epsilon}}
Gt,i+ϵα越来越小,这种求解方式有效地减少了在极值点附近的震荡次数,但是如果选取的初始点距离极值点附近比较远,迭代次数将大幅上升。
RMSprop算法
该算法主要针对Adgard算法在极值点附近震荡过多,而提出的,迭代公式如下
x
t
+
1
,
i
=
x
t
,
i
−
α
g
t
,
i
+
ϵ
▽
x
t
,
i
f
(2.9)
\textbf{x}_{t+1,i}=\textbf{x}_{t,i}-\frac{\alpha}{\sqrt{g_{t,i}+\epsilon}}\triangledown_{\textbf{x}_{t,i}}{f}\tag{2.9}
xt+1,i=xt,i−gt,i+ϵα▽xt,if(2.9)
g
t
,
i
=
γ
G
t
−
1
,
i
+
(
1
−
γ
)
G
t
,
i
(2.10)
g_{t,i}=\gamma{G_{t-1,i}}+(1-\gamma){G_{t,i}}\tag{2.10}
gt,i=γGt−1,i+(1−γ)Gt,i(2.10)
G
t
,
i
=
∑
i
=
0
i
=
t
▽
x
t
,
i
2
f
(2.11)
G_{t,i}=\sum_{i=0}^{i=t}\triangledown_{\textbf{x}_{t,i}^2}{f}\tag{2.11}
Gt,i=i=0∑i=t▽xt,i2f(2.11)
添加公式(2.10),可以缓解在极值点附近的震荡次数。
Adam算法
前面我们提到CM算法与NAG算法减少迭代次数,但是在极值点附近常常出现过多的震荡,RMSprop算法与Adam算法可以有效降低这种震荡,但是开始的迭代次数比较多。所以有人就思考将两者结合起来,总体思想就是将CM算法作为分子,Adgard算法作为分母,期望达到在离极值点较远的时候分子不断增加从而减少初始迭代步骤,在离极值点较近的时候分母不断增加从而减少震荡的目的,由于公式过于臃肿,而且参数过多,导致本人不愿意敲打该公式,所以将原论文(Adam: A Method for Stochastic Optimization)中的伪代码粘贴到下面以表敬意。
