神经网络向量化
From Ufldl
Line 26: | Line 26: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
- | 这个<tt>for</tt> | + | 这个<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]])。 | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
这是监督学习,所以我们会有一个含<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>,其中第<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 |