An Introduction to Neural Networks in Java

Artificial Intelligence programming is something that has interested nearly every programmer at one point or another. In this introduction to neural networks, Jeff Heaton shows you how to use a simple neural network to recognize patterns.

From the author of

From the author of

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.

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.