Click here to Skip to main content
11,921,491 members (67,594 online)
Click here to Skip to main content
Add your own
alternative version


76 bookmarked

Neural Network Classifier

, 29 Jan 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
A Multilayer perceptron used to classify blue and red points.

Sample Image - Demo.png


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.

Sample screenshot

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:

  1. Clear screen by pressing on the Clear button.
  2. 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).
  3. Put some blue and red points on screen by clicking on it. (Select color from combo box).
  4. Now you can press “initialize” network button.
  5. 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.
  6. 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…


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hossein Khosravi
Software Developer (Senior)
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Currently I'm working at Dept. of Electrical Engineering in University of Shahrood.
Pattern Recognition (specially OCR), Neural Networks, Image Processing and Machine Vision are my interests. However I'm a PROGRAMMER as well.
BSc: Sharif University of technology @ 2002
MSc. and PhD: Tarbiat Modarres University @ 2006 & 2010 respectively

Personal Blog: Andisheh Online

Religious Blogs: Shia Muslims , Ashura , Islamic Quotes

Commercial Site: Farsi OCR

You may also be interested in...

Comments and Discussions

Generalhelp me Pin
lechat232628-Sep-09 8:19
memberlechat232628-Sep-09 8:19 
GeneralRed&Blue vs Yellow&Blue, see similar software: Sharky Neural Network Pin
SharkTime6-Aug-09 8:44
memberSharkTime6-Aug-09 8:44 
Generalimage processing & neural network Pin
Member 352189429-Jun-09 22:22
memberMember 352189429-Jun-09 22:22 
Generalhelp text to speech Pin
elhamhaj31-Jan-09 20:08
memberelhamhaj31-Jan-09 20:08 
GeneralSOM Pin
aparna tiwari18-Jan-09 3:31
memberaparna tiwari18-Jan-09 3:31 
GeneralExe crashes under Vista Pin
DPLNeural1-Oct-08 0:45
memberDPLNeural1-Oct-08 0:45 
GeneralRe: Exe crashes under Vista Pin
Jeff Robertson20-Nov-08 3:32
memberJeff Robertson20-Nov-08 3:32 
Generali need a vc6 version Pin
philophos29-Aug-07 6:24
memberphilophos29-Aug-07 6:24 
Generalmlp Pin
m_kh26-Jul-06 10:04
memberm_kh26-Jul-06 10:04 
Generalseems the code forget to free the memory resourses Pin
ninnyknox16-Apr-06 12:46
memberninnyknox16-Apr-06 12:46 
GeneralRe: seems the code forget to free the memory resourses Pin
Hossein Khosravi16-Apr-06 19:57
memberHossein Khosravi16-Apr-06 19:57 
GeneralRe: need help Pin
Hossein Khosravi8-Apr-06 20:25
memberHossein Khosravi8-Apr-06 20:25 
NewsVery Large Handwritten Farsi Digit Dataset [modified] Pin
Hossein Khosravi15-Jan-06 21:36
memberHossein Khosravi15-Jan-06 21:36 
QuestionDo these NN classes need any change for OCR app? Pin
caykahve27-Dec-05 14:33
membercaykahve27-Dec-05 14:33 
GeneralDifferent training set Pin
patrick tran13-Sep-05 4:55
memberpatrick tran13-Sep-05 4:55 
Questionwhat about voice recognition Pin
payam govahi9-Aug-05 6:46
susspayam govahi9-Aug-05 6:46 
AnswerRe: what about voice recognition Pin
payamtooba21-Jan-09 0:06
memberpayamtooba21-Jan-09 0:06 
GeneralDoing something very similar Pin
zsnow4-Feb-05 11:25
memberzsnow4-Feb-05 11:25 
GeneralRe: Doing something very similar Pin
sgenie6821-Jun-05 2:54
membersgenie6821-Jun-05 2:54 
GeneralThought-provoking Pin
Jerry Evans31-Jan-05 12:30
memberJerry Evans31-Jan-05 12:30 
GeneralRe: Thought-provoking Pin
Hossein Khosravi31-Jan-05 21:05
memberHossein Khosravi31-Jan-05 21:05 
at first I extract letters from some handwritten forms, then I did normalization, at last the normalized image(64*64 pixel) was segmented into 8*8 block and gray level average in each block was the value send to each input neuron(64 neuron was at input)... of course there are another features that can be used but the scope of this article is not so that I can describe all my workConfused | :confused: . but its interesting that by this easy feature I reached 96% correctness on my training data(12800 letters) and 88% correctness on my test data(3200 letters)OMG | :OMG:
QuestionIs that really you Hossien Khosravi?? Pin
Anonymous30-Jan-05 12:35
sussAnonymous30-Jan-05 12:35 
AnswerRe: Is that really you Hossien Khosravi?? Pin
toxcct1-Feb-05 7:02
membertoxcct1-Feb-05 7:02 
GeneralInteresting Pin
Rui A. Rebelo30-Jan-05 6:57
memberRui A. Rebelo30-Jan-05 6:57 
GeneralAt last some info... Pin
Anonymous30-Jan-05 2:25
sussAnonymous30-Jan-05 2:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151120.1 | Last Updated 30 Jan 2005
Article Copyright 2005 by Hossein Khosravi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid