image.png

하나의 은닉층과 하나의 출력층을 가지고 있다.

입력 $x$는 은닉층으로 전달된다.

은닉층에서 가중치 $W1$과 시그모이드 활성화 함수 $σ$를 통해 출력 $h = \sigma(W_1 \cdot x)$가 계산된다.

은닉층 출력 $h$는 출력층에서 또 다른 가중치 W_2와 곱해져 최종 출력 $\hat{y}$가 계산된다.

손실함수는 $L = (\hat{y}-y)^2$로 정의된다.

우리는 이 손실을 최소화하기 위해 $W_1$의 가중치를 조정해야한다.

  1. chain-rule의 적용

    $$ \frac{\partial \mathcal{L}}{\partial W_1} = \frac{\partial \mathcal{L}}{\partial \hat{y}} \cdot \frac{\partial \hat{y}}{\partial h} \cdot \frac{\partial h}{\partial W_1} $$

  2. $\frac{\partial \mathcal{L}}{\partial \hat{y}}$ : 손실의 예측값에 대한 편미분

    $$ \frac{\partial \mathcal{L}}{\partial \hat{y}} = 2(\hat{y}-y) $$

    손실 함수 $\mathcal{L}$이 예측값 $\hat{y}$에 따라 어떻게 변하는지를 나타낸다.

  3. $\frac{\partial \hat{y}}{\partial h}$: 출력이 은닉층 출력 h에 미치는 영향

    $\hat{y}$는 $h$와 $W_2$의 곱으로 표현되므로, $h$에 대한 미분은 $W_2$가 된다.

    $$ \frac{\partial \hat{y}}{\partial h}=W_2 $$

  4. $\frac{\partial h}{\partial W_1}$: 은닉층 출력이 W_1에 미치는 영향

    은닉층에서의 출력 $h$는 $h = \sigma(W_1 \cdot x)$로 정의된다.

    여기서 $σ$는 시그모이드 함수로, 시그모이드 함수의 미분은 다음과 같다:

    $$ \frac{\partial\sigma(z)}{\partial z} = \sigma(z)(1 - \sigma(z)) $$

    h에 대해 미분하면:

    $$ \frac{\partial h}{\partial z} = h(1 - h) $$

    $z=W_1 \cdot x$이다.

    $$ \frac{\partial h}{\partial z} \cdot \frac{\partial z}{\partial W_1} = h(1 - h) \cdot x $$

    $z=W_1 \cdot x$에서 $W_1$은 행렬이고 $x$는 벡터이기 때문에, 행렬의 각 요소에 대해 미분을 할 때 벡터 $x$의 각 요소가 그대로 나타난다.

    따라서 $W_1$에 대한 $h$의 미분은 다음과 같다.

    $$ \frac{\partial h}{\partial W_1} = h(1 - h) \cdot x $$

  5. W_1에 대한 손실의 편미분

    $$ \frac{\partial \mathcal{L}}{\partial W_1} = 2(\hat{y} - y) \cdot W_2 \cdot h(1 - h) \cdot x $$