Click here to Skip to main content
Click here to Skip to main content

Neural Network Classifier

By , 29 Jan 2005
 

Sample Image - Demo.png

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.

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…

License

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) Persia Dade Pardaz - داده پردازی پرشیا
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Member
I am an electronic engineer interested in Pattern Recognition (specially OCR), Neural Networks, Image Processing and of course PROGRAMMING. I was born in Khezri, a small town in Khorasan, the largest province of Iran, I have taken My BS. from Sharif University of technology, MSc. and PhD. from Tarbiat Modarres University.
Currently I'm working in Shahrood university as an assistant professor in Faculty of Electrical & Robotic.
 
Hossein Khosravi's Blog: Andisheh Online
 
Educational Site: C++ Tutorial - آموزش برنامه نویسی سی پلاس پلاس
 
Other Sites: Free Farsi OCR Datasets, Farsi OCR Software

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalhelp mememberlechat232628 Sep '09 - 7:19 
Please, would you like to help me to prepare my project handwritten recognition word or letters with TDNN (time delay neuronal network) ,a language is c# or .
Thank you very match
Contact me in:
Doc_dh23000@hotmail.com
GeneralRed&Blue vs Yellow&Blue, see similar software: Sharky Neural NetworkmemberSharkTime6 Aug '09 - 7:44 
Great. I wrote similar software: Sharky Neural Network
Try and compare with yours.
 
SNN is a free software for playing with neural networks classification.
You can control more parameters.
 
I got some problems using your software, suddenly your application closed during learning.
 
You may consider remove 'initialize network' feature, and add it by default to Learn button.
If it is not good for you, you can make two buttons: Learn (with initialization), and Learn more (without init.).
It will be much easier to use it, just one click to start.
Also, more points at start is better idea. Neural networks likes more learning data.
 
Rgds,
SharkTime.com
Generalimage processing & neural networkmemberMember 352189429 Jun '09 - 21:22 
سلام
من در زمینه پردازش تصویر و شبکه عصبی در حال تحقیق و پیاده سازی پروژه ای هستم و پروژه مورد نظرم را با مطلب پیاده سازی کرده ام و الان می خواهم معادل توابع مطلب را در ویژوال
استودیو پیدا کنم و
این کار را با استفاده از کتابخانه های
open cv و emgu
انجام می دهم.
و چون آشنایی کافی با این کتابخانه ها ندارم نتوانسته ام این کار را انجام دهم. لطفا اگر در این زمینه کار کرده اید من را راهنمایی بفرمایید.
در کل من می خواهم شبکه عصبی ای که در مطلب پیاده سازی کرده ام را در ویژوال استودیو (در سی شارپ) پیاده سازی کنم
Generalhelp text to speechmemberelhamhaj31 Jan '09 - 19:08 
proje man dar morede text to speeche with neural network. age mitoonid komakam konid.
GeneralSOMmemberaparna tiwari18 Jan '09 - 2:31 
hi
i want to work on a SOM subject for my major
project.
of cource i already worked on MLP
please help me
GeneralExe crashes under VistamemberDPLNeural30 Sep '08 - 23:45 
has anyone experienced problems running this code in Vista? I compiled the project under VS 2008 but it still crashed...any similar experiences as it ran fine under XP Pro with VC6
Thanks in advance
GeneralRe: Exe crashes under VistamemberJeff Robertson20 Nov '08 - 2:32 
In Visual C++ 7.1 it was dieing in ErrorDlg.cpp
 
I changed the following
 
void CErrorDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);
	RECT rc,rc2;
	GetClientRect(&rc);
	rc.bottom -= 30;
	if(m_errorGraph.m_hWndOwner)   // Change HERE 
        {
             m_errorGraph.MoveWindow(&rc);
	    rc2.top = rc.bottom; rc2.left = rc.left; rc2.right   =           rc2.left + 40; rc2.bottom = rc2.top + 30;
	    CWnd* pwnd = GetDlgItem(IDOK);
	    if(pwnd)
            pwnd->MoveWindow(&rc2);
	    m_errorGraph.UpdateGraph();
	    Invalidate();
        }
	// TODO: Add your message handler code here
}

Generali need a vc6 versionmemberphilophos29 Aug '07 - 5:24 
that is my wish
Generalmlpmemberm_kh26 Jul '06 - 9:04 
hi
i want to work on a new mlp subject for my graduation
project.
of cource i already worked on OCR .
plz guide me.
Generalseems the code forget to free the memory resoursesmemberninnyknox16 Apr '06 - 11:46 
this is a very useful class, thanks!
but i have two problems:
 
[1] seems the code forget to free the memory resourses
 
[2] why the network converg even slower if i increase the learningRate?
 

