反向传导算法

From Ufldl

Jump to: navigation, search
 
Line 1: Line 1:
-
:【原文】:
+
假设我们有一个固定样本集 <math>\textstyle \{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math>,它包含 <math>\textstyle m</math> 个样例。我们可以用批量梯度下降法来求解神经网络。具体来讲,对于单个样例 <math>\textstyle (x,y)</math>,其代价函数为:
-
Suppose we have a fixed training set <math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math> of <math>m</math> training examples. We can train our neural network using batch gradient descent.  In detail, for a single training example <math>(x,y)</math>, we define the cost function with respect to that single example to be:
+
 
-
:【初译】:
+
-
假设我们有一个固定的训练集<math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math>,它包含<math>m</math>个训练样本。我们可以用批量梯度下降法训练我们的神经网络。下面进行详细介绍。针对单独的训练样本<math>(x,y)</math>,我们定义关于它的代价函数为:
+
-
:【一校】:
+
:<math>
:<math>
\begin{align}
\begin{align}
Line 9: Line 6:
\end{align}
\end{align}
</math>
</math>
-
:【原文】:
+
 
-
This is a (one-half) squared-error cost function. Given a training set of <math>m</math> examples, we then define the overall cost function to be:
+
这是一个(二分之一的)方差代价函数。给定一个包含 <math>\textstyle m</math> 个样例的数据集,我们可以定义整体代价函数为:
-
:【初译】:
+
 
-
这是一个(二分之一的)平方差代价函数。给定一个包含<math>m</math>个训练样本的训练集,我们于是可以定义整体代价函数为:
+
:<math>  
-
:【一校】:
+
-
:<math>
+
\begin{align}
\begin{align}
J(W,b)
J(W,b)
Line 25: Line 20:
</math>
</math>
-
:【原文】:
+
以上关于<math>\textstyle J(W,b)</math>定义中的第一项是一个均方差项。第二项是一个规则化项(也叫'''权重衰减项'''),其目的是减小权重的幅度,防止过度拟合。
-
The first term in the definition of <math>J(W,b)</math> is an average sum-of-squares error term. The second term is a regularization term (also called a '''weight decay''' term) that tends to decrease the magnitude of the weights, and helps prevent overfitting.
+
-
:【初译】:
+
-
以上定义中的第一项<math>J(W,b)</math>是一个均方差项。第二项是一个规则化项(也叫权重衰减项),其目的是减小权重的幅度,防止过度拟合。
+
-
:【一校】:
+
-
:【原文】:
 
-
[Note: Usually weight decay is not applied to the bias terms <math>b^{(l)}_i</math>, as reflected in our definition for <math>J(W, b)</math>.  Applying weight decay to the bias units usually makes only a small difference to the final network, however.  If you've taken CS229 (Machine Learning) at Stanford or watched the course's videos on YouTube, you may also recognize this weight decay as essentially a variant of the Bayesian regularization method you saw there, where we placed a Gaussian prior on the parameters and did MAP (instead of maximum likelihood) estimation.]
 
-
:【初译】:
 
-
[注:通常权重衰减的计算并不使用偏置项<math>b^{(l)}_i</math>,如同我们在<math>J(W, b)</math>的定义中所反映出来的一样。将偏置单元包含在权重衰减中通常只对最终的神经网络产生很小的影响。如果你在斯坦福选修过CS229(机器学习)课程,或者在YouTube上看过课程视频,你会发现这个权重衰减实际上是一个课上提到的贝叶斯规则化方法的变种,在这种方法中,我们将高斯先验概率放入参数中计算MAP(极大后验假设)估计(而不是极大似然估计)。]
 
-
:【一校】:
 
-
:【原文】:
+
[注:通常权重衰减的计算并不使用偏置项 <math>\textstyle b^{(l)}_i</math>,比如我们在 <math>\textstyle J(W, b)</math> 的定义中就没有使用。一般来说,将偏置项包含在权重衰减项中只会对最终的神经网络产生很小的影响。如果你在斯坦福选修过CS229(机器学习)课程,或者在YouTube上看过课程视频,你会发现这个权重衰减实际上是课上提到的贝叶斯规则化方法的变种。在贝叶斯规则化方法中,我们将高斯先验概率引入到参数中计算MAP(极大后验)估计(而不是极大似然估计)。]
-
The '''weight decay parameter''' <math>\lambda</math> controls the relative importance of the two terms. Note also the slightly overloaded notation: <math>J(W,b;x,y)</math> is the squared error cost with respect to a single example; <math>J(W,b)</math> is the overall cost function, which includes the weight decay term.
+
-
:【初译】:
+
-
'''权重衰减参数'''<math>\lambda</math>用于控制公式中两项的相对重要性。在此再次重申一下这两个复杂函数的含义:<math>J(W,b;x,y)</math>是针对单独样本计算的方差代价;<math>J(W,b)</math>是整体代价函数,它包含权重衰减项。
+
-
:【一校】:
+
-
:【原文】:
 
-
This cost function above is often used both for classification and for regression problems. For classification, we let <math>y = 0</math> or <math>1</math> represent the two class labels (recall that the sigmoid activation function outputs values in <math>[0,1]</math>; if we were using a tanh activation function, we would instead use -1 and +1 to denote the labels).  For regression problems, we first scale our outputs to ensure that they lie in the <math>[0,1]</math> range (or if we were using a tanh activation function, then the <math>[-1,1]</math> range).
 
-
:【初译】:
 
-
以上的代价函数经常被用于分类和回归问题。在分类问题中,我们使得<math>y = 0</math>或<math>1</math> ,来代表两种类型的标签(回忆一下,这是因为S型(sigmoid)激励函数的值域为<math>[0,1]</math>;如果我们使用双曲正切型激励函数,我们应该选用-1和+1作为标签)。对于回归问题,我们首先要对我们的输出值域进行缩放,以保证其范围为<math>[0,1]</math>(同样地,如果我们使用双曲正切型激励函数,使其值域范围为<math>[-1,1]</math>)。
 
-
:【一校】:
 
-
:【原文】:
+
'''权重衰减参数''' <math>\textstyle \lambda</math> 用于控制公式中两项的相对重要性。在此重申一下这两个复杂函数的含义:<math>\textstyle J(W,b;x,y)</math> 是针对单个样例计算得到的方差代价函数;<math>\textstyle J(W,b)</math> 是整体样本代价函数,它包含权重衰减项。
-
Our goal is to minimize <math>J(W,b)</math> as a function of <math>W</math> and <math>b</math>. To train our neural network, we will initialize each parameter <math>W^{(l)}_{ij}</math> and each <math>b^{(l)}_i</math> to a small random value near zero (say according to a <math>{Normal}(0,\epsilon^2)</math> distribution for some small <math>\epsilon</math>, say <math>0.01</math>), and then apply an optimization algorithm such as batch gradient descent. Since <math>J(W, b)</math> is a non-convex function,
+
 
-
gradient descent is susceptible to local optima; however, in practice gradient descent
+
 
-
usually works fairly well. Finally, note that it is important to initialize
+
以上的代价函数经常被用于分类和回归问题。在分类问题中,我们用 <math>\textstyle y = 0</math> <math>\textstyle 1</math>,来代表两种类型的标签(回想一下,这是因为 sigmoid激活函数的值域为 <math>\textstyle [0,1]</math>;如果我们使用双曲正切型激活函数,那么应该选用 <math>\textstyle -1</math> <math>\textstyle +1</math> 作为标签)。对于回归问题,我们首先要变换输出值域(译者注:也就是 <math>\textstyle y</math>),以保证其范围为 <math>\textstyle [0,1]</math> (同样地,如果我们使用双曲正切型激活函数,要使输出值域为 <math>\textstyle [-1,1]</math>)。
-
the parameters randomly, rather than to all 0's.  If all the parameters start off
+
 
-
at identical values, then all the hidden layer units will end up learning the same
+
 
-
function of the input (more formally, <math>W^{(1)}_{ij}</math> will be the same for all values of <math>i</math>, so that <math>a^{(2)}_1 = a^{(2)}_2 = a^{(2)}_3 = \ldots</math> for any input <math>x</math>). The random initialization serves the purpose of '''symmetry breaking'''.
+
我们的目标是针对参数 <math>\textstyle W</math> <math>\textstyle b</math> 来求其函数 <math>\textstyle J(W,b)</math> 的最小值。为了求解神经网络,我们需要将每一个参数 <math>\textstyle W^{(l)}_{ij}</math> 和 <math>\textstyle b^{(l)}_i</math> 初始化为一个很小的、接近零的随机值(比如说,使用正态分布 <math>\textstyle {Normal}(0,\epsilon^2)</math> 生成的随机值,其中 <math>\textstyle \epsilon</math> 设置为 <math>\textstyle 0.01</math> ),之后对目标函数使用诸如批量梯度下降法的最优化算法。因为 <math>\textstyle J(W, b)</math> 是一个非凸函数,梯度下降法很可能会收敛到局部最优解;但是在实际应用中,梯度下降法通常能得到令人满意的结果。最后,需要再次强调的是,要将参数进行随机初始化,而不是全部置为 <math>\textstyle 0</math>。如果所有参数都用相同的值作为初始值,那么所有隐藏层单元最终会得到与输入值有关的、相同的函数(也就是说,对于所有 <math>\textstyle i</math>,<math>\textstyle W^{(1)}_{ij}</math>都会取相同的值,那么对于任何输入 <math>\textstyle x</math> 都会有:<math>\textstyle a^{(2)}_1 = a^{(2)}_2 = a^{(2)}_3 = \ldots</math> )。随机初始化的目的是使'''对称失效'''。
-
:【初译】:
+
 
-
我们的目标是求得函数<math>J(W,b)</math>针对<math>W</math><math>b</math>的最小值。为了训练我们的神经网络,我们需要将每一个参数<math>W^{(l)}_{ij}</math>和<math>b^{(l)}_i</math>初始化为一个很小的、接近零的随机值(比如说,使用正态分布<math>{Normal}(0,\epsilon^2)</math>生成随机值,其中<math>\epsilon</math>设置为<math>0.01</math>),之后对目标函数使用诸如批量梯度下降法的最优化算法。因为<math>J(W, b)</math>是一个非凸函数,梯度下降法容易只找到局部最优解;但是,在实际应用中,梯度下降法通常都会工作的很好。最后,需要再次强调的是,要将参数进行随机的初始化,而不是全部设置为0。如果所有参数都用相同的值作为初始值,那么所有隐藏层单元最终会根据输入习得相同的函数(更具体的说,<math>W^{(1)}_{ij}</math>对于所有<math>i</math>都会取相同的值,于是对于任何输入<math>x</math>都会有:<math>a^{(2)}_1 = a^{(2)}_2 = a^{(2)}_3 = \ldots</math>)。随机初始化的目的是使'''对称破缺'''。
+
 
-
:【一校】:
+
梯度下降法中每一次迭代都按照如下公式对参数 <math>\textstyle W</math> 和<math>\textstyle b</math> 进行更新:
-
:【原文】:
 
-
One iteration of gradient descent updates the parameters <math>W,b</math> as follows:
 
-
:【初译】:
 
-
每一次梯度下降法迭代都会按如下方式对参数W和b进行更新:
 
-
:【一校】:
 
:<math>
:<math>
\begin{align}
\begin{align}
Line 70: Line 42:
b_{i}^{(l)} &= b_{i}^{(l)} - \alpha \frac{\partial}{\partial b_{i}^{(l)}} J(W,b)
b_{i}^{(l)} &= b_{i}^{(l)} - \alpha \frac{\partial}{\partial b_{i}^{(l)}} J(W,b)
\end{align}
\end{align}
-
</math>
+
</math>  
-
:【原文】:
+
 
-
where <math>\alpha</math> is the learning rate.  The key step is computing the partial derivatives above. We will now describe the '''backpropagation''' algorithm, which gives an
+
其中 <math>\textstyle \alpha</math> 是学习速率。其中关键步骤是计算偏导数。我们现在来讲一下'''反向传播'''算法,它是计算偏导数的一种有效方法。
-
efficient way to compute these partial derivatives.
+
 
-
:【初译】:
+
 
-
其中<math>\alpha</math>是学习速率。其中关键步骤是计算偏导数。我们现在来描述'''反向传播'''算法,它能够提供一种有效的方法来计算偏导数。
+
我们首先来讲一下如何使用反向传播算法来计算 <math>\textstyle \frac{\partial}{\partial W_{ij}^{(l)}} J(W,b; x, y)</math> 和 <math>\textstyle \frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x, y)</math>,这两项是单个样例 <math>\textstyle (x,y)</math> 的代价函数 <math>\textstyle J(W,b;x,y)</math> 的偏导数。一旦我们求出该偏导数,就可以推导出整体代价函数 <math>\textstyle J(W,b)</math> 的偏导数:
-
:【一校】:
+
 
