神经网络向量化

From Ufldl

Jump to: navigation, search
Line 26: Line 26:
</syntaxhighlight>  
</syntaxhighlight>  
-
这个<tt>for</tt>循环能去掉吗?对于很多算法而言,我们使用向量来表示计算过程中的中间结果。例如在前面的非向量化实现(9-2)中,<tt>z2</tt>,<tt>a2</tt>,<tt>z3</tt>都是列向量,分别用来计算隐层和输出层的激励结果。为了充分利用并行化和高效矩阵运算的优势,我们希望算法能同时处理多个训练样本。让我们先暂时忽略前面公式中的<tt>b1</tt>和<tt>b2</tt>(把它们设置为0),那么可以实现如下:
+
这个<tt>for</tt>循环能否去掉呢?对于很多算法而言,我们使用向量来表示计算过程中的中间结果。例如在前面的非向量化实现(9-2)中,<tt>z2</tt>,<tt>a2</tt>,<tt>z3</tt>都是列向量,分别用来计算隐层和输出层的激励结果。为了充分利用并行化和高效矩阵运算的优势,我们希望算法能同时处理多个训练样本。让我们先暂时忽略前面公式中的<tt>b1</tt>和<tt>b2</tt>(把它们设置为0),那么可以实现如下:
<syntaxhighlight>  
<syntaxhighlight>  
Line 81: Line 81:
现在我们来描述反向传播向量化的思路。在阅读这一节之前,强烈建议各位仔细阅读前面介绍的正向传播的例子代码,确保你已经完全理解。下边我们只会给出反向传播向量化实现的大致纲要,而由你来完成具体细节的推导(见 [[Exercise:Vectorization]])。
现在我们来描述反向传播向量化的思路。在阅读这一节之前,强烈建议各位仔细阅读前面介绍的正向传播的例子代码,确保你已经完全理解。下边我们只会给出反向传播向量化实现的大致纲要,而由你来完成具体细节的推导(见 [[Exercise:Vectorization]])。
-
We are in a supervised learning setting, so that we have a training set <math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math> of <math>m</math> training examples.  (For the autoencoder, we simply set <math>y^{(i)} = x^{(i)}</math>, but our derivation here will consider this more general setting.)
 
-
 
-
'''初译:'''
 
-
我们在监督学习的场景下,因此我们有一个有<math>m</math>个训练样本的训练集<math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math>。
 
-
(对于自动编码器,我们简单的设置 <math>y^{(i)} = x^{(i)}</math> ,  但是我们的推导将会考虑更通用的情况)
 
-
 
-
'''一审:'''
 
这是监督学习,所以我们会有一个含<math>m</math>个带标号训练样本的训练集合<math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math>。
这是监督学习,所以我们会有一个含<math>m</math>个带标号训练样本的训练集合<math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math>。
(对于自编码网络,我们只需令<math>y^{(i)} = x^{(i)}</math>即可,  但这里考虑的是更一般的情况。)
(对于自编码网络,我们只需令<math>y^{(i)} = x^{(i)}</math>即可,  但这里考虑的是更一般的情况。)
Line 94: Line 87:
Suppose we have <math>s_3</math> dimensional outputs, so that our target labels are <math>y^{(i)} \in \Re^{s_3}</math>.  In our Matlab/Octave datastructure, we will stack these in columns to form a Matlab/Octave variable <tt>y</tt>, so that the <math>i</math>-th column <tt>y(:,i)</tt> is <math>y^{(i)}</math>.  
Suppose we have <math>s_3</math> dimensional outputs, so that our target labels are <math>y^{(i)} \in \Re^{s_3}</math>.  In our Matlab/Octave datastructure, we will stack these in columns to form a Matlab/Octave variable <tt>y</tt>, so that the <math>i</math>-th column <tt>y(:,i)</tt> is <math>y^{(i)}</math>.  
-
'''初译:'''假定我们有一个<math>s_3</math>维度的输出,我们的目标标签就是<math>y^{(i)} \in \Re^{s_3}</math>。在Matlab/Octave数据结构中,我们将要把这些列合在一起变成一个Matlab/Octave变量<tt>y</tt>,因此第<math>i</math>个列<tt>y(:,i)</tt>就是<math>y^{(i)}</math>。
+
假定每个样本的输出有<math>s_3</math>维,因而每个样本的类别标号向量就记为<math>y^{(i)} \in \Re^{s_3}</math> 。在我们的Matlab/Octave数据结构实现中,把这些输出按列合在一起形成一个Matlab/Octave风格变量<tt>y</tt>,其中第<tt>i</tt><tt>y(:,i)</tt>就是y(i) 。
-
 
+
-
'''一审:'''
+
-
假定我们的输出有<math>s_3</math>维(即这里考虑的是向量值输出--每个输入样本都被映射到<math>s_3</math>个输出节点—译注),因而每个输入样本的目标标号向量就记为<math>y^{(i)} \in \Re^{s_3}</math> 。在我们的Matlab/Octave数据结构实现中,把这些列合在一起形成一个Matlab/Octave风格变量<tt>y</tt>,其中第<tt>i</tt>个列<tt>y(:,i)</tt>就是y(i) 。
+
We now want to compute the gradient terms  
We now want to compute the gradient terms  

Revision as of 03:47, 16 March 2013

Personal tools