2023.02.15 - [분류 전체보기] - implement_MLP(parameter_update)(5 back propagation)
implement_MLP(parameter_update)(5 back propagation)
2023.02.13 - [분류 전체보기] - implement_MLP(parameter_update)(4 cost function) implement_MLP(parameter_update)(4 cost function) 2023.02.11 - [분류 전체보기] - implement_MLP(parameter_update)(3) implement_MLP(parameter_update)(3) 2023.01.31 - [
teach-meaning.tistory.com
역전파법을 통한 가중치 변화량에 대한 비용 함수의 변화량을 계산했고,
이를 사용하여 가중치를 변화해가며 비용 함수를 감소시킬 수 있다.
def update_weight(self, learning_rate):
self.weight_update = self.weight_update[::-1]
for i in range(len(self.weight)):
weight = self.weight[i]
weight_update = self.weight_update[i]
self.weight[i] = weight - weight_update * learning_rate
새롭게 구한 가중치를 사용해 순전파 계산 시행,
mlp.update_weight(0.01)
mlp.weight
>>>
[array([[0.09992524, 0.19998253],
[0.29985047, 0.39996505],
[0.49977571, 0.59994758]]),
array([[0.69959521, 0.79887016],
[0.89958337, 0.09883712]])]
mlp2 = MLP()
mlp2.forward_cal(data, mlp.weight, mlp.bias)
>>>
array([[0.86093442],
[0.75838284]])
비용 함수의 변화를 관찰하면
mlp.cost_function(target)
>>>
0.2821757530435978
mlp2.cost_function(target)
>>>
0.28187080575359613
비용함수가 감소한 것을 확인할 수 있다.
'implement_ml_models > MLP' 카테고리의 다른 글
implement_MLP(weight_update 3) (0) | 2023.02.19 |
---|---|
implement_MLP(weight_update 2) (0) | 2023.02.19 |
implement_MLP(parameter_update)(5 back propagation) (0) | 2023.02.15 |
implement_MLP(parameter_update)(4 cost function) (0) | 2023.02.13 |
implement_MLP(parameter_update)(3) (0) | 2023.02.11 |