-
:【原文】:
 
-
We will first describe how backpropagation can be used to compute <math>\textstyle \frac{\partial}{\partial W_{ij}^{(l)}} J(W,b; x, y)</math> and <math>\textstyle \frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x, y)</math>, the partial derivatives of the cost function <math>J(W,b;x,y)</math> defined with respect to a single example <math>(x,y)</math>. Once we can compute these, we see that the derivative of the overall cost function <math>J(W,b)</math> can be computed as:
 
-
:【初译】:
 
-
我们首先来描述如何使用反向传播算法来计算<math>\textstyle \frac{\partial}{\partial W_{ij}^{(l)}} J(W,b; x, y)</math>和<math>\textstyle \frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x, y)</math>,这两项是针对单独样本<math>(x,y)</math>的代价函数<math>J(W,b;x,y)</math>的偏导数。一旦我们求得了偏导数,我们就可以推导出整体代价函数<math>J(W,b)</math>的偏导数
 
-
:【一校】:
 
:<math>
:<math>
\begin{align}
\begin{align}
Line 90: Line 57:
\frac{1}{m}\sum_{i=1}^m \frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x^{(i)}, y^{(i)})
\frac{1}{m}\sum_{i=1}^m \frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x^{(i)}, y^{(i)})
\end{align}
\end{align}
-
</math>
+
</math>  
-
:【原文】:
+
 
