我有以下代码,它似乎会在以下位上生成数组错误:
int run = 0;
while(myNet.RunNet(q) > 0.2 && run < 1000) {
myNet.TrainNet(templates, 10);
run += 1;
}
关键是,当我在循环外的模板上运行 TrainNet 时,它不会返回相同的错误......:S
public void SetInput(ArrayList<Double> inputs) {
ArrayList<Neuron> inputNeurons = networkLayers.get(0).getLayerNeurons();
for(int i = 0; i < inputNeurons.size(); i++) {
inputNeurons.get(i).ResetInput();
inputNeurons.get(i).ReceiveInput(inputs.get(i));
}
}
哪个返回
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at NeuralNet.Network.SetInput(Network.java:82)
at NeuralNet.Network.TrainNet(Network.java:100)
at nnTest.RunNet.main(RunNet.java:90)
为了:
ArrayList<Double> m = new ArrayList<Double>();
m.add(0.0);
m.add(0.0);
m.add(0.0);
ArrayList<Double> n = new ArrayList<Double>();
n.add(1.0);
n.add(1.0);
n.add(0.0);
ArrayList<Double> o = new ArrayList<Double>();
o.add(1.0);
o.add(0.0);
o.add(1.0);
ArrayList<Double> p = new ArrayList<Double>();
p.add(1.0);
p.add(1.0);
p.add(1.0);
ArrayList<ArrayList<Double>> templates = new ArrayList<ArrayList<Double>>();
templates.add(m);
templates.add(n);
templates.add(o);
templates.add(p);
解析通过
public void TrainNet(ArrayList<ArrayList<Double>> templates, int epochs) {
int j = 1;
for(ArrayList<Double> currentTemplate : templates) {
System.out.println("------------------------");
System.out.println("Testing through set " + j);
j += 1;
outputNeuron.setDesired(currentTemplate.get(0));
currentTemplate.remove(0);
SetInput(currentTemplate);
for(int i = 0; i < epochs; i++) {
FeedForward();
BackPropagate();
}
}
}
public void SetInput(ArrayList<Double> inputs) {
ArrayList<Neuron> inputNeurons = networkLayers.get(0).getLayerNeurons();
for(int i = 0; i < inputNeurons.size(); i++) {
inputNeurons.get(i).ResetInput();
inputNeurons.get(i).ReceiveInput(inputs.get(i));
}
}
有什么建议么?:)