3

I have implemented a neural network using encog library as below,

MLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);

    final Propagation  train =  new Backpropagation(network, trainingSet);
    int epoch = 1;
    do {
        train.iteration();
        System.out.println("Epoch #" + epoch + 
                " Error:" + train.getError());
                epoch++;

    } while (train.getError() < 0.009);

    double e = network.calculateError(trainingSet);
    System.out.println("Network trained to error :" + e);
    System.out.println("Saving Network");


    EncogDirectoryPersistence.saveObject(new File(FILENAME), network);
}


public void loadAndEvaluate(){
    System.out.println("Loading Network");
    BasicNetwork network = (BasicNetwork) EncogDirectoryPersistence.loadObject(new File(FILENAME));

    BasicMLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT,XOR_IDEAL);

    double e = network.calculateError(trainingSet);

    System.out.println("Loaded network's error is (should be the same as above ):" + e);

}

This outputs the error. But i want to test this with custom data and check if the output given for a set of data is a

jee1tha
  • 33
  • 4

1 Answers1

0

I see that you are following one of the persistence example. To obtain outputs for some input, use the "compute" function. As an example:

    double[] output = new double[1];
    network.compute(new double[]{1.0, 1.0}, output);
    System.out.println("Network output: " + output[0] + " (should be close to 0.0)");

Here's the java user guide. It's quite helpful.

Frank Ibem
  • 828
  • 1
  • 11
  • 19
  • i sued the following data to train and test the neural network but the output is not constant. public static double train_INPUT[][] = { {0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}, {1.0, 1.0} }; public static double tester[] ={1.0, 0.0},; public static double train_IDEAL[][] = { {0.0}, {1.0}, {1.0}, {0.0} }; – jee1tha Aug 25 '16 at 04:28
  • I'm just noticing that your loop condition is train.getError() < 0.009. Shouldn't that be train.getError() > 0.009 ? I used a 2-3-1 network to test and was able to get down to 0.008 error. (See https://gist.github.com/frankibem/94e588cb2d8ccda2af675f9bde3e25fa and here: https://gist.github.com/frankibem/eeaa066595e6ba791dfc6cea558f92ca – Frank Ibem Aug 25 '16 at 14:49