thanks you!
GeneralRe: seems the code forget to free the memory resoursesmemberHossein Khosravi16 Apr '06 - 18:57 
1. may be.
2. Thats because of Momentum, set m to zero then you can see that by increasing Learning rate at the begining, MLP converges faster.Cool | :cool:
GeneralRe: need helpmemberHossein Khosravi8 Apr '06 - 19:25 
Thats very simple. in fact its the sme as what I done in my demo application, unless you must get inputs from text file rather than screen. assume red points are class -1 and blue points are class +1. other things are the same. good luck.Smile | :)
NewsVery Large Handwritten Farsi Digit Dataset [modified]memberHossein Khosravi15 Jan '06 - 20:36 
Hello allRoll eyes | :rolleyes:
to use this neural network with some real data, there is a free dataset of handwritten farsi digits at this location:
http://www.farsiocr.ir/farsi-digit-dataset[^]
also you can directly contact me(HosseinKhosravi@gmail.com) I will guide you how to access the whole dataset of Farsi digits. This dataset is free for non commercial use.It has more than 102,000 handwritten Persian digits.
GoodLuck;P
 
Hossein Khosravi
 
modified on Saturday, August 29, 2009 1:33 AM

QuestionDo these NN classes need any change for OCR app?membercaykahve27 Dec '05 - 13:33 
Hello,
I'm trying to use your code for an OCR application. I'm facing two problems.
1. I cannot converge to less than 0.15 error
2. After training, I always get the same output value set whatever input set I apply.
Have you changed or added something to the NN classes you have used here when you made the Farsi OCR application?
 
Thanks
GeneralDifferent training setmemberpatrick tran13 Sep '05 - 3:55 
This is absolutely kool, Andrew. I would like to ask you 2 questions.
1. I would like to reuse the code of NN to train a different dataset which has both nominal and numerical attributes. Is it possible your NN can accept nominal inputs?
2. Is that true that I need only to replace your training data generation by another dataset? And the NN would work just fine?
Thanks
Patrick
Questionwhat about voice recognitionsusspayam govahi9 Aug '05 - 5:46 
i want to use nural network for recognize 3 sound command but i cannot create nural network like this ,can i use this article to write a program for my purpose ?
it is very important for my program about knitting persian rugs ,for now i recogniz sound frequencies by fourier transform (FFT) but i have forced to recognize only frequencies..
 
regards
payam govahi
www.payamsoft.com

AnswerRe: what about voice recognitionmemberpayamtooba20 Jan '09 - 23:06 
someone help me D'Oh! | :doh:
GeneralDoing something very similarmemberzsnow4 Feb '05 - 10:25 
As my small research work during my study i am analysing some emulsion diagrams and the thing here i quite similar, except i have 5 colors: picture of training data and predicited values
 
first i was trying to train my net with standard backpropagation but had a few problems, so i decided to use genetic algorithm for training my net and i got more satisfying results.
 
A great source of information for me was faq of comp.ai.neural-nets.
 
questions, comments?
GeneralRe: Doing something very similarmembersgenie6821 Jun '05 - 1:54 
Can I get a description of how you did training for your implementation? You can write me off-line to avoid cluttering this thread.
GeneralThought-provokingmemberJerry Evans31 Jan '05 - 11:30 
Thanks for the article, most interesting. One suggestion: You mention using your backprop system to do OCR for Farsi - it would be great if you could elaborate/describe this process in more detail. This is exactly the kind of discussionthat gets missed from most articles/books. For example how do you format your data ready for input to the MLP and how do you check the recogniser is working correctly ?
GeneralRe: Thought-provokingmemberHossein Khosravi31 Jan '05 - 20: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??sussAnonymous30 Jan '05 - 11:35 
Khosravi, do you remember me???
I am Damon Chitsaz, your old highschool friend! Remember Javad(Reza Goodarzi??)
It has been so long! A weird coincident to meet you here!
What is your email address??
Mine is damoncz@hotmail.com
Contact me!
AnswerRe: Is that really you Hossien Khosravi??membertoxcct1 Feb '05 - 6:02 
hey, do you remember me ?
 
toxcct, the guy you never met... Sniff | :^)
 
toxcct@blablabla.com
(D'Oh! | :doh: oops, i forgot, that's not a meeting forum...)
 

TOXCCT >>> GEII power
[toxcct][VisualCalc]
GeneralInterestingmemberRui A. Rebelo30 Jan '05 - 5:57 
You code is excellent. It is efficient and easy to understand, provided that the reader knows the teory behind back error propagation neural nets. The program is also very nice, with appealing graphics.
However your article doesn't explain well the theory behind the code. For those willing to understand how the neural nets work I suggest:
http://www.generation5.org/articles.asp?Action=List&Topic=Neural+Networks
It has lots of articles covering back propagation and kohonen neural nets.

 
Rui A. Rebelo
GeneralAt last some info...sussAnonymous30 Jan '05 - 1:25 
Excellent, I havent checked the code yet, but at last something that seems to be an easy implementation of a N.Network.
 
I've been working with similar classes but it was a long time ago and I couldnt find anything from that time, so this is great...
 
Cheers

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

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