激活函数

激活函数是非线性函数,如果不用激活函数,再深的网络也是线性模型。

sigmoid

也叫s函数,其函数和导函数:

sigmod(x)=11+ex(0,1)sigmod(x)=sigmod(x)(1sigmod(x))=11+exex1+ex=ex(1+ex)2(0,0.25)\begin{aligned} &\operatorname{sigmod}(x)=\frac{1}{1+e^{-x}} \in(0,1) \\ &\operatorname{sigmod}^{\prime}(x)=\operatorname{sigmod}(x) *(1-\operatorname{sigmod}(x))=\frac{1}{1+e^{-x}} * \frac{e^{-x}}{1+e^{-x}}=\frac{e^{-x}}{\left(1+e^{-x}\right)^{2}} \in(0,0.25) \end{aligned}
  • 输出范围在0~1之间,均值为0.5,需要做数据偏移,不方便下一层的学习。

  • 当x很小或很大时,存在导数很小的情况。另外,神经网络主要的训练方法是BP算法,BP算法的基础是导数的链式法则,也就是多个导数的乘积。而sigmoid的导数最大为0.25,多个小于等于0.25的数值相乘,其运算结果很小。随着神经网络层数的加深,梯度后向传播到浅层网络时,基本无法引起参数的扰动,也就是没有将loss的信息传递到浅层网络,这样网络就无法训练学习了。这就是所谓的梯度消失。

tanh

tanh(x)=1e2x1+e2x(1,1)tanh(x)=1(tanh(x))2=4e2x(1+e2x)2(0,1]\begin{aligned} &\tanh (x)=\frac{1-e^{-2 x}}{1+e^{-2 x}} \in(-1,1) \\ &\tanh ^{\prime}(x)=1-(\tanh (x))^{2}=\frac{4 e^{-2 x}}{\left(1+e^{-2 x}\right)^{2}} \in(0,1] \end{aligned}
  • 在神经网络的应用中,tanh通常要优于sigmod的,因为tanh的输出在-1~1之间,均值为0,更方便下一层网络的学习。但有一个例外,如果做二分类,输出层可以使用sigmod,因为他可以算出属于某一类的概率

  • Sigmod(x)和tanh(x)都有一个缺点:在深层网络的学习中容易出现梯度消失,造成学习无法进行。

Relu

relu(x)=max(x,0)={x,x00,x<0[0,+)relu(x)={1,x00,x<0{0,1}\begin{aligned} &\operatorname{relu}(x)=\max (x, 0)=\left\{\begin{array}{ll} x, & x \geq 0 \\ 0, & x<0 \end{array} \in[0,+\infty)\right. \\ &\operatorname{relu}^{\prime}(x) & =\left\{\begin{array}{ll} 1, & x \geq 0 \\ 0, & x<0 \end{array} \in\{0,1\}\right. \end{aligned}
  • 有 Dead ReLU 问题,当x为负时导数等于零,但是在实践中没有问题,也可以使用leaky Relu。

LeakyReLU

 LeakyReLU (x)={x,x0ax,x<0R LeakyReL U(x)={1,x0a,x<0{a,1}\begin{aligned} &\text { LeakyReLU }(x)=\left\{\begin{array}{l} x, \quad x \geq 0 \\ a x, \quad x<0 \end{array} \in R\right. \\ &\text { LeakyReL } U^{\prime}(x)=\left\{\begin{array}{ll} 1, & x \geq 0 \\ a, & x<0 \end{array} \in\{a, 1\}\right. \end{aligned}

Relu6

 relu 6(x)=min(max(x,0),6)[0,6] relu 6(x)={1,0<x<60, 其他 {0,1}\begin{aligned} & \text { relu } 6(x)=\min (\max (x, 0), 6) \in[0,6] \\ \text { relu } 6^{\prime}(x) &=\left\{\begin{array}{ll} 1, & 0<x<6 \\ 0, & \text { 其他 } \end{array} \in\{0,1\}\right. \end{aligned}

ELu

g(x)=ELU(x)={x,x>0α(ex1),x0g(x)=\operatorname{ELU}(x)=\left\{\begin{aligned} x, & x>0 \\ \alpha\left(\mathrm{e}^{x}-1\right), & x \leqslant 0 \end{aligned}\right.
  • 没有 Dead ReLU 问题,输出的平均值接近 0,以 0 为中心;

  • ELU 通过减少偏置偏移的影响,使正常梯度更接近于单位自然梯度,从而使均值向零加速学习;

  • ELU 在较小的输入下会饱和至负值,从而减少前向传播的变异和信息。

  • 一个小问题是它的计算强度更高。

PRelu

f(yi)={yi, if yi>0aiyi, if yi0f\left(y_{i}\right)= \begin{cases}y_{i}, & \text { if } y_{i}>0 \\ a_{i} y_{i}, & \text { if } y_{i} \leq 0\end{cases}
  • 如果 a_i= 0,则 f 变为 ReLU

  • 如果 a_i> 0,则 f 变为 leaky ReLU

  • 如果 a_i 是可学习的参数,则 f 变为 PReLU

Last updated

Was this helpful?