0
0

More than 5 years have passed since last update.

Python3で活性化関数のシグモイド関数とReLU関数を描く

Last updated at Posted at 2019-08-22

活性化関数のうちこの2つを描いてみます

%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import matplotlib.pyplot as plt
import numpy as np

まずはsigmoid関数

sigmoid関数の定義

def sigmoid(x):
    return 1/(1+np.exp(-x))

横軸xの取りうる範囲は -6.0から6.0まで0.1ずつ増加

x = np.arange(-6.0,6.0,0.1)

yを今作ったsigmoid関数の戻り値とする

y =sigmoid(x)

実際にプロット

plt.plot(x,y)

download.png

次にReLU(ランプ)関数

ReLU関数の定義

def relu(x):
    return np.maximum(0,x)
#xが0以下ではyは0、xが正の時はidentity mapping(つまりy=xの恒等写像)

y_reluを今作ったReLU関数の戻り値とする(xの取りうる範囲は先ほどと同様-6から6)

y_relu =relu(x)

実際にプロット

plt.plot(x,y_relu)

download-1.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0