# -*- 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])
python利用matplotlib绘制sigmoid函数,tanh函数,ReLU函数,PReLU函数
最新推荐文章于 2024-01-20 14:54:12 发布
本文介绍了如何使用Python的matplotlib库绘制常见的激活函数图像,包括sigmoid函数、tanh函数、ReLU函数和PReLU函数,详细展示了它们的图形效果。
摘要由CSDN通过智能技术生成