神经网络

From Ufldl

Jump to: navigation, search
 
Line 1: Line 1:
-
举一个监督学习的例子,假设我们有训练样本集 <math>\textstyle (x(^ i),y(^ i))</math> ,那么神经网络算法能够提供一种复杂且非线性的假设模型 <math>\textstyle h_{W,b}(x)</math> ,它具有参数 <math>\textstyle W, b</math> ,可以以此参数来拟合我们的数据。
+
==概述==
 +
 
 +
以监督学习为例,假设我们有训练样本集 <math>\textstyle (x(^ i),y(^ i))</math> ,那么神经网络算法能够提供一种复杂且非线性的假设模型 <math>\textstyle h_{W,b}(x)</math> ,它具有参数 <math>\textstyle W, b</math> ,可以以此参数来拟合我们的数据。
Line 5: Line 7:
[[Image:SingleNeuron.png|300px|center]]
[[Image:SingleNeuron.png|300px|center]]
 +
这个“神经元”是一个以 <math>\textstyle x_1, x_2, x_3</math> 及截距 <math>\textstyle +1</math> 为输入值的运算单元,其输出为 <math>\textstyle  h_{W,b}(x) = f(W^Tx) = f(\sum_{i=1}^3 W_{i}x_i +b)</math> ,其中函数 <math>\textstyle f : \Re \mapsto \Re</math> 被称为“激活函数”。在本教程中,我们选用sigmoid函数作为'''激活函数''' <math>\textstyle f(\cdot)</math>  
这个“神经元”是一个以 <math>\textstyle x_1, x_2, x_3</math> 及截距 <math>\textstyle +1</math> 为输入值的运算单元,其输出为 <math>\textstyle  h_{W,b}(x) = f(W^Tx) = f(\sum_{i=1}^3 W_{i}x_i +b)</math> ,其中函数 <math>\textstyle f : \Re \mapsto \Re</math> 被称为“激活函数”。在本教程中,我们选用sigmoid函数作为'''激活函数''' <math>\textstyle f(\cdot)</math>  
 +
:<math>
:<math>
f(z) = \frac{1}{1+\exp(-z)}.
f(z) = \frac{1}{1+\exp(-z)}.
Line 12: Line 16:
可以看出,这个单一“神经元”的输入-输出映射关系其实就是一个逻辑回归(logistic regression)。
可以看出,这个单一“神经元”的输入-输出映射关系其实就是一个逻辑回归(logistic regression)。
 +
虽然本系列教程采用sigmoid函数,但你也可以选择双曲正切函数(tanh):
虽然本系列教程采用sigmoid函数,但你也可以选择双曲正切函数(tanh):
 +
:<math>
:<math>
Line 27: Line 33:
<math>\textstyle \tanh(z)</math>  函数是sigmoid函数的一种变体,它的取值范围为 <math>\textstyle [-1,1]</math> ,而不是sigmoid函数的 <math>\textstyle [0,1]</math> 。
<math>\textstyle \tanh(z)</math>  函数是sigmoid函数的一种变体,它的取值范围为 <math>\textstyle [-1,1]</math> ,而不是sigmoid函数的 <math>\textstyle [0,1]</math> 。
 +
注意,与其它地方(包括OpenClassroom公开课以及斯坦福大学CS229课程)不同的是,这里我们不再令 <math>\textstyle x_0=1</math> 。取而代之,我们用单独的参数 <math>\textstyle b</math> 来表示截距。
注意,与其它地方(包括OpenClassroom公开课以及斯坦福大学CS229课程)不同的是,这里我们不再令 <math>\textstyle x_0=1</math> 。取而代之,我们用单独的参数 <math>\textstyle b</math> 来表示截距。
 +