-
The two lines above differ slightly because weight decay is applied to <math>W</math> but not <math>b</math>.
+
以上两行公式稍有不同,第一行比第二行多出一项,是因为权重衰减是作用于 <math>\textstyle W</math> 而不是 <math>\textstyle b</math>
-
:【初译】:
+
 
-
以上两行公式稍有不同,第一行比第二行多出一项,是因为权重衰减是作用于<math>W</math>而不是<math>b</math>
+
 
-
:【一校】:
+
反向传播算法的思路如下:给定一个样例 <math>\textstyle (x,y)</math>,我们首先进行“前向传导”运算,计算出网络中所有的激活值,包括 <math>\textstyle h_{W,b}(x)</math> 的输出值。之后,针对第 <math>\textstyle l</math> 层的每一个节点 <math>\textstyle i</math>,我们计算出其“残差” <math>\textstyle \delta^{(l)}_i</math>,该残差表明了该节点对最终输出值的残差产生了多少影响。对于最终的输出节点,我们可以直接算出网络产生的激活值与实际值之间的差距,我们将这个差距定义为 <math>\textstyle \delta^{(n_l)}_i</math>  (第 <math>\textstyle n_l</math> 层表示输出层)。对于隐藏单元我们如何处理呢?我们将基于节点(译者注:第 <math>\textstyle l+1</math> 层节点)残差的加权平均值计算 <math>\textstyle \delta^{(l)}_i</math>,这些节点以 <math>\textstyle a^{(l)}_i</math> 作为输入。下面将给出反向传导算法的细节:
-
:【原文】:
 
