python实现并绘制 sigmoid函数,tanh函数,ReLU函数,PReLU函数
# -*- coding:utf-8 -*-
from matplotlib import pyplot as plt
import numpy as np
import mpl_toolkits.axisartist as axisartist
def sigmoid(x):
return 1. / (1 + np.exp(-x))
def tanh(x):
return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))
def relu(x):
return np.where(x<0,0,x)
def prelu(x):
return np.where(x<0,0.5*x,x)
def plot_sigmoid():
x = np.arange(-10, 10, 0.1)
y = sigmoid(x)
fig = plt.figure()
# ax = fig.add_subplot(111)
ax = axisartist.Subplot(fig,111)
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
# ax.spines['bottom'].set_color('none')
# ax.spines['left'].set_color('none')
ax.axis['bottom'].set_axisline_style("-|>",size=1.5)
ax.spines['left'].set_position(('data', 0))
ax.plot(x, y)
plt.xlim([-10.05, 10.05])
plt.ylim([-0.02, 1.02])
plt.tight_layout()
plt.savefig("sigmoid.png")
plt.show()
def plot_tanh():
x = np.arange(-10, 10, 0.1)
y = tanh(x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
# ax.spines['bottom'].set_color('none')
# ax.spines['left'].set_color('none')
ax.spines['left'].set_position(('data', 0))
ax.spines['bottom'].set_position(('data', 0))
ax.plot(x, y)
plt.xlim([-10.05, 10.05])
plt.ylim([-1.02, 1.02])
ax.set_yticks([-1.0, -0.5, 0.5, 1.0])
ax.set_xticks([-10, -5, 5, 10])
plt.tight_layout()
plt.savefig("tanh.png")
plt.show()
def plot_relu():
x = np.arange(-10, 10, 0.1)
y = relu(x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
# ax.spines['bottom'].set_color('none')
# ax.spines['left'].set_color('none')
ax.spines['left'].set_position(('data', 0))
ax.plot(x, y)
plt.xlim([-10.05, 10.05])
plt.ylim([0, 10.02])
ax.set_yticks([2, 4, 6, 8, 10])
plt.tight_layout()
plt.savefig("relu.png")
plt.show()
def plot_prelu():
x = np.arange(-10, 10, 0.1)
y = prelu(x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
# ax.spines['bottom'].set_color('none')
# ax.spines['left'].set_color('none')
ax.spines['left'].set_position(('data', 0))
ax.spines['bottom'].set_position(('data', 0))
ax.plot(x, y)
plt.xticks([])
plt.yticks([])
plt.tight_layout()
plt.savefig("prelu.png")
plt.show()
if __name__ == "__main__":
plot_sigmoid()
plot_tanh()
plot_relu()
plot_prelu()
python实现并绘制 sigmoid函数,tanh函数,ReLU函数,PReLU函数的更多相关文章
- 深度学习的激活函数 :sigmoid、tanh、ReLU 、Leaky Relu、RReLU、softsign 、softplus、GELU
深度学习的激活函数 :sigmoid.tanh.ReLU .Leaky Relu.RReLU.softsign .softplus.GELU 2019-05-06 17:56:43 wamg潇潇 阅 ...
- 激活函数--(Sigmoid,tanh,Relu,maxout)
Question? 激活函数是什么? 激活函数有什么用? 激活函数怎么用? 激活函数有哪几种?各自特点及其使用场景? 1.激活函数 1.1激活函数是什么? 激活函数的主要作用是提供网络的非线性建模能力 ...
- 深度学习基础系列(三)| sigmoid、tanh和relu激活函数的直观解释
常见的激活函数有sigmoid.tanh和relu三种非线性函数,其数学表达式分别为: sigmoid: y = 1/(1 + e-x) tanh: y = (ex - e-x)/(ex + e-x) ...
- 激活函数Sigmoid、Tanh、ReLu、softplus、softmax
原文地址:https://www.cnblogs.com/nxf-rabbit75/p/9276412.html 激活函数: 就是在神经网络的神经元上运行的函数,负责将神经元的输入映射到输出端. 常见 ...
- 激活函数sigmoid、tanh、relu、Swish
激活函数的作用主要是引入非线性因素,解决线性模型表达能力不足的缺陷 sigmoid函数可以从图像中看出,当x向两端走的时候,y值越来越接近1和-1,这种现象称为饱和,饱和意味着当x=100和x=100 ...
- 激活函数的比较,sigmoid,tanh,relu
1. 什么是激活函数 如下图,在神经元中,输入inputs通过加权.求和后,还被作用了一个函数.这个函数就是激活函数Activation Function 2. 为什么要用激活函数 如果不用激活函数, ...
- 深度学习:激活函数的比较和优缺点,sigmoid,tanh,relu
https://blog.csdn.net/u011684265/article/details/78039280
- 神经网络中的激活函数——加入一些非线性的激活函数,整个网络中就引入了非线性部分,sigmoid 和 tanh作为激活函数的话,一定要注意一定要对 input 进行归一话,但是 ReLU 并不需要输入归一化
1 什么是激活函数? 激活函数,并不是去激活什么,而是指如何把“激活的神经元的特征”通过函数把特征保留并映射出来(保留特征,去除一些数据中是的冗余),这是神经网络能解决非线性问题关键. 目前知道的激活 ...
- Matlab绘制三维曲面(以二维高斯函数为例)
原文地址为:Matlab绘制三维曲面(以二维高斯函数为例) 寒假学习了一下Python下的NumPy和pymatlab,感觉不是很容易上手.来学校之后,决定继续看完数字图像处理一书.还是想按照上学期的 ...
随机推荐
- cache和buffer区别探讨
一. 1.Buffer(缓冲区)是系统两端处理速度平衡(从长时间尺度上看)时使用的.它的引入是为了减小短期内突发I/O的影响,起到流量整形的作用.比如生产者——消费者问题,他们产生和消耗资源的速度大体 ...
- <LeetCode OJ> 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- hdu3336解读KMP算法的next数组
查看原题 题意大致是:给你一个字符串算这里面全部前缀出现的次数和.比方字符串abab,a出现2次.ab出现2次,aba出现1次.abab出现1次.总计6次. 而且结果太大.要求对1007进行模运算. ...
- 【cocos2dx开发技巧10】cocosStudio的集成以及c++11的新特性
转发.请保持地址:http://blog.csdn.net/stalendp/article/details/38880997 非常长时间没有碰cocos2dx了,近期又用起来了.花了好几个小时又一次 ...
- C# 缓存技术
缓存主要是为了提高数据的读取速度.因为服务器和应用客户端之间存在着流量的瓶颈,所以读取大容量数据时,使用缓存来直接为客户端服务,可以减少客户端与服务器端的数据交互,从而大大提高程序的性能. 本章从缓存 ...
- Jlink升级_官网
Jlink官网:https://www.segger.com/ 关于JLINK固件丢失或升级固件后提示Clone的解决办法 本人用的JLINK仿真器(某宝上买的),在使用新版KEIL时,提示要升级固件 ...
- 06 Memcached中的一些参数限制
一: Memcached中的一些参数限制 Key的长度:250字节(二进制协议支持65536个字节) value的限制:1M ,一般都是存储一些文本,如新闻标题等等这个值足够了, 内存的限制:32位下 ...
- usermod命令
usermod 功能: 修改用户 常用参数:-c 账号说明-d 账号家目录-e 密码失效日期-g 主用户组GID-G 次用户组GID-l 账号名称-s she ...
- 【BZOJ2530】[Poi2011]Party (xia)构造
[BZOJ2530][Poi2011]Party Description 给定一张N(保证N是3的倍数)个节点M条边的图,并且保证该图存在一个大小至少为2N/3的团. 请输出该图的任意一个大小为N/3 ...
- openCV图像形态学
#include <cv.h> #include <highgui.h> #include <stdio.h> //平滑处理 int main() { IplIma ...