sigmoid函数
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
plt.figure(figsize=(10, 5))
#创建数据x
x = np.arange(-10, 10, 0.1)
#sigmoid函数
s = 1.0 / (1 + np.exp(0. - x))
#画图
f = plt.subplot(121)
plt.plot(x, s, color='r')
currentAxis=plt.gca()
plt.text(-9.0, 0.9, r'$y=Sigmoid(x)$', fontsize=13)
currentAxis.xaxis.set_label_text('x', fontsize=15)
currentAxis.yaxis.set_label_text('y', fontsize=15)
plt.show()
relu函数
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 5))
#创建数据x
x = np.arange(-10, 10, 0.1)
#relu函数
y = np.clip(x, a_min=0., a_max=None)
#图像
f = plt.subplot(122)
plt.plot(x, y, color='g')
plt.text(-3.0, 9, r'$y=ReLU(x)$', fontsize=13)
currentAxis=plt.gca()
currentAxis.xaxis.set_label_text('x', fontsize=15)
currentAxis.yaxis.set_label_text('y', fontsize=15)
plt.show()