無限不可能性ドライブ

『ニューラルネットワーク自作入門』に刺激されてExcelVBAでニューラルネットワークを作ってみたものの、やっぱり数学やらなきゃと思い少しずつやってきたのもあって、自分の知識の整理とかそういった感じです。

【数式編】(逆伝播)1つめの隠れ層の重みとバイアスを更新する 3-(3)

f:id:celaeno42:20181027205933p:plain

ユニットh12 の重みとバイアスの更新式

もう一度、前回までで求めた更新式を見てみましょう。

(再掲)
 \displaystyle \begin{align}
\nabla E = \frac{\partial E}{\partial w_{11}^2} &= \frac{\partial E}{\partial u_1^2} \frac{\partial u_1^2}{\partial w_{11}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{11}^3 \times ReLU'(u_1^2) \\
\\ + \delta_2^3 \times w_{21}^3 \times ReLU'(u_1^2) \\
\\ + \delta_3^3 \times w_{31}^3 \times ReLU'(u_1^2) \\
\\ + \delta_4^3 \times w_{41}^3 \times ReLU'(u_1^2)
\end{pmatrix}
\times x_1
\end{align}

よく見ると、


 \displaystyle \left(\delta \times 次の層のユニットの関係する重み \times 自ユニットの u の微分 \right) を足し合わせたもの \times 更新する重みへの入力


という構造になっていることがわかります。
それを踏まえると以下のようになると思います。
今回の共通部は  \displaystyle \delta_2^2 としましょう。


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{21}^2} &= \frac{\partial E}{\partial u_2^2} \frac{\partial u_2^2}{\partial w_{21}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{12}^3 \times ReLU'(u_2^2) \\
\\ + \delta_2^3 \times w_{22}^3 \times ReLU'(u_2^2) \\
\\ + \delta_3^3 \times w_{32}^3 \times ReLU'(u_2^2) \\
\\ + \delta_4^3 \times w_{42}^3 \times ReLU'(u_2^2)
\end{pmatrix}
\times x_1
= \delta_2^2 \times x_1
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{22}^2} &= \frac{\partial E}{\partial u_2^2} \frac{\partial u_2^2}{\partial w_{22}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{12}^3 \times ReLU'(u_2^2) \\
\\ + \delta_2^3 \times w_{22}^3 \times ReLU'(u_2^2) \\
\\ + \delta_3^3 \times w_{32}^3 \times ReLU'(u_2^2) \\
\\ + \delta_4^3 \times w_{42}^3 \times ReLU'(u_2^2)
\end{pmatrix}
\times x_2
= \delta_2^2 \times x_2
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{23}^2} &= \frac{\partial E}{\partial u_2^2} \frac{\partial u_2^2}{\partial w_{23}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{12}^3 \times ReLU'(u_2^2) \\
\\ + \delta_2^3 \times w_{22}^3 \times ReLU'(u_2^2) \\
\\ + \delta_3^3 \times w_{32}^3 \times ReLU'(u_2^2) \\
\\ + \delta_4^3 \times w_{42}^3 \times ReLU'(u_2^2)
\end{pmatrix}
\times x_3
= \delta_2^2 \times x_3
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{24}^2} &= \frac{\partial E}{\partial u_2^2} \frac{\partial u_2^2}{\partial w_{24}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{12}^3 \times ReLU'(u_2^2) \\
\\ + \delta_2^3 \times w_{22}^3 \times ReLU'(u_2^2) \\
\\ + \delta_3^3 \times w_{32}^3 \times ReLU'(u_2^2) \\
\\ + \delta_4^3 \times w_{42}^3 \times ReLU'(u_2^2)
\end{pmatrix}
\times x_4
= \delta_2^2 \times x_4
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial b_2^2} &= \frac{\partial E}{\partial u_2^2} \frac{\partial u_2^2}{\partial b_2^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{12}^3 \times ReLU'(u_2^2) \\
\\ + \delta_2^3 \times w_{22}^3 \times ReLU'(u_2^2) \\
\\ + \delta_3^3 \times w_{32}^3 \times ReLU'(u_2^2) \\
\\ + \delta_4^3 \times w_{42}^3 \times ReLU'(u_2^2)
\end{pmatrix}
\times 1
= \delta_2^2 \times 1
\end{align}


ユニットh13 の重みとバイアスの更新式

同じパターンなので以下のようになります。
共通部は  \displaystyle \delta_3^2 とします。


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{31}^2} &= \frac{\partial E}{\partial u_3^2} \frac{\partial u_3^2}{\partial w_{31}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{13}^3 \times ReLU'(u_3^2) \\
\\ + \delta_2^3 \times w_{23}^3 \times ReLU'(u_3^2) \\
\\ + \delta_3^3 \times w_{33}^3 \times ReLU'(u_3^2) \\
\\ + \delta_4^3 \times w_{43}^3 \times ReLU'(u_3^2)
\end{pmatrix}
\times x_1
= \delta_3^2 \times x_1
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{32}^2} &= \frac{\partial E}{\partial u_3^2} \frac{\partial u_3^2}{\partial w_{32}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{13}^3 \times ReLU'(u_3^2) \\
\\ + \delta_2^3 \times w_{23}^3 \times ReLU'(u_3^2) \\
\\ + \delta_3^3 \times w_{33}^3 \times ReLU'(u_3^2) \\
\\ + \delta_4^3 \times w_{43}^3 \times ReLU'(u_3^2)
\end{pmatrix}
\times x_2
= \delta_3^2 \times x_2
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{33}^2} &= \frac{\partial E}{\partial u_3^2} \frac{\partial u_3^2}{\partial w_{33}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{13}^3 \times ReLU'(u_3^2) \\
\\ + \delta_2^3 \times w_{23}^3 \times ReLU'(u_3^2) \\
\\ + \delta_3^3 \times w_{33}^3 \times ReLU'(u_3^2) \\
\\ + \delta_4^3 \times w_{43}^3 \times ReLU'(u_3^2)
\end{pmatrix}
\times x_3
= \delta_3^2 \times x_3
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial w_{34}^2} &= \frac{\partial E}{\partial u_3^2} \frac{\partial u_3^2}{\partial w_{34}^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{13}^3 \times ReLU'(u_3^2) \\
\\ + \delta_2^3 \times w_{23}^3 \times ReLU'(u_3^2) \\
\\ + \delta_3^3 \times w_{33}^3 \times ReLU'(u_3^2) \\
\\ + \delta_4^3 \times w_{43}^3 \times ReLU'(u_3^2)
\end{pmatrix}
\times x_4
= \delta_3^2 \times x_4
\end{align}


 \displaystyle \begin{align}
\frac{\partial E}{\partial b_3^2} &= \frac{\partial E}{\partial u_3^2} \frac{\partial u_3^2}{\partial b_3^2}
= 
\begin{pmatrix}
 \delta_1^3 \times w_{13}^3 \times ReLU'(u_3^2) \\
\\ + \delta_2^3 \times w_{23}^3 \times ReLU'(u_3^2) \\
\\ + \delta_3^3 \times w_{33}^3 \times ReLU'(u_3^2) \\
\\ + \delta_4^3 \times w_{43}^3 \times ReLU'(u_3^2)
\end{pmatrix}
\times 1
= \delta_3^2 \times 1
\end{align}


これで必要な計算式がすべて求まりました。