jeffheaton's picture

    The Encog workbench provides two ways that you can make use of your neural network in Java code. First, you can save the neural network and training data to an .EG file. Java applications can then load data from this .EG file. Using .EG files will be covered in much greater detail in Chapter 9, “Encog Persistence”.

    Another way to generate code is to use the Encog Workbench. The Encog workbench can generate code in the following languages.

  • Java
  • C#
  • VB.Net

    Code generation simply generates the code needed to create the neural network. For the generated program to be of any use, you will need to add your own training code. Listing 4.1 shows the generated Java code from the XOR, feedforward neural network.

Listing 4.1: Generated Java Code

import org.encog.neural.activation.ActivationSigmoid;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.layers.BasicLayer;
import org.encog.neural.networks.layers.Layer;

/**
 * Neural Network file generated by Encog.  This file shows just a simple
 * neural network generated for the structure designed in the workbench.
 * Additional code will be needed for training and processing.
 * 
 * http://www.encog.org
 * 
 */

public class EncogGeneratedClass {

  public static void main(final String args[]) {

    BasicNetwork network = new BasicNetwork();

    Layer inputLayer = new BasicLayer( new ActivationSigmoid(),true,2);
    inputLayer.addNext(inputLayer);

    Layer hiddenLayer1 = new BasicLayer( new ActivationSigmoid(),true,2);
    inputLayer.addNext(hiddenLayer1);

    Layer outputLayer = new BasicLayer( new ActivationSigmoid(),true,1);
    hiddenLayer1.addNext(outputLayer);
    network.tagLayer("INPUT",inputLayer);
    network.tagLayer("OUTPUT",outputLayer);
    network.getStructure().finalizeStructure();
    network.reset();
  }
}

Copyright 2005 - 2012 by Heaton Research, Inc.. Heaton Research™ and Encog™ are trademarks of Heaton Research. Click here for copyright, license and trademark information.