Reputation: 309
I am trying to train a neural network using Neuroph library but I get this error:
44 [NeurophLearningThread] INFO org.neuroph.core.learning.LearningRule - Learning Started
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at org.neuroph.util.NeurophArrayList.writeObject(NeurophArrayList.java:710)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
The thing is, I used the same code to train a neural network in another project which has the same imported jars and it worked properly. Here is the code I used to create and train the NN:
public void TrainNeuralNetwork(double[] inputs, double[] outputs){
DataSet set = new DataSet(inputs.length,outputs.length);
set.addRow(inputs,outputs);
System.out.println("Training...");
MultiLayerPerceptron loadSnakeNN = new MultiLayerPerceptron(TransferFunctionType.LINEAR, inputs.length, 500, outputs.length);
if( loadSnakeNN.getLearningRule() instanceof MomentumBackpropagation )
((MomentumBackpropagation)loadSnakeNN.getLearningRule()).setBatchMode(true);
MomentumBackpropagation learningRule = (MomentumBackpropagation)loadSnakeNN.getLearningRule();// Set learningRule
learningRule.setMaxError(0.01);
loadSnakeNN.learn(set);
loadSnakeNN.save("SnakeNN.nnet");
System.out.println("Neural Network Trained!");
}
Update
I found where the problem is. When I use more than 90 inputs I get the above error. So my new question is, how to train this neural network with more than 90 inputs?
Upvotes: 0
Views: 594
Reputation: 6363
You can increase the stack size available to your program by using JVM parameter -Xss
.
`java -Xss2048m ...`
means that you get a stack of 2048Mb
. If you're running this from your IDE you can search to find out how to pass JVM parameters for your specific IDE.
I'm assuming that there is no bug either in your code or the library, otherwise increasing the stack will probably not be enough.
Upvotes: 2