深度学习基础(二)Backpropagation Algorithm

我们知道神经网络有forward propagation,很自然会想那有没有Backpropagation,结果还真有。

forward progation相当于神经网络额一次初始化,但是这个神经网络还缺少训练,而Backpropagation Algorithm就是用来训练神经网络的。

深度学习基础(二)Backpropagation Algorithm_第1张图片

假设现在又m组训练集

\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}

代价函数为:

单个神经元的

\begin{align}J(W,b; x,y) = \frac{1}{2} \left\| h_{W,b}(x) - y \right\|^2.\end{align}

神经网络的:

深度学习基础(二)Backpropagation Algorithm_第2张图片

现在用经典的梯度下降法求解:

深度学习基础(二)Backpropagation Algorithm_第3张图片

其中


我们引入误差项\delta^{(l)}_i代表第l层的第i个单元对于整个我们整个神经网络输出误差的贡献大小

还记得我们前面提到

\textstyle z_i^{(2)} = \sum_{j=1}^n W^{(1)}_{ij} x_j + b^{(1)}_i  

a^{(l)}_i = f(z^{(l)}_i)



Backpropagation algorithm:

  1. Perform a feedforward pass, computing the activations for layers L2L3, and so on up to the output layer L_{n_l}.
  2. For each output unit i in layer nl (the output layer), set
    \begin{align}\delta^{(n_l)}_i= \frac{\partial}{\partial z^{(n_l)}_i} \;\;        \frac{1}{2} \left\|y - h_{W,b}(x)\right\|^2 = - (y_i - a^{(n_l)}_i) \cdot f'(z^{(n_l)}_i)\end{align}
  3. For l = n_l-1, n_l-2, n_l-3, \ldots, 2
    For each node  i in layer  l, set
                     \delta^{(l)}_i = \left( \sum_{j=1}^{s_{l+1}} W^{(l)}_{ji} \delta^{(l+1)}_j \right) f'(z^{(l)}_i)
  4. Compute the desired partial derivatives, which are given as:
    深度学习基础(二)Backpropagation Algorithm_第4张图片

The algorithm can then be written:

  1. Perform a feedforward pass, computing the activations for layers \textstyle L_2\textstyle L_3, up to the output layer \textstyle L_{n_l}, using the equations defining the forward propagation steps
  2. For the output layer (layer \textstyle n_l), set
    \begin{align}\delta^{(n_l)}= - (y - a^{(n_l)}) \bullet f'(z^{(n_l)})\end{align}
  3. For \textstyle l = n_l-1, n_l-2, n_l-3, \ldots, 2
    Set
    \begin{align}                 \delta^{(l)} = \left((W^{(l)})^T \delta^{(l+1)}\right) \bullet f'(z^{(l)})                 \end{align}
  4. Compute the desired partial derivatives:
    \begin{align}\nabla_{W^{(l)}} J(W,b;x,y) &= \delta^{(l+1)} (a^{(l)})^T, \\\nabla_{b^{(l)}} J(W,b;x,y) &= \delta^{(l+1)}.\end{align}


还BP算法中很重要的是中间隐层误差项的推导,我们接下来特别地详细研究一下:

我们假设代价函数为

,

其中

 是训练集的输出线
 是实际的输出项

对于每个单元的输出项:


我们现在也求解


其中




特别地,如果是隐含层j,那么



综上可以得到:

我们可以看到,BP算法的误差由输出向输入方向累计传递。这使得如果中间某一层单元的误差出现计算错误时,会影响最后收敛的结果,因此最好在求解过程中进行梯度检验(gradient check),也就是在参数附近选两个点用差分逼近偏导数,如果差分法求出的结果与偏导数相差太大,则很有可能是计算出错了。

参考资料:

http://en.wikipedia.org/wiki/Backpropagation

http://deeplearning.stanford.edu/wiki/index.php/UFLDL_Tutorial

你可能感兴趣的:(深度学习基础(二)Backpropagation Algorithm)