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?

More than 5 years have passed since last update.

活性化関数の実装

Last updated at Posted at 2019-11-27

活性化関数の実装

ステップ関数

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

x = np.arange(-5, 5, 0.1)
y = step_function(x)

plt.plot(x, y)
plt.xlim((-4,4))
plt.show()

ステップ関数.png

シグモイド関数

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

x = np.arange(-5, 5, 0.1)
y = sigmoid(x)

plt.plot(x, y)
plt.xlim((-5, 5))
plt.show()

シグモイド関数.png

ReLU関数

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

x = np.arange(-5, 5, 0.1)
y = relu(x)

plt.plot(x, y)
plt.xlim((-5, 5))
plt.show()

ReLU関数.png

tanh関数

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

x = np.arange(-5, 5, 0.1)
y = tanh(x)

plt.plot(x, y)
plt.xlim((-5, 5))
plt.show()

tanh.png

ソフトマックス関数

・分類問題を解くためのアルゴリズムとして利用される。
・出力値の総和が常に1となる。

def softmax(x):
    exp_x = np.exp(x)
    sum_exp_x = np.sum(exp_x)
    y = exp_x / sum_exp_x
    return y

x = np.arange(-5, 5, 0.1)
y = softmax(x)

plt.plot(x, y)
plt.xlim((-5, 5))
plt.show()

ソフトマックス関数.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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?