1. 神经网络结构
1.1. Multi-Layer Neural Network}
A.3-layer network: Input Layer,Hidden Lyer,Output layer\
Except input units,each unit has a bias.
1.2. preassumption calculation}
Hidden Layer:
netj=i=1∑dxiwji+wj0=i=0∑dxiwji=wjtx
Specifically, a signal xi at the input of synapse i connected to nueron j us multiplied by the synaptic weight wji\
i refers input layer,j refers hidden layer.wj0 is the bias.x0=+1\
- Each neuron is represented by a set of linear synaptic links, an externally applied bias,
and a possibly nonlinear activation link.The bias is represented by a synaptic link connected to an input fixed at +1.
- The synaptic links of a neuron weight their respective input signals.
- The weighted sum of the input signals defines the induced local field of the neuron in
question.
- The activation link squashes the induced local field of the neuron to produce an output.
Output layer:
yj=f(netj)
f() is the \emph{activation function}.It defines the output of a neuron in terms of
the induced local field net .
{% math %}
\xymatrix {
%x_{0}=+1 \ar[ddr]|(0.6){w_{j0}} & &\\
%x_{1} \ar[r]|(0.6){w_{j1}} & B & C\\
%x_{2} \ar[r]^(0.6){w_{j2}} & net_{j} \ar[r]^(0.6){f()} & y_{j} \\
x
}
{% endmath %}
For example:
netk=j=1∑nHyiwkj+wk0=j=0∑nHxiwji=wkty
nHis the number of hidden layers.\
So:
gk(x)=f(j=1∑nHwkj+f(i=0∑dxiwji+wj0)+wk0)
The activate function of output layer can be different from hidden layer while each unit can have different activate function.
1.3. BP Algorithm
The popularity of on-line learning for the supervised training of multilayer perceptrons
has been further enhanced by the development of the back-propagation algorithm.
Backpropagation, an abbreviation for "backward propagation of errors",is the easiest way of supervised training.We need to generate output activations of each hidden layer.\
The partial derivative ∂J/∂wji represents a sensitivity factor, determining the
direction of search in weight space for the synaptic weight wji
Learning:
T={x(n),d(n)}n=1Nej(n)=dj(n)−yj(n)
the instantaneous error energy of neuron j is defined by
J(w)=21k=1∑c(ek)2=21∣∣t−δ∣∣2
In the batch method of supervised learning, adjustments to the synaptic weights of the
multilayer perceptron are performed \emph{after} the presentation of all the %N% examples in the
training sample T that constitute one \emph{epoch} of training. In other words, the cost function
for batch learning is defined by the average error energy J(w).
- firstly define the training bias of output layer:
Δw=−η∂w∂J(w)w(m+1)=w(m)+/deltaw(m)
∂wkj∂J=∂netk∂J∂wkj∂netk∂netk∂J=∂δk∂J∂J∂δk=−(tk−δk)f′(netk)Δwkj=η∂netk∂J=η(tk−δk))f′(netk)yj
- input->hidden
1.4. 仿射层(Affine Layer)
神经网络中的一个全连接层。仿射(Affine)的意思是前面一层中的每一个神经元都连接到当前层中的每一个神经元。在许多方面,这是神经网络的「标准」层。仿射层通常被加在卷积神经网络或循环神经网络做出最终预测前的输出的顶层。仿射层的一般形式为 y = f(Wx + b),其中 x 是层输入,w 是参数,b 是一个偏差矢量,f 是一个非线性激活函数。
1.5. 多层感知器(MLP:Multilayer Perceptron)
多层感知器是一种带有多个全连接层的前馈神经网络,这些全连接层使用非线性激活函数(activation function)处理非线性可分的数据。MLP 是多层神经网络或有两层以上的深度神经网络的最基本形式。
1.6. 反向传播(Backpropagation)
反向传播是一种在神经网络中用来有效地计算梯度的算法,或更一般而言,是一种前馈计算图(feedforward computational graph)。其可以归结成从网络输出开始应用分化的链式法则,然后向后传播梯度。反向传播的第一个应用可以追溯到 1960 年代的 Vapnik 等人,但论文 Learning representations by back-propagating errors常常被作为引用源。
技术博客:计算图上的微积分学:反向传播(http://colah.github.io/posts/2015-08-Backprop/)
1.7. 通过时间的反向传播(BPTT:Backpropagation Through Time)
通过时间的反向传播是应用于循环神经网络(RNN)的反向传播算法。BPTT 可被看作是应用于 RNN 的标准反向传播算法,其中的每一个时间步骤(time step)都代表一个计算层,而且它的参数是跨计算层共享的。因为 RNN 在所有的时间步骤中都共享了同样的参数,一个时间步骤的错误必然能「通过时间」反向到之前所有的时间步骤,该算法也因而得名。当处理长序列(数百个输入)时,为降低计算成本常常使用一种删节版的 BPTT。删节的 BPTT 会在固定数量的步骤之后停止反向传播错误。
论文:Backpropagation Through Time: What It Does and How to Do It
给定训练集D={(x1,y1),(x2,y2),…,(xm,ym)},xi∈Rd,yi∈Rc,即输入实例由d个属性描述,输出c维实值向量.
下图给出了一个拥有d个输入神经元、m个隐层神经元、c个输出神经元的多层前馈网络结构:

- 隐层第h个神经元的阈值用γh表示,
- 输出层第j个神经元的阈值用θj表示。
- 输入层第i个神经元与隐层第h个神经元之间的连接权为vih;
- 隐层第h个神经元与输出层第j个神经元之间的连接权为whj;
- 记隐层第h个神经元接收到的输入为αh=∑i=1dvihxi;
- 输出层第j个神经元接收到的输入为βj=∑h=1mwhjbh, 其中bh为隐层第h个神经元的输出;
- 假设隐层和输出层神经元都使用Logistic函数:
P(t)=1+e−t1
以串行为例,对训练样本(xk,yk),假定神经网络的输出为y^k=(y^1k,y^2k,…,y^ck),即
y^jk=f(βj−θj),
则网络在(xk,yk)上的均方误差(LMS算法)为
Ek=21j=1∑c(y^jk−yjk)2.
根据广义的感知机学习规则对参数进行更新,任意参数v的更新估计式为
v←v+Δv
BP算法基于梯度下降策略,对误差Ek,给定学习率η,有
Δwhj=−η∂whj∂Ek
考虑到whj先影响到第j个输出层神经元的输入值βj,再影响到其输出值y^jk,最后影响到Ek,有
∂whj∂Ek=∂y^jk∂Ek∂βj∂y^jk∂whj∂βj
根据βj的定义,显然有
∂whj∂βj=bh
而Logistic函数有一个性质:
f′(x)=f(x)(1−f(x))
于是有
gj=−∂y^jk∂Ek∂βj∂y^jk=−(y^jk−yjk)f′(βj−θj)=y^jk(1−y^jk)(yjk−y^jk).
于是得到了BP算法中关于whj的更新公式
Δwhj=ηgjbh
根据前面的推导
Δθj=−η∂y^jk∂Ek⋅∂θj∂y^jk=η(y^jk−yjk)f′(βj−θj)=−ηgj
bh为第h个隐层神经元的输出,即
bh=f(αh−γh)
考虑到vih先影响到第h个隐层神经元的输入值αh,再影响到其输出值bh,最后影响到Ek,有
∂vih∂Ek=∂bh∂Ek⋅∂αh∂bh⋅∂vih∂αh
类似(2)中的gj,有
eh=−∂bh∂Ek⋅∂αh∂bh=−j=1∑c∂βj∂Ek⋅∂bh∂βjf′(αh−γh)=j=1∑cwhjgjf′(αh−γh)=bh(1−bh)j=1∑cwhjgj
所以
Δvih=ηehxi
另外,类似Δθj
Δγh=−ηeh
信号流图:

1.8. Siamese Networks
One Shot Learning with Siamese Networks in PyTorch