Sigmoid激活函数

import math
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10,10)
a=np.array(x)
y1=1/(1+math.e**(-x))
y2=math.e**(-x)/((1+math.e**(-x))**2)
plt.xlim(-11,11)
ax = plt.gca()                                            # get current axis 获得坐标轴对象
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')         # 将右边 上边的两条边颜色设置为空 其实就相当于抹掉这两条边
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')          # 指定下边的边作为 x 轴   指定左边的边为 y 轴
ax.spines['bottom'].set_position(('data', 0))   #指定 data  设置的bottom(也就是指定的x轴)绑定到y轴的0这个点上
ax.spines['left'].set_position(('data', 0))
plt.plot(x,y1,label='Sigmoid',linestyle="-", color="blue")#label为标签
plt.plot(x,y2,label='Deriv.Sigmoid',linestyle="--", color="red")#l
#plt.legend(loc=0,ncol=2)
plt.legend(['Sigmoid','Deriv.Sigmoid'])plt.savefig('plot_test.png', dpi=500) #指定分辨率
plt.show()

Tanh激活函数

import math
import numpy as np
import matplotlib.pyplot as pltx = np.arange(-10,10)
a=np.array(x)
y1=(math.e**(x)-math.e**(-x))/(math.e**(x)+math.e**(-x))
plt.xlim(-11,11)
ax = plt.gca()                                            # get current axis 获得坐标轴对象
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')         # 将右边 上边的两条边颜色设置为空 其实就相当于抹掉这两条边
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')          # 指定下边的边作为 x 轴   指定左边的边为 y 轴
ax.spines['bottom'].set_position(('data', 0))   #指定 data  设置的bottom(也就是指定的x轴)绑定到y轴的0这个点上
ax.spines['left'].set_position(('data', 0))
plt.plot(x,y1,label='Tanh',linestyle="-", color="green")#label为标签
plt.legend(['Tanh'])
plt.savefig('Tanh.png', dpi=500) #指定分辨
plt.show()

ReLU激活函数

import numpy as np
import matplotlib.pyplot as pltfig = plt.figure(figsize=(6,4))
ax = fig.add_subplot(111)
x = np.arange(-10, 10)
y = np.where(x<0,0,x)#满足条件(condition),输出x,不满足输出y
plt.xlim(-11,11)
plt.ylim(-11,11)
ax = plt.gca()                                            # get current axis 获得坐标轴对象
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')         # 将右边 上边的两条边颜色设置为空 其实就相当于抹掉这两条边
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')          # 指定下边的边作为 x 轴   指定左边的边为 y 轴
ax.spines['bottom'].set_position(('data', 0))   #指定 data  设置的bottom(也就是指定的x轴)绑定到y轴的0这个点上
ax.spines['left'].set_position(('data', 0))plt.plot(x,y,label='ReLU',linestyle="-", color="darkviolet")#label为标签
plt.legend(['ReLU'])
plt.savefig('ReLU.png', dpi=500) #指定分辨
plt.show()
#!/usr/bin/python #encoding:utf-8
import math
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
mpl.rcParams['axes.unicode_minus']=Falsedef  sigmoid(x):return 1.0 / (1.0 + np.exp(-x))fig = plt.figure(figsize=(6,4))
ax = fig.add_subplot(111)x = np.linspace(-10, 10)
y = sigmoid(x)
tanh = 2*sigmoid(2*x) - 1plt.xlim(-11,11)
plt.ylim(-1.1,1.1)ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.set_xticks([-10,-5,0,5,10])
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
ax.set_yticks([-1,-0.5,0.5,1])plt.plot(x,y,label="Sigmoid",color = "blue")
plt.plot(2*x,tanh,label="Tanh", color = "red")
plt.legend()
plt.show()

转自:参考1与参考2

