Null pointer exception on iteration

Help
elisacarli
2012-11-05
2012-12-24
  • elisacarli
    elisacarli
    2012-11-05

    Hi,
    I've the following code
    TrainingSet trainingSet = new TrainingSet(2, 1);
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{0, 0}, new double{0}));
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{0, 1}, new double{1}));
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{1, 0}, new double{1}));
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{1, 1}, new double{0}));

    MultiLayerPerceptron network =
    new MultiLayerPerceptron(TransferFunctionType.TANH, 2, 3, 1);

    DynamicBackPropagation train = new DynamicBackPropagation();
    train.setNeuralNetwork(network);
    network.setLearningRule(train);

    int epoch = 1;
    do
    {
      train.doOneLearningIteration(trainingSet);
      System.out.println("Epoch " + epoch + ", error=" + train.getTotalNetworkError());
      epoch++;

      } while(train.getTotalNetworkError()>0.01);

    When I run it I get the following error
    java.lang.NullPointerException
    at org.neuroph.nnet.learning.MomentumBackpropagation.updateNeuronWeights(MomentumBackpropagation.java:71)
    at org.neuroph.nnet.learning.SigmoidDeltaRule.calculateErrorAndUpdateOutputNeurons(SigmoidDeltaRule.java:84)
    at org.neuroph.nnet.learning.BackPropagation.updateNetworkWeights(BackPropagation.java:56)
    at org.neuroph.core.learning.SupervisedLearning.learnPattern(SupervisedLearning.java:175)
    at org.neuroph.core.learning.SupervisedLearning.doLearningEpoch(SupervisedLearning.java:148)
    at org.neuroph.core.learning.IterativeLearning.doOneLearningIteration(IterativeLearning.java:205)

    How can I fix it?

    Thank you

     
  • Almeida.BR
    Almeida.BR
    2012-11-19

    Man, did you have any solution? could you do it? Please, let me know if yes, cause I'm facing the same problem.

     

  • Anonymous
    2012-11-19

    Ahoi

    Sometimes…. i have something like this.

    I got an error and dont know what or where to find the sollution.
    What i do is easy, maby not so nice but you can find the way to get run.

    Use debug. Debug is also running through the programm. Only step by step! So you see all variables, function calls, etc

    Or if you have no environment try this:
    Just put trance() or println() to every place you can imagine the upcomming exception.
    Bevore and after big function calls :d

    like….

    i,
    I've the following code
    TrainingSet trainingSet = new TrainingSet(2, 1);
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{0, 0}, new double{0}));
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{0, 1}, new double{1}));
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{1, 0}, new double{1}));
    trainingSet.addElement(new SupervisedTrainingElement
    (new double{1, 1}, new double{0}));

    println(" Comming to bottleneck01/n ");

    MultiLayerPerceptron network =
    new MultiLayerPerceptron(TransferFunctionType.TANH, 2, 3, 1);

    println(" Comming to bottleneck02 /n");

    DynamicBackPropagation train = new DynamicBackPropagation();
    println(" Comming to bottleneck03 /n");

    train.setNeuralNetwork(network);
    println(" Comming to bottleneck04 /n");
    network.setLearningRule(train);
    println(" Comming to bottleneck05 /n");

    int epoch = 1;
    do
    {
    println(" Comming to bottleneck loop 06/n ");
      train.doOneLearningIteration(trainingSet);
    println(" Comming to bottleneck loop07/n ");
      System.out.println("Epoch " + epoch + ", error=" + train.getTotalNetworkError());
    println(" Comming to bottleneck loop08/n ");
      epoch++;

      } while(train.getTotalNetworkError()>0.01);

    println(" Comming to bottleneck after loop09/n ");

     
  • Almeida.BR
    Almeida.BR
    2012-11-19

    Thanks for answering. I've known about Debug tools already, problem is I'm added neuroph framework through its .jar file, so Debug doesn't have access to its source code. I thought you've discovered what was causing that error, something about the framework, or something like that. But anyway, thanks for helping.

     
  • Zoran Sevarac
    Zoran Sevarac
    2012-11-21

    Hi,

    Get the latest version of framework 2.7 and let me know if it works for you
    http://neuroph.sourceforge.net/download.html

    You can also attach sources to debugger  so you can track execution even when it gets into jar…
    NetBeans has 'attach sources' option, and other IDE's should have that as well

    Zoran