他の多くの人々のニューラルネットワークコードを読んだ後、私は自分のコードに何かが正しくないと確信しています。それは機能し、ネットワークをトレーニングできます。隠れ層で次のパーセプトロンをトレーニングするには、最後のパーセプトロンをトレーニングする必要があります。隠れ層のすべてのユニットを並行してトレーニングできるのではないでしょうか。
隠れ層のエラーを計算するコードは次のとおりです。
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;
}
}
単一のパーセプトロンではなく、レイヤー全体に対して合計変数を宣言する必要があるのはなぜですか?