【发布时间】:2011-10-28 12:02:40
【问题描述】:
在阅读了很多其他人的神经网络代码后,我确信我的代码有问题。它有效,我可以训练一个网络,只是为了训练隐藏层中的下一个感知器,我必须训练最后一个,我不应该能够并行训练隐藏层中的所有单元吗?
下面是它计算隐藏层误差的代码:
for(int i=n->numOfPerceptronLayers-2;i>=1;i--) { // for all hidden layers
float sum = 0.0; // <- This here is the problem
for(int j=0;j<n->perceptronLayers[i].numOfPerceptrons;j++) { // For all the units in the current hidden layer
for(int k=0;k<n->perceptronLayers[i].perceptrons[j].numOfConnections;k++) { // Loop through the current units connections to the previous layer (output layer)
sum += n->perceptronLayers[i+1].perceptrons[k].error * n->perceptronLayers[i+1].perceptrons[k].weights[j];
}
n->perceptronLayers[i].perceptrons[j].error = n->perceptronLayers[i].perceptrons[j].output * (1.0 - n->perceptronLayers[i].perceptrons[j].output) * sum;
}
}
应该是这样的(但这不起作用):
for(int i=n->numOfPerceptronLayers-2;i>=1;i--) { // for all hidden layers
for(int j=0;j<n->perceptronLayers[i].numOfPerceptrons;j++) { // For all the units in the current hidden layer
float sum = 0.0;
for(int k=0;k<n->perceptronLayers[i].perceptrons[j].numOfConnections;k++) { // Loop through the current units connections to the previous layer (output layer)
sum += n->perceptronLayers[i+1].perceptrons[k].error * n->perceptronLayers[i+1].perceptrons[k].weights[j];
}
n->perceptronLayers[i].perceptrons[j].error = n->perceptronLayers[i].perceptrons[j].output * (1.0 - n->perceptronLayers[i].perceptrons[j].output) * sum;
}
}
为什么必须为整个层而不是单个感知器声明 sum 变量?
【问题讨论】:
-
您能否更具体地说明“它不起作用”的含义。您能否添加您尝试编码的确切数学公式,因为我觉得这里的翻译可能会丢失一些东西。
-
数学公式是反向传播学习,我试图计算隐藏层中感知器的误差。它不起作用意味着训练过程不起作用,网络永远不会学习第二段代码中的假设。
标签: c math parallel-processing neural-network backpropagation