Neural network 训练偏差权反向传播
我正在尝试使用神经网络和Neural network 训练偏差权反向传播,neural-network,backpropagation,Neural Network,Backpropagation,我正在尝试使用神经网络和sigmoid激活函数编写一个XOR解决方案。(使用True=0.9和False=0.1) 我现在在反向传播部分 计算重量调整的公式I为: delta_weight(l,i,j) = gamma*output(l,i)*error_signal(l,j) i、 e-节点2第1层(隐藏)和节点0第2层(输出)之间链接的权重调整为: delta_weight(1,2,0) 我选择了gamma=0.5 由于偏差权重与单个节点关联,我猜权重调整公式为: delta_weigh
sigmoid
激活函数编写一个XOR
解决方案。(使用True=0.9
和False=0.1
)
我现在在反向传播部分
计算重量调整的公式I为:
delta_weight(l,i,j) = gamma*output(l,i)*error_signal(l,j)
i、 e-节点2第1层(隐藏)和节点0第2层(输出)之间链接的权重调整为:
delta_weight(1,2,0)
我选择了gamma=0.5
由于偏差权重与单个节点关联,我猜权重调整公式为:
delta_weight(l,i) = gamma*output(l,i)
我的程序不起作用,显然我的猜测是错误的。有人能帮我吗
非常感谢
编辑:代码
def applyInputs(self, inps):
for i in range(len(self.layers)-1):
for n, node in enumerate(self.layers[i+1].nodes):
ans = 0
for m, mode in enumerate(self.layers[i].nodes):
ans += self.links[stringify(i,m,i+1,n)].weight * mode.output
if node.bias == True:
ans+= self.links[stringify(-1,-1,i+1,n)].weight
node.set_output(response(ans))
return self.layers[len(self.layers)-1].nodes[0].output
def computeErrorSignals(self, out): # 'out' is the output of the entire network (only 1 output node)
# output node error signal
output_node = self.layers[len(self.layers)-1].nodes[0]
fin_err = (out - output_node.output)*output_node.output*(1-output_node.output)
output_node.set_error(fin_err)
# hidden node error signals
for j in range(len(self.layers[1].nodes)):
hid_node = self.layers[1].nodes[j]
err = (hid_node.output)*(1-hid_node.output)*self.layers[2].nodes[0].error_signal*self.links[stringify(1,j,2,0)].weight
hid_node.set_error(err)
def computeWeightAdjustments(self):
for i in range(len(self.layers)-1):
for n, node in enumerate(self.layers[i+1].nodes):
for m, mode in enumerate(self.layers[i].nodes):
self.links[stringify(i,m,i+1,n)].weight += ((0.5)*self.layers[i+1].nodes[n].error_signal*self.layers[i].nodes[m].output)
if node.bias == True:
self.links[stringify(-1,-1,i+1,n)].weight += ((0.5)*self.layers[i].nodes[m].output)
你能发布整个代码吗?Gamma代表学习率?是的Gamma是学习率。。。你想要整个代码。。。-200行,或者仅仅是反向传播?基本上,使用反向传播的更新过程的一部分会更好。也许你没有遗漏一件事。你能发布整个代码吗?Gamma代表学习率?是的Gamma是学习率。。。你想要整个代码。。。-200行,或者仅仅是反向传播?基本上,使用反向传播的更新过程的一部分会更好,也许你没有遗漏一件事。