【发布时间】:2020-08-24 05:42:03
【问题描述】:
我正在尝试创建一个简单的神经网络,并坚持在两层中更新第一层的权重。我想我对 w2 所做的第一次更新是正确的,就像我从反向传播算法中学到的一样。我暂时不包括偏见。但是我们如何更新第一层的权重是我所困的地方。
import numpy as np
np.random.seed(10)
def sigmoid(x):
return 1.0/(1+ np.exp(-x))
def sigmoid_derivative(x):
return x * (1.0 - x)
def cost_function(output, y):
return (output - y) ** 2
x = 2
y = 4
w1 = np.random.rand()
w2 = np.random.rand()
h = sigmoid(w1 * x)
o = sigmoid(h * w2)
cost_function_output = cost_function(o, y)
prev_w2 = w2
w2 -= 0.5 * 2 * cost_function_output * h * sigmoid_derivative(o) # 0.5 being learning rate
w1 -= 0 # What do you update this to?
print(cost_function_output)
【问题讨论】:
标签: python machine-learning neural-network backpropagation