- Neural Network Structure
- Using the Network Class
- Output Computation Method
- Dealing with Errors
- Training for Errors
- Further Study

## Using the Network Class

The neural network provided by this article is contained in a file called Network.java. This neural network class is shown in Listing 1. This class implements a feed-forward neural network with an input, hidden, and output layer. Most neural networks will have only one or two hidden layers.

Like most classes in Java, the Network class makes available a specialized constructor that will accept some basic configuration information about how the neural network is to be constructed. The signature for the neural network constructor is as follows:

public Network(int inputCount, int hiddenCount, int outputCount, double learnRate, double momentum)

As you can see from the constructor, several configuration parameters must be passed to the neural network class as it is instantiated:

inputCount—The number of neurons that are in the input layer.

hiddenCount—The number of neurons that are in the hidden layer.

outputCount—The number of neurons that are in the output layer.

learnRate—The learning rate for the backpropagation training algorithm.

momentum—The momentum for the backpropagation training algorithm.

The number of input neurons depends on the problem that you are applying the network to. In the case of the XOR problem, there are two input variables. Because of this, only two input neurons are needed. Because there is one single output from the XOR problem, one output neuron is needed.

Determining the number of hidden neurons that is required is a more complex task. Generally, it should be a number that is close to the input and output layers. Often, the process of determining the correct number of hidden neurons is simply trial-and-error. If the network does not train properly, you change the number of hidden neurons.

The learning rate and momentum are both backpropagation algorithms that will affect the learning process of the neural network. In general, both of these values should be set to values that are greater than zero, but also less than 1. They will affect the rate at which the network learns.

Once the neural network has been instantiated using the constructor, it is basically ready for use. At this point, the neural network has a random weight matrix and should be trained before any patterns are to be recalled from the neural network. In the next section, you will see how the neural network is used to recall a pattern.