最后要说明的是,有一个等式我们以后会经常用到:如果选择 <math>\textstyle f(z) = 1/(1+\exp(-z))</math> ,也就是sigmoid函数,那么它的导数就是 <math>\textstyle f'(z) = f(z) (1-f(z))</math> (如果选择tanh函数,那它的导数就是 <math>\textstyle f'(z) = 1- (f(z))^2</math> ,你可以根据sigmoid(或tanh)函数的定义自行推导这个等式。
最后要说明的是,有一个等式我们以后会经常用到:如果选择 <math>\textstyle f(z) = 1/(1+\exp(-z))</math> ,也就是sigmoid函数,那么它的导数就是 <math>\textstyle f'(z) = f(z) (1-f(z))</math> (如果选择tanh函数,那它的导数就是 <math>\textstyle f'(z) = 1- (f(z))^2</math> ,你可以根据sigmoid(或tanh)函数的定义自行推导这个等式。
Line 42: Line 50:
-
我们用 <math>\textstyle {n}_l</math> 来表示网络的层数,本例中 <math>\textstyle n_l=3</math> ,我们将第 <math>\textstyle l</math> 层记为 <math>\textstyle L_l</math> ,于是 <math>\textstyle L_1</math> 是输入层,输出层是 <math>\textstyle L_{n_l}</math> 。本例神经网络有参数 <math>\textstyle (W,b) = (W^{(1)}, b^{(1)}, W^{(2)}, b^{(2)})</math> ,其中 <math>\textstyle W^{(l)}_{ij}</math> <math>\textstyle l</math> 层第 <math>\textstyle j</math> 单元与第 <math>\textstyle l+1</math> 层第 <math>\textstyle i</math> 单元之间的联接参数(其实就是连接线上的权重,注意标号顺序), <math>\textstyle b^{(l)}_i</math> 是第 <math>\textstyle l+1</math> 层第 <math>\textstyle i</math> 单元的偏置项。因此在本例中, <math>\textstyle W^{(1)} \in \Re^{3\times 3}</math> , <math>\textstyle W^{(2)} \in \Re^{1\times 3}</math> 。注意,没有其他单元连向偏置单元(即偏置单元没有输入),因为它们总是输出 <math>\textstyle +1</math>。同时,我们用 <math>\textstyle s_l</math> 表示第 <math>\textstyle l</math> 层的节点数(偏置单元不计在内)。
+
我们用 <math>\textstyle {n}_l</math> 来表示网络的层数,本例中 <math>\textstyle n_l=3</math> ,我们将第 <math>\textstyle l</math> 层记为 <math>\textstyle L_l</math> ,于是 <math>\textstyle L_1</math> 是输入层,输出层是 <math>\textstyle L_{n_l}</math> 。本例神经网络有参数 <math>\textstyle (W,b) = (W^{(1)}, b^{(1)}, W^{(2)}, b^{(2)})</math> ,其中 <math>\textstyle W^{(l)}_{ij}</math> (下面的式子中用到)是第 <math>\textstyle l</math> 层第 <math>\textstyle j</math> 单元与第 <math>\textstyle l+1</math> 层第 <math>\textstyle i</math> 单元之间的联接参数(其实就是连接线上的权重,注意标号顺序), <math>\textstyle b^{(l)}_i</math> 是第 <math>\textstyle l+1</math> 层第 <math>\textstyle i</math> 单元的偏置项。因此在本例中, <math>\textstyle W^{(1)} \in \Re^{3\times 3}</math> , <math>\textstyle W^{(2)} \in \Re^{1\times 3}</math> 。注意,没有其他单元连向偏置单元(即偏置单元没有输入),因为它们总是输出 <math>\textstyle +1</math>。同时,我们用 <math>\textstyle s_l</math> 表示第 <math>\textstyle l</math> 层的节点数(偏置单元不计在内)。
我们用 <math>\textstyle a^{(l)}_i</math> 表示第 <math>\textstyle l</math> 层第 <math>\textstyle i</math> 单元的'''激活值'''(输出值)。当 <math>\textstyle l=1</math> 时, <math>\textstyle a^{(1)}_i = x_i</math> ,也就是第 <math>\textstyle i</math> 个输入值(输入值的第 <math>\textstyle i</math> 个特征)。对于给定参数集合 <math>\textstyle W,b</math> ,我们的神经网络就可以按照函数 <math>\textstyle h_{W,b}(x)</math>  来计算输出结果。本例神经网络的计算步骤如下:
我们用 <math>\textstyle a^{(l)}_i</math> 表示第 <math>\textstyle l</math> 层第 <math>\textstyle i</math> 单元的'''激活值'''(输出值)。当 <math>\textstyle l=1</math> 时, <math>\textstyle a^{(1)}_i = x_i</math> ,也就是第 <math>\textstyle i</math> 个输入值(输入值的第 <math>\textstyle i</math> 个特征)。对于给定参数集合 <math>\textstyle W,b</math> ,我们的神经网络就可以按照函数 <math>\textstyle h_{W,b}(x)</math>  来计算输出结果。本例神经网络的计算步骤如下:
 +
:<math>  
:<math>  
Line 55: Line 64:
\end{align}
\end{align}
</math>  
</math>  
 +
