Python image rendering different activation function

1  '' ' 
2  functionality: Python image rendering different activation functions
 3  Name: Houjun Long
 4  Date: 2019/12/07
 . 5  "" " 
. 6  
. 7  Import matplotlib.pyplot AS PLT
 . 8  Import numpy AS NP
 . 9  
10 X = np.linspace ( -10,10 )
 11  # draw sigmoid image 
12 is Fig = plt.figure ()
 13 is y_sigmoid. 1 = / (np.exp. 1 + (- X))
 14 AX = fig.add_subplot (221 )
 15  ax.plot (X, y_sigmoid)
 16  ax.grid ()
 . 17 ax.set_title ( ' (A) the Sigmoid ')
18 
19 # 绘制Tanh图像
20 ax = fig.add_subplot(222)
21 y_tanh = (np.exp(x)-np.exp(-x))/(np.exp(x)+np.exp(-x))
22 ax.plot(x,y_tanh)
23 ax.grid()
24 ax.set_title('(b) Tanh')
25 
26 # 绘制Relu图像
27 ax = fig.add_subplot(223)
28 y_relu = np.array([0*item  if item<0 else item for item in x ])
29 ax.plot(x,y_relu)
30 ax.grid()
31 ax.set_title('(c) ReLu')
32 
33 # 绘制Leaky ReLu图像
34 ax = fig.add_subplot(224)
35 y_relu = np.array([0.2*item  if item<0 else item for item in x ])
36 ax.plot(x,y_relu)
37 ax.grid()
38 ax.set_title('(d) Leaky ReLu')
39 
40 plt.tight_layout()
41 plt.show()
Python image rendering different activation function

 

Guess you like

Origin www.cnblogs.com/Junlong/p/12002886.html