误差表达式:
\( \large E(w) = \frac{1}{2} \sum_{d\in D} \sum_{k\in outputs} (t_{kd} - o_{kd}) ^2 \)
其中,\(outputs\)是网络输出单元的集合,\(D\)还是代表所有训练样本空间,\(t_{kd}\)和\(o_{kd}\)是与训练样例d和第k个输出单元相关的预期值与输出值。
每次只处理一个样本实例,然后更新各个权值,通过大量的样本实例逐渐的调整权值。那么对于每一次的训练样例d来说,它的输出误差为:
\( \large E_{d}(w) = \frac{1}{2} \sum_{k\in outputs} (t_{kd} - o_{kd}) ^2 \)
梯度
\( \large \bigtriangleup w_i = -\eta \frac{\partial E_{d} }{\partial w_i } \)
\( \large \bigtriangleup w_i = -\eta \frac{\partial E_{d} }{\partial net } \frac{\partial net }{\partial w_i } \)
\( \large \bigtriangleup w_i = -\eta \frac{\partial E_{d} }{\partial net } x_i \)
情况1:对于输出单元的权值训练法则:
因为\( \large \frac{\partial E_{d} }{\partial net } = \frac{\partial E_{d} }{\partial o} \frac{\partial o }{\partial net } = -(t-o)o(1-o)\)
所以
\( \large \bigtriangleup w_i = -\eta (t-o)o(o-1) x_i \)
\( \large \bigtriangleup w_i = \eta (t-o)o(1-o)x_i \)
情况2:隐藏单元的权值训练法则
隐藏层中的任意结点上的连结线权值都是通过影响以它的输出作为输入的下一层(downstream)的结点而最终影响误差的,所以隐藏层的推导如下:
因为\( \large \frac{\partial E_{d} }{\partial net_i } = \sum_{k\in ds(i)} \frac{\partial E_{d} } {\partial net_k} \frac {\partial net_k} {\partial o_i } \frac{\partial o_i }{\partial net_i } \)
\(= \sum_{k\in ds(i)} \delta_k w_{ik} o_i(1-o_i) = o_i(1-o_i) \sum_{k\in ds(i)} \delta_k w_{ik} \)
所以
\( \large \bigtriangleup w_i = -\eta \frac{\partial E_{d} }{\partial net_i } x_i \)
reference: 点击打开链接
=====================================================================================================================
定义误差:
\( \large net_j = \sum_i w_{ij} O_i\), \( \large net_k = \sum_j w_{jk} O_j\)
\( \large O_i= 1/ ( 1 + e ^ {- net _i} ) = f(net_i)\)
\( \large O_j = 1/ ( 1 + e ^ {- net _j} ) = f(net_j)\)
\( \large O_k = 1/ ( 1 + e ^ {- net _k} ) = f(net_k)\)
\( \large E = \frac {1}{2} \sum_j (y_j - O_j)^2 \) 其中\(y_j\)是理想输出,\(O_j\)是实际输出,
\( \Large \frac{\partial E} { \partial w_{ij} } = \frac{\partial E} { \partial net_j} \frac { \partial net_j} {\partial w_{ij}} = \delta_j O_i , \ \ \ 其中局部梯度( \delta_j= \frac{\partial E} { \partial net_j} )\)
则修正量定义为:
\( \large \bigtriangleup w_{ij}(t) = - \eta \frac{\partial E} { \partial w_{ij} } = -\eta \delta_j O_i \)
当节点j是输出单元时:
\( \Large \delta_j= \frac{\partial E} { \partial net_j} = \frac{\partial E} { \partial O_j} \frac{\partial O_j} { \partial net_j} = -(y_j - O_j) f'(net_j)\)
当节点j不是输出单元时:
\( \Large \delta_j= \frac{\partial E} { \partial net_j} = \sum_k \frac{\partial E} { \partial net_k} \frac{\partial net_k} { \partial O_j} \frac{\partial O_j} { \partial net_j} = \sum_k \delta_k w_{jk} f'(net_j)\)
当采用sigmod函数\(y = f(x) = 1/ ( 1 + e ^ {- x} ) \)时 \( f'(x) = y(1-y) \)
即:\( \large f'(net_j) = O_j(1-O_j)\)
最终修正量为:
\( \large \bigtriangleup w_{ij}(t) = - \eta \delta_j O_i + \alpha \bigtriangleup w_{ij}(t-1) \)
算法步骤:
1)从前向后各层计算各单元 \( O_j\)
\( \large net_j = \sum_i w_{ij} O_i\)
\( \large O_j = 1/ ( 1 + e ^ {- net _j} ) \)
2) 对输出层计算\( \delta_j \)
\( \large \delta_j = (y-O_j)O_j(1- O_j)\)
3)从后向前计算各隐层
\( \large \delta_j = O_j(1- O_j) \sum_k w_{jk} \delta_k\)
4)计算并保存各权值修正量
\( \large \bigtriangleup w_{ij}(t) = \alpha \bigtriangleup w_{ij}(t-1) + \eta \delta_j O_i\)
5)修正权值
\( \large w_{ij}(t+1) = w_{ij}(t) + \bigtriangleup w_{ij}(t) \)
步长系数\(\eta\) 对收敛性影响很大,通常在0.1~3之间
惯性系数\(\alpha\)影响收敛速度,一般现在0.9~1之间,大于1时不收敛,有些情况可以不使用惯性系数(等于0)
reference:《模式识别》 张学工