神经网络向量化

From Ufldl

Jump to: navigation, search
(正向传导)
Line 15: Line 15:
一审:
一审:
-
考虑一个三层网络(一个输入层、一个隐含层、以及一个输出层),并且假定x是包含一个单一训练样本   的列向量。则正向传导的步骤可向量化表示如下:
+
考虑一个三层网络(一个输入层、一个隐含层、以及一个输出层),并且假定x是包含一个单一训练样本<math>x^{(i)} \in \Re^{n}</math> 的列向量。则正向传导的步骤可向量化表示如下:
:<math>\begin{align}
:<math>\begin{align}
Line 35: Line 35:
初译:更具体点来说,参照逻辑回归向量化的例子,我们用Matlab/Octave变量<tt>x</tt>表示一个包含输入训练样本的矩阵,<tt>x(:,i)</tt>代表第<math>\textstyle i</math>个训练样本。我们可以用如下的方式实现正向传导:
初译:更具体点来说,参照逻辑回归向量化的例子,我们用Matlab/Octave变量<tt>x</tt>表示一个包含输入训练样本的矩阵,<tt>x(:,i)</tt>代表第<math>\textstyle i</math>个训练样本。我们可以用如下的方式实现正向传导:
-
一审:更具体点来说,参照Logistic回归向量化的例子,我们用Matlab/Octave风格变量<tt>x</tt>表示包含输入训练样本的矩阵,<tt>x(:,i)</tt>代表第math>\textstyle i</math>个训练样本。则可实现正向传导如下:
+
一审:更具体点来说,参照Logistic回归向量化的例子,我们用Matlab/Octave风格变量<tt>x</tt>表示包含输入训练样本的矩阵,<tt>x(:,i)</tt>代表第<math>\textstyle i</math>个训练样本。则可实现正向传导如下:
<syntaxhighlight>  
<syntaxhighlight>  
Line 49: Line 49:
Can we get rid of the <tt>for</tt> loop?  For many algorithms, we will represent intermediate stages of computation via vectors.  For example, <tt>z2</tt>, <tt>a2</tt>, and <tt>z3</tt> here are all column vectors that're used to compute the activations of the hidden and output layers.  In order to take better advantage of parallelism and efficient matrix operations, we would like to ''have our algorithm operate simultaneously on many training examples''.  Let us temporarily ignore <tt>b1</tt> and <tt>b2</tt> (say, set them to zero for now).  We can then implement the following:
Can we get rid of the <tt>for</tt> loop?  For many algorithms, we will represent intermediate stages of computation via vectors.  For example, <tt>z2</tt>, <tt>a2</tt>, and <tt>z3</tt> here are all column vectors that're used to compute the activations of the hidden and output layers.  In order to take better advantage of parallelism and efficient matrix operations, we would like to ''have our algorithm operate simultaneously on many training examples''.  Let us temporarily ignore <tt>b1</tt> and <tt>b2</tt> (say, set them to zero for now).  We can then implement the following:
-
初译:我们能否去掉这个<tt>for</tt>循环?对于很多算法,我们使用向量来表达计算过程中的中间阶段。例如在前面的非向量化实现(9-2)中,<tt>z2</tt>,<tt>a2</tt>,<tt>z3<tt>都是列向量。这几个列向量被用来计算隐含层和输出层的激活。为了能够使得矩阵运算并行和更有效率,我们希望我们的算法操作能够同时使用在多个训练样本上。让我们暂时忽略前面公式(9-2)中的<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)。我们可以有如下的实现:
-
一审:这个<tt>for</tt>循环能否去掉?对于很多算法,我们使用向量来表示计算过程中的中间结果。例如在前面的非向量化实现(9-2)中,<tt>z2</tt>,<tt>a2</tt>,<tt>z3<tt>都是列向量,分别用来计算隐层和输出层的激励结果(译者注:这个表述不是十分准确,<tt>z2</tt>和<tt>z3</tt>分别是对隐层和输出层的输入刺激,a2才是隐层的激励结果)。为了充分发挥快捷矩阵运算和并行化计算的优势,我们希望算法操作能够处理多个训练样本。让我们先暂时忽略前面公式(9-2)中的<tt>b1</tt>和<tt>b2</tt>(把它们设置为0),那么可以实现如下:
+
一审:这个<tt>for</tt>循环能否去掉?对于很多算法,我们使用向量来表示计算过程中的中间结果。例如在前面的非向量化实现(9-2)中,<tt>z2</tt>,<tt>a2</tt>,<tt>z3</tt>都是列向量,分别用来计算隐层和输出层的激励结果(译者注:这个表述不是十分准确,<tt>z2</tt>和<tt>z3</tt>分别是对隐层和输出层的输入刺激,a2才是隐层的激励结果)。为了充分发挥快捷矩阵运算和并行化计算的优势,我们希望算法操作能够处理多个训练样本。让我们先暂时忽略前面公式中的<tt>b1</tt>和<tt>b2</tt>(把它们设置为0),那么可以实现如下:
<syntaxhighlight>  
<syntaxhighlight>  

Revision as of 02:34, 9 March 2013

Personal tools