Skip to content


Using Artificial Neural Networks

Machine learning is an exciting area in computer science. In this post I will show you how to use a neural network to learn trends from some data that you have and then classify some new data. This has many applications like detecting the language of a written text, hand written character recognition, etc.

For this post I will be using Fast Artificial Neural Network (FANN). The first step is to install the library. In Ubuntu, you can install it using the repositories with this command:

sudo apt-get install libfann1-dev

Once the library is installed, you can write a simple program to learn some patterns.

Lets see some of the included examples. First, copy them to a writeable folder:

cd ~
mkdir libfannSamples
cp /usr/share/doc/libfann1-dev/examples/* libfannSamples

Now let’s compile the examples.

cd libfannSamples
make clean;make

We are ready to train a neural network. I will use the included example to learn the exclusive OR function. First, I will show you how you can define the data for learning, in this case, the exclusive OR function. This is the content of the xor.data file.

The first row defines the format of the file. In this case, it says that there are 4 data pairs, with 2 inputs and 1 output. The next rows represent the data itself, which in this case is the exclusive OR function, considering that -1 is false and 1 is true. For each data pair, the first line represents the inputs and the next line, the outputs for those inputs.

We are now ready to run the training process:

./xor_train


You will see the output of the library and the trained neural network will be saved to the xor_float.net file. You can then run the test program:

./xor_test


As the results show, the exclusive OR function was learnt by the neural network without a problem. You can change the xor.data file to suit your needs for a simple application or you can use the source files as a starting point for your own application using neural networks.

Posted in Open Source, Programming.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.