-
The intuition behind the backpropagation algorithm is as follows. Given a training example <math>(x,y)</math>, we will first run a "forward pass" to compute all the activations throughout the network, including the output value of the hypothesis <math>h_{W,b}(x)</math>.  Then, for each node <math>i</math> in layer <math>l</math>, we would like to compute an "error term" <math>\delta^{(l)}_i</math> that measures how much that node was "responsible" for any errors in our output. For an output node, we can directly measure the difference between the network's activation and the true target value, and use that to define <math>\delta^{(n_l)}_i</math> (where layer <math>n_l</math> is the output layer).  How about hidden units?  For those, we will compute <math>\delta^{(l)}_i</math> based on a weighted average of the error terms of the nodes that uses <math>a^{(l)}_i</math> as an input.  In detail, here is the backpropagation algorithm:
 
-
:【初译】:
 
-
反向传播算法的思路如下。给出一个训练样本<math>(x,y)</math>,我们首先进行“前向传递”运算,计算出所有通过网络的激励,包括输出的假设值<math>h_{W,b}(x)</math>。之后,针对第l层的每一个节点<math>i</math>,我们可以计算出“残差项”<math>\delta^{(l)}_i</math>,该残差项表明了该节点对最终的输出值的残差产生了多少贡献。对于最终的输出节点,我们可以直接得出网络产生的激励值与最终目标样本的真实值之间的差距,我们将这个差距定义为<math>\delta^{(n_l)}_i</math> (where layer <math>n_l</math>(这里的第<math>n_l</math>层代表的是输出层)。对于隐藏单元我们将如何处理呢?我们首先计算以激励 为输入的节点的残差项的加权平均值,以此为基础计算 。下面将给出反向传播算法的细节:
 
-
:【一校】:
 
-
:【原文】:
 
<ol>
<ol>
-
<li>Perform a feedforward pass, computing the activations for layers <math>L_2</math>, <math>L_3</math>, and so on up to the output layer <math>L_{n_l}</math>.
+
<li>进行前馈传导计算,利用前向传导公式,得到 <math>\textstyle L_2, L_3, \ldots </math> 直到输出层 <math>\textstyle L_{n_l}</math> 的激活值。
-
<li>For each output unit <math>i</math> in layer <math>n_l</math> (the output layer), set
+
<li>对于第 <math>\textstyle n_l</math> 层(输出层)的每个输出单元 <math>\textstyle i</math>,我们根据以下公式计算残差:
 +
 
 +
 
:<math>
:<math>
\begin{align}
\begin{align}
Line 114: Line 77:
\end{align}
\end{align}
</math>
</math>
-
<li>For <math>l = n_l-1, n_l-2, n_l-3, \ldots, 2</math>
+
 
-
:For each node <math>i</math> in layer <math>l</math>, set
+
[译者注:
-
::<math>
+
:<math>  
-
                \delta^{(l)}_i = \left( \sum_{j=1}^{s_{l+1}} W^{(l)}_{ji} \delta^{(l+1)}_j \right) f'(z^{(l)}_i)
+
-
                </math>
+
-
<li>Compute the desired partial derivatives, which are given as:
+
-
:<math>
+
\begin{align}
\begin{align}
-
\frac{\partial}{\partial W_{ij}^{(l)}} J(W,b; x, y) &= a^{(l)}_j \delta_i^{(l+1)} \\
+
\delta^{(n_l)}_i &= \frac{\partial}{\partial z^{n_l}_i}J(W,b;x,y)
-
\frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x, y) &= \delta_i^{(l+1)}.
+
= \frac{\partial}{\partial z^{n_l}_i}\frac{1}{2} \left\|y - h_{W,b}(x)\right\|^2 \\
 +
&= \frac{\partial}{\partial z^{n_l}_i}\frac{1}{2} \sum_{j=1}^{S_{n_l}} (y_j-a_j^{(n_l)})^2
 +
= \frac{\partial}{\partial z^{n_l}_i}\frac{1}{2} \sum_{j=1}^{S_{n_l}} (y_j-f(z_j^{(n_l)}))^2 \\
 +
&= - (y_i - f(z_i^{(n_l)})) \cdot f'(z^{(n_l)}_i)
 +
= - (y_i - a^{(n_l)}_i) \cdot f'(z^{(n_l)}_i)
\end{align}
\end{align}
-
</math>
+
</math>  
-
</ol>
+
]
-
:【初译】:
+
 
