######后期会更新
import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLocator import numpy as np import math plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False # sigmoid激活函数用的最少,但为二分类问题时,可作为输出层会出现梯度消失(即当x趋于无穷大或无穷小时会使得导数趋于0) def sigmoid(x): return 1 / (1 + np.exp(-x)) # ReLU def ReLU(x): return np.maximum(0, 0.1 * x) # tanh def tanh(x): return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x)) x1 = np.arange(-10.0, 10.0, 0.1) y1 = sigmoid(x1) y2 = ReLU(x1) y3 = tanh(x1) plt.rc('font', family='Times New Roman', size=13) # 全局中英文为字体“罗马字体” # plt.rcParams['xtick.direction'] = 'in' # plt.rcParams['ytick.direction'] = 'in' plt.plot(x1, y1, label='sigmoid') plt.plot(x1, y2, label='ReLU') plt.plot(x1, y3, label='tanh') plt.xlabel('X1') plt.ylabel('Scores of Diff-act') plt.grid(True) plt.legend(loc="lower right")
"""去掉图上边框,与右边框""" ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') plt.show()