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
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.