-
<ol>
+
<li><math>\textstyle l = n_l-1, n_l-2, n_l-3, \ldots, 2</math> 的各个层,第 <math>\textstyle l</math> 层的第 <math>\textstyle i</math> 个节点的残差计算方法如下:
-
<li>进行前馈传导计算,得到<math>L_2</math><math>L_3</math>…直到输出层<math>L_{n_l}</math>的激励值。
+
: <math>  
-
<li>针对第<math>n_l</math>层(输出层)的每个输出单元<math>i</math>,我们根据以下公式计算残差项:
+
\delta^{(l)}_i = \left( \sum_{j=1}^{s_{l+1}} W^{(l)}_{ji} \delta^{(l+1)}_j \right) f'(z^{(l)}_i)
-
:<math>
+
</math>  
 +
 
 +
{译者注:
 +
:<math>  
\begin{align}
\begin{align}
-
\delta^{(n_l)}_i
+
\delta^{(n_l-1)}_i &=\frac{\partial}{\partial z^{n_l-1}_i}J(W,b;x,y)
-
= \frac{\partial}{\partial z^{(n_l)}_i} \;\;
+
= \frac{\partial}{\partial z^{n_l-1}_i}\frac{1}{2} \left\|y - h_{W,b}(x)\right\|^2  
-
        \frac{1}{2} \left\|y - h_{W,b}(x)\right\|^2 = - (y_i - a^{(n_l)}_i) \cdot f'(z^{(n_l)}_i)
+
= \frac{\partial}{\partial z^{n_l-1}_i}\frac{1}{2} \sum_{j=1}^{S_{n_l}}(y_j-a_j^{(n_l)})^2 \\
 +
&= \frac{1}{2} \sum_{j=1}^{S_{n_l}}\frac{\partial}{\partial z^{n_l-1}_i}(y_j-a_j^{(n_l)})^2
 +
= \frac{1}{2} \sum_{j=1}^{S_{n_l}}\frac{\partial}{\partial z^{n_l-1}_i}(y_j-f(z_j^{(n_l)}))^2 \\
 +
&= \sum_{j=1}^{S_{n_l}}-(y_j-f(z_j^{(n_l)})) \cdot \frac{\partial}{\partial z_i^{(n_l-1)}}f(z_j^{(n_l)})
 +
= \sum_{j=1}^{S_{n_l}}-(y_j-f(z_j^{(n_l)})) \cdot  f'(z_j^{(n_l)}) \cdot \frac{\partial z_j^{(n_l)}}{\partial z_i^{(n_l-1)}} \\
 +
&= \sum_{j=1}^{S_{n_l}} \delta_j^{(n_l)} \cdot \frac{\partial z_j^{(n_l)}}{\partial z_i^{n_l-1}}
 +
= \sum_{j=1}^{S_{n_l}} \left(\delta_j^{(n_l)} \cdot \frac{\partial}{\partial z_i^{n_l-1}}\sum_{k=1}^{S_{n_l-1}}f(z_k^{n_l-1}) \cdot W_{jk}^{n_l-1}\right) \\
 +
&= \sum_{j=1}^{S_{n_l}} \delta_j^{(n_l)} \cdot  W_{ji}^{n_l-1} \cdot f'(z_i^{n_l-1})
 +
= \left(\sum_{j=1}^{S_{n_l}}W_{ji}^{n_l-1}\delta_j^{(n_l)}\right)f'(z_i^{n_l-1})
\end{align}
\end{align}
-
</math>
+
</math>  
-
<li>对<math>l = n_l-1, n_l-2, n_l-3, \ldots, 2</math>的各个层,第<math>l</math>层的第<math>i</math>个节点的残差项计算方法如下:
+
 
-
::<math>
+
将上式中的<math>\textstyle n_l-1</math>与<math>\textstyle n_l</math>的关系替换为<math>\textstyle l</math><math>\textstyle l+1</math>的关系,就可以得到:
-
                \delta^{(l)}_i = \left( \sum_{j=1}^{s_{l+1}} W^{(l)}_{ji} \delta^{(l+1)}_j \right) f'(z^{(l)}_i)
+
: <math>  
-
                </math>
+
\delta^{(l)}_i = \left( \sum_{j=1}^{s_{l+1}} W^{(l)}_{ji} \delta^{(l+1)}_j \right) f'(z^{(l)}_i)
-
[译者注:由于原作者简化了推导过程,使我本人看着十分费解,于是就自己推导了一遍,将过程写在这里:
+
</math>  
-
:<math>公式</math>
+
以上逐次从后向前求导的过程即为“反向传导”的本意所在。
-
根据递推过程,将n_l-1与n_l的关系替换为l与l+1的关系,可以得到原作者的结果:
+
 
-
:<math>公式</math>
+
-
我认为以上的逐步向前递推求导的过程就是“反向传播”算法的本意所在,推导结束,欢迎指正。
+
]
]
 +
 +
 +
<li>计算我们需要的偏导数,计算方法如下:
<li>计算我们需要的偏导数,计算方法如下:
-
:<math>
+
:<math>  
\begin{align}
\begin{align}
\frac{\partial}{\partial W_{ij}^{(l)}} J(W,b; x, y) &= a^{(l)}_j \delta_i^{(l+1)} \\
\frac{\partial}{\partial W_{ij}^{(l)}} J(W,b; x, y) &= a^{(l)}_j \delta_i^{(l+1)} \\
\frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x, y) &= \delta_i^{(l+1)}.
\frac{\partial}{\partial b_{i}^{(l)}} J(W,b; x, y) &= \delta_i^{(l+1)}.
\end{align}
\end{align}
-
</math>
+
</math>  
</ol>
</ol>
-
:【一校】:
 
-
:【原文】:
 
-
Finally, we can also re-write the algorithm using matrix-vectorial notation. We will use "<math>\textstyle \bullet</math>" to denote the element-wise product operator (denoted "<tt>.*</tt>" in Matlab or Octave, and also called the Hadamard product), so that if <math>\textstyle a = b \bullet c</math>, then <math>\textstyle a_i = b_ic_i</math>. Similar to how we extended the definition of <math>\textstyle f(\cdot)</math> to apply element-wise to vectors, we also do the same for <math>\textstyle f'(\cdot)</math> (so that <math>\textstyle f'([z_1, z_2, z_3]) =
 
