LoginSignup
0
1

More than 3 years have passed since last update.

はじめに

Deeplearningでは,活性化関数というものが用いられます.基本的な活性化関数(Tanh, Sigmoid, Relu)の特徴,及びそれら関数のpythonコードをメモしました.

Tanh

出力は、-1.0 ~ 1.0の間。

$$
o = \tanh (i) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
$$

image.png

Sigmoid

出力は、0.0 ~ 1.0の間(確率)。

$$
o = sigmoid (i) = \frac{1}{1 + e^{-x}}
$$

image.png

Relu(Rectified Linear Unit)

入力 < 0の時、出力 = 0
入力 > 0の時、出力 = 入力

Reluは画像データと相性が良い。
画像データはuint(負がない)なので、画像を処理してマイナスになったものは「ノイズ」とみなして切り捨てる(=0にする)。

$$
o = max(0, i)
$$

image.png

pythonコード

import numpy as np

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

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

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

補足

一つのモデルの中で、relu, sigmoid, tanhなどを混在して使う場合あり。

0
1
1

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
1