An Introduction to Neural Networks in Java
- Neural Network Structure
- Using the Network Class
- Output Computation Method
- Dealing with Errors
- Training for Errors
- Further Study
This article will show you how to use a feed-forward-backpropagation neural network from a Java program. The neural network presented in this article is designed to recognize patterns. For this article, we will teach the neural network to recognize only a very simple pattern. It is possible to use this same neural network class to learn much more complex patterns. The code presented here is reusable and can be used for any neural network that involves a single level of neurons.
The pattern that we will teach the neural network to recognize is the XOR operator. The XOR operator's truth table is shown here for the operation z = x XOR y.
X |
Y |
Z (result) |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
Neural Network Structure
A neural network is composed of layers of neurons. The most common neural networks have an input, output, and one or more hidden layers. Figure 1 shows the neural network that I will construct in this article.
Figure 1 A typical neural network.
Patterns are presented to the input layer of the neural network. The output layer relays the result of the neural network processing the input pattern. One or more hidden layers add further processing power to the neural network.
Now that I have shown you what a neural network looks like, I will show you how to construct a neural network class. In the next section, you will be shown how the neural network class provided by the article was created.