在计算误差导数时,我正在使用以下工作,但不确定原因。
double errorDerivative = (-output * (1-output) *(desiredOutput - output));
当我从第一个输出中删除减号时,它会失败并达到最大时期限制。我假设这就是不使用减号运算符的http://homepages.gold.ac.uk/nikolaev/311imlti.htm示例。
double errorDerivative2 = (output * (1-output) *(desiredOutput - output));
我目前正在查看一个修改现有的 BackPropagation 实现,它使用随机梯度下降并希望让它使用标准的反向传播算法。目前,它看起来像这样。
public void applyBackpropagation(double expectedOutput[]) {
// error check, normalize value ]0;1[
/*for (int i = 0; i < expectedOutput.length; i++) {
double d = expectedOutput[i];
if (d < 0 || d > 1) {
if (d < 0)
expectedOutput[i] = 0 + epsilon;
else
expectedOutput[i] = 1 - epsilon;
}
}*/
int i = 0;
for (Neuron n : outputLayer) {
System.out.println("neuron");
ArrayList<Connection> connections = n.getAllInConnections();
for (Connection con : connections) {
double output = n.getOutput();
System.out.println("final output is "+output);
double ai = con.leftNeuron.getOutput();
System.out.println("ai output is "+ai);
double desiredOutput = expectedOutput[i];
double errorDerivative = (-output * (1-output) *(desiredOutput - output));
double errorDerivative2 = (output * (1-output) *(desiredOutput - output));
System.out.println("errorDerivative is "+errorDerivative);
System.out.println("errorDerivative my one is "+(output * (1-output) *(desiredOutput - output)));
double deltaWeight = -learningRate * errorDerivative2;
double newWeight = con.getWeight() + deltaWeight;
con.setDeltaWeight(deltaWeight);
con.setWeight(newWeight + momentum * con.getPrevDeltaWeight());
}
i++;
}
// update weights for the hidden layer
for (Neuron n : hiddenLayer) {
ArrayList<Connection> connections = n.getAllInConnections();
for (Connection con : connections) {
double output = n.getOutput();
double ai = con.leftNeuron.getOutput();
double sumKoutputs = 0;
int j = 0;
for (Neuron out_neu : outputLayer) {
double wjk = out_neu.getConnection(n.id).getWeight();
double desiredOutput = (double) expectedOutput[j];
double ak = out_neu.getOutput();
j++;
sumKoutputs = sumKoutputs
+ (-(desiredOutput - ak) * ak * (1 - ak) * wjk);
}
double partialDerivative = output * (1 - output) * ai * sumKoutputs;
double deltaWeight = -learningRate * partialDerivative;
double newWeight = con.getWeight() + deltaWeight;
con.setDeltaWeight(deltaWeight);
con.setWeight(newWeight + momentum * con.getPrevDeltaWeight());
}
}
}