Example #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);
  }
Example #2
0
  public void testHopfieldPersist() throws Exception {
    boolean input[] = {true, false, true, false};

    BasicNetwork network = new BasicNetwork();
    network.addLayer(new HopfieldLayer(4));

    NeuralData data = new BiPolarNeuralData(input);
    Train train = new TrainHopfield(data, network);
    train.iteration();

    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 network2 = (BasicNetwork) encog2.getList().get(0);

    BiPolarNeuralData output = (BiPolarNeuralData) network2.compute(new BiPolarNeuralData(input));
    TestCase.assertTrue(output.getBoolean(0));
    TestCase.assertFalse(output.getBoolean(1));
    TestCase.assertTrue(output.getBoolean(2));
    TestCase.assertFalse(output.getBoolean(3));
  }
Example #3
0
  /**
   * * <br>
   * Updates the neural networks</br> <br>
   * Assumes that the *
   */
  private void trainNeuralNets(int id) {

    Train train =
        new ResilientPropagation(array_of_neural_nets[id], input_datas[id].getTrainingSet());

    int epoch = 0;
    while (train.getError() > error_allowed && epoch < max_epoch) {

      train.iteration();
      epoch++;
    }
  }
  private BasicNetwork trainNetwork(
      BasicNetwork network,
      NeuralDataSet trainingSet,
      double learningRate,
      double momentum,
      double maxError,
      int maxIteration) {
    final Train train = new Backpropagation(network, trainingSet, learningRate, momentum);

    int epoch = 1;

    do {
      train.iteration();
      epoch++;
    } while ((epoch < maxIteration) && (train.getError() > maxError));

    return (BasicNetwork) train.getNetwork();
  }