Category: Artificial Intelligence

Using Neural Networks for Classification

Posted on 7:18pm 10/15/2008 by Bruno Silva in .NET, Artificial Intelligence, Programming, Software

During the last weeks I’ve been doing some research related to my Master thesis. One of the topics I’m studying is Unsupervised Machine Learning. The main goal is to have a piece of software that given a training set (a set of examples representative of the whole population) allow the software to accept input that it has never seen before and behave as expected.

Imagine for instance a concept called Color Classifier. We usually have several named colors such as red, green, blue, yellow, gray, orange, etc.  You have different flavors of each color, and you can consider different combinations of RGB colors the same color. How  can you, given a RGB Color code, name that color?

One approach is using Neural Networks (which is a unsupervised learning method) for classification.

I won’t talk about the details of Neural Networks algorithms, since it is the reason why many people avoid this kind of approach: complexity. I’ll just show you how, with a library that hides the implementation details, you can use them.

NeuronDotNet is a .NET library which allows you to use Neural Networks algorithms as a black box. They have some samples which can guide you, as they guided me.

The algorithm I’m using is called Self-organizing Map (SOM). The main idea is to generate a 2D map which topology (dispersion of the points and their positions) is based on the relation between the input data. Back to the example, from a set of random colors which can be represented as a vector with 3 dimensions (input), we generate a map with 2 dimensions, where similar colors get close to each other and completely different colors are set apart. The picture bellow represents the results.

(Left: input, Right: 2D map that results from the algorithm)

The number of colors that will be recognized (the number of neurons of the output layer) can be customized in the neural network configuration, prior to the training phase. In the example above I recognize 25 different colors.

Once the SOM algorithm runs in training mode, the resultant neural network is able to classify new colors into the different slots of the map. If you name each slot with the name of a color, you get a color classifier. In the example above you can label several flavors of green, blue, red,  brown, pink, etc. In each slot you have several stripes that represent the colors from the training set and in which slot they ended up.

In the demo application the basic steps are:

  1. Play with the different settings (or leave them alone… take special attention to Layer Width/Height and Set Size)
  2. Generate Training Set
  3. Start (Learning)
  4. Choose Color (to classify)
  5. Classify (the neuron that best matches the selected color will be highlighted with a red border)

Download and try the Color Classifier. Keep in mind that a lot of the source code is UI-related, and not Algorithm-related, so don’t be afraid!

Download Demo | Download Source Code

© Bruno Silva | Powered by Wordpress