9日目は、numpyのステップ関数、シグモイド関数、RELU関数



Ninth Day Numpys Step Function



始める前に、numpyの配列関数を使用して学習する方法を知っておく必要があります。今日、3つのディープラーニング関連機能を学びましょう。
1つはステップ関数、1つはシグモイド関数、もう1つはrelu関数で、matplotlibで表示されます。これら3つはすべて階段関数を生成していますが、2つはポリラインです。もう1つは滑らかな曲線です。まず、コードを見てみましょう。

import numpy as np import matplotlib as plt def function(x): return np.array(x>0,dtype = np.int) Ty =np.arange(-5.0,5.0,0.1) #Generate a matrix from -5.0 to 5.0 with a step of 0.1 T = function(Ty) plt.plot(Ty,T) plt.ylim(-0.1,1.1) plt.show 1 ​ 2 def function(x): 3 return np.array(x>0,dtype = np.int) 4 Ty =np.arange(-5.0,5.0,0.1) #Generate a matrix from -5.0 to 5.0 with a step of 0.1 5 T = function(Ty) 6 plt.plot(Ty,T) 7 plt.ylim(-0.1,1.1) 8 plt.show Out[27]: !Step function](https://img-blog.csdnimg.cn/20190311213559393.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMwMDc4NzUx,size_16,color_FFFFFF,t_70) 1 def sigmoid_fun(x): 2 return 1/(1+np.exp(-x)) 3 R_l = np.arange(-5.0,5.0,0.1) 4 ​ 5 R_y = sigmoid_fun(R_l) 6 ​ 7 plt.plot(R_l,R_y) 8 ​ 9 plt.ylim(-0.1,1.1) 10 plt.show() 11 ​ 12 ![Smooth curve](https://img-blog.csdnimg.cn/20190311213523180.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMwMDc4NzUx,size_16,color_FFFFFF,t_70) 13 ​ 14 ​ Def Relu_function(x): # Enter a number, if it is less than or equal to 0, it will output 0. If it is greater than 0, it will be returned. return np.maximum(0,x) R_x = np.arange(-1.2,2.5,0.05) # Generate -1.2 to 2.5 array with 0.1 step R_Y = Relu_function(R_x) plt.plot(R_x,R_Y) plt.ylim(-2.0,3) plt.show() Output: ![polyline](https://img-blog.csdnimg.cn/20190311221600657.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMwMDc4NzUx,size_16,color_FFFFFF,t_70)

関数のexp(-x)は実際にはe ^(-x)であり、eはネーピア定数2.7182です。 。 。 。