python绘制sigmoid及tanh函数相关推荐

  1. 最全面:python绘制Sigmoid、Tanh、Swish、ELU、SELU、ReLU、ReLU6、Leaky ReLU、Mish、hard-Sigmoid、hard-Swish等激活函数(有源码)

    python绘制激活函数 代码 示例 代码 我构建了一个关于激活函数的类,大家可以随意使用,包括其输出值和梯度值. 关于这些激活函数详解可以参考我这篇博客:深度学习-激活函数详解(Sigmoid.ta ...

  2. relu,sigmoid,tanh函数图像(python)

    relu,sigmoid,tanh函数图像(python) 1.导入工具包 import math import matplotlib.pyplot as plt import numpy as np ...

  3. python绘制条形图用什么函数_Python绘制正余弦函数图像完整代码

    通过python绘制正弦和余弦函数,从默认的设置开始,一步一步地调整改进,让它变得好看,变成我们初高中学习过的图象那样.通过这个过程来学习如何进行对图表的一些元素的进行调整. 01. 简单绘图 mat ...

  4. python绘制一个简单的函数图像使用到了matplotlib库和numpy库

    文章目录 效果展示: 视频链接 实现的思想 使用到的函数包 图片一对应的代码展示 图片二 对应的代码展示 注意事项 效果展示: 视频链接 python绘制一个简单的函数图像(B站视频) 实现的思想 其 ...

  5. 使用matlab画sigmoid和tanh函数图像

    在学深度学习的时候,会遇到激活函数,下面就用matlab画出sigmoid和tanh的函数图像,直观感受一下. x=linspace(-10.0,10.0); y=1./(1.0+exp(-1.0*x ...

  6. python 画sigmoid、tanh、relu和ELU等激活函数

    1.前言 写毕业论文时候画了激活函数的函数图,也是参考别人的代码做的,我将格式统一了一些,现在分享出来. 2.代码 2.1 sigmoid和tanh import math import matplo ...

  7. 深度学习常用的激活函数以及python实现(Sigmoid、Tanh、ReLU、Softmax、Leaky ReLU、ELU、PReLU、Swish、Squareplus)

    2022.05.26更新 增加SMU激活函数 前言 激活函数是一种添加到人工神经网络中的函数,类似于人类大脑中基于神经元的模型,激活函数最终决定了要发射给下一个神经元的内容. 此图来自百度百科,其中s ...

  8. python绘制条形图用什么函数_python绘制条形图方法代码详解

    1.首先要绘制一个简单的条形图 import numpy as np import matplotlib.pyplot as plt from matplotlib import mlab from ...

  9. Python绘制sigmoid函数及其导数图像

    import numpy as np import matplotlib.pyplot as plt def sigmoid(x):y=1/(1+np.exp(-x))#dy=y*(1-y)retur ...

最新文章

  1. python中6 2是什么意思_python2.6中SyntaxError是什么错误?
  2. LSA 安装及管理应用程序
  3. Matlab中plot基本用法
  4. css的一种预处理器 sass
  5. 前后端分离 与 不分离
  6. 世界各国国家代码简称 - 备用
  7. 1688淘口令链接API接口-item_password-获得淘口令真实url 接口,淘口令API接口
  8. POJ2208 Pyramids 四面体体积
  9. 关于Spring IOC (DI-依赖注入)你需要知道的一切
  10. 3D 旋转立方体的完整代码
  11. hau 1874 畅通工程续
  12. linux 赋权文件,linux文件赋权
  13. Android切换APP前后台展示开屏广告
  14. 用计算机编程做微信,电脑端微信双开,教你两种简单的方法,上手即用!
  15. Java 微服务架构
  16. 资料员报考建筑八大员报考建筑资料员工程竣工资料整理的举措
  17. jdbc 批量执行sql
  18. my firefox常用的插件介绍
  19. 难道没有GPHONE??
  20. Excel用排序做工资条

热门文章

  1. harris位_【论文阅读】Harris角点算法
  2. oracle存储过程解锁
  3. 数据预处理之数据相关性分析
  4. 【pacing 1】PACER模块、PacedSender 及关键参数
  5. android 6.0 touchwiz ui,三星Android 6.0新TouchWiz UI界面流出
  6. 反对第三方中国联通的淘宝充值
  7. CC2530————A-D转换应用之实现外部电压测量
  8. 数据清洗之 数据分组方法
  9. 图片素材之高清沙滩美女
  10. Zipline框架初探(上)