-
[f'(z_1),
 
-
f'(z_2),
 
-
f'(z_3)]</math>).
 
-
:【初译】:
 
-
最后,我们用矩阵-向量表示法重写以上算法。我们使用“ ” 表示逐个元素相乘运算(在Matlab或Octave里用“.*”表示,也称作阿达马乘积),例如在向量运算 中,对每个元素有 。我们可以类似地扩展 运算符的定义,将其用于向量的逐元素运算,对于偏导数运算 ,我们也做相同的处理(于是又有 )。
 
-
:【一校】:
 
-
:【原文】:
+
最后,我们用矩阵-向量表示法重写以上算法。我们使用“<math>\textstyle \bullet</math>” 表示向量乘积运算符(在Matlab或Octave里用“<tt>.*</tt>”表示,也称作阿达马乘积)。若 <math>\textstyle a = b \bullet c</math>,则 <math>\textstyle a_i = b_ic_i</math>。在上一个教程中我们扩展了 <math>\textstyle f(\cdot)</math> 的定义,使其包含向量运算,这里我们也对偏导数 <math>\textstyle f'(\cdot)</math> 也做了同样的处理(于是又有 <math> \textstyle f'([z_1, z_2, z_3]) = [f'(z_1), f'(z_2), f'(z_3)]</math> )。
-
The algorithm can then be written:
+
-
<ol>
+
 
-
<li>Perform a feedforward pass, computing the activations for layers <math>\textstyle L_2</math>, <math>\textstyle L_3</math>, up to the output layer <math>\textstyle L_{n_l}</math>, using the equations defining the forward propagation steps
+
那么,反向传播算法可表示为以下几个步骤:
-
<li>For the output layer (layer <math>\textstyle n_l</math>), set
+
-
:<math>\begin{align}
+
-
\delta^{(n_l)}
+
-
= - (y - a^{(n_l)}) \bullet f'(z^{(n_l)})
+
-
\end{align}</math>
+
-
<li>For <math>\textstyle l = n_l-1, n_l-2, n_l-3, \ldots, 2</math>
+
-
:Set
+
-
::<math>\begin{align}
+
-
                \delta^{(l)} = \left((W^{(l)})^T \delta^{(l+1)}\right) \bullet f'(z^{(l)})
+
-
                \end{align}</math>
+
-
<li>Compute the desired partial derivatives:
+
-
:<math>\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}</math>
+
-
</ol>
+
-
:【初译】:
+
-
后向传播算法的向量表示法为:
+
<ol>
<ol>
-
<li>进行前馈传导计算,利用前向传播的定义公式,得到<math>\textstyle L_2</math>、<math>\textstyle L_3</math>…直到输出层<math>\textstyle L_{n_l}</math>的激励值。
+
<li>进行前馈传导计算,利用前向传导公式,得到 <math>\textstyle L_2, L_3, \ldots</math>直到输出层 <math>\textstyle L_{n_l}</math> 的激活值。
-
<li>对输出层(第<math>\textstyle n_l</math>层),计算:
+
 
-
:<math>\begin{align}
+
<li>对输出层(第 <math>\textstyle n_l</math> 层),计算:
 +
 
 +
:<math> \begin{align}
\delta^{(n_l)}
\delta^{(n_l)}
= - (y - a^{(n_l)}) \bullet f'(z^{(n_l)})
= - (y - a^{(n_l)}) \bullet f'(z^{(n_l)})
-
\end{align}</math>
+
\end{align}</math>  
-
<li><math>\textstyle l = n_l-1, n_l-2, n_l-3, \ldots, 2</math>的各层,计算:
+
 
-
::<math>\begin{align}
+
<li>对于 <math>\textstyle l = n_l-1, n_l-2, n_l-3, \ldots, 2</math> 的各层,计算:
-
                \delta^{(l)} = \left((W^{(l)})^T \delta^{(l+1)}\right) \bullet f'(z^{(l)})
+
:<math> \begin{align}
-
                \end{align}</math>
+
\delta^{(l)} = \left((W^{(l)})^T \delta^{(l+1)}\right) \bullet f'(z^{(l)})
 +
\end{align}</math>  
 +
 
<li>计算最终需要的偏导数值:
<li>计算最终需要的偏导数值:
-
:<math>\begin{align}
+
:<math> \begin{align}
\nabla_{W^{(l)}} J(W,b;x,y) &= \delta^{(l+1)} (a^{(l)})^T, \\
\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)}.
\nabla_{b^{(l)}} J(W,b;x,y) &= \delta^{(l+1)}.
-
\end{align}</math>
+
\end{align}</math>  
</ol>
</ol>
-
:【一校】:
 
