当前位置:网站首页>【激活函数】
【激活函数】
2022-06-28 21:08:00 【2345VOR】
1. 激活函数简述
激活函数是向神经网络中引入非线性因素,通过激活函数神经网络就可以拟合各种曲线。激活函数主要分为饱和激活函数(Saturated Neurons)和非饱和函数(One-sided Saturations)。Sigmoid和Tanh是饱和激活函数,而ReLU以及其变种为非饱和激活函数。非饱和激活函数主要有如下优势:
非饱和激活函数可以解决梯度消失问题。
非饱和激活函数可以加速收敛。
2.激活函数特点
一般来说,在神经元中,激活函数是很重要的一部分,为了增强网络的表示能力和学习能力,神经网络的激活函数都是非线性的,通常具有以下几点性质:
- 连续并可导(允许少数点上不可导),可导的激活函数可以直接利用数值优化的方法来学习网络参数;
- 激活函数及其导数要尽可能简单一些,太复杂不利于提高网络计算率;
- 激活函数的导函数值域要在一个合适的区间内,不能太大也不能太小,否则会影响训练的效率和稳定性。
3. 相关疑问
- 什么是激活函数,为什么需要激活函数?
激活函数是在神经网络层间输入与输出之间的一种函数变换,目的是为了加入非线性因素,增强模型的表达能力。
了解那些激活函数以及应用?回答主要分两类(饱和/非饱和),以及应用场景等。有时候可能特定到具体经典模型,比如LSTM用到Tanh,Transfromer中用到的ReLU,Bert中的GeLU,YOLO的Leaky ReLU等。

梯度消失与梯度爆炸现象与原因以及解决办法?参看梯度消失与梯度爆炸部分。
ReLU激活函数为什么会出现死神经元,解决办法?
除上文提到输入为负值时,ReLU的梯度为0造成神经元死亡。还有Learning rate太高导致在训练过程中参数更新太大 。
解决办法主要有:1.优化参数。 2.避免将learning rate设置太大,或者使用Adam等自动调节learning rate的方法。3.更换激活函数。
4. python绘制激活函数图像
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10,10)
##### 绘制sigmoid图像
fig = plt.figure()
y_sigmoid = 1/(1+np.exp(-x))
ax = fig.add_subplot(321)
ax.plot(x,y_sigmoid,color='blue')
ax.grid()
ax.set_title('(a) Sigmoid')
ax.spines['right'].set_color('none') # 去除右边界线
ax.spines['top'].set_color('none') # 去除上边界线
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
##### 绘制Tanh图像
ax = fig.add_subplot(322)
y_tanh = (np.exp(x)-np.exp(-x))/(np.exp(x)+np.exp(-x))
ax.plot(x,y_tanh,color='blue')
ax.grid()
ax.set_title('(b) Tanh')
ax.spines['right'].set_color('none') # 去除右边界线
ax.spines['top'].set_color('none') # 去除上边界线
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
##### 绘制Relu图像
ax = fig.add_subplot(323)
y_relu = np.array([0*item if item<0 else item for item in x ])
ax.plot(x,y_relu,color='darkviolet')
ax.grid()
ax.set_title('(c) ReLu')
ax.spines['right'].set_color('none') # 去除右边界线
ax.spines['top'].set_color('none') # 去除上边界线
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
##### 绘制Leaky Relu图像
ax = fig.add_subplot(324)
y_relu = np.array([0.2*item if item<0 else item for item in x ])
ax.plot(x,y_relu,color='darkviolet')
ax.grid()
ax.set_title('(d) Leaky Relu')
ax.spines['right'].set_color('none') # 去除右边界线
ax.spines['top'].set_color('none') # 去除上边界线
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
##### 绘制ELU图像
ax = fig.add_subplot(325)
y_elu = np.array([2.0*(np.exp(item)-1) if item<0 else item for item in x ])
ax.plot(x,y_elu,color='darkviolet')
ax.grid()
ax.set_title('(d) ELU alpha=2.0')
ax.spines['right'].set_color('none') # 去除右边界线
ax.spines['top'].set_color('none') # 去除上边界线
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
ax = fig.add_subplot(326)
y_sigmoid_dev = y_sigmoid*(1-y_sigmoid)
ax.plot(x,y_sigmoid_dev,color='green')
ax.grid()
ax.set_title('(e) Sigmoid Dev')
ax.spines['right'].set_color('none') # 去除右边界线
ax.spines['top'].set_color('none') # 去除上边界线
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
plt.tight_layout()
plt.savefig('Activation.png')
plt.show()

参考文献:
python绘制激活函数图像
详解激活函数(Sigmoid/Tanh/ReLU/Leaky ReLu等)
深度学习笔记:如何理解激活函数?
边栏推荐
- 在哪个软件上开户比较安全,开户流程是什么?
- 应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)
- Ref attribute, props configuration, mixin mixing, plug-in, scoped style
- Keyword long
- Analysis of variance
- Bitbucket 使用 SSH 拉取仓库失败的问题
- LeetCode每日一题——剑指 Offer II 091. 粉刷房子
- Proficient in data analysis, double the income? What is the strongest competitiveness
- LeetCode每日一题——522. 最长特殊序列 II
- How to open an account in great wisdom? Is it safe
猜你喜欢

On the complexity of software development and the way to improve its efficiency

数据资产为王,如何解析企业数字化转型与数据资产管理的关系?

Leetcode 36. 有效的数独(可以,一次过)

How do I download videos? Look at the super simple method!

RT-Thread线程同步与线程通信

图神经网络也能用作CV骨干模型,华为诺亚ViG架构媲美CNN、Transformer

Visualization of neural network structure in different frames

LeetCode每日一题——515. 在每个树行中找最大值

The further application of Li Kou tree

How to use dataant to monitor Apache apisex
随机推荐
Ehcache配置资料,方便自己查
The further application of Li Kou tree
Resilience4j retry source code analysis and retry index collection
LeetCode1114. Print in sequence
Web 自动化环境搭建
国产数据库名录一览
Ref attribute, props configuration, mixin mixing, plug-in, scoped style
Binary tree problems
LeetCode877. 石子游戏
穩定性總結
请问同业存单是否靠谱,安全吗
Ehcache configuration data, convenient for self checking
题解 Andy s First Dictionary(UVa10815)紫书P112set的应用
The comprehensive application of the setstack computer (uva12096) Purple Book p116stl
题解 The Blocks Problem(UVa101)紫书P110vector的应用
Keyword long
LeetCode每日一题——515. 在每个树行中找最大值
题解 Pie(POJ3122)超详细易懂的二分入门
学习太极创客 — MQTT 第二章(七)ESP8266 MQTT 遗嘱应用
券商公司开户哪个最靠谱最安全呢