Create 4th_assignment_sigmoid_이민준 #18
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


import numpy as np
시그모이드 함수 및 그 미분
def sigmoid(z):
return 1 / (1 + np.exp(-z))
def sigmoid_derivative(z):
s = sigmoid(z)
return s * (1 - s)
입력값
x1 = 0.1
x2 = 0.2
y_real = 0.3
learning_rate = 0.5
가중치 초기값
w1, w2, w3, w4, w5, w6 = 0.1, 0.2, 0.3, 0.15, 0.25, 0.35
순전파
z1 = x1 * w1 + x2 * w2
h1 = sigmoid(z1)
z2 = x1 * w3 + x2 * w4
h2 = sigmoid(z2)
z3 = h1 * w5 + h2 * w6
y_pred = sigmoid(z3)
손실 함수의 출력값에 대한 오차 (Mean Squared Error 기준)
error = y_pred - y_real
출력층에서의 gradient
dL_dy = 2 * error
dy_dz3 = sigmoid_derivative(z3)
dz3_dw5 = h1
w5에 대한 gradient
dL_dw5 = dL_dy * dy_dz3 * dz3_dw5
h1에 대한 gradient
dz3_dh1 = w5
dh1_dz1 = sigmoid_derivative(z1)
dz1_dw1 = x1
w1에 대한 gradient
dL_dw1 = dL_dy * dy_dz3 * dz3_dh1 * dh1_dz1 * dz1_dw1
가중치 w1 업데이트
w1_new = w1 - learning_rate * dL_dw1
print(f"업데이트된 w1: {w1_new:.5f}")
#결과값
#업데이트된 w1: 0.09958
4th_assignment_sigmoid_이민준 - Colab.pdf