0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

活性化関数

1:ステップ関数 サカズキ(赤犬)

特徴

閾値を越えたらオン、そうでなければオフ。白黒はっきり。

import numpy as np
import matplotlib.pyplot as plt

###### ステップ関数
def step_function(x):
  # 0 以下の場合は 0 を返し、それ以外は 1を返す
  return np.where(x<=0, 0, 1)

### 実行
x = np.linspace(-5, 5)
y = step_function(x)

plt.plot(x, y)
plt.show()

ステップ-1.png

2:シグモイド関数 チョッパー

特徴

0〜1の間でなめらかに変化。弱い入力でもちょっと反応する。

import numpy as np
import matplotlib.pyplot as plt

###### シグモイド関数
def sigmoid_function(x):
  return 1/(1+np.exp(x)) # exp => ネイピア数の累乗を表す

### 実行 ###
x = np.linspace(-5, 5)
y = sigmoid_function(x)

plt.plot(x, y)
plt.show()

シグモイド関数-1.png

3:tanh(双曲線正接)ゾロ

特徴

-1〜1の間で出力。シグモイドを強調したような「プラスにもマイナスにも反応」する。
極端。

import numpy as np
import matplotlib.pyplot as plt

####### tanh
### -1 から 1 の間を滑らかに変化する関数
def tanh_function(x):
  return np.tanh(x)

### 実行 ###
x = np.linspace(-5, 5)
y = tanh_function(x)

plt.plot(x, y)
plt.show()

4:ReLU(Rectified Linear Unit) ルフィ

特徴

0以下は全部0、0を超えたら直線的に伸びる。シンプルで強力。

import numpy as np
import matplotlib.pyplot as plt

def relu_function(x):
  return np.where(x <= 0, 0, x)

### 実行 ###
x = np.linspace(-5, 5)
y = relu_function(x)

plt.plot(x, y)
plt.show()

ReLU-1.png

5:恒等関数(Identity Function) ブルック

特徴

入力 = 出力。加工なし。

import numpy as np
import matplotlib.pyplot as plt

def relu_function(x):
    return np.where(x <= 0, 0, x)

### 実行 ###
x = np.linspace(-5, 5)
y = relu_function(x)

plt.plot(x, y)
plt.show()

スクリーンショット 2025-08-21 14.10.13.png

6:ソフトマックス関数(Softmax) ナミ

特徴

: 出力を「確率」に変換し、全部で1になるように分配。多クラス分類で必須。

import numpy as np

def softmax_function(x):
    return np.exp(x) / np.sum(np.exp(x)) # ソフトマックス関数

### 実行
y = softmax_function(np.array([1,2,3]))
print(y)

出力結果

.txt
[0.09003057 0.24472847 0.66524096]
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?