-
:【原文】:
+
'''实现中应注意:'''在以上的第2步和第3步中,我们需要为每一个 <math>\textstyle i</math> 值计算其 <math>\textstyle f'(z^{(l)}_i)</math>。假设 <math>\textstyle f(z)</math> 是sigmoid函数,并且我们已经在前向传导运算中得到了 <math>\textstyle a^{(l)}_i</math>。那么,使用我们早先推导出的 <math>\textstyle f'(z)</math>表达式,就可以计算得到 <math>\textstyle f'(z^{(l)}_i) = a^{(l)}_i (1- a^{(l)}_i)</math>。
-
'''Implementation note:''' In steps 2 and 3 above, we need to compute <math>\textstyle f'(z^{(l)}_i)</math> for each value of <math>\textstyle i</math>. Assuming <math>\textstyle f(z)</math> is the sigmoid activation function, we would already have <math>\textstyle a^{(l)}_i</math> stored away from the forward pass through the network.  Thus, using the expression that we worked out earlier for <math>\textstyle f'(z)</math>,
+
-
we can compute this as <math>\textstyle f'(z^{(l)}_i) = a^{(l)}_i (1- a^{(l)}_i)</math>. 
+
-
:【初译】:
+
-
'''实现中应注意:'''在以上的第2步和第3步中,我们需要为每一个<math>\textstyle i</math>值计算<math>\textstyle f'(z^{(l)}_i)</math>。假设<math>\textstyle f(z)</math>是s形激励函数,并且我们已经在神经网络的前向传播运算中得到了<math>\textstyle a^{(l)}_i</math>,并将其存储了起来。于是,使用我们早先推导出的s形函数的导数<math>\textstyle f'(z)</math>的表达式,我们可以计算得到<math>\textstyle f'(z^{(l)}_i) = a^{(l)}_i (1- a^{(l)}_i)</math>。
+
-
:【一校】:
+
-
:【原文】:
 
-
Finally, we are ready to describe the full gradient descent algorithm.  In the pseudo-code
 
-
below, <math>\textstyle \Delta W^{(l)}</math> is a matrix (of the same dimension as <math>\textstyle W^{(l)}</math>), and <math>\textstyle \Delta b^{(l)}</math> is a vector (of the same dimension as <math>\textstyle b^{(l)}</math>). Note that in this notation,
 
-
"<math>\textstyle \Delta W^{(l)}</math>" is a matrix, and in particular it isn't "<math>\textstyle \Delta</math> times <math>\textstyle W^{(l)}</math>." We implement one iteration of batch gradient descent as follows:
 
-
:【初译】:
 
-
最终,我们完成了梯度下降算法过程的全部描述。在下面的伪代码中,<math>\textstyle \Delta W^{(l)}</math>是一个与矩阵<math>\textstyle W^{(l)}</math>维度相同的矩阵,<math>\textstyle \Delta b^{(l)}</math>是一个与<math>\textstyle b^{(l)}</math>维度相同的向量。注意这里“<math>\textstyle \Delta W^{(l)}</math>”是一个矩阵,而不是“<math>\textstyle \Delta</math>与<math>\textstyle W^{(l)}</math>相乘”。下面,我们实现批量梯度下降法的一部迭代:
 
-
:【一校】:
 
-
:【原文】:
+
最后,我们将对梯度下降算法做个全面总结。在下面的伪代码中,<math>\textstyle \Delta W^{(l)}</math> 是一个与矩阵 <math>\textstyle W^{(l)}</math> 维度相同的矩阵,<math>\textstyle \Delta b^{(l)}</math> 是一个与 <math>\textstyle b^{(l)}</math> 维度相同的向量。注意这里“<math>\textstyle \Delta W^{(l)}</math>”是一个矩阵,而不是“<math>\textstyle \Delta</math> 与 <math>\textstyle W^{(l)}</math> 相乘”。下面,我们实现批量梯度下降法中的一次迭代:
-
<ol>
+
 
-
<li>Set <math>\textstyle \Delta W^{(l)} := 0</math>, <math>\textstyle \Delta b^{(l)} := 0</math> (matrix/vector of zeros) for all <math>\textstyle l</math>.
+
-
<li>For <math>\textstyle i = 1</math> to <math>\textstyle m</math>,
+
-
<ol type="a">
+
-
<li>Use backpropagation to compute <math>\textstyle \nabla_{W^{(l)}} J(W,b;x,y)</math> and
+
-
<math>\textstyle \nabla_{b^{(l)}} J(W,b;x,y)</math>.
+
-
<li>Set <math>\textstyle \Delta W^{(l)} := \Delta W^{(l)} + \nabla_{W^{(l)}} J(W,b;x,y)</math>.
+
-
<li>Set <math>\textstyle \Delta b^{(l)} := \Delta b^{(l)} + \nabla_{b^{(l)}} J(W,b;x,y)</math>.
+
-
</ol>
+
-
<li>Update the parameters:
 
-
:<math>\begin{align}
 
-
W^{(l)} &= W^{(l)} - \alpha \left[ \left(\frac{1}{m} \Delta W^{(l)} \right) + \lambda W^{(l)}\right] \\
 
-
b^{(l)} &= b^{(l)} - \alpha \left[\frac{1}{m} \Delta b^{(l)}\right]
 
-
\end{align}</math>
 
-
</ol>
 
-
:【初译】:
 
<ol>
<ol>
-
<li>对于所有<math>\textstyle l</math>,设置<math>\textstyle \Delta W^{(l)} := 0</math>, <math>\textstyle \Delta b^{(l)} := 0</math>,(设置为全零矩阵或全零向量)
+
<li>对于所有 <math>\textstyle l</math>,令 <math>\textstyle \Delta W^{(l)} := 0</math> , <math>\textstyle \Delta b^{(l)} := 0</math> (设置为全零矩阵或全零向量)
-
<li><math>\textstyle i = 1</math>到<math>\textstyle m</math>,
+
 
 +
<li>对于 <math>\textstyle i = 1</math> 到 <math>\textstyle m</math>,
 +
 
