Depth articles - Neural Network (b) on ANN and DNN structure and common activation function

Skip to main content

Returns the neural network directory

Previous: depth articles - neural networks (a)  neurons and Perceptron

Next: depth articles - Neural Networks (c)  network topology and train the neural network

 

This section, with the elaborate ANN and DNN common activation function, and the next section elaborate train the neural network topology

 

Two. ANN and DNN

1. ANN structure and DNN

When the neural network has only one hidden layer, become ANN

When the hidden layer neural network is two or more, referred DNN

(1) The activation function

       Converting the net input signal into a single neuron output signal, for further dissemination in the network

(2) Network Topology

      It describes a model number of neurons and the number of layers and how they are attached:

   

(3) The training algorithm

      Specifies how connection weights, in order to inhibit or increase the proportion of neurons in the input signal

(4). Tuning neural network

 

2. The neural network activation function

(1). Understanding of the activation function

     Activation function neural network to decide whether a signal is transmitted in a neural network, or decide what transmission signal (e.g., a positive or negative signal embodiment example of the signal)

 

(2) The type of activation function

   ①. Linear activation function

      This is a simple linear function of the company is:

            f(x) = x

      Basically, the input to the output without modification process

        

   ②. Nonlinear activation function

      Nonlinear separable for separating data, the activation function is the most common. Nonlinear Equations control input to output mapping. Nonlinear activation function used are:

       Tanh, Sigmoid, necessary, LReLU, necessary, Softmax .....

 

Reason (3) neural network using a nonlinear activation function

   ①. Neural Network for achieving complex functions, non-linear activation function neural network can approximate any arbitrarily complex function

   ②. If using a linear activation function, the input of each layer is on the linear output network layer, and therefore, no matter how many layers of the neural network, the final output is a linear combination of input, hidden layer and the effect is not quite this case is the most primitive of perceptron. And also reduces efficiency.

   ③.  因此,才需要引入非线性函数作为激活函数,这样深层神经网络才有意义,输出不再是输入的线性组合,才可以逼近任意函数。

 

