chakokuのブログ(rev4)

テック・コミック・DTM・・・ごくまれにチャリ

【DLfS】3.2章、3種類の活性化関数を学ぶ

ゼロから作るDeep Learningでは、3種類の活性化関数が紹介されている(3.2章 P44)
1. シグモイド関数
2. ステップ関数
3. ReLU(Rectified Linear Unit)

本通りに実装してpyplotでグラフ化してみた

#!/usr/bin/python3

import numpy as np
import matplotlib.pyplot as plt

def step_function(x):
   y = x > 0
   return y.astype(np.int)

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

def relu(x):
   return np.maximum(0,x)

x=np.arange(-2,2,0.1)
y1=step_function(x)
y2=sigmoid(x)
y3=relu(x)


plt.plot(x,y1,label='step_F')
plt.plot(x,y2,label='sigmoid')
plt.plot(x,y3,linestyle='--',label='RELU')
plt.legend(loc='upper left')
plt.show()