Exemple #1
0
  public void testFeedforwardPersist() throws Throwable {
    NeuralDataSet trainingData = new BasicNeuralDataSet(XOR.XOR_INPUT, XOR.XOR_IDEAL);

    BasicNetwork network = createNetwork();
    Train train = new Backpropagation(network, trainingData, 0.7, 0.9);

    for (int i = 0; i < 5000; i++) {
      train.iteration();
      network = (BasicNetwork) train.getNetwork();
    }

    TestCase.assertTrue("Error too high for backpropagation", train.getError() < 0.1);
    TestCase.assertTrue("XOR outputs not correct", XOR.verifyXOR(network, 0.1));

    EncogPersistedCollection encog = new EncogPersistedCollection();
    encog.add(network);
    encog.save("encogtest.xml");

    EncogPersistedCollection encog2 = new EncogPersistedCollection();
    encog2.load("encogtest.xml");
    new File("encogtest.xml").delete();

    BasicNetwork n = (BasicNetwork) encog2.getList().get(0);
    TestCase.assertTrue("Error too high for load", n.calculateError(trainingData) < 0.1);
  }
  public void testClone() throws Throwable {
    BasicNetwork source = XOR.createThreeLayerNet();
    source.reset();

    BasicNetwork target = (BasicNetwork) source.clone();

    TestCase.assertTrue(target.equals(source));
  }