(4). 神经网络常用的非线性激活函数

   ①. Sigmoid

      Sigmoid又叫作Logistic激活函数,它将实数值压缩进 0 ~ 1 的区间内,还可以在预测概率的输出层中使用。该函数将大的负数换成0,将大的正数换成1. 数学公式及图形:

      \large f(x) = \frac{1}{1 + e^{-x}}

      \large f'(x) = f(x)(1 - f(x))

      Sigmoid函数的三个主要缺陷:

      a. 梯度消失

         Sigmoid函数趋近于0 和 1 的时候,变化率会变得平坦,也就是说,Sigmoid的梯度趋近于 0。神经网络使用Sigmoid激活函数进行反向传播时,输出接近 0 或1 的神经元其梯度趋近于 0。这些神经元叫做饱和神经元。因此,这些神经元的权重不会变更。此外,与此类神经元的权重也更新得很慢,该问题叫做梯度消失。因此,可以想象一下,如果一个大型神经网络包含Sigmoid神经元,而其中很多个都处于饱和状态,那么该网络就无法执行反向传播了,就无法对网络进行学习优化了。

      b. 不以零为中心

         Sigmoid输出不以零为中心,容易导致后面的激活函数输出的结果偏移中心点,而 Sigmoid 函数的有效范围在 [-4, 4] 之间,偏移到有效范围之外之后,就会导致梯度消失。

      c. 计算成本高昂

         指数函数与其他非线性激活函数相比,计算成本高昂

 

   ②. Tanh

       Tanh激活函数又叫做双曲正切激活函数(hyperbolic tangent activation function)。与sigmoid函数类似,Tanh函数也使用真值,但Tanh函数将其压缩至(-1, 1)的区间内。与Sigmoid不同,Tanh函数的输出以零为中心,因为区间在(-1, 1)之间,可以将Tanh函数想象成两个Sigmoid函数放在一起。在实践中,Tanh函数的使用优先性高于Sigmoid函数。负数输入被当作负值,零输入值的映射接近零,正数输入被当作正值。中心点在零处可以防止经过多次迭代后,中心点偏离零点很大,而偏离零点很大的地方可能会梯度消失。

        Tanh的数学公式与图像:

       \large Tanh(x) = 2 sigmoid(2x) - 1

        \large f(x) = Tanh(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} = \frac{2}{1 + e^{-2x}} - 1

        \large f'(x) = 1 - f(x)^{2}

    

        Tanh的缺点:

         a. Tanh函数也会有梯度消失的问题,因此饱和时也会“杀死”梯度

         b. 计算成本高昂

 

   ③.  Softmax

       Softmax激活函数可以看作是Sigmoid函数的一般化,可以进行多分类。Softmax激活函数的数学表达式如下:

             \large f(x_{j}) = \frac{e^{x_{j}}}{\sum_{k} e^{x_{k}}}

        \large k:为 \large k 分类

        \large x_{j}:为第 \large j 个分类的样本数

        \large f(x_{j}):为第 \large j 个分类的概率。在 softmax 中,各分类的概率是相互影响的。如果某个 \large x_{j} 大过其他的 \large x_{i},那这个分量就逼近于 1,其他分量就逼近于 0。

      softmax 激活函数用于多分类

 

   ④. Relu

     ReLU (rectified linear unit, relu) 修正线性单元

     relu 是从底部开始半修正的一种函数。该激活函数使网络快速地收敛。它不会饱和(指 x > 0 部分), 即它可以对抗梯度消失问题,至少在正区域(x > 0)可以这样,因此神经网络至少在一半区域中不会把所有零进行反向传播。由于使用了简单的阈值化(thresholding), relu 计算效率很高。

     relu 的数学公式及图像如下:

         \large f(x) = max(0, x)

         即 \large f(x) =\left\{\begin{matrix} x &\;\;\; x > 0 \\ 0&\;\;\; x \leqslant 0 \end{matrix}\right.

              \large f'(x) =\left\{\begin{matrix} 1 &\;\;\; x > 0 \\ 0&\;\;\; x \leqslant 0 \end{matrix}\right.

   

        relu 的缺点:

        a. 不以零为中心,和 sigmoid 激活函数类似, relu 函数的输出不以零为中心,会导致中心偏移

        b. 前向传导(forward pass)过程中,如果 x < 0, 则神经元保持非激活状态,且在反向传播(backward pass) 中 “杀死” 梯度。这样权重无法得到更新,网络无法学习。当 x = 0 时,该点的梯度未定义,但是这个问题在实现中得到了解决,通过采用左侧或右侧的梯度的方式。

 

   ⑤. Swish

       swish 激活函数又叫做自门控激活函数,它是由谷歌的研究者近期发布的,swish 激活函数的性能优于 relu 函数。swish 在 x 轴的负区域曲线的形状与 relu 激活函数不同, swish 函数的输出可能下降,即使在输入值增大的情况下。大多数激活函数是单调的,即输入值增大的情况下,输出值不可能下降。swish 函数为 0 时,具备单侧有界(one-sided boundedness)的特性,它是平滑、非单调的。

        swish 的数学公式及图像如下:

         \large f(x) = x Sigmoid(\beta x) = \frac{x}{1 + e^{-\beta x}}

       

         导数:

              

              当 β = 0 时,swish 变为线性函数  \large f(x) = \frac{x}{2}

              swish 函数可以看作是介于线性函数与 relu 函数之间的平滑函数。

 

   ⑥.  Leaky Relu

       leaky relu 试图缓解 relu 梯度消失的问题

       leaky relu 的概念:  当 x < 0 时,它得到 0.1 的梯度,该函数在一定程度上缓解了 relu 梯度消失的问题。尽管 leaky relu 具备 relu 激活函数的所有特征,如计算高效,快速收敛,在正区域不会饱和。但是,使用 leaky relu 函数的结果并不连贯。

       leaky relu 的数学公式及图像如下: 

           \large f(x) = max(0.1 x, x)

           即  \large f(x) = \left\{\begin{matrix} x &\;\;\; x > 0 \\ 0.1 x&\;\;\; x \leqslant 0 \end{matrix}\right.

             

 

   ⑦.  Parametric Relu

       PReLU 函数的数学公式为:

         \large f(x) = max(\alpha x, x)      

         \large \alpha :为超参,常取 0.7

      这里引入一个随机的超参数 α,它可以被学习,因为可以对它进行反向传播。这使神经元能够选择负区域最好的梯度,有了这种能力,它可以变成 relu 或 leaky relu。类似的还有 RReLU  \large (Rondom \; \alpha),这里的 \large \alpha 为随机数。

 

   ⑧.  ELU

       ELU (exponential linear unit, ELU) 指数线性单元,也属于 relu 修正类激活函数的一员。和 perlu 以及 rrelu 类似,为负值输入添加了一个非零输出。和其他修正激活函数不同的是,它包括一个负指数项,从而防止静默神经元出现,导致收敛为零,从而提高学习率。

       ELU数学公式及图像如下:

          \large f(x) =\left\{\begin{matrix} x &\;\;\; x > 0 \\ \alpha (e^{x} - 1) &\;\;\; x \leqslant 0 \end{matrix}\right.

         \large f'(x) =\left\{\begin{matrix} 1 &\;\;\; x > 0 \\ \alpha e^{x} &\;\;\; x \leqslant 0 \end{matrix}\right.

          \large \alpha :为超参,常取 0.7

        

 

   其他还有不少激活函数(如,SELu,SRelu,LeCun Tanh, ArcTanh, SoftPlus….等),但是,并不如何常用,就不一一细说了,反正,基本很少用,特别是在别人的预训练模型上,更是见不到。

 

 

 

                

 

 

返回主目录

返回神经网络目录

上一章:深度篇——神经网络(一)  神经元与感知机

下一章:深度篇——神经网络(三)  网络拓扑与训练神经网络

Published 42 original articles · won praise 15 · views 2769

Guess you like

Origin blog.csdn.net/qq_38299170/article/details/104118845