<ol type="a">
<ol type="a">
-
<li>使用反向传播计算<math>\textstyle \nabla_{W^{(l)}} J(W,b;x,y)</math>和<math>\textstyle \nabla_{b^{(l)}} J(W,b;x,y)</math>。
+
<li>使用反向传播算法计算 <math>\textstyle \nabla_{W^{(l)}} J(W,b;x,y)</math> 和 <math>\textstyle \nabla_{b^{(l)}} J(W,b;x,y)</math>。
-
<li>计算<math>\textstyle \Delta W^{(l)} := \Delta W^{(l)} + \nabla_{W^{(l)}} J(W,b;x,y)</math>。
+
<li>计算 <math>\textstyle \Delta W^{(l)} := \Delta W^{(l)} + \nabla_{W^{(l)}} J(W,b;x,y)</math>。
-
<li>计算<math>\textstyle \Delta b^{(l)} := \Delta b^{(l)} + \nabla_{b^{(l)}} J(W,b;x,y)</math>。  
+
<li>计算 <math>\textstyle \Delta b^{(l)} := \Delta b^{(l)} + \nabla_{b^{(l)}} J(W,b;x,y)</math>。  
</ol>
</ol>
<li>更新权重参数:
<li>更新权重参数:
-
:<math>\begin{align}
+
:<math> \begin{align}
W^{(l)} &= W^{(l)} - \alpha \left[ \left(\frac{1}{m} \Delta W^{(l)} \right) + \lambda W^{(l)}\right] \\
W^{(l)} &= W^{(l)} - \alpha \left[ \left(\frac{1}{m} \Delta W^{(l)} \right) + \lambda W^{(l)}\right] \\
b^{(l)} &= b^{(l)} - \alpha \left[\frac{1}{m} \Delta b^{(l)}\right]
b^{(l)} &= b^{(l)} - \alpha \left[\frac{1}{m} \Delta b^{(l)}\right]
-
\end{align}</math>
+
\end{align}</math>  
</ol>
</ol>
-
:【一校】:
 
-
:【原文】:
+
现在,我们可以重复梯度下降法的迭代步骤来减小代价函数 <math>\textstyle J(W,b)</math> 的值,进而求解我们的神经网络。
-
To train our neural network, we can now repeatedly take steps of gradient descent to reduce our cost function <math>\textstyle J(W,b)</math>.
+
 
-
:【初译】:
+
 
-
我们现在就可以重复梯度下降法的迭代步骤以减小代价函数<math>\textstyle J(W,b)</math>的值,从而训练我们的神经网络。
+
==中英文对照==
-
:【一校】:
+
 
 +
:反向传播算法 Backpropagation Algorithm
 +
:(批量)梯度下降法 (batch) gradient descent
 +
:(整体)代价函数 (overall) cost function
 +
:方差 squared-error
 +
:均方差 average sum-of-squares error
 +
:规则化项 regularization term
 +
:权重衰减 weight decay
 +
:偏置项 bias terms
 +
:贝叶斯规则化方法 Bayesian regularization method
 +
:高斯先验概率 Gaussian prior
 +
:极大后验估计 MAP
 +
:极大似然估计 maximum likelihood estimation
 +
:激活函数 activation function
 +
:双曲正切函数 tanh function
 +
:非凸函数 non-convex function
 +
:隐藏层单元 hidden (layer) units
 +
:对称失效 symmetry breaking
 +
:学习速率 learning rate
 +
:前向传导 forward pass
 +
:假设值 hypothesis
 +
:残差 error term
 +
:加权平均值 weighted average
 +
:前馈传导 feedforward pass
 +
:阿达马乘积 Hadamard product
 +
:前向传播 forward propagation
 +
 
 +
 
 +
==中文译者==
 +
 
 +
王方(fangkey@gmail.com),林锋(xlfg@yeah.net),许利杰(csxulijie@gmail.com)
 +
 
 +
 
 +
{{稀疏自编码器}}
 +
 
-
:【专业术语对照表】:
 
-
为了在后期校对时,使前后章节专业术语翻译统一,再此将此章中专业术语翻译的中英文对照总结到下表,以便统一修改,或用于后期专业名词附录。
 
-
反向传播算法 Backpropagation Algorithm
 
-
(批量)梯度下降法 (batch) gradient descent
 
-
(整体)代价函数 (overall) cost function
 
-
平方差 squared-error
 
-
均方差 average sum-of-squares error
 
-
规则化项 regularization term
 
-
权重衰减 weight decay
 
-
偏置项 bias terms
 
-
贝叶斯规则化方法 Bayesian regularization method
 
-
高斯先验概率 Gaussian prior
 
-
极大后验假设 MAP
 
-
极大似然估计 maximum likelihood estimation
 
-
S型函数 sigmoid function
 
-
激励函数 activation function
 
-
双曲正切函数 tanh function
 
-
非凸函数 non-convex function
 
-
隐藏层单元 hidden (layer) units
 
-
对称破缺 symmetry breaking
 
-
学习速率 learning rate
 
-
前向传递 forward pass
 
-
假设值 hypothesis
 
-
残差项 error term
 
-
加权平均值 weighted average
 
-
前馈传导 feedforward pass
 
-
阿达马乘积 Hadamard product
 
-
前向传播 forward propagation
 
-
{{Sparse_Autoencoder}}
+
{{Languages|Backpropagation_Algorithm|English}}

Latest revision as of 01:30, 2 December 2016

Personal tools