nural in matlab
TRANSCRIPT
-
8/3/2019 Nural in Matlab
1/12
8,490,423 members and growing! (44,047 online)
vedha rengharaju 300 Sign out
Home
Articles
o Chapters and Sections >
o Search
o Latest Articleso Latest Tips/Tricks
o Top Articles
o Beginner Articles
o Video Articles
o Technical Blogs
o Post an Article or Tip
o Post your Blog
o Posting/Update Guidelines
o Article Competition
Quick Answers
o Ask a Question about this article
o Ask a Question
o View Unanswered Questionso View All Questions...
o C# questions
o ASP.NET questions
o VB.NET questions
o C++ questions
o C#4.0 questions
Discussions
o All Message Boards...
o Application Lifecycle >
Design and Architecture
Running a Business
Sales / Marketing Collaboration / Beta Testing
Work & Training Issues
o Free Tools
o C / C++ / MFC >
ATL / WTL / STL
Managed C++/CLI
o C#
o Database
http://www.codeproject.com/Members/vedha-rengharajuhttp://www.codeproject.com/script/Reputation/List.aspx?mid=8650093http://www.codeproject.com/script/Membership/LogOff.aspx?rp=%2FArticles%2F19323%2FImage-Recognition-with-Neural-Networkshttp://www.codeproject.com/http://www.codeproject.com/script/Articles/Latest.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/search.aspxhttp://www.codeproject.com/script/Articles/Latest.aspx?at=1,3,7http://www.codeproject.com/script/Articles/Latest.aspx?at=6,8http://www.codeproject.com/script/Articles/TopArticles.aspx?ta_so=5http://www.codeproject.com/search.aspx?aidlst=152&sa_us=Truehttp://www.codeproject.com/script/Articles/VideoArticleList.aspxhttp://www.codeproject.com/script/Articles/BlogArticleList.aspxhttp://www.codeproject.com/script/Articles/Submit.aspxhttp://www.codeproject.com/script/Articles/BlogFeed.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1http://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks#_commentshttp://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/script/Answers/List.aspx?tab=unansweredhttp://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=81http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=85http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=842http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=78http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=308http://www.codeproject.com/script/Forums/List.aspxhttp://www.codeproject.com/script/Forums/List.aspxhttp://www.codeproject.com/script/Forums/List.aspxhttp://www.codeproject.com/Forums/1580997/Application-Lifecycle.aspxhttp://www.codeproject.com/Forums/369270/Design-and-Architecture.aspxhttp://www.codeproject.com/Forums/1533717/Running-a-Business.aspxhttp://www.codeproject.com/Forums/1533716/Sales-Marketing.aspxhttp://www.codeproject.com/Forums/1651/Collaboration-Beta-Testing.aspxhttp://www.codeproject.com/Forums/3304/Work-Training-Issues.aspxhttp://www.codeproject.com/Forums/1627782/Free-Tools.aspxhttp://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspxhttp://www.codeproject.com/Forums/4486/ATL-WTL-STL.aspxhttp://www.codeproject.com/Forums/3785/Managed-Cplusplus-CLI.aspxhttp://www.codeproject.com/Forums/1649/Csharp.aspxhttp://www.codeproject.com/Forums/1725/Database.aspxhttp://www.codeproject.com/http://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks#Mainhttp://www.codeproject.com/script/Reputation/List.aspx?mid=8650093http://www.codeproject.com/script/Membership/LogOff.aspx?rp=%2FArticles%2F19323%2FImage-Recognition-with-Neural-Networkshttp://www.codeproject.com/http://www.codeproject.com/script/Articles/Latest.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/search.aspxhttp://www.codeproject.com/script/Articles/Latest.aspx?at=1,3,7http://www.codeproject.com/script/Articles/Latest.aspx?at=6,8http://www.codeproject.com/script/Articles/TopArticles.aspx?ta_so=5http://www.codeproject.com/search.aspx?aidlst=152&sa_us=Truehttp://www.codeproject.com/script/Articles/VideoArticleList.aspxhttp://www.codeproject.com/script/Articles/BlogArticleList.aspxhttp://www.codeproject.com/script/Articles/Submit.aspxhttp://www.codeproject.com/script/Articles/BlogFeed.aspxhttp://www.codeproject.com/info/Submit.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1http://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks#_commentshttp://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/script/Answers/List.aspx?tab=unansweredhttp://www.codeproject.com/script/Answers/List.aspx?tab=activehttp://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=81http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=85http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=842http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=78http://www.codeproject.com/script/Answers/List.aspx?tab=active&alltags=true&tags=308http://www.codeproject.com/script/Forums/List.aspxhttp://www.codeproject.com/script/Forums/List.aspxhttp://www.codeproject.com/Forums/1580997/Application-Lifecycle.aspxhttp://www.codeproject.com/Forums/369270/Design-and-Architecture.aspxhttp://www.codeproject.com/Forums/1533717/Running-a-Business.aspxhttp://www.codeproject.com/Forums/1533716/Sales-Marketing.aspxhttp://www.codeproject.com/Forums/1651/Collaboration-Beta-Testing.aspxhttp://www.codeproject.com/Forums/3304/Work-Training-Issues.aspxhttp://www.codeproject.com/Forums/1627782/Free-Tools.aspxhttp://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspxhttp://www.codeproject.com/Forums/4486/ATL-WTL-STL.aspxhttp://www.codeproject.com/Forums/3785/Managed-Cplusplus-CLI.aspxhttp://www.codeproject.com/Forums/1649/Csharp.aspxhttp://www.codeproject.com/Forums/1725/Database.aspxhttp://www.codeproject.com/Members/vedha-rengharaju -
8/3/2019 Nural in Matlab
2/12
o Hardware & Devices >
System Admin
o Hosting and Servers
o Java
o .NET 4.5 and Visual Studio 11
o .NET Framework
o Mobileo Sharepoint
o Silverlight / WPF
o Visual Basic
o Web Development >
ASP.NET
CSS
JavaScript
PHP
o Site Bugs / Suggestions
o Other Languages>
General Indian Topics
General Chinese Topics
Learning Zones
o The Commerce Zone
o The Mobile & App Zone
o The Cloud Zone
o The Hardware Zone
o The Parallelism Zone
o The WPF / Silverlight Zone
o The Flex / Flash Zone
o The HTML5 / CSS3 Zone
o SharePoint Zone
o The SQL Zone
o WhitePapers / Webcastso Solutions Center
Features
o Who's Who
o Most Valuable Professionals
o Company Listings
o Component & Service Catalog
o Competitions
o News
o
o Daily Insider
o Newsletter archive
o Press Releases
o Surveyso CodeProject Stuff
o
Help!
o What is 'The Code Project'?
o General FAQ
o Post a Question
o Bugs and Suggestions
o Site Directory
http://www.codeproject.com/Forums/186301/Hardware-Devices.aspxhttp://www.codeproject.com/Forums/1644/System-Admin.aspxhttp://www.codeproject.com/Forums/1606152/Hosting-and-Servers.aspxhttp://www.codeproject.com/Forums/1643/Java.aspxhttp://www.codeproject.com/Forums/1653293/NET-4-5-and-Visual-Studio-11.aspxhttp://www.codeproject.com/Forums/1650/NET-Framework.aspxhttp://www.codeproject.com/Forums/13695/Mobile.aspxhttp://www.codeproject.com/Forums/1540733/Sharepoint.aspxhttp://www.codeproject.com/Forums/1004257/Silverlight-WPF.aspxhttp://www.codeproject.com/Forums/1646/Visual-Basic.aspxhttp://www.codeproject.com/Forums/1640/Web-Development.aspxhttp://www.codeproject.com/Forums/12076/ASP-NET.aspxhttp://www.codeproject.com/Forums/1580227/CSS.aspxhttp://www.codeproject.com/Forums/1580226/JavaScript.aspxhttp://www.codeproject.com/Forums/1213656/PHP.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/Forums/1580229/Hindi.aspxhttp://www.codeproject.com/Forums/1580230/Chinese.aspxhttp://www.codeproject.com/Zones/index.aspxhttp://www.codeproject.com/Zones/Commerce/http://www.codeproject.com/Zones/Mobile/http://www.codeproject.com/Zones/Cloud/http://www.codeproject.com/Zones/Hardware/http://www.codeproject.com/Zones/Parallelism/http://www.codeproject.com/Zones/WPF-Silverlight/http://www.codeproject.com/Zones/Flex-Flash/http://www.codeproject.com/Zones/HTML-CSS/http://www.codeproject.com/Zones/SharePoint/http://www.codeproject.com/Zones/SqlServer/http://www.codeproject.com/Zones/WhitePapers/http://www.codeproject.com/KB/solution-center/http://www.codeproject.com/Feature/http://www.codeproject.com/script/Membership/Profiles.aspxhttp://www.codeproject.com/script/Awards/MVPWinners.aspxhttp://www.codeproject.com/script/Membership/Profiles.aspx?mgtid=1&mgm=Truehttp://www.codeproject.com/script/Catalog/List.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1&awsac=truehttp://www.codeproject.com/script/News/List.aspxhttp://www.codeproject.com/Feature/Insider/http://www.codeproject.com/script/Mailouts/Archive.aspx?mtpid=1http://www.codeproject.com/script/PressReleases/Preview.aspxhttp://www.codeproject.com/script/Surveys/List.aspxhttp://www.codeproject.com/Info/Stuff.aspxhttp://www.codeproject.com/KB/FAQs/http://www.codeproject.com/info/guide.aspxhttp://www.codeproject.com/KB/FAQs/http://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/Forums/186301/Hardware-Devices.aspxhttp://www.codeproject.com/Forums/1644/System-Admin.aspxhttp://www.codeproject.com/Forums/1606152/Hosting-and-Servers.aspxhttp://www.codeproject.com/Forums/1643/Java.aspxhttp://www.codeproject.com/Forums/1653293/NET-4-5-and-Visual-Studio-11.aspxhttp://www.codeproject.com/Forums/1650/NET-Framework.aspxhttp://www.codeproject.com/Forums/13695/Mobile.aspxhttp://www.codeproject.com/Forums/1540733/Sharepoint.aspxhttp://www.codeproject.com/Forums/1004257/Silverlight-WPF.aspxhttp://www.codeproject.com/Forums/1646/Visual-Basic.aspxhttp://www.codeproject.com/Forums/1640/Web-Development.aspxhttp://www.codeproject.com/Forums/12076/ASP-NET.aspxhttp://www.codeproject.com/Forums/1580227/CSS.aspxhttp://www.codeproject.com/Forums/1580226/JavaScript.aspxhttp://www.codeproject.com/Forums/1213656/PHP.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/Forums/1580229/Hindi.aspxhttp://www.codeproject.com/Forums/1580230/Chinese.aspxhttp://www.codeproject.com/Zones/index.aspxhttp://www.codeproject.com/Zones/Commerce/http://www.codeproject.com/Zones/Mobile/http://www.codeproject.com/Zones/Cloud/http://www.codeproject.com/Zones/Hardware/http://www.codeproject.com/Zones/Parallelism/http://www.codeproject.com/Zones/WPF-Silverlight/http://www.codeproject.com/Zones/Flex-Flash/http://www.codeproject.com/Zones/HTML-CSS/http://www.codeproject.com/Zones/SharePoint/http://www.codeproject.com/Zones/SqlServer/http://www.codeproject.com/Zones/WhitePapers/http://www.codeproject.com/KB/solution-center/http://www.codeproject.com/Feature/http://www.codeproject.com/script/Membership/Profiles.aspxhttp://www.codeproject.com/script/Awards/MVPWinners.aspxhttp://www.codeproject.com/script/Membership/Profiles.aspx?mgtid=1&mgm=Truehttp://www.codeproject.com/script/Catalog/List.aspxhttp://www.codeproject.com/script/Awards/CurrentCompetitions.aspx?cmpTpId=1&awsac=truehttp://www.codeproject.com/script/News/List.aspxhttp://www.codeproject.com/Feature/Insider/http://www.codeproject.com/script/Mailouts/Archive.aspx?mtpid=1http://www.codeproject.com/script/PressReleases/Preview.aspxhttp://www.codeproject.com/script/Surveys/List.aspxhttp://www.codeproject.com/Info/Stuff.aspxhttp://www.codeproject.com/KB/FAQs/http://www.codeproject.com/info/guide.aspxhttp://www.codeproject.com/KB/FAQs/http://www.codeproject.com/Questions/ask.aspxhttp://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspxhttp://www.codeproject.com/script/Content/SiteMap.aspx -
8/3/2019 Nural in Matlab
3/12
o Advertise with us
o About Us
The Lounge
o The Insider News
o The Lounge
o Clever Code
o Hall of Shame
o The Soapbox
149
Languages C# General
Licence CPOLFirst Posted 24 Jun 2007
Views 271,435Downloads 10,356
Bookmarked 236 times
Image Recognition with Neural NetworksBy Murat Firat | 30 Oct 2007.NET2.0VS2005C#2.0WindowsDevAdvanced
This article contains a brief description of BackPropagation Artificial Neural Network and its
implementation for Image Recognition
See Also
More like this
More by this author
Article Browse Code Stats Revisions
4.80 (63 votes)
Is your email address OK? You are signed up for our newsletters but your email
address is either unconfirmed, or has not been reconfirmed in a long time. Please
click here to have a confirmation email sent so we can confirm your email address and startsending you newsletters again. Alternatively, you can update your subscriptions.
Download source -286.16 KB
Download demo project -257.52 KB
http://lakequincy.com/http://www.codeproject.com/info/about.aspxhttp://www.codeproject.com/Lounge.aspxhttp://www.codeproject.com/insider.aspxhttp://www.codeproject.com/Lounge.aspxhttp://www.codeproject.com/feature/CleverCode.aspxhttp://www.codeproject.com/Feature/HallOfShame.aspxhttp://www.codeproject.com/Forums/1536756/The-Soapbox.aspxhttp://www.codeproject.com/Chapters/5/Languages.aspxhttp://www.codeproject.com/KB/cs/http://www.codeproject.com/KB/cs/http://www.codeproject.com/KB/cs/#Generalhttp://www.codeproject.com/KB/cs/#Generalhttp://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=3413994http://www.codeproject.com/search.aspx?aidlst=12http://www.codeproject.com/search.aspx?aidlst=39http://www.codeproject.com/search.aspx?aidlst=39http://www.codeproject.com/search.aspx?aidlst=65http://www.codeproject.com/search.aspx?aidlst=65http://www.codeproject.com/search.aspx?aidlst=94http://www.codeproject.com/search.aspx?aidlst=94http://www.codeproject.com/search.aspx?aidlst=118http://www.codeproject.com/search.aspx?aidlst=118http://www.codeproject.com/search.aspx?aidlst=154http://www.codeproject.com/search.aspx?aidlst=154http://www.codeproject.com/search.aspx?q=Image+Recognition+with+Neural+Networkshttp://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=3413994http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=19323http://www.codeproject.com/script/Articles/Statistics.aspx?aid=19323http://www.codeproject.com/script/Articles/ListVersions.aspx?aid=19323http://www.codeproject.com/script/Membership/SendConfirmRequest.aspx?rp=%2FArticles%2F19323%2FImage-Recognition-with-Neural-Networks%2Fhttp://www.codeproject.com/script/Membership/Subscribe.aspx?rp=%2FArticles%2F19323%2FImage-Recognition-with-Neural-Networks%2Fhttp://www.codeproject.com/KB/cs/BackPropagationNeuralNet/BPSimplified_src.ziphttp://www.codeproject.com/KB/cs/BackPropagationNeuralNet/BPSimplified_demo.ziphttp://www.codeproject.com/script/Content/SiteMap.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks?display=Printhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks#_commentshttp://www.codeproject.com/script/Bookmarks/Add.aspx?obid=19323&obtid=2&action=AddBookmark&bio=truehttp://lakequincy.com/http://www.codeproject.com/info/about.aspxhttp://www.codeproject.com/Lounge.aspxhttp://www.codeproject.com/insider.aspxhttp://www.codeproject.com/Lounge.aspxhttp://www.codeproject.com/feature/CleverCode.aspxhttp://www.codeproject.com/Feature/HallOfShame.aspxhttp://www.codeproject.com/Forums/1536756/The-Soapbox.aspxhttp://www.codeproject.com/Chapters/5/Languages.aspxhttp://www.codeproject.com/KB/cs/http://www.codeproject.com/KB/cs/#Generalhttp://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=3413994http://www.codeproject.com/search.aspx?aidlst=12http://www.codeproject.com/search.aspx?aidlst=39http://www.codeproject.com/search.aspx?aidlst=65http://www.codeproject.com/search.aspx?aidlst=94http://www.codeproject.com/search.aspx?aidlst=118http://www.codeproject.com/search.aspx?aidlst=154http://www.codeproject.com/search.aspx?q=Image+Recognition+with+Neural+Networkshttp://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=3413994http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=19323http://www.codeproject.com/script/Articles/Statistics.aspx?aid=19323http://www.codeproject.com/script/Articles/ListVersions.aspx?aid=19323http://www.codeproject.com/script/Membership/SendConfirmRequest.aspx?rp=%2FArticles%2F19323%2FImage-Recognition-with-Neural-Networks%2Fhttp://www.codeproject.com/script/Membership/Subscribe.aspx?rp=%2FArticles%2F19323%2FImage-Recognition-with-Neural-Networks%2Fhttp://www.codeproject.com/KB/cs/BackPropagationNeuralNet/BPSimplified_src.ziphttp://www.codeproject.com/KB/cs/BackPropagationNeuralNet/BPSimplified_demo.zip -
8/3/2019 Nural in Matlab
4/12
Introduction
Artificial Neural Networks are a recent development tool that are modeled from biological
neural networks. The powerful side of this new tool is its ability to solve problems that arevery hard to be solved by traditional computing methods (e.g. by algorithms). This work
briefly explains Artificial Neural Networks and their applications, describing how toimplement a simple ANN for image recognition.
Background
I will try to make the idea clear to the reader who is just interested in the topic.
About Artificial Neural Networks (ANNs)
Artificial Neural Networks (ANNs) are a new approach that follow a different way fromtraditional computing methods to solve problems. Since conventional computers usealgorithmic approach, if the specific steps that the computer needs to follow are not known,
the computer cannot solve the problem. That means, traditional computing methods canonly solve the problems that we have already understood and knew how to solve. However,
ANNs are, in some way, much more powerful because they can solve problems that we donot exactly know how to solve. That's why, of late, their usage is spreading over a wide
range of area including, virus detection, robot control, intrusion detection systems, pattern(image, fingerprint, noise..) recognition and so on.
-
8/3/2019 Nural in Matlab
5/12
ANNs have the ability to adapt, learn, generalize, cluster or organize data. There are manystructures of ANNs including, Percepton, Adaline, Madaline, Kohonen, BackPropagation and
many others. Probably, BackPropagation ANN is the most commonly used, as it is verysimple to implement and effective. In this work, we will deal with BackPropagation ANNs.
BackPropagation ANNs contain one or more layers each of which are linked to the next
layer. The first layer is called the "input layer" which meets the initial input (e.g. pixels froma letter) and so does the last one "output layer" which usually holds the input's identifier(e.g. name of the input letter). The layers between input and output layers are called
"hidden layer(s)" which only propagate the previous layer's outputs to the next layer and[back] propagates the following layer's error to the previous layer. Actually, these are the
main operations of training a BackPropagation ANN which follows a few steps.
A typical BackPropagation ANN is as depicted below. The black nodes (on the extreme left)
are the initial inputs. Training such a network involves two phases. In the first phase, theinputs are propagated forward to compute the outputs for each output node. Then, each of
these outputs are subtracted from its desired output, causing an error [an error for eachoutput node]. In the second phase, each of these output errors is passed backward and the
weights are fixed. These two phases is continued until the sum of [square of output errors]reaches an acceptable value.
Implementation
The network layers in the figure above are implemented as arrays of structs. The nodes ofthe layers are implemented as follows:
Collapse | Copy Code
[Serializable]
struct PreInput
{
publicdouble Value;
http://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks -
8/3/2019 Nural in Matlab
6/12
publicdouble[] Weights;
};
[Serializable]
struct Input
{
publicdouble InputSum;
publicdouble Output;publicdouble Error;
publicdouble[] Weights;
};
[Serializable]
struct Hidden
{
publicdouble InputSum;
publicdouble Output;
publicdouble Error;
publicdouble[] Weights;
};
[Serializable]
struct Output where T : IComparable{
publicdouble InputSum;
publicdouble output;
publicdouble Error;
publicdouble Target;
public T Value;
};
The layers in the figure are implemented as follows (for a three layer network):
Collapse | Copy Code
private PreInput[] PreInputLayer;
private Input[] InputLayer;private Hidden[] HiddenLayer;
private Output[] OutputLayer;
Training the network can be summarized as follows:
Apply input to the network.
Calculate the output.
Compare the resulting output with the desired output for the given input. This iscalled the error.
Modify the weights for all neurons using the error.
Repeat the process until the error reaches an acceptable value (e.g. error < 1%),
which means that the NN was trained successfully, or if we reach a maximum countof iterations, which means that the NN training was not successful.
It is represented as shown below:
Collapse | Copy Code
void TrainNetwork(TrainingSet,MaxError)
{
http://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks -
8/3/2019 Nural in Matlab
7/12
while(CurrentError>MaxError)
{
foreach(Pattern in TrainingSet)
{
ForwardPropagate(Pattern);//calculate output
BackPropagate()//fix errors, update weights
}
}}
This is implemented as follows:
Collapse | Copy Code
publicbool Train()
{
double currentError = 0;
int currentIteration = 0;
NeuralEventArgs Args = new NeuralEventArgs() ;
do
{currentError = 0;
foreach (KeyValuePair p in TrainingSet)
{
NeuralNet.ForwardPropagate(p.Value, p.Key);
NeuralNet.BackPropagate();
currentError += NeuralNet.GetError();
}
currentIteration++;
if (IterationChanged != null && currentIteration % 5 == 0)
{
Args.CurrentError = currentError;
Args.CurrentIteration = currentIteration;
IterationChanged(this, Args);}
} while (currentError > maximumError && currentIteration = maximumIteration || Args.Stop)
returnfalse;//Training Not Successful
returntrue;
}
Where ForwardPropagate(..) and BackPropagate() methods are as shown for a three
layer network:
Collapse | Copy Code
http://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks -
8/3/2019 Nural in Matlab
8/12
privatevoid ForwardPropagate(double[] pattern, T output)
{
int i, j;
double total;
//Apply input to the network
for (i = 0; i < PreInputNum; i++)
{
PreInputLayer[i].Value = pattern[i];}
//Calculate The First(Input) Layer's Inputs and Outputs
for (i = 0; i < InputNum; i++)
{
total = 0.0;
for (j = 0; j < PreInputNum; j++)
{
total += PreInputLayer[j].Value * PreInputLayer[j].Weights[i];
}
InputLayer[i].InputSum = total;
InputLayer[i].Output = F(total);
}
//Calculate The Second(Hidden) Layer's Inputs and Outputs
for (i = 0; i < HiddenNum; i++)
{total = 0.0;
for (j = 0; j < InputNum; j++)
{
total += InputLayer[j].Output * InputLayer[j].Weights[i];
}
HiddenLayer[i].InputSum = total;
HiddenLayer[i].Output = F(total);
}
//Calculate The Third(Output) Layer's Inputs, Outputs, Targets and Errors
for (i = 0; i < OutputNum; i++)
{
total = 0.0;
for (j = 0; j < HiddenNum; j++)
{total += HiddenLayer[j].Output * HiddenLayer[j].Weights[i];
}
OutputLayer[i].InputSum = total;
OutputLayer[i].output = F(total);
OutputLayer[i].Target = OutputLayer[i].Value.CompareTo(output) == 0 ? 1.0 :
0.0;
OutputLayer[i].Error = (OutputLayer[i].Target - OutputLayer[i].output) *
(OutputLayer[i].output) * (1 -
OutputLayer[i].output);
}
}
privatevoid BackPropagate()
{ int i, j;
double total;
//Fix Hidden Layer's Error
for (i = 0; i < HiddenNum; i++)
{
total = 0.0;
for (j = 0; j < OutputNum; j++)
{
total += HiddenLayer[i].Weights[j] * OutputLayer[j].Error;
-
8/3/2019 Nural in Matlab
9/12
}
HiddenLayer[i].Error = total;
}
//Fix Input Layer's Error
for (i = 0; i < InputNum; i++)
{
total = 0.0;
for (j = 0; j < HiddenNum; j++){
total += InputLayer[i].Weights[j] * HiddenLayer[j].Error;
}
InputLayer[i].Error = total;
}
//Update The First Layer's Weights
for (i = 0; i < InputNum; i++)
{
for(j = 0; j < PreInputNum; j++)
{
PreInputLayer[j].Weights[i] +=
LearningRate * InputLayer[i].Error * PreInputLayer[j].Value;
}
}
//Update The Second Layer's Weights for (i = 0; i < HiddenNum; i++)
{
for (j = 0; j < InputNum; j++)
{
InputLayer[j].Weights[i] +=
LearningRate * HiddenLayer[i].Error * InputLayer[j].Output;
}
}
//Update The Third Layer's Weights
for (i = 0; i < OutputNum; i++)
{
for (j = 0; j < HiddenNum; j++)
{
HiddenLayer[j].Weights[i] +=
LearningRate * OutputLayer[i].Error * HiddenLayer[j].Output;}
}
}
Testing the App
The program trains the network using bitmap images that are located in a folder. This foldermust be in the following format:
There must be one (input) folder that contains input images [*.bmp].
Each image's name is the target (or output) value for the network (the pixel values
of the image are the inputs, of course) .
As testing the classes requires to train the network first, there must be a folder in this
format. "PATTERNS" and "ICONS" folders [depicted below] in the Debug folder fit thisformat.
-
8/3/2019 Nural in Matlab
10/12
History
30th September, 2007: Simplified the app
24th June, 2007: Initial Release
References & External Links
Principles of training multi-layer neural network using backpropagation algorithm
Neural Networks by Christos Stergiou and Dimitrios Siganos An Introduction to Neural Networks, Ben Krose & Patrick van der Smagt
License
This article, along with any associated source code and files, is licensed under The Code
Project Open License (CPOL)
About the Author
Murat Firat
Software Developer(Senior)
Turkey
Member
Has BS degree on CS, working as SW engineer at istanbul.
Article Top
http://galaxy.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.htmlhttp://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol4/cs11/report.htmlhttp://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/Members/Murat-Firathttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks#_articleTophttp://galaxy.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.htmlhttp://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol4/cs11/report.htmlhttp://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/info/cpol10.aspxhttp://www.codeproject.com/Members/Murat-Firathttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks#_articleTop -
8/3/2019 Nural in Matlab
11/12
Rate this: Poor Excellent Vote
Comments and Discussions
New Message
Searchthisforum
Go
Profile popups Noise Layout Per page
Refresh
My vote of 5 praneshkmr
Please help ! hovu
Entering and outputting more than one character ibnkhaldun
input value not the same as output value Member 3913283
My vote of 3 HansiHermann
flow chart baguswahyu
Logic behind the programm Member 8203782
little confused about PreInput and Input swarajs
Great Work:-) chikkisherry
Increase probability RonZohan
Last Visit: 20:28 15 Feb '12 Last Update: 20:27 15 Feb '12 12
General News Suggestion Question Bug Answer Joke
Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads,
Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise |Privacy|MobileWeb02 | 2.5.120215.1 | Last Updated 30 Oct 2007Article Copyright 2007 by Murat Firat
Everything else Copyright CodeProject, 1999-2012Terms of UseLayout:fixed|fluid
Related ArticlesCreating animations with Dundas Chart for ASP.NET
Smarter Data Labels with Dundas Chart SmartLabels
Understanding Chart Areas with Dundas Chart for .NET
http://www.codeproject.com/script/Forums/Edit.aspx?fid=431623&floc=/Articles/19323/Image-Recognition-with-Neural-Networks/http://www.codeproject.com/KB/FAQs/MessageBoardsFAQ.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?fid=431623http://www.codeproject.com/Messages/4137843/My-vote-of-5.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=8129252http://www.codeproject.com/Messages/4134414/Please-help.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=1490236http://www.codeproject.com/Messages/4117073/Entering-and-outputting-more-than-one-character.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=8374045http://www.codeproject.com/Messages/4094332/input-value-not-the-same-as-output-value.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=3913283http://www.codeproject.com/Messages/4064498/My-vote-of-3.aspxhttp://www.codeproject.com/Messages/4064498/My-vote-of-3.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=4927214http://www.codeproject.com/Messages/4063454/flow-chart.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/script/Membership/View.aspx?mid=7820709http://www.codeproject.com/Messages/4022967/Logic-behind-the-programm.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/script/Membership/View.aspx?mid=8203782http://www.codeproject.com/Messages/3984832/little-confused-about-PreInput-and-Input.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=6575997http://www.codeproject.com/Messages/3965585/Great-Work.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=6191021http://www.codeproject.com/Messages/3964607/Increase-probability.aspxhttp://www.codeproject.com/Messages/3964607/Increase-probability.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=7336535http://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?fid=431623&fr=11#xx0xxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://lakequincy.com/http://lakequincy.com/http://www.codeproject.com/info/privacy.aspxhttp://www.codeproject.com/info/privacy.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?display=Mobilehttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?display=Mobilemailto:[email protected]:[email protected]://www.codeproject.com/info/TermsOfUse.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?PageFlow=FixedWidthhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?PageFlow=FixedWidthhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?PageFlow=FixedWidthhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?PageFlow=Fluidhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?PageFlow=Fluidhttp://www.codeproject.com/KB/showcase/dundas_chartani.aspxhttp://www.codeproject.com/KB/showcase/dundas_smartlabels.aspxhttp://www.codeproject.com/KB/showcase/Dundas_chartareas.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://www.codeproject.com/KB/FAQs/MessageBoardsFAQ.aspxhttp://www.codeproject.com/script/Forums/Edit.aspx?fid=431623&floc=/Articles/19323/Image-Recognition-with-Neural-Networks/http://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?fid=431623http://www.codeproject.com/Messages/4137843/My-vote-of-5.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=8129252http://www.codeproject.com/Messages/4134414/Please-help.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=1490236http://www.codeproject.com/Messages/4117073/Entering-and-outputting-more-than-one-character.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=8374045http://www.codeproject.com/Messages/4094332/input-value-not-the-same-as-output-value.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=3913283http://www.codeproject.com/Messages/4064498/My-vote-of-3.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=4927214http://www.codeproject.com/Messages/4063454/flow-chart.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=7820709http://www.codeproject.com/Messages/4022967/Logic-behind-the-programm.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=8203782http://www.codeproject.com/Messages/3984832/little-confused-about-PreInput-and-Input.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=6575997http://www.codeproject.com/Messages/3965585/Great-Work.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=6191021http://www.codeproject.com/Messages/3964607/Increase-probability.aspxhttp://www.codeproject.com/script/Membership/View.aspx?mid=7336535http://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?fid=431623&fr=11#xx0xxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networkshttp://lakequincy.com/http://www.codeproject.com/info/privacy.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?display=Mobilemailto:[email protected]://www.codeproject.com/info/TermsOfUse.aspxhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?PageFlow=FixedWidthhttp://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks/?PageFlow=Fluidhttp://www.codeproject.com/KB/showcase/dundas_chartani.aspxhttp://www.codeproject.com/KB/showcase/dundas_smartlabels.aspxhttp://www.codeproject.com/KB/showcase/Dundas_chartareas.aspx -
8/3/2019 Nural in Matlab
12/12
Making Sense of Geographic Data with Dundas Map and AJAX
DestroyWindow in VBScript
SmartLink
Create data-driven applications with the Hera Application Framework
Towards the self-documenting database: extended properties
Digital Signatures and PDF Documents
WMP Power Hour APP
Using Barcodes in Documents Best Practices
How to Retrieve EMC Centera Cluster/Pool Capabilities
Using multiple keyboards with different layouts on the same machine
"Hey! Is That My Car? How to Sharpen a QuickBird Satellite Image Using DotImage"
Integrate your SharePoint environment into the open standards-based WebSphere Portal platform using the VisualStudio IDE
VBScript / Excel 2007 - An easy way to access DBF files
Retrieving and Storing Call History
Knit - A Visual Studio Add-In
Drivers, Exceptions and C++
gzTx - A File Transfer DaemonAutomating Multipart Zip File Creation
The Daily Insider30 free programming books
Daily News: Signup now.
http://www.codeproject.com/KB/showcase/DundasMap_AJAX.aspxhttp://www.codeproject.com/KB/vbscript/gopal_code.aspxhttp://www.codeproject.com/KB/vb/SmarLink.aspxhttp://www.codeproject.com/KB/showcase/HeraAppFramework.aspxhttp://www.codeproject.com/KB/showcase/RedGate_SelfDocDatabase.aspxhttp://www.codeproject.com/KB/showcase/digitalsignatures.aspxhttp://www.codeproject.com/KB/vb/Windows_Media_Player_COM.aspxhttp://www.codeproject.com/KB/showcase/barcodes_in_docs.aspxhttp://www.codeproject.com/KB/winsdk/HowToRetrieve.aspxhttp://www.codeproject.com/KB/winsdk/RightKeyboard.aspxhttp://www.codeproject.com/KB/showcase/dotimage_toolkit.aspxhttp://www.codeproject.com/KB/showcase/sharpoint_federator.aspxhttp://www.codeproject.com/KB/showcase/sharpoint_federator.aspxhttp://www.codeproject.com/KB/office/Excel-2007-dbf-files.aspxhttp://www.codeproject.com/KB/windows/wm_callhistory.aspxhttp://www.codeproject.com/KB/macros/KnitAddIn.aspxhttp://www.codeproject.com/KB/system/excpt.aspxhttp://www.codeproject.com/KB/IP/gzTx.aspxhttp://www.codeproject.com/KB/files/ZipMaker1.aspxhttp://citizen428.net/archives/434http://www.codeproject.com/Feature/Insider/http://www.codeproject.com/KB/showcase/DundasMap_AJAX.aspxhttp://www.codeproject.com/KB/vbscript/gopal_code.aspxhttp://www.codeproject.com/KB/vb/SmarLink.aspxhttp://www.codeproject.com/KB/showcase/HeraAppFramework.aspxhttp://www.codeproject.com/KB/showcase/RedGate_SelfDocDatabase.aspxhttp://www.codeproject.com/KB/showcase/digitalsignatures.aspxhttp://www.codeproject.com/KB/vb/Windows_Media_Player_COM.aspxhttp://www.codeproject.com/KB/showcase/barcodes_in_docs.aspxhttp://www.codeproject.com/KB/winsdk/HowToRetrieve.aspxhttp://www.codeproject.com/KB/winsdk/RightKeyboard.aspxhttp://www.codeproject.com/KB/showcase/dotimage_toolkit.aspxhttp://www.codeproject.com/KB/showcase/sharpoint_federator.aspxhttp://www.codeproject.com/KB/showcase/sharpoint_federator.aspxhttp://www.codeproject.com/KB/office/Excel-2007-dbf-files.aspxhttp://www.codeproject.com/KB/windows/wm_callhistory.aspxhttp://www.codeproject.com/KB/macros/KnitAddIn.aspxhttp://www.codeproject.com/KB/system/excpt.aspxhttp://www.codeproject.com/KB/IP/gzTx.aspxhttp://www.codeproject.com/KB/files/ZipMaker1.aspxhttp://citizen428.net/archives/434http://www.codeproject.com/Feature/Insider/