赞
踩
import numpy as np
import matplotlib.pyplot as plt
plt.subplots_adjust(hspace=0.5 , wspace=0.5)
rows = 3
cols = 2
# Sigmoid(x)=1/(1+e^(-x))
x=np.linspace(-10,10,100)
Sigmoid=1/(1+np.power(np.e,(-x)))
plt.subplot(rows,cols,1)
plt.plot(x,Sigmoid)
plt.title('Sigmoid(x)=1/(1+e^(-x))')
# plt.show()
# ReLU = max(0,x)
x=np.linspace(-10,10,100)
p=0
cond = x>=0
ReLU = np.where(cond,x,p*x)
plt.subplot(rows,cols,2)
plt.plot(x,ReLU)
plt.title(' ReLU = max(0,x)')
# plt.show()
#LeayReLU = x(x>0);px(x<0)
x=np.linspace(-10,10,100)
p=0.3
cond = x>=0
LeayReLU = np.where(cond,x,p*x)
plt.subplot(rows,cols,3)
plt.plot(x,LeayReLU)
plt.title(' LeayReLU = x(x>0);px(x<0)')
# plt.show()
#tanh(x)=(e^x - e(-x)) / (e^x + e^(-x))
# = 2 * Sigmoid(2x) - 1
x=np.linspace(-10,10,100)
tanh = np.tanh(x)
plt.subplot(rows,cols,4)
plt.plot(x,tanh)
plt.title(' tanh(x) = (e^x - e(-x)) / (e^x + e^(-x))')
# plt.show()
# softmax(zi) = e^zi / (e^z1 + ... + e^zj)
x=np.linspace(0,10,20)
# x=[ 2 ,1 ,0.1]
sumx = np.sum(np.power(np.e,x))
softmax = np.power(np.e, x) / sumx
plt.subplot(rows,cols,5)
plt.scatter(x,softmax)
plt.title('softmax(zi) = e^zi / (e^z1 + ... + e^zj)')
plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。