srnet.sf.ehcache.ElementlyP{VJ creationTimeJhitCountJlastAccessTimeJnextToLastAccessTimeJversionLkeytLjava/lang/Object;Lvalueq~xpUsr*org.apache.cocoon.caching.PipelineCacheKey;KJћIhashCodeLkeystLjava/util/List;LtoStringtLjava/lang/String;xpBsrjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xpBtresourcetUfile:/usr/local/forrest/main/webapp/skins/common/images/built-with-forrest-button.pngpxpsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xpԀt image/pngpur[BTxpPNG  IHDRXT tEXtTitleBuilt with Apache Forrest!3 tEXtAuthorstevenn@apache.org˜](tEXtCopyrightThe Apache Software FoundationFtEXtCreation Time11/05/02}TtIME  F*+ pHYs B4gAMA aPLTE))5Oi1+ bEUTbqM&`k !.Ifeõ! 4ff3IhDA333 p}wI Sfx(?]XA\g]gq'SHG e%2RB;@ PXb 6\MYs?8d9:q+DZq LdFO6W`k-;Tְ?M2tq?̻#fW+Zӡs`2!B2B;A>&1Qa8,ZLT]GA-(bC8 kkt`hF2:0@Y$*LQtp%& 0 o&-:{}6l%L0/G)*J `je>#6)EcRWf, () l':Z/p//yTF75f=MVa.%XLPDuJ'79DKlIDATxڵ։[F4AmS⢫Ю8F} ^Je-[mE/D7W]p=yߗyonp}=TU.1 ,9ܐF-7d,>x MGBҍR>q{%r$"Pຟc`YsaabdI7byC`QH>cBw\6j/7'7ܾ[x >Ray,bb_9,$KRi4 G 0\LܨBΜ⡷n۽,RsWó{Gx2|Xq 0`D0U#6Q&gI=upE w|5L{F^XlIJ=nCa ׁq~x8>;f}KUCshS!7lwY\^ܚk?ι8_y<702Wֹ8?ksebZs}DKwY=6?mh^ IENDB`ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xp=sr java.io.File-E Lpathq~xptP/usr/local/forrest/main/webapp/skins/common/images/built-with-forrest-button.pngw/xsrnet.sf.ehcache.ElementlyP{VJ creationTimeJhitCountJlastAccessTimeJnextToLastAccessTimeJversionLkeytLjava/lang/Object;Lvalueq~xpsr*org.apache.cocoon.caching.PipelineCacheKey;KJћIhashCodeLkeystLjava/util/List;LtoStringtLjava/lang/String;xp lsrjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xptfiletZfile:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/neuralNetworks.xmltaG-file-file:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/neuralNetworks.xmlsq~ `GtxslttNfile:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xsltUT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xslxtPK_G-file-file:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/neuralNetworks.xml_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xslsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xppppur[BTxp0CXML  Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. document header title:OCR example using Backpropagation networks in ruby :: ai4r  body idCDATAnn-Introductionsection Introduction to Neural Networks p  The utility of artificial neural network models lies in the fact that they can be used to infer a function from observations. This is particularly useful in applications where the complexity of the data or task makes the design of such a function by hand impractical. Neural Networks are being used in many businesses and applications. Their ability to learn by example makes them attractive in environments where the business rules are either not well defined or are hard to enumerate and define. Many people believe that Neural Networks can only solve toy problems. Give them a try, and let you decide if they are good enough to solve your needs.     In this module you will find an implementation of neural networks using the Backpropagation is a supervised learning technique  (described by Paul Werbos in 1974, and further developed by David E. Rumelhart, Geoffrey E. Hinton and Ronald J. Williams in 1986)     nn-example 7Modeling the OCR problem using Neural Networks networks  c Let's imagine that we have to implement a program to identify simple patterns (triangles, squares, crosses, etc). The main problem is that this program must be resistant to random noise in the image (pixels with wrong values) and line noise (similar to the unwanted direct current that we usually have in a signal).    * In order to solve this problem, we can take an example of each pattern to be recognized, and train a neural network to identify similar patterns. In fact, one of the most popular uses of neural networks in business applications is OCR (opticar character recognition)     In our porposed solotion, we create a network with the following architecture: 256 input neurons and 3 output neurons. We feed this network with 16x16 matrices (in fact will convert them to vectors of length 256). Each pixel is represented with a number from 0 (white pixel) to 10 (black pixel). The output of this network if a 3 vector of dimension 3, where ideally:   ul  li (1, 0, 0) for triangles   (0, 1, 0) for squares   (0, 0, 1) for crosses     IWe train our backpropagation neural network using the following examples:  table  captionTraining patterns tr colspan1rowspantdaltTriangule training examplesrc /images/t.pngimg Square training example /images/s.png Cross training example /images/c.png      nn2-example 8Implementing a basic OCR application using ruby and AI4R  ZThe code bellow shows the basic steps to use Backpropagation Neural Networks in AI4R:  $http://www.w3.org/XML/1998/namespacespace xml:spacepreservesource"T # Create the network with: # 4 inputs # 1 hidden layer with 3 neurons # 2 outputs net = Ai4r::NeuralNetwork::Backpropagation.new([4, 3, 2]) # Train the network 100.times do |i| net.train(example[i], result[i]) end # Use it: Evaluate data with the trained network net.eval([12, 48, 12, 25]) # => [0.89, 0.04] ""  {This is the source code used to elaborate this simple OCR application (You can find it inside the AI4R zip file release):   !""z require "rubygems" require "ai4r" require File.dirname(__FILE__) + '/training_patterns' require File.dirname(__FILE__) + '/patterns_with_noise' require File.dirname(__FILE__) + '/patterns_with_base_noise' # Create a network with 256 inputs, and 3 outputs net = Ai4r::NeuralNetwork::Backpropagation.new([256, 3]) # Load training data tr_input = TRIANGLE.flatten.collect { |input| input.to_f / 10} sq_input = SQUARE.flatten.collect { |input| input.to_f / 10} cr_input = CROSS.flatten.collect { |input| input.to_f / 10} # Train the network puts "Training the network, please wait." 100.times do net.train(tr_input, [1,0,0]) net.train(sq_input, [0,1,0]) net.train(cr_input, [0,0,1]) end # Load test data with noise tr_with_noise = TRIANGLE_WITH_NOISE.flatten.collect { |input| input.to_f / 10} sq_with_noise = SQUARE_WITH_NOISE.flatten.collect { |input| input.to_f / 10} cr_with_noise = CROSS_WITH_NOISE.flatten.collect { |input| input.to_f / 10} tr_with_base_noise = TRIANGLE_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10} sq_with_base_noise = SQUARE_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10} cr_with_base_noise = CROSS_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10} # Print the evaluation results def result_label(result) if result[0] > result[1] && result[0] > result[2] "TRIANGLE" elsif result[1] > result[2] "SQUARE" else "CROSS" end end puts "Training Examples" puts "#{net.eval(tr_input).inspect} => #{result_label(net.eval(tr_input))}" puts "#{net.eval(sq_input).inspect} => #{result_label(net.eval(sq_input))}" puts "#{net.eval(cr_input).inspect} => #{result_label(net.eval(cr_input))}" puts "Examples with noise" puts "#{net.eval(tr_with_noise).inspect} => #{result_label(net.eval(tr_with_noise))}" puts "#{net.eval(sq_with_noise).inspect} => #{result_label(net.eval(sq_with_noise))}" puts "#{net.eval(cr_with_noise).inspect} =m> #{result_label(net.eval(cr_with_noise))}" puts "Examples with base noise" puts "#{net.eval(tr_with_base_noise).inspect} => #{result_label(net.eval(tr_with_base_noise))}" puts "#{net.eval(sq_with_base_noise).inspect} => #{result_label(net.eval(sq_with_base_noise))}" puts "#{net.eval(cr_with_base_noise).inspect} => #{result_label(net.eval(cr_with_base_noise))}" ""   nn3-example ,Results obtained with the AI4R OCR algorithm  T The results we got when we evaluate patterns with our trained network are:      AEvaluating the training patterns with the trained network: ol$   % [0.98, 0.03, 0.01] => TRIANGLE     # [0.00, 0.96, 0.03] => SQUARE     " [0.00, 0.00, 0.99] => CROSS   $$    JEvaluating the patterns with random noise with the trained network: $$   #Triangule pattern with random noise/images/t_wn.png [0.98, 0.01, 0.01] => TRIANGLE      Square pattern with random noise/images/s_wn.png [0.00, 0.96, 0.02] => SQUARE     Cross pattern with random noise/images/c_wn.png [0.00, 0.00, 0.98] => CROSS   $$    CEvaluating the patterns with line noise with the trained network:  $$   !Triangule pattern with line noise/images/t_wbn.png [0.62, 0.00, 0.02] => TRIANGLE     Square pattern with line noise/images/s_wbn.png [0.00, 0.75, 0.01] => SQUARE     Cross pattern with line noise/images/c_wbn.png [0.00, 0.00, 0.98] => CROSS   $$      ~These results are satisfactory. The network could sucessfully identify the patterns despite the noise introduced to them.    nn-custom 'Customizing your neural network in ai4r  ~Sometime for a given problem, you will have to "play around" with some parameters to get to a solution. This parameters are:    strong2 Learning Rate228: a real number, usually between 0.05 and 0.25.     22Momentum22l: A momentum will avoid oscillations during learning, converging to a solution in less iterations.    22Propagation function22C: By default, f(x) = 1/(1 + e^(-x)). This function is called href3-http://en.wikipedia.org/wiki/Sigmoid_function%wikipedia article on Sigmoid functionlink6 Sigmoid function 665. You can see it like a "smoothed" version of the 334http://en.wikipedia.org/wiki/Heaviside_step_function)Heaviside step function wikipedia article66 Heaviside step function 665. It will always provide a value between 0 and 1.    images/sigmoid.pngSigmoid function   t Sometimes you will have better results with f(x) = tanh(x), or even with f(x) = x. If you modify the propagatqion function, you have to supply the derivative function too (in terms of the propagation function result).    RTo customize these parameters in AI4R, you can user the "set_parameters" method:   !"" net.set_parameters( :momentum => 0.15, :learning_rate => 0.5, :propagation_function => lambda { |x| Math.tanh(x) }, :derivative_propagation_function => lambda { |y| 1.0 - y**2 } ) ""  (You can also use the attribute accesors:   !"" net.momentum = 0.15 net.learning_rate = 0.5 net.propagation_function = lambda { |x| Math.tanh(x) } net.derivative_propagation_function = lambda { |y| 1.0 - y**2 } ""  note;ARemember to set the custom parameters BEFORE training the network;; nn-more .More about Neural Networks and Backpropagation     336http://en.wikipedia.org/wiki/Artificial_neural_network66/Wikipedia article on Artificial Neural Networks66     33,http://en.wikipedia.org/wiki/Backpropagation66.Wikipedia article on Backpropagation Algorithm66     33>http://www.tek271.com/articles/neuralNet/IntoToNeuralNets.html660Neural Networks - An Introduction by Abdul Habra66     33:http://galaxy.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html66iA graphical explanation of the backpropagation algorithm by Mariusz Bernacki and Przemysław Włodarczyk66       ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xp߈sr java.io.File-E Lpathq~xptU/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/neuralNetworks.xmlw/xsrgq~tXfile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslt_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslsq~ #q~tLfile:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsltST-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xslsq~ 3:q~tqfile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=geneticAlgorithms.htmltxT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=geneticAlgorithms.htmlsq~ 81q~tlfile:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=geneticAlgorithms.htmltsT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=geneticAlgorithms.htmlxtEPK_G-file-cocoon://site.navigation.links.xml?pipelinehash=786357640368091306_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/absolutize-linkmap.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=geneticAlgorithms.html_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=geneticAlgorithms.htmlsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xp̰ppur[BTxp tCXML  Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.  Forrest site.xml This file contains an outline of the site's information content. It is used to: - Generate the website menus (though these can be overridden - see docs) - Provide semantic, location-independent aliases for internal 'site:' URIs, eg links to changes.html (or ../changes.html if in subdir). - Provide aliases for external URLs in the external-refs section. Eg, links to http://cocoon.apache.org/ See http://forrest.apache.org/docs/linking.html for more info  The label attribute of the outer "site" element will only show in the linkmap (linkmap.html). Use elements project-name and group-name in skinconfig to change name of your site or project that is usually shown at the top of page. No matter what you configure for the href attribute, Forrest will always use index.html when you request http://yourHost/ See FAQ: "How can I use a start-up-page other than index.html?" site tabCDATAlabelHomeabout Indexhref index.html description 'ai4r - Artificial Intelligence for Rubyindex   Practical ExamplespracticalExamples Genetic AlgorithmsgeneticAlgorithms.html Genetic Algorithms in rubygeneticAlgorithms Machine LearningmachineLearning.html ID3 Decision Trees in rubymachineLearning Neural NetworksneuralNetworks.html &Backpropagation Neural Network in rubyneuralNetworks   Downloadsdownloads.html ai4r - Download Filesdownload Forum-http://forum.jadeferret.com/viewforum.php?f=3  Ai4r Forumforum""" Source Code repositorysvn.html ai4r Subversion repositorysvn&&&  AI4R Wiki(http://wiki.jadeferret.com/Category:AI4R 3ai4r wiki with How-to guides and more documentationwiki*** API doc (Rdoc))http://ai4r.rubyforge.org/rdoc/index.html  Ai4 RDoc docsrdoc...  ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsrLorg.apache.cocoon.components.source.impl.SitemapSource$SitemapSourceValidity+{yyLvalidityt,Lorg/apache/excalibur/source/SourceValidity;xpsr'KTKCWMR{_ tlowS@\cbfGbÓ/6 P|8"9 BH*]d+ʈڠ MZ'ge5'U#yO15mYyi>99ulVζpH^U#|sYn+3ֿyl;'?/q`"D5 {[W>VDk4Y-v0dHl_\/lWUbdwzRG==o>qOJg;>ߒs%&8M/>zxHꌄcY_zAXNXng7յSe'%QeOkr bl7VV8I&ּwu/xzR+ ¯:cgsvK5VGnulu᧊y$s,w|Hzѓ?u7>9Sxog1Ͻ}-/2_|u9o*-hn6|ͣZ-oa؝?Ƌ&)i߬dPx<j@5{ll!i8zs#!aKl q&*>+IdHZE $IH*RiBDG%QH*T-TU^V"ȩKa%CKեrYjv]QSUox>isih?kktIRP{3 tttc|1`Wzzuٳ_I`4 7hAӁkpNEۍL4Mz,9l|e , V6営vKV0W90V1VZt2Ykl.m{Xxyux|+|8~fNE̠alЖ+)mUQ;bŕ&rZ}ão6f̘sY;wꊊ !C?~|ɒ%_… ]dddEEO?q\SSԩSz=a7O(11Quɸ?%0,",Dt˗//^8--/ D=vWbcchC hMMMDdXlrrT*Zeeelj%K.iTΛ[4t|||86ˆشXd⫽tbtttƪj6(&)'''A@`\VVkrvl0w ,Fÿ9` qSX,|r9;%ͻ˸Λw| =p56T*5FQ(S9<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validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xpAsr java.io.File-E Lpathq~xptQ/home/sfierens/workspace/ai4r/site/src/documentation/resources/images/fitness.pngw/xsrnet.sf.ehcache.ElementlyP{VJ creationTimeJhitCountJlastAccessTimeJnextToLastAccessTimeJversionLkeytLjava/lang/Object;Lvalueq~xpsr*org.apache.cocoon.caching.PipelineCacheKey;KJћIhashCodeLkeystLjava/util/List;LtoStringtLjava/lang/String;xp}]srjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xp!tfilet2cocoon://svn.xml?pipelinehash=-7004163430053168949psq~ tidgent-8355019975799787170psq~ iYstxincludetXIncludepxpsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xpppur[BTxp_CXMLdocument header titleASubversion repository for ai4r (Artificial Intelligence for Ruby)  body idCDATA Anonymoussection Anonymous Subversion Access p hThis project's SVN repository can be checked out through anonymous access with the following command(s).  ul  li 0svn checkout http://ai4r.rubyforge.org/svn/trunk   3svn checkout svn://rubyforge.org/var/svn/ai4r/trunk     Browse Browse latest files  ;You can see the latest ai4r code directly in your browser: href http://ai4r.rubyforge.org/svn/linkhttp://ai4r.rubyforge.org/svn/   warningThe latest code in http://ai4r.rubyforge.org/svn/trunk will probably be a work in progess. If you want something that works, please download the releases.   moreinfor More info on Subversion (svn)  YIf you need help about using Subversion (svn), the (IMO) best documentation is available  http://svnbook.red-bean.com/here.   !If you work in SCM, you may find  http://scm.jadeferret.comJade Ferret’s SCM initiative intresting.   softsizo_report Source code evolution   http://softsizo.jadeferret.com Soft Sizo is a report generation tool that extends the concept of Lines Of Code (LOC) metrics, using changes information stored in a Subversion repository.   You can access  7http://softsizo.jadeferret.com/examples/ai4r/index.htmlAI4R Soft Sizo report: for some AI4R source code evolution metrics.     ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsrLorg.apache.cocoon.components.source.impl.SitemapSource$SitemapSourceValidity+{yyLvalidityt,Lorg/apache/excalibur/source/SourceValidity;xpsr   t * Can contain a mount statement as a sibling to components and locator *  locator  * Can contain a mount within a selector where a selector is valid.  patternproject.rewrite.**match  !http://cocoon.apache.org/{1}.htmllocation  project.remote.**.xml  ehttp://svn.apache.org/repos/asf/forrest/trunk/main/fresh-site/src/documentation/content/xdocs/{1}.xml   * Can use a selector inside a match. *   To locate all your source documents in a slide repository you can do:    ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xpAsr java.io.File-E Lpathq~xptL/home/sfierens/workspace/ai4r/site/src/documentation/content/locationmap.xmlw/xsrnet.sf.ehcache.ElementlyP{VJ creationTimeJhitCountJlastAccessTimeJnextToLastAccessTimeJversionLkeytLjava/lang/Object;Lvalueq~xp'ޣYsr*org.apache.cocoon.caching.PipelineCacheKey;KJћIhashCodeLkeystLjava/util/List;LtoStringtLjava/lang/String;xpQ^srjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xp<>tfiletFfile:/home/sfierens/workspace/ai4r/site/src/documentation/skinconf.xmlpsq~ /!txslttKfile:/usr/local/forrest/main/webapp/resources/stylesheets/strip-doctype.xslpsq~ ~q~tNfile:/usr/local/forrest/main/webapp/resources/stylesheets/upgrade-skinconf.xslpsq~ 9q~t;file:/usr/local/forrest/main/webapp/skins/pelt/skinconf.xslpsq~ q~t=file:/usr/local/forrest/main/webapp/skins/common/skinconf.xslpxpsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xp0ppur[BTxpCXML skinconfig nameCDATA MyProjectdomainmydomainprovidergooglesearch   disable-print-link true  disable-pdf-link false  disable-pod-link true  disable-txt-link true  disable-xml-linktrue disable-external-link-imagefalse disable-compliance-linksfalse obfuscate-mail-linkstrue obfuscate-mail-value.at. disable-font-scripttrue  project-nameai4r project-description'AI4R - Artificial Intelligence for Ruby  project-urlhttp://ai4r.rubyforge.org/  project-logoimages/ai4r-logo.png  group-name Jade Ferret group-description Jade Ferret  group-urlhttp://www.jadeferret.com  group-logoimages/jadeferret.png host-url#http://rubyforge.org/projects/ai4r/  host-logoimages/rubyforge.png  favicon-url disable-copyright-footerfalse  inception trueyear"2007"" vendor#Sergio Fierens, Jade Ferret## copyright-link$http://www.jadeferret.com/$$ location%nonetrail' ai4rhref)http://ai4r.rubyforge.org/link1+++ ())*link2,,, ))link3--- ''  max-depth.2 min-sections01%%pagetoc333 type4boxedheadings666  extra-css7 p.quote { margin-left: 2em; padding: .5em; background-color: #f0f0f0; font-family: monospace; } #footer a { color: #0F3660; } #footer a:visited { color: #009999; } #top :searchbox { height: 34px; background-color: #DDDDDD; } 77 pdf8 size9letter orientation;portrait text-align=left2222 page-numbering-format?Page 1??  double-sided@falsemarginsB topC1inCC bottomD1inDD innerE1.25inEE outerF1inFF BB show-external-urlsGfalseGG false 88 creditsH  box-locationIaltcreditK Built with Apache Forrest urlLhttp://forrest.apache.org/LL imageM$images/built-with-forrest-button.pngMM widthN88NN heightO31OO KK HH colorsPheadervalueR#FFFFFFcolorTTT tab-selectedRR#a5b6c6linkW#000000vlinkYXhlinkZXTTTTtab-unselectedRR#F7F7F7WWXYYXZZXTTTTsubtab-selectedRRVWWXYYXZZXTTTTsubtab-unselectedRRVWWXYYXZZXTTTTheadingRRVTTTT subheadingRR#CFDCEDTTTTnavstripRRafontcXWWXYYXZZXTTTTtoolboxRRVTTTTborderRRVTTTTmenuRR\WWXYYXZZXTTTTdialogRR\TTTTbodyRR#ffffffWW#0F3660YY#009999ZZ#000066TTTTtableRRVTTTT table-cellRRiTTTT highlightRR#ffff00TTTTfixmeRR#cc6600TTTTnoteRR#006699TTTTwarningRR#990000TTTTcodeRRVTTTTfooterRRVTTTTalignycenterccSRR#4C6C8FfeedbackTTTTccSRR{ publishedTTTTccXRR#cfdced menuheadingTTTTccXRR#E5E4D9 searchboxTTTTPPur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xppsr java.io.File-E Lpathq~xptA/home/sfierens/workspace/ai4r/site/src/documentation/skinconf.xmlw/xsrgq~tXfile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslt_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslsq~ #q~tLfile:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsltST-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xslsq~ q~tofile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=machineLearning.htmltvT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=machineLearning.htmlsq~ cIq~tjfile:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=machineLearning.htmltqT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=machineLearning.htmlxtAPK_G-file-cocoon://site.navigation.links.xml?pipelinehash=786357640368091306_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/absolutize-linkmap.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=machineLearning.html_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=machineLearning.htmlsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xphppur[BTxp tCXML  Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.  Forrest site.xml This file contains an outline of the site's information content. It is used to: - Generate the website menus (though these can be overridden - see docs) - Provide semantic, location-independent aliases for internal 'site:' URIs, eg links to changes.html (or ../changes.html if in subdir). - Provide aliases for external URLs in the external-refs section. Eg, links to http://cocoon.apache.org/ See http://forrest.apache.org/docs/linking.html for more info  The label attribute of the outer "site" element will only show in the linkmap (linkmap.html). Use elements project-name and group-name in skinconfig to change name of your site or project that is usually shown at the top of page. No matter what you configure for the href attribute, Forrest will always use index.html when you request http://yourHost/ See FAQ: "How can I use a start-up-page other than index.html?" site tabCDATAlabelHomeabout Indexhref index.html description 'ai4r - Artificial Intelligence for Rubyindex   Practical ExamplespracticalExamples Genetic AlgorithmsgeneticAlgorithms.html Genetic Algorithms in rubygeneticAlgorithms Machine LearningmachineLearning.html ID3 Decision Trees in rubymachineLearning Neural NetworksneuralNetworks.html &Backpropagation Neural Network in rubyneuralNetworks   Downloadsdownloads.html ai4r - Download Filesdownload Forum-http://forum.jadeferret.com/viewforum.php?f=3  Ai4r Forumforum""" Source Code repositorysvn.html ai4r Subversion repositorysvn&&&  AI4R Wiki(http://wiki.jadeferret.com/Category:AI4R 3ai4r wiki with How-to guides and more documentationwiki*** API doc (Rdoc))http://ai4r.rubyforge.org/rdoc/index.html  Ai4 RDoc docsrdoc...  ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsrLorg.apache.cocoon.components.source.impl.SitemapSource$SitemapSourceValidity+{yyLvalidityt,Lorg/apache/excalibur/source/SourceValidity;xpsrgq~tXfile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslt_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslsq~ #q~tLfile:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsltST-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xslsq~ zLJq~tcfile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=svn.htmltjT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=svn.htmlsq~ Xx#q~t^file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=svn.htmlteT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=svn.htmlxt)PK_G-file-cocoon://site.navigation.links.xml?pipelinehash=786357640368091306_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/absolutize-linkmap.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=svn.html_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=svn.htmlsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xpppur[BTxp tCXML  Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.  Forrest site.xml This file contains an outline of the site's information content. It is used to: - Generate the website menus (though these can be overridden - see docs) - Provide semantic, location-independent aliases for internal 'site:' URIs, eg links to changes.html (or ../changes.html if in subdir). - Provide aliases for external URLs in the external-refs section. Eg, links to http://cocoon.apache.org/ See http://forrest.apache.org/docs/linking.html for more info  The label attribute of the outer "site" element will only show in the linkmap (linkmap.html). Use elements project-name and group-name in skinconfig to change name of your site or project that is usually shown at the top of page. No matter what you configure for the href attribute, Forrest will always use index.html when you request http://yourHost/ See FAQ: "How can I use a start-up-page other than index.html?" site tabCDATAlabelHomeabout Indexhref index.html description 'ai4r - Artificial Intelligence for Rubyindex   Practical ExamplespracticalExamples Genetic AlgorithmsgeneticAlgorithms.html Genetic Algorithms in rubygeneticAlgorithms Machine LearningmachineLearning.html ID3 Decision Trees in rubymachineLearning Neural NetworksneuralNetworks.html &Backpropagation Neural Network in rubyneuralNetworks   Downloadsdownloads.html ai4r - Download Filesdownload Forum-http://forum.jadeferret.com/viewforum.php?f=3  Ai4r Forumforum""" Source Code repositorysvn.html ai4r Subversion repositorysvn&&&  AI4R Wiki(http://wiki.jadeferret.com/Category:AI4R 3ai4r wiki with How-to guides and more documentationwiki*** API doc (Rdoc))http://ai4r.rubyforge.org/rdoc/index.html  Ai4 RDoc docsrdoc...  ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsrLorg.apache.cocoon.components.source.impl.SitemapSource$SitemapSourceValidity+{yyLvalidityt,Lorg/apache/excalibur/source/SourceValidity;xpsrgq~tXfile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslt_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xslsq~ #q~tLfile:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsltST-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xslsq~ q~tnfile:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=neuralNetworks.htmltuT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=neuralNetworks.htmlsq~ Pq~tifile:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=neuralNetworks.htmltpT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=neuralNetworks.htmlxt?PK_G-file-cocoon://site.navigation.links.xml?pipelinehash=786357640368091306_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/absolutize-linkmap.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-normalizetabs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/normalizehrefs.xsl_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/site-to-site-selectnode.xsl;path=neuralNetworks.html_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/relativize-linkmap.xsl;path=neuralNetworks.htmlsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xpppur[BTxp tCXML  Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.  Forrest site.xml This file contains an outline of the site's information content. It is used to: - Generate the website menus (though these can be overridden - see docs) - Provide semantic, location-independent aliases for internal 'site:' URIs, eg links to changes.html (or ../changes.html if in subdir). - Provide aliases for external URLs in the external-refs section. Eg, links to http://cocoon.apache.org/ See http://forrest.apache.org/docs/linking.html for more info  The label attribute of the outer "site" element will only show in the linkmap (linkmap.html). Use elements project-name and group-name in skinconfig to change name of your site or project that is usually shown at the top of page. No matter what you configure for the href attribute, Forrest will always use index.html when you request http://yourHost/ See FAQ: "How can I use a start-up-page other than index.html?" site tabCDATAlabelHomeabout Indexhref index.html description 'ai4r - Artificial Intelligence for Rubyindex   Practical ExamplespracticalExamples Genetic AlgorithmsgeneticAlgorithms.html Genetic Algorithms in rubygeneticAlgorithms Machine LearningmachineLearning.html ID3 Decision Trees in rubymachineLearning Neural NetworksneuralNetworks.html &Backpropagation Neural Network in rubyneuralNetworks   Downloadsdownloads.html ai4r - Download Filesdownload Forum-http://forum.jadeferret.com/viewforum.php?f=3  Ai4r Forumforum""" Source Code repositorysvn.html ai4r Subversion repositorysvn&&&  AI4R Wiki(http://wiki.jadeferret.com/Category:AI4R 3ai4r wiki with How-to guides and more documentationwiki*** API doc (Rdoc))http://ai4r.rubyforge.org/rdoc/index.html  Ai4 RDoc docsrdoc...  ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsrLorg.apache.cocoon.components.source.impl.SitemapSource$SitemapSourceValidity+{yyLvalidityt,Lorg/apache/excalibur/source/SourceValidity;xpsrtEXtCommentCreated with The GIMPd%n6IDAT(cTWWe ?ĄD0aT40ZPP-/ p6IENDB`ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xpAsr java.io.File-E Lpathq~xptK/home/sfierens/workspace/ai4r/site/src/documentation/resources/images/s.pngw/xsrnet.sf.ehcache.ElementlyP{VJ creationTimeJhitCountJlastAccessTimeJnextToLastAccessTimeJversionLkeytLjava/lang/Object;Lvalueq~xpˀsr*org.apache.cocoon.caching.PipelineCacheKey;KJћIhashCodeLkeystLjava/util/List;LtoStringtLjava/lang/String;xpsrjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xpBtfilet4cocoon://index.xml?pipelinehash=-3413672797934272206psq~ tidgent-8355019975799787170psq~ iYstxincludetXIncludepxpsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xpppur[BTxpCXML  Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. document header title(AI4R :: Artificial Intelligence for Ruby  body idCDATA Introductionsection  Introduction p  AI4R is a collection of ruby algorithms implementations, covering several Artificial intelligence fields, and simple practical examples using them. It implements:   ul  li href /http://en.wikipedia.org/wiki/Genetic_algorithmslinkGenetic algorithms    +http://en.wikipedia.org/wiki/Neural_network*Neural networks (Backpropagation networks)    machineLearning.html(Automatic classifiers (Machine Learning)     *http://en.wikipedia.org/wiki/ID3_algorithmID3 (Decision Trees)   PRISM (J. Cendrowska, 1987)    Ihttp://en.wikipedia.org/wiki/Association_rule_learning#One-attribute-rule!OneR (AKA One Attribute Rule, 1R)    Jhttp://en.wikipedia.org/wiki/Association_rule_learning#Zero-attribute-ruleZeroR        ,http://en.wikipedia.org/wiki/Data_clusteringData clustering     $http://en.wikipedia.org/wiki/k_meansK-means algorithm    Bisecting k-means         Examples_offered Practical examples   strongGenetic Algorithmsbr  geneticAlgorithms.htmlAOptimization of the Travelling salesman problem (NP-hard problem)   altGenetic Algorithms Examplesrc%images/genetic_algorithms_example.pngimg      Neural networks  neuralNetworks.html+Simple OCR (recognition of visual patterns)   Neural Network Example!images/neural_network_example.png      Automatic classifiers  6Automatic identification of relevant marketing targets     howtoinstall How to install  1. Install the gem:  xml$http://www.w3.org/XML/1998/namespace$space xml:spacepreservesource(gem install ai4r((#  +2. Include require statements in your code:  #$$%&'(() require "rubygems" require "ai4r" ((#   ContactMe  Contact me  v If you have questions or constructive comments about this project, please post them in the  -http://forum.jadeferret.com/viewforum.php?f=3 Ai4r Forumforumn. I get an email notification when you post, and I do my best to answer as soon as possible.    f If you do not want to make it public, send it to me: Sergio Fierens, email address: +(sergio (dot) fierens (at) gmail (dot) com)images/my_email.pngSergio Fierens contact email. But please, try to post them in the forum. I get tons of emails and it would be great to make them public to help everyone.    warranty Disclaimer Note   This software is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.     ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsrLorg.apache.cocoon.components.source.impl.SitemapSource$SitemapSourceValidity+{yyLvalidityt,Lorg/apache/excalibur/source/SourceValidity;xpsr -9   CThat is: From 0 to 2 costs 5. From 2 to 1 costs 4. Total cost is 9.   chromosome-impl-reproduce Reproduce function  hReproduction is used to vary the programming of a chromosome or chromosomes from one generation to the next. There are several ways to combine two chromosomes: One-point crossover, Two-point crossover, "Cut and splice", edge recombination, and more. The method is usually dependant of the problem domain. In this case, we have implemented edge recombination, wich is the most used reproduction algorithm for the Travelling salesman problem. The edge recombination operator (ERO) is an operator that creates a path that is similar to a set of existing paths (parents) by looking at the edges rather than the vertices.    Edge recombination images/ero.gif   [The previous image was taken from the wikipedia, so hail to the author: Koala man (not me).   chromosome-impl-mutation Mutation function  CMutation funtion will be called fro every member of the population, on each generations. But you do not want to mutate your chromosomes every time, specialy if the are very fit. This is how it is currently implemented: With a probabilty of changing inversely proportional to its fitness, we swap 2 consecutive random nodes.  K def self.mutate(chromosome) if chromosome.normalized_fitness && rand < ((1 - chromosome.normalized_fitness) * 0.3) data = chromosome.data index = rand(data.length-1) data[index], data[index+1] = data[index+1], data[index] chromosome.data = data @fitness = nil end end   chromosome-impl-seed  Seed function  -Initializes an individual solution (chromosome) for the initial population. The built in seed function generates a chromosome randomly, but you can use some problem domain knowledge, to generate better initial solutions (although this not always deliver better results, it improves convergency times).  : def self.seed data_size = @@costs[0].length available = [] 0.upto(data_size-1) { |n| available << n } seed = [] while available.length > 0 do index = rand(available.length) seed << available.delete_at(index) end return Chromosome.new(seed) end     search-impl Implementation of GeneticSearch  The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.  search-impl-init Initialize the search  You have to provide two parameters during instantiation: The initial population size, and the how many generations produce. Large numbers will usually converge to better results, while small numbers will have better performance.  R search = Ai4r::GeneticAlgorithm::GeneticSearch.new(10, 20) result = search.run   search-impl-run  Run method  Once you initialize an instance of GeneticSearch class, you can perform the search executing the run method. This method will:   Choose initial population 9Evaluate the fitness of each individual in the population 0Repeat as many times as generations we allow  9Select randomly the best-ranking individuals to reproduce dBreed new generation through crossover and mutation (genetic operations) and give birth to offspring 2Evaluate the individual fitnesses of the offspring 6Replace worst ranked part of population with offspring     search-impl-selection  Selection  Selection is the stage of a genetic algorithm in which individual genomes are chosen from a population for later breeding. There are several generic selection algorithms, such as tournament selection and roulette wheel selection. We implemented the latest.   OThe fitness function is evaluated for each individual, providing fitness values 6The population is sorted by descending fitness values. The fitness values ar then normalized. (Highest fitness gets 1, lowest fitness gets 0). The normalized value is stored in the "normalized_fitness" attribute of the chromosomes.  A random number R is chosen. R is between 0 and the accumulated normalized value (all the normalized fitness values added togheter). The selected individual is the first one whose accumulated normalized value (its is normalized value plus the normalized values of the chromosomes prior it) greater than R. 7We repeat steps 4 and 5, 2/3 times the population size.    " images/fitness.png   VThe previous image was taken from the wikipedia, so hail to the author: Simon Hatthon.   search-impl-reproduction  Reproduction  kThe reproduction function combines each pair of selected chromosomes using the method Chromosome.reproduce.   The reproduction will also call the Chromosome.mutate method with each member of the population. You should implement Chromosome.mutate to only change (mutate) randomly. E.g. You could effectivly change the chromosome only if:   6 rand < ((1 - chromosome.normalized_fitness) * 0.4)     how-to-run -How to use AI4R Genetic Search implementation | #Cost of traveling from one point to another. E.g. Travelling from Node 0 to Node 2 costs 5. data_set = [ [ 0, 10, 5], [ 6, 0, 4], [25, 4, 0] ] Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set) search = Ai4r::GeneticAlgorithm::GeneticSearch.new(10, 20) result = search.run puts "Result cost: #{result.fitness}" puts "Result nodes: #{result.data.inspect}"    example-run How to run the example  qYou can run the example with "ruby genetic_algorithm_example.rb". The genetic_algorithm_example.rb file contains:   require "rubygems" require "ai4r/genetic_algorithm/genetic_algorithm" require "csv" # Load data from data_set.csv data_set = [] CSV::Reader.parse(File.open("#{File.dirname(__FILE__)}/travel_cost.csv", 'r')) do |row| data_set << row end data_labels = data_set.shift data_set.collect! do |column| column.collect { |element| element.to_f} end Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set) puts "Beginning genetic search, please wait... " search = Ai4r::GeneticAlgorithm::GeneticSearch.new(800, 100) result = search.run puts "Result cost: #{result.fitness}" puts "Result tour: " result.data.each { |c| print " #{data_labels[c]}"}   Results jResults of using Genetic Algorithms to the The European Rock Tour Problem (or Travelling salesman problem)  &The cost of 3 randomly selected tours:  ul/ t$17486.01 : Madrid Vienna Moscow Berlin Brussels Munich Milan Barcelona London Hamburg Warsaw Dublin Kiev Paris Rome t$20198.92 : London Rome Brussels Kiev Hamburg Warsaw Barcelona Paris Munich Dublin Vienna Moscow Madrid Milan Berlin t$17799.34 : Madrid Milan Kiev Vienna Warsaw London Barcelona Hamburg Paris Munich Dublin Berlin Moscow Rome Brussels //  N3 tours obtained with an initial population of 800, and after 100 generations:  // s$7611.99 : Moscow Kiev Warsaw Hamburg Berlin Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin $7596.74 : Moscow Kiev Warsaw Berlin Hamburg Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin (See Image) s$7641.61 : Madrid Barcelona Rome Milan Paris Dublin London Brussels Hamburg Berlin Vienna Munich Warsaw Kiev Moscow //   1Best tour result using Genetic Algorithms in ruby images/europe3.png   The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.   more-genetic-run AMore about Genetic Algorithms and the Travelling salesman problem  (Travelling salesman problem at Wikipedia   .http://en.wikipedia.org/wiki/Genetic_algorithmGenetic Algorithms at Wikipedia    ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsrLorg.apache.cocoon.components.source.impl.SitemapSource$SitemapSourceValidity+{yyLvalidityt,Lorg/apache/excalibur/source/SourceValidity;xpsrsrjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xptresourcetTfile:/home/sfierens/workspace/ai4r/site/src/documentation/resources/images/c_wbn.pngpxpsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xpt image/pngpur[BTxp͉PNG  IHDRh6 pHYs  tIME /tEXtCommentCreated with The GIMPd%nCIDAT(푡 c.ZI:HL* ^UfVh<LuI[5IURfnUIi%ŞIENDB`ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xpAsr java.io.File-E Lpathq~xptO/home/sfierens/workspace/ai4r/site/src/documentation/resources/images/c_wbn.pngw/xsrnet.sf.ehcache.ElementlyP{VJ creationTimeJhitCountJlastAccessTimeJnextToLastAccessTimeJversionLkeytLjava/lang/Object;Lvalueq~xpˀsr*org.apache.cocoon.caching.PipelineCacheKey;KJћIhashCodeLkeystLjava/util/List;LtoStringtLjava/lang/String;xpmsrjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xpD(tfiletQfile:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/index.xmltXG-file-file:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/index.xmlsq~ `GtxslttNfile:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xsltUT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xslxtPK_G-file-file:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/index.xml_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xslsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xpppur[BTxpCXML  Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. document header title(AI4R :: Artificial Intelligence for Ruby  body idCDATA Introductionsection  Introduction p  AI4R is a collection of ruby algorithms implementations, covering several Artificial intelligence fields, and simple practical examples using them. It implements:   ul  li href /http://en.wikipedia.org/wiki/Genetic_algorithmslinkGenetic algorithms    +http://en.wikipedia.org/wiki/Neural_network*Neural networks (Backpropagation networks)    machineLearning.html(Automatic classifiers (Machine Learning)     *http://en.wikipedia.org/wiki/ID3_algorithmID3 (Decision Trees)   PRISM (J. Cendrowska, 1987)    Ihttp://en.wikipedia.org/wiki/Association_rule_learning#One-attribute-rule!OneR (AKA One Attribute Rule, 1R)    Jhttp://en.wikipedia.org/wiki/Association_rule_learning#Zero-attribute-ruleZeroR        ,http://en.wikipedia.org/wiki/Data_clusteringData clustering     $http://en.wikipedia.org/wiki/k_meansK-means algorithm    Bisecting k-means         Examples_offered Practical examples   strongGenetic Algorithmsbr  geneticAlgorithms.htmlAOptimization of the Travelling salesman problem (NP-hard problem)   src%images/genetic_algorithms_example.pngaltGenetic Algorithms Exampleimg      Neural networks  neuralNetworks.html+Simple OCR (recognition of visual patterns)   !images/neural_network_example.pngNeural Network Example      Automatic classifiers  6Automatic identification of relevant marketing targets     howtoinstall How to install   1. Install the gem:  $http://www.w3.org/XML/1998/namespacespace xml:spacepreservesource'gem install ai4r''  +2. Include require statements in your code:  #$%&'') require "rubygems" require "ai4r" ''   ContactMe  Contact me  v If you have questions or constructive comments about this project, please post them in the  -http://forum.jadeferret.com/viewforum.php?f=3 Ai4r Forumforumn. I get an email notification when you post, and I do my best to answer as soon as possible.    f If you do not want to make it public, send it to me: Sergio Fierens, email address: images/my_email.png+(sergio (dot) fierens (at) gmail (dot) com)Sergio Fierens contact email. But please, try to post them in the forum. I get tons of emails and it would be great to make them public to help everyone.    warranty Disclaimer Note   This software is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.     ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xpoqhsr java.io.File-E Lpathq~xptL/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/index.xmlw/xsr3٣D+Q++~zR bG(r"Qḱ:bt&p ~JcIJ &,AƛvHH +teJA$BhbD`VG # #Zv Λ:BB(.l!d+YBLAf-rB4BZB(("{EBdq\K(|FBL-H(%ļ+QiE * &@ʊ^] !:B"hnnEA.B#S#!D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) sCaQۋA^¦-p3r;ɝ}~",uoY)c zKH?Zπ()+AZا)HLtT4cڕhtc#Ԩ^w`c3lŰ ժ]**? k]k` ֌ Ee`˶-l𙡜*ER0끟oBݩX~ Kzb|{PRZn \K5 tQmY6j zΚQRl6 Nx Gdᡬx/x=56>e @aa!`պUxx@<5ڐJ 3`xEGCaWYDjuyI׽ LIcFCĎnkEBF .I]I&a`'mȠ/`ѰҚ2~]۝/UVV /RҜg̛~O:_"f>;zCC׻+aˆ0`8rx?I$A9ej'vPt'sޅ3^yfBbb2%3;wnEQ\w[jTc~:>͆lx+ի٣пw&Nx ?luWcC QHYt+_)t0w @g\a8ڴ6l?3{͚6 \pϷa;թSGץGs52l'NĤiQ|5koG\]hFBNI81TTVF7э!;}ZBHEDJP63f@-0{lv̘L._(DGGsxW0}tʕ+ٳ'-Z 4ov/_ƕ+WKHH͛ѯ_?|n㓞%*-˙41GoaA0m 7ߌR_Fdd$"##͛W^DiӦ*_j%K &&RRRdt+laӧʕ+1tP̘1u5k|cLL9pF E==n2U 7O# P i>ʭpE{ax \̣П >Cq&a0+@v_1==Y^h>T}&=X Ә$ieRUT踌S+&]!ϡO]RZ8aOG3~-B\1@u8#+U q f #Z 0͗_SB4kZMTŮ vI v6weՐ'B]F1E "AG`G lP޿'S !of˾smgENHY)B!TMR !pAE"H$BH&D2u8'H(B1$V'!U!!BY@ f G!YA -jnzL!BC!B(C !)rABZV )B!R !\pB!!bU?rPm&'IENDB`ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xpAsr java.io.File-E Lpathq~xptQ/home/sfierens/workspace/ai4r/site/src/documentation/resources/images/europe2.pngw/xsrnet.sf.ehcache.ElementlyP{VJ creationTimeJhitCountJlastAccessTimeJnextToLastAccessTimeJversionLkeytLjava/lang/Object;Lvalueq~xpۨܒsr*org.apache.cocoon.caching.PipelineCacheKey;KJћIhashCodeLkeystLjava/util/List;LtoStringtLjava/lang/String;xpy%srjava.util.ArrayListxaIsizexpwsr+org.apache.cocoon.caching.ComponentCacheKey*cZ cachePointIhashCodeItypeL identifierq~LkeytLjava/io/Serializable;LtoStringq~xp[tfilet[file:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/machineLearning.xmltbG-file-file:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/machineLearning.xmlsq~ `GtxslttNfile:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xsltUT-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xslxtPK_G-file-file:/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/machineLearning.xml_T-xslt-file:/usr/local/forrest/main/webapp/resources/stylesheets/docv20-to-docv13.xslsr(org.apache.cocoon.caching.CachedResponseq6?J lastModifiedL contentTypeq~LexpirestLjava/lang/Long;[responset[B[validityObjectst-[Lorg/apache/excalibur/source/SourceValidity;xphppur[BTxpCXMLdocument header title0Machine Learning with ID3 Decision Trees in Ruby  body idCDATA mach-introsection Introduction to ID3 algorithm p  AI4R implements the ID3 algorithm (Quinlan) as one of its automatic classifiers. Given a set of preclassified examples, it builds a top-down induction of decision tree, biased by the information gain and entropy measure.    y The good thing about this automatic learning method is that humans learns as well. Unlike other AI techniques like neural networks, classifiers can generate ruby code with if / else sentences. You can use this to evaluate parameters on realtime, copy paste them in a code, or just read them to learn about your problem domain.     mach-HowTo BMarketing target strategy example using ID3 Decision Trees in Ruby  Let's suppose that you are writting an application that must identify people as relevant marketing targets or not. The only information that you have is a collection of examples, provided by a marketing survey:  $http://www.w3.org/XML/1998/namespacespace xml:spacepreservesource> DATA_LABELS = [ 'city', 'age_range', 'gender', 'marketing_target' ] DATA_SET = [ ['New York', '<30', 'M', 'Y'], ['Chicago', '<30', 'M', 'Y'], ['Chicago', '<30', 'F', 'Y'], ['New York', '<30', 'M', 'Y'], ['New York', '<30', 'M', 'Y'], ['Chicago', '[30-50)', 'M', 'Y'], ['New York', '[30-50)', 'F', 'N'], ['Chicago', '[30-50)', 'F', 'Y'], ['New York', '[30-50)', 'F', 'N'], ['Chicago', '[50-80]', 'M', 'N'], ['New York', '[50-80]', 'F', 'N'], ['New York', '[50-80]', 'M', 'N'], ['Chicago', '[50-80]', 'M', 'N'], ['New York', '[50-80]', 'F', 'N'], ['Chicago', '>80', 'F', 'Y'] ]   @You can create an ID3 Decision tree to do the dirty job for you:   , id3 = ID3.new(DATA_SET, DATA_LABELS)   IThe Decision tree will automatically create the "rules" to parse new data., and identify new posible marketing targets:    id3.get_rules # => if age_range=='<30' then marketing_target='Y' elsif age_range=='[30-50)' and city=='Chicago' then marketing_target='Y' elsif age_range=='[30-50)' and city=='New York' then marketing_target='N' elsif age_range=='[50-80]' then marketing_target='N' elsif age_range=='>80' then marketing_target='Y' else raise 'There was not enough information during training to do a proper induction for this data element' end id3.eval(['New York', '<30', 'M']) # => 'Y'    mach-dataload Better data loading   In real life you will use many more data training examples, with more attributes. Consider moving your data to an external CSV (comma separate values) file.     data_set = [] CSV::Reader.parse(File.open("#{File.dirname(__FILE__)}/data_set.csv", 'r')) do |row| data_set << row end data_labels = data_set.shift id3 = ID3.new(data_set, data_labels)     mach-eval A good tip for data evaluation  : The ID3 class provides a method to evaluate new data.    3 id3.eval(['New York', '<30', 'M']) # => 'Y'    But instead of going through the tree every time, you can take advantage of the fact that the method "get_rules" generates proper ruby code!     id3 = ID3.new(DATA_SET, DATA_LABELS) age_range = '<30' city = 'New York' gender = 'M' marketing_target = nil eval id3.get_rules puts marketing_target # => 'Y'    mach-more !More about ID3 and decision trees   href*http://en.wikipedia.org/wiki/Decision_treelink#Wikipedia article on Decision trees *http://en.wikipedia.org/wiki/ID3_algorithm"Wikipedia article on ID3 Algorithm     ur-[Lorg.apache.excalibur.source.SourceValidity;l|e0xpsr?org.apache.excalibur.source.impl.validity.FileTimeStampValidity ǹJ m_timeStampLm_filetLjava/io/File;xpjsr java.io.File-E Lpathq~xptV/home/sfierens/workspace/ai4r/site/src/documentation/content/xdocs/machineLearning.xmlw/xsr