专注于工业智能预警系统研发, 通过机理算法和数据驱动算法分析振动信号、音频、DCS、PLC信号、SCADA信号等设备运行状态数据对机器设备进行看病预诊,为机器设备健康运行保驾护航。 网站正在不断建设和完善过程中,欢迎大家给予建议和参与社区建设
52phm,专注于预测性维护知识学习和交流,欢迎广大从事预测性维护行业人员投稿,投稿请联系管理员(wx: www52phmcn),投稿内容可以是:
对于激活函数的应用是比较熟悉和频繁的,但一直以来没有系统性地把深度学习中地激活函数做一个总结,因此小知同学特地对常用的激活函数做一个比较全面的总结,在讲述理论的同时,也根据激活函数的公式进行编程实现
2020.1.7 & 小知同学
所谓激活函数(Activation Function),就是在人工神经网络的神经元上运行的函数,负责将神经元的输入映射到输出端。
激活函数(Activation functions)对于人工神经网络模型去学习、理解非常复杂和非线性的函数来说具有十分重要的作用。它们将非线性特性引入到我们的网络中。如图1,在神经元中,输入的 inputs 通过加权,求和后,还被作用了一个函数,这个函数就是激活函数。引入激活函数是为了增 加神经网络模型的非线性。没有激活函数的每层都相当于矩阵相乘。就算你叠加了若干层之后,无非还是个矩阵相乘罢了。
如果不用激活函数,每一层输出都是上层输入的线性函数,无论神经网络有多少层,输出都是输入的线性组合,这种情况就是最原始的感知机(Perceptron)。 如果使用的话,激活函数给神经元引入了非线性因素,使得神经网络可以任意逼近任何非线性函数,这样神经网络就可以应用到众多的非线性模型中。
我觉得机器学习的传统算法与深度学习算法的比较重要的区别是:
1. 从广义上来讲,机器学习的传统算法一般只能使用一种目标模型函数,比如逻辑回归使用logistic函数、只能解决单维度问题;而深度学习可以在不同神经层使用不同或者多种激活函数、因此拥有多种或者不同函数的特性,所以解决问题具有多维度、线性、非线性等处理能力
2. 深度学习的激活函数使得深度学习算法既能解决简单的线性问题、也能处理复杂的非线性问题
3. 数据中的特征往往具有不同的特性、特征与不同模型之间也有较大的辨识差异,机器学习的传统算法的单一模型可能只能对部分特征产生重要作用,而深度学习的多种激活函数则比较全面、多维度对特征进行学习
import warnings
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
warnings.filterwarnings('ignore')
%matplotlib inline
x = np.linspace(-10, 10, 100)
!pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade pip
!pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow==2.0
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Requirement already up-to-date: pip in /opt/conda/lib/python3.6/site-packages (19.3.1)
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Requirement already up-to-date: tensorflow==2.0 in /opt/conda/lib/python3.6/site-packages (2.0.0)
Requirement already satisfied, skipping upgrade: termcolor>=1.1.0 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (1.1.0)
Requirement already satisfied, skipping upgrade: protobuf>=3.6.1 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (3.11.2)
Requirement already satisfied, skipping upgrade: astor>=0.6.0 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (0.8.1)
Requirement already satisfied, skipping upgrade: numpy<2.0,>=1.16.0 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (1.18.1)
Requirement already satisfied, skipping upgrade: keras-preprocessing>=1.0.5 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (1.1.0)
Requirement already satisfied, skipping upgrade: opt-einsum>=2.3.2 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (3.1.0)
Requirement already satisfied, skipping upgrade: six>=1.10.0 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (1.13.0)
Requirement already satisfied, skipping upgrade: tensorboard<2.1.0,>=2.0.0 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (2.0.2)
Requirement already satisfied, skipping upgrade: wrapt>=1.11.1 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (1.11.2)
Requirement already satisfied, skipping upgrade: google-pasta>=0.1.6 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (0.1.8)
Requirement already satisfied, skipping upgrade: gast==0.2.2 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (0.2.2)
Requirement already satisfied, skipping upgrade: absl-py>=0.7.0 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (0.9.0)
Requirement already satisfied, skipping upgrade: grpcio>=1.8.6 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (1.26.0)
Requirement already satisfied, skipping upgrade: wheel>=0.26 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (0.33.6)
Requirement already satisfied, skipping upgrade: tensorflow-estimator<2.1.0,>=2.0.0 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (2.0.1)
Requirement already satisfied, skipping upgrade: keras-applications>=1.0.8 in /opt/conda/lib/python3.6/site-packages (from tensorflow==2.0) (1.0.8)
Requirement already satisfied, skipping upgrade: setuptools in /opt/conda/lib/python3.6/site-packages (from protobuf>=3.6.1->tensorflow==2.0) (45.0.0)
Requirement already satisfied, skipping upgrade: google-auth-oauthlib<0.5,>=0.4.1 in /opt/conda/lib/python3.6/site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (0.4.1)
Requirement already satisfied, skipping upgrade: requests<3,>=2.21.0 in /opt/conda/lib/python3.6/site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (2.22.0)
Requirement already satisfied, skipping upgrade: google-auth<2,>=1.6.3 in /opt/conda/lib/python3.6/site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (1.10.0)
Requirement already satisfied, skipping upgrade: markdown>=2.6.8 in /opt/conda/lib/python3.6/site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (3.1.1)
Requirement already satisfied, skipping upgrade: werkzeug>=0.11.15 in /opt/conda/lib/python3.6/site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (0.16.0)
Requirement already satisfied, skipping upgrade: h5py in /opt/conda/lib/python3.6/site-packages (from keras-applications>=1.0.8->tensorflow==2.0) (2.10.0)
Requirement already satisfied, skipping upgrade: requests-oauthlib>=0.7.0 in /opt/conda/lib/python3.6/site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (1.3.0)
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /opt/conda/lib/python3.6/site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (2.6)
Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/lib/python3.6/site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (1.25.7)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /opt/conda/lib/python3.6/site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (2018.11.29)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.6/site-packages (from requests<3,>=2.21.0->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (3.0.4)
Requirement already satisfied, skipping upgrade: pyasn1-modules>=0.2.1 in /opt/conda/lib/python3.6/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (0.2.8)
Requirement already satisfied, skipping upgrade: cachetools<5.0,>=2.0.0 in /opt/conda/lib/python3.6/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (4.0.0)
Requirement already satisfied, skipping upgrade: rsa<4.1,>=3.1.4 in /opt/conda/lib/python3.6/site-packages (from google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (3.4.2)
Requirement already satisfied, skipping upgrade: oauthlib>=3.0.0 in /opt/conda/lib/python3.6/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (3.1.0)
Requirement already satisfied, skipping upgrade: pyasn1<0.5.0,>=0.4.6 in /opt/conda/lib/python3.6/site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard<2.1.0,>=2.0.0->tensorflow==2.0) (0.4.8)
tf.__version__
'2.0.0'
# 手写计算函数
def sigmoid(z, mode=False):
if mode: # 手写公式
L = []
for i in range(len(z)):
sigmoid_value = 1/(1(2.7183)**(-z[i]))
L.append(sigmoid_value)
return L
else: # 使用numpy
return 1/(1np.exp(-z))
plt.plot(x, sigmoid(z=x))
[<matplotlib.lines.Line2D at 0x7f71497d14e0>]
# 调用 Tensorflow 的 sigmoid 函数
y_sigmoid = tf.nn.sigmoid(x)
plt.plot(x, y_sigmoid)
[<matplotlib.lines.Line2D at 0x7f7167556c50>]
def tanh(z, mode=True):
if mode: # 手写公式
L = []
for i in range(len(z)):
exp1 = 2.7183**(z[i])
exp2 = 2.7183**(-z[i])
tanh_value = (exp1-exp2)/(exp1exp2)
L.append(tanh_value)
return L
else: # 使用numpy
return (np.exp(x)-np.exp(-x))/(np.exp(x)np.exp(-x))
plt.plot(x,tanh(z=x))
[<matplotlib.lines.Line2D at 0x7f71482a5128>]
# 调用 Tensorflow 的 tanh 函数
y_tanh = tf.nn.tanh(x)
plt.plot(x, y_tanh)
[<matplotlib.lines.Line2D at 0x7f714820c4a8>]
修正线性单元(Rectified linear unit,ReLU)
1. relu函数计算公式
def relu(x): # 手写公式
relu_list = []
for i in range(len(x)):
relu_list.append(max(0, x[i]))
return relu_list
plt.ylim(-1,6)
plt.plot(x, relu(x))
[<matplotlib.lines.Line2D at 0x7f71481d5860>]
# 调用 Tensorflow 的 relu 函数
y_relu = tf.nn.relu(x)
plt.ylim(-1,6)
plt.plot(x, y_relu)
[<matplotlib.lines.Line2D at 0x7f714815fbe0>]
带泄露修正线性单元(Leaky ReLU)函数是经典(以及广泛使用的)的ReLu激活函数的变体,该函数输出对负值输入有很小的坡度,它旨在解决负梯度神经元死亡的问题。由于负梯度神经元导数总是不为零,这能减少静默神经元的出现,允许基于梯度的学习(虽然会很慢),解决了Relu函数进入负区间后神经元不学习的问题。
def leaky_rule(z): # 手写公式
L = []
for i in range(len(z)):
lrule_value = max(0.1*z[i], z[i])
L.append(lrule_value)
return L
plt.plot(x, leaky_rule(z=x))
[<matplotlib.lines.Line2D at 0x7f71480d1630>]
# 调用 Tensorflow 的 leaky_relu 函数
y_lrelu = tf.nn.leaky_relu(x)
plt.plot(x, y_lrelu)
[<matplotlib.lines.Line2D at 0x7f714803f160>]
指数线性单元(Exponential Linear Units)
def elu(z, a=0.1): # 手写公式
L = []
for i in range(len(z)):
if z[i] >= 0:
elu_value = z[i]
L.append(elu_value)
else:
elu_value = a*(2.7183**(z[i]) - 1)
L.append(elu_value)
return L
plt.plot(x, elu(z=x, a=1))
[<matplotlib.lines.Line2D at 0x7f71407ec2e8>]
# 调用 Tensorflow 的 elu 函数
y_elu = tf.nn.elu(x)
plt.plot(x, y_elu)
[<matplotlib.lines.Line2D at 0x7f714074abe0>]
参考资料
[1] 百度百科,激活函数,https://baike.baidu.com/item/%E6%BF%80%E6%B4%BB%E5%87%BD%E6%95%B0/2520792?fr=aladdin
[2] 百面机器学习,深度神经网络中的激活函数
[3] CSDN博客,常用激活函数,https://blog.csdn.net/qq_23304241/article/details/80300149
[4] CSDN博客,ELU激活函数, https://blog.csdn.net/zrh_CSDN/article/details/81266188
2021-12-17 14:28:16
互联网
815
分类:开发环境
专栏:下载安装
2021-12-25 19:50:04
互联网
756
分类:算法开发
专栏:时间序列预测
2022-01-17 22:21:56
博客笔记
486
分类:算法开发
专栏:python基础
关注公众号进群
让志同道合读者学习交流
本文主要介绍如何使用python搭建:一个基于深度学习的滚动轴承故障诊断系统项目中涉及使用了多种方法对比检测结果,包括:传统机器学习方法:随机森林深度学习方法:CNN增加残差模块后的深度学习方法:ResNet如各位童鞋需要更换训练数据,完全可以根据源码将图像和标注文件更换即可直接运行。
2021-12-10 18:15:00
互联网
1174
分类:算法开发
专栏:故障诊断
第一次接触Python,可能是爬虫或者是信息AI开发的小朋友,都说Python 语言简单,那么多学一些总是有好处的,下面从一个完全不懂的Python 的小白来安装Python 等一系列工作的记录,并且遇到的问题也会写出,让完全不懂的小白也可上手安装,并且完成第一个Hello world代码。[Python 安装]进入Python的官方下载页面http://www.python.org/download/出现很
2021-12-15 14:47:52
互联网
1404
分类:开发环境
专栏:下载安装
论文:Angle-Based Outlier Detection in High-dimensional Data,kdd2008问题高维度情况下,距离同质化。基础:1、在高维空间中角度比距离更稳定[1]2、如果其他大部分的点都在相似的方向上,那么点O是个离群点3、如果许多其他的点在不同的方向上,那么点O不是离群点。方法对于一个给定的点P,它与任意其他点x,y之间的角度构成一个...
2021-12-19 14:55:27
互联网
954
分类:论文速递
专栏:工业异常检测
异常值是与其余数据存在显然不同的数据点。 霍金斯定义异常值如下: <br> “异常值是一个与其他观察结果有很大差异的观察结果,以此引起人们怀疑它是由不同的机制产生的”。 <br> 在数据挖掘和统计学文献中,异常值也被称为abnormalities、discordants、deviants或anomalies。 在大多数应用中,数据是由一个或多个生成过程创建的,这些生成过程既可以反映系统中的活动,也可以反映收集的有关实体的观察结果。当生成过程表现异常时,会导致创建异常值。 因此,异常经常包含有关系统和实体影响数据生成过程的异常特征的有用信息。 对这些不寻常的特性的认识提供了有用的应用特定见解。 一些例子如下:
2021-12-21 11:00:12
互联网
424
分类:算法开发
专栏:工业异常检测
几乎所有异常值检测算法都会建立数据中正常模式的模型,然后根据这些模式的偏差计算给定数据点的异常值。 例如,该数据模型可以是生成模型,例如高斯混合模型,基于回归的模型或基于邻近的模型。 所有这些模型对数据的“正常”行为做出不同的假设。 然后通过评估数据点与模型之间的拟合质量来计算数据点的离群值分数。 在很多情况下,模型可能是算法定义的。 例如,基于最近邻的离群值检测算法根据其最近邻距离的分布对数据点
2021-12-21 11:00:33
互联网
401
分类:算法开发
专栏:工业异常检测
# Sen's slopeimport numpy as npfrom pandas import Seriesfrom scipy.stats import normdef sens_slope_trend_detection(inputdata,conf_level=0.95): inputdata = Series(inputdata) n = inputda...
2021-12-21 11:05:07
互联网
736
分类:算法开发
专栏:工业异常检测
XGBoost Regression
2021-12-25 19:52:19
互联网
458
分类:算法开发
专栏:时间序列预测
python输入input输出print函数python输入输出语句分别对应着input()和print()函数,下面分别对这两个函数进行介绍和实操。1、输入语句input()新建一个tmp.py文件当我们输入字符串时,返回数据类型是字符串# -*- coding: utf-8 -*-name = input("请输入您的名字:")print(name, type(name))运行tmp.py后,会提示手动输入信息,回车后就可以得到输出结果:请输入您的名字:小知小知 <c
2022-01-17 23:25:01
博客笔记
837
分类:算法开发
专栏:python基础
python模块import导入模块导入分为python内置模块(或者第三方模块)导入和自定义模块导入。模块导入方法可以总结为5大导入方法,下面以python内置模块角度来举例介绍5大导入方法。(1)import… 方法表示导入某个模块# 导入numpy模块import numpyarr = numpy.array([1, 2, 4])print(arr)# [1 2 4](2)import…as…方法import xx as yy,意思是把xx作为yy表示,相当于xx可以使用yy来
2022-01-17 23:59:41
博客笔记
1256
分类:算法开发
专栏:python基础
1. 当运用计算机实现工程测试信号处理时,不可能对无限长的信号进行测量和运算,而是取其有限的时间片段进行分析。做法是从信号中截取一个时间片段,然后用观察的信号时间片段进行周期延拓处理,得到虚拟的无限长的信号,然后就可以对信号进行傅里叶变换、相关分析等数学处理。无线长的信号被截断以后,其频谱发生了畸变,原来集中在f(0)处的能量被分散到两个较宽的频带中去了(这种现象称之为频谱能量泄漏)。 1. 为了减少频谱能量泄漏,可采用不同的截取函数对信号进行截断,截断函数称为窗函数,简称为窗。 1. 信号截断以后产生的能量泄漏现象是必然的,因为窗函数w(t)是一个频带无限的函数,所以即使原信号x(t)是限带宽信号,而在截断以后也必然成为无限带宽的函数,即信号在频域的能量与分布被扩展了。又从采样定理可知,无论采样频率多高,只要信号一经截断,就不可避免地引起混叠,因此信号截断必然导致一些误差。泄漏与窗函数频谱的两侧旁瓣有关,如果两侧瓣的高度趋于零,而使能量相对集中在主瓣,就可以较为接近于真实的频谱,为此,在时间域中可采用不同的窗函数来截断信号。
2022-02-11 13:19:32
博客笔记
905
分类:算法开发
专栏:振动信号预处理
从事设备故障预测与健康管理行业多年的PHM算法工程师(机器医生)、国际振动分析师, 实践、研发和交付的项目涉及“化工、工业机器人、风电机组、钢铁、核电、机床、机器视觉”等领域。专注于工业智能预警系统研发, 通过机理算法和数据驱动算法分析振动信号、音频、DCS、PLC信号、SCADA信号等设备运行状态数据对机器设备进行看病预诊,为机器设备健康运行保驾护航。