Neural Network Classifier






4.47/5 (21 votes)
A Multilayer perceptron used to classify blue and red points.
Introduction
Neural Network is a powerful tool used in modern intelligent systems. Nowadays, many applications that involve pattern recognition, feature mapping, clustering, classification and etc. use Neural Networks as an essential component. In recent decades, several types of neural networks have been developed. Back Error Propagation, Kohonen feature map and Hopfield network are some of basic networks that have been developed and are used in many applications.
In this article general Multi Layer Perceptron or Back Error Propagation is presented. The sample application uses this Multi Layer Perceptron and classifies the blue and red patterns generated by user.
Network structure
Figure below shows a typical MLP with three layers of weights.
In a typical neural network, these objects exist: layers (usually 3 layers), some neurons in each layer and synapses between layers. Based on these objects, I developed appropriate classes.
Classes used in MLP
Neuron
: This is the basic element of network, that has some members such as output
, sum
and delta
.
static double momentum;// = 0.9; static double learningRate;// = 0.05; CList<Synapse*> inlinks;//a list of synapses brings to this neuron CList<Synapse*> outlinks; double output; // range from 0.0 to 1.0 double sum; // weighted sum of inputs double delta; CString label;
Layer
: This class has a list of neurons
and some methods for computing errors and weight adjustment.
CList<Neuron*> neurons; int size; CString name; Layer(CString strLbl,int size); Neuron* getNeuron(int i); void computeOutputs(); void computeBackpropDeltas(Samples s); // for output neurons void computeBackpropDeltas(); // for hidden neurons void computeWeights();
Synapse
: This class has its weight
and two pointers to its connected neurons (from
and to
).
double weight;//weight between "to" and "from" neurons double data; Neuron* from; Neuron* to;
Perceptron
: This is the last class that has some lists of layers
, inputSamples
and outputSamples
(targets).
CList<Layer*> layers; CList<Samples> inputSamples;//Samples are array of double CList<Samples> outputSamples; Layer* inputLayer; Layer* outputLayer; double error;
How to use Sample Application
To use this program follow these steps:
- Clear screen by pressing on the Clear button.
- Define your network structure by putting appropriate values in H1, H2 and H3 edit boxes. These are the number of neurons in hidden layers. If some value was 0, that layer will not be included in network (by default the network has three layers: one input, one hidden and one output).
- Put some blue and red points on screen by clicking on it. (Select color from combo box).
- Now you can press “initialize” network button.
- Set maximum number of iterations and press “learn” as more as the network correctly classifies all points on screen. You can see the error graph by clicking on “Show error graph”. The “smartgraph” component is used in this project and you must download and register it on your computer to see error graph correctly. It is available here.
- Error values can be written into a text file, if you check in “Write errors to file”.
This program is fully object oriented and can be understood easily if you are familiar with Multi Layer Perceptron. At last, I used this class to develop a Farsi OCR application and it was working very well!.
Use and enjoy…