训练偏向重量反向传播

时间:2016-09-10 22:32:49

标签: neural-network backpropagation

我正在尝试使用神经网络和XOR激活函数编写sigmoid解决方案。 (使用True=0.9False=0.1

我现在正处于反向传播部分。

计算体重调整的公式是:

delta_weight(l,i,j) = gamma*output(l,i)*error_signal(l,j)

即 - layer 1 (hidden), node 2layer 2(output), node 0之间链接的权重调整为:

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)

0 个答案:

没有答案
相关问题