反向传导算法

From Ufldl

Jump to: navigation, search
Line 3: Line 3:
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
 
:<math>
:<math>
\begin{align}
\begin{align}
Line 10: Line 9:
</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:
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
 
-
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>
:<math>
\begin{align}
\begin{align}
Line 26: Line 24:
:【原文】:
:【原文】:
 +
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.
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
 
-
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.
 
:【原文】:
:【原文】:
 +
[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.]
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
 
-
[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.]
 
:【原文】:
:【原文】:
 +
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.
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
 
-
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.
 
:【原文】:
:【原文】:
 +
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).
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
 
-
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).
 
:【原文】:
:【原文】:
-
:【初译】:
 
-
:【一校】:
 
-
待补
 
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,
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
gradient descent is susceptible to local optima; however, in practice gradient descent
Line 59: Line 50:
at identical values, then all the hidden layer units will end up learning the same
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'''.
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'''.
-
 
-
:【原文】:
 
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
+
 
 +
:【原文】:
One iteration of gradient descent updates the parameters <math>W,b</math> as follows:
One iteration of gradient descent updates the parameters <math>W,b</math> as follows:
:<math>
:<math>
Line 71: Line 61:
\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
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
efficient way to compute these partial derivatives.
efficient way to compute these partial derivatives.
-
 
-
:【原文】:
 
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
+
 
-
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:
+
:【原文】:
:【原文】:
 +
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>
:<math>
\begin{align}
\begin{align}
Line 95: Line 82:
\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>.
 
-
 
:【原文】:
:【原文】:
 +
The two lines above differ slightly because weight decay is applied to <math>W</math> but not <math>b</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:
 
:【原文】:
:【原文】:
 +
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:
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
+
 
 +
:【原文】:
<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>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>.
Line 134: Line 118:
</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]) =
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_1),
Line 164: Line 147:
\end{align}</math>
\end{align}</math>
</ol>
</ol>
 +
:【初译】:
 +
:【一校】:
:【原文】:
:【原文】:
-
:【初译】:
 
-
:【一校】:
 
-
待补
 
'''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>,  
'''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>.   
we can compute this as <math>\textstyle f'(z^{(l)}_i) = a^{(l)}_i (1- a^{(l)}_i)</math>.   
Line 193: Line 175:
\end{align}</math>
\end{align}</math>
</ol>
</ol>
 +
:【初译】:
 +
:【一校】:
:【原文】:
:【原文】:
 +
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>.
:【初译】:
:【初译】:
:【一校】:
:【一校】:
-
待补
 
-
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>.
 
{{Sparse_Autoencoder}}
{{Sparse_Autoencoder}}

Revision as of 15:55, 7 March 2013

Personal tools