我们用 <math>\textstyle z^{(l)}_i</math> 表示第 <math>\textstyle l</math> 层第 <math>\textstyle i</math> 单元输入加权和(包括偏置单元),比如, <math>\textstyle  z_i^{(2)} = \sum_{j=1}^n W^{(1)}_{ij} x_j + b^{(1)}_i</math> ,则 <math>\textstyle a^{(l)}_i = f(z^{(l)}_i)</math> 。
我们用 <math>\textstyle z^{(l)}_i</math> 表示第 <math>\textstyle l</math> 层第 <math>\textstyle i</math> 单元输入加权和(包括偏置单元),比如, <math>\textstyle  z_i^{(2)} = \sum_{j=1}^n W^{(1)}_{ij} x_j + b^{(1)}_i</math> ,则 <math>\textstyle a^{(l)}_i = f(z^{(l)}_i)</math> 。
Line 60: Line 70:
这样我们就可以得到一种更简洁的表示法。这里我们将激活函数 <math>\textstyle f(\cdot)</math> 扩展为用向量(分量的形式)来表示,即 <math>\textstyle f([z_1, z_2, z_3]) = [f(z_1), f(z_2), f(z_3)]</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> ,那么,上面的等式可以更简洁地表示为:
 +
:<math>\begin{align}
:<math>\begin{align}
Line 67: Line 78:
h_{W,b}(x) &= a^{(3)} = f(z^{(3)})
h_{W,b}(x) &= a^{(3)} = f(z^{(3)})
\end{align}</math>  
\end{align}</math>  
 +
我们将上面的计算步骤叫作'''前向传播'''。回想一下,之前我们用 <math>\textstyle a^{(1)} = x</math>  表示输入层的激活值,那么给定第 <math>\textstyle l</math> 层的激活值 <math>\textstyle a^{(l)}</math> 后,第 <math>\textstyle l+1</math> 层的激活值 <math>\textstyle a^{(l+1)}</math> 就可以按照下面步骤计算得到:
我们将上面的计算步骤叫作'''前向传播'''。回想一下,之前我们用 <math>\textstyle a^{(1)} = x</math>  表示输入层的激活值,那么给定第 <math>\textstyle l</math> 层的激活值 <math>\textstyle a^{(l)}</math> 后,第 <math>\textstyle l+1</math> 层的激活值 <math>\textstyle a^{(l+1)}</math> 就可以按照下面步骤计算得到:
 +
:<math> \begin{align}
:<math> \begin{align}
Line 83: Line 96:
神经网络也可以有多个输出单元。比如,下面的神经网络有两层隐藏层: <math>\textstyle L_2</math>  及 <math>\textstyle L_3</math> ,输出层 <math>\textstyle L_4</math> 有两个输出单元。
神经网络也可以有多个输出单元。比如,下面的神经网络有两层隐藏层: <math>\textstyle L_2</math>  及 <math>\textstyle L_3</math> ,输出层 <math>\textstyle L_4</math> 有两个输出单元。
 +
[[Image:Network3322.png|500px|center]]
[[Image:Network3322.png|500px|center]]
 +
要求解这样的神经网络,需要样本集  <math>\textstyle (x^{(i)}, y^{(i)})</math>  ,其中 <math>\textstyle y^{(i)} \in \Re^2</math> 。如果你想预测的输出是多个的,那这种神经网络很适用。(比如,在医疗诊断应用中,患者的体征指标就可以作为向量的输入值,而不同的输出值 <math>\textstyle y_i</math> 可以表示不同的疾病存在与否。)
要求解这样的神经网络,需要样本集  <math>\textstyle (x^{(i)}, y^{(i)})</math>  ,其中 <math>\textstyle y^{(i)} \in \Re^2</math> 。如果你想预测的输出是多个的,那这种神经网络很适用。(比如,在医疗诊断应用中,患者的体征指标就可以作为向量的输入值,而不同的输出值 <math>\textstyle y_i</math> 可以表示不同的疾病存在与否。)
Line 104: Line 119:
feedforward neural network 前馈神经网络(参照Mitchell的《机器学习》的翻译)
feedforward neural network 前馈神经网络(参照Mitchell的《机器学习》的翻译)
-
 
-
{{Sparse_Autoencoder}}
 
==中文译者==
==中文译者==
-
@天天吃泡芙成胖子,林锋(xlfg@yeah.net), @我是DarkScope, 许利杰(csxulijie@gmail.com)
+
孙逊(sunpaofu@foxmail.com),林锋(xlfg@yeah.net),刘鸿鹏飞(just.dark@foxmail.com), 许利杰(csxulijie@gmail.com)
 +
 
 +
 
 +
{{稀疏自编码器}}
 +
 
 +
 
 +
{{Languages|Neural_Networks|English}}

Latest revision as of 12:34, 7 April 2013

Personal tools