1
1

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.

ゼロから作るDeep Learning② 1章 自分用まとめ

Last updated at Posted at 2019-01-04

Matrix Multiply (MatMul) 行列の積

アフィンの元となる計算式。

Forward (P30)

y=xW
return x*W

Backward (P31)

\frac{\delta{L}}{\delta{x}}=\frac{\delta{L}}{\delta{y}}W^T
\frac{\delta{L}}{\delta{W}}=x^T\frac{\delta{L}}{\delta{y}}
dx = np.dot(dout, W.T)
dW = np.dot(x.T, dout)

Affine アフィン

ニューロンの値に、重みWを掛け、バイアスbを足す。

Forward (P10)

h=xW+b
return np.dot(x, W) + b

Backward

数式はMatMul参考

dx = np.dot(dout, W.T)
dW = np.dot(x.T, dout)
db = np.sum(dout, axis=0)

Sigmoid function シグモイド関数

活性化関数の一部。アクティベーションを求める。
各クラスのスコアを出力する。スコアは0〜1の値となる。
スコアとは「確率」になる前の値。スコアが高ければ高いほど、そのニューロンに対応するクラスの確率も高くなる。ソフトマックスとは違い、それぞれの入力値は独立して0〜1の範囲に収まるよう計算される。

Forward (P12)

σ(x) = \frac{1}{1+exp(-x)}
return 1 / 1 + np.exp(-x)

Backward (P36)

\delta{x} = \frac{\delta{L}}{\delta{y}}y(1-y)
return dout * (1.0 - out) * out

Softmax function ソフトマックス関数

出力の各要素は0〜1の値を取り、全ての要素の合計は1になる。つまり、「確率」と解釈できる。

Forward (P19)

y_k = \frac{exp(s_k)}{\sum_{i=1}^{n}exp(s_i)}
x = np.exp(x)
x /= x.sum(axis=1, keepdims=True)
return x

Backward (P38)

特に数式はない。

Cross Entropy Error 交差エントロピー誤差

入力が、確率(要素合計が1となるリスト)と教師ラベル(ont-hotベクトル)を取り、その誤差(1つの数値)を出力する。
数式を見ると、教師ラベルが0(tk=0)の要素は、出力結果に影響しないので、実質的には正解ラベルが1の要素に対応する出力の自然対数(log)を計算するだけになる。

Forward (P20)

L=-\sum_{k}t_k\log y_k

ミニバッチを考慮した場合

L=-\frac{1}{n}\sum_{n}\sum_{k}t_{nk}\log y_{nk}
r = t * np.log(y)
return - r.sum() / r.ndim

Backward (P38)

特に数式はない。

参考
https://qiita.com/PlanetMeron/items/63ac58898541cbe81ada

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?