神经网络入门——基本概念

2020年10月12日

神经元的结构

一个神经元有一个或多个输入,有且仅有一个输出。

神经网络中的一层的神经元数目等于该层的输出值数目。

单层神经网络且输出值数目为1,该模型又可称为感知器。感知器就是一个神经元。每个神经元有一个多元组作为参数,元组的长度为输入数目。

从数学上看,若example有3个特征,该神经层输出2个值,则有算式[latex]\eqref{两个神经元}[/latex],第一个神经元的参数是[latex]w_{11}, w_{12}, w_{13}[/latex],第二个神经元的参数是[latex]w_{21}, w_{22}, w_{23}[/latex]。

\[\begin{equation}
\begin{bmatrix}
x_1 & x_2 & x_3
\end{bmatrix}
\begin{bmatrix}
w_{11} & w_{21}\\
w_{12} & w_{22}\\
w_{13} & w_{23}
\end{bmatrix} \label{两个神经元}\end{equation}
\]

神经网络的一层就是一个矩阵。

若神经元的参数不固定为0,则该层为全连接层。(?)

使用mxnet建立双层神经网络。

net = nn.Sequential()
net.add(nn.Dense(256),
		nn.Dense(1))
net.initialize(init.Normal(sigma=0.02))

该代码表示,第一层神经层的输出为256个值,第二层接受256个输入,输出1个值。那第一层的参数矩阵的维度是多少呢?一定是256列,那几行呢?不知道,因为神经网络的输入还没出现,所以net.initialize(init.Normal(sigma=0.02))进行延迟初始化,等数据传进来了,再初始化参数。

我们可以验证,访问net[0].weight.data(),类库抛出异常“Parameter ‘dense0_weight’ has not been initialized yet because initialization was deferred. Actual initialization happens during the first forward pass. Please pass one batch of data through the network before accessing Parameters. You can also avoid deferred initialization by specifying in_units, num_features, etc., for network layers.”

神经网络层

\[a(dM+b)\]

d为examples;m是神经网络层,一个矩阵;b为bias,一个向量(一维矩阵);a为激活函数。

神经网络有多层,就要嵌套。

\[
a_1(a_2(a_3(dM_3+b_3)M_2+b_2)M_1+b_1)
\]

这就是一个3层的神经网络。