我今天创建了一个学习XOR算子的神经网络,它就像一个魅力。 然后我重构了它(没有保存图像,呃)它已经不再工作了。
现在它再次运作,但它非常糟糕:
Learing...
749142 out of 1000000 training samples were correct (74.9142%)
Testing...
756 out of 1000 testing samples were correct (75.6%)
今天早些时候,它在测试阶段的成功率总是达到100.0%...... 我在隐藏层中尝试了不同数量的隐藏层或神经元,我无法将其恢复到这些令人敬畏的结果。经过1000000次训练迭代后,它应该很容易有100.0%的权利吗?
这是我的训练方法:
public void train() {
float delta = (float) ((1.0 - output)*(1.0+output) * error * NNetwork.LEARING_RATE);
for(NConnection n : inputs) {
n.getInputNeuron().error += n.getWeight() * error;
n.setWeight(n.getWeight() + n.output() * delta);
}
error = 0;
}
设置错误:
public float setError(float desired) {
error = desired - output;
return error;
}
输出计算:
public float calcOutput() {
if(isInputNeuron) {
return valueIfInputNeuron;
} else {
float input_sum = 0.0f;
for(NConnection n : inputs) {
input_sum += n.input() * n.getWeight();
}
output = lookupSigmoid(input_sum);
return output;
}
}
以上所有方法都在Neuron类中。 这是Network类用于训练自己的方法:
/**
* Trains the net by giving the correct desired result to it
* The network will then calculate its error and try to improve
* @param correctResult the correct desired result
* @return whether the average error per output neuron is below the acceptable error or not
*/
public boolean train(float correctResult) {
float totalOutputError = 0.0f;
for(int i = 0; i < output_layer.length; i++) {
totalOutputError += output_layer[i].setError(correctResult);
output_layer[i].train();
}
for (int i = hidden_layers.length-1; i >= 0; i--) {
for (int j = 0; j < hidden_layers[i].length; j++) {
hidden_layers[i][j].train();
}
}
if(Math.abs(totalOutputError / output_layer.length) < ACCEPTABLE_ERROR) {
return true;
} else {
return false;
}
}
有没有人在这里看到错误? 也许我的sigmoid功能不适合? 如果你需要,我可以发布更多代码......
(顺便说一句,当网络达到100.0%时,它有2个输入神经元,2个隐藏的神经元和一个输出神经元)
答案 0 :(得分:0)
实际上,我认为之前网络运行不正常,现在确实如此。我过去常常了解神经网络的网站说,考虑到它的简单性,75%对于像我这样的网络来说是一个不错的结果。