ai4r 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. data/README.rdoc +21 -20
  2. data/examples/decision_trees/id3_example.rb +3 -2
  3. data/examples/genetic_algorithm/genetic_algorithm_example.rb +6 -6
  4. data/examples/neural_network/backpropagation_example.rb +2 -2
  5. data/lib/ai4r/classifiers/classifier_helper.rb +54 -0
  6. data/lib/ai4r/classifiers/id3.rb +356 -0
  7. data/lib/ai4r/classifiers/one_r.rb +148 -0
  8. data/lib/ai4r/classifiers/prism.rb +231 -0
  9. data/lib/ai4r/classifiers/zero_r.rb +104 -0
  10. data/lib/ai4r/genetic_algorithm/genetic_algorithm.rb +272 -0
  11. data/lib/ai4r/neural_network/backpropagation.rb +271 -0
  12. data/site/build/tmp/locationmap.xml +14 -14
  13. data/site/build/tmp/output.xmap +23 -23
  14. data/site/build/tmp/pluginlist2fetchbuild.xml +144 -144
  15. data/site/build/tmp/plugins-1.xml +0 -11
  16. data/site/build/tmp/plugins-2.xml +54 -0
  17. data/site/build/tmp/projfilters.properties +41 -41
  18. data/site/build/webapp/WEB-INF/logs/core.log +681 -788
  19. data/site/build/webapp/WEB-INF/logs/error.log +281 -248
  20. data/site/build/webapp/WEB-INF/logs/sitemap.log +1015 -0
  21. data/site/src/documentation/content/xdocs/forum.html +9 -0
  22. data/site/src/documentation/content/xdocs/geneticAlgorithms.xml +82 -68
  23. data/site/src/documentation/content/xdocs/index.xml +47 -18
  24. data/site/src/documentation/content/xdocs/machineLearning.xml +10 -9
  25. data/site/src/documentation/content/xdocs/neuralNetworks.xml +60 -36
  26. data/site/src/documentation/content/xdocs/site.xml +8 -5
  27. data/site/src/documentation/content/xdocs/svn.xml +11 -1
  28. data/site/src/documentation/resources/images/Thumbs.db +0 -0
  29. data/site/src/documentation/resources/images/ai4r-logo.png +0 -0
  30. data/site/src/documentation/resources/images/genetic_algorithms_example.png +0 -0
  31. data/site/src/documentation/resources/images/jadeferret.png +0 -0
  32. data/site/src/documentation/resources/images/neural_network_example.png +0 -0
  33. data/site/src/documentation/resources/images/sub-dir/Thumbs.db +0 -0
  34. data/site/src/documentation/skinconf.xml +18 -18
  35. data/test/classifiers/id3_test.rb +206 -0
  36. data/test/classifiers/one_r_test.rb +62 -0
  37. data/test/classifiers/prism_test.rb +83 -0
  38. data/test/classifiers/zero_r_test.rb +48 -0
  39. data/test/genetic_algorithm/chromosome_test.rb +41 -38
  40. data/test/genetic_algorithm/genetic_algorithm_test.rb +64 -61
  41. data/test/neural_network/backpropagation_test.rb +20 -18
  42. metadata +109 -199
  43. data/lib/decision_tree/id3.rb +0 -354
  44. data/lib/genetic_algorithm/genetic_algorithm.rb +0 -268
  45. data/lib/neural_network/backpropagation.rb +0 -264
  46. data/site/build/site/en/broken-links.xml +0 -2
  47. data/site/build/site/en/downloads.html +0 -187
  48. data/site/build/site/en/downloads.pdf +0 -151
  49. data/site/build/site/en/geneticAlgorithms.html +0 -564
  50. data/site/build/site/en/geneticAlgorithms.pdf +0 -911
  51. data/site/build/site/en/images/ai4r-logo.png +0 -0
  52. data/site/build/site/en/images/built-with-forrest-button.png +0 -0
  53. data/site/build/site/en/images/c.png +0 -0
  54. data/site/build/site/en/images/c_wbn.png +0 -0
  55. data/site/build/site/en/images/c_wn.png +0 -0
  56. data/site/build/site/en/images/ero.gif +0 -0
  57. data/site/build/site/en/images/europe2.png +0 -0
  58. data/site/build/site/en/images/europe3.png +0 -0
  59. data/site/build/site/en/images/fitness.png +0 -0
  60. data/site/build/site/en/images/instruction_arrow.png +0 -0
  61. data/site/build/site/en/images/my_email.png +0 -0
  62. data/site/build/site/en/images/rubyforge.png +0 -0
  63. data/site/build/site/en/images/s.png +0 -0
  64. data/site/build/site/en/images/s_wbn.png +0 -0
  65. data/site/build/site/en/images/s_wn.png +0 -0
  66. data/site/build/site/en/images/sigmoid.png +0 -0
  67. data/site/build/site/en/images/t.png +0 -0
  68. data/site/build/site/en/images/t_wbn.png +0 -0
  69. data/site/build/site/en/images/t_wn.png +0 -0
  70. data/site/build/site/en/index.html +0 -258
  71. data/site/build/site/en/index.pdf +0 -306
  72. data/site/build/site/en/linkmap.html +0 -231
  73. data/site/build/site/en/linkmap.pdf +0 -94
  74. data/site/build/site/en/locationmap.xml +0 -72
  75. data/site/build/site/en/machineLearning.html +0 -325
  76. data/site/build/site/en/machineLearning.pdf +0 -337
  77. data/site/build/site/en/neuralNetworks.html +0 -446
  78. data/site/build/site/en/neuralNetworks.pdf +0 -604
  79. data/site/build/site/en/skin/CommonMessages_de.xml +0 -23
  80. data/site/build/site/en/skin/CommonMessages_en_US.xml +0 -23
  81. data/site/build/site/en/skin/CommonMessages_es.xml +0 -23
  82. data/site/build/site/en/skin/CommonMessages_fr.xml +0 -23
  83. data/site/build/site/en/skin/basic.css +0 -166
  84. data/site/build/site/en/skin/breadcrumbs-optimized.js +0 -90
  85. data/site/build/site/en/skin/breadcrumbs.js +0 -237
  86. data/site/build/site/en/skin/fontsize.js +0 -166
  87. data/site/build/site/en/skin/getBlank.js +0 -40
  88. data/site/build/site/en/skin/getMenu.js +0 -45
  89. data/site/build/site/en/skin/images/README.txt +0 -1
  90. data/site/build/site/en/skin/images/add.jpg +0 -0
  91. data/site/build/site/en/skin/images/built-with-forrest-button.png +0 -0
  92. data/site/build/site/en/skin/images/chapter.gif +0 -0
  93. data/site/build/site/en/skin/images/chapter_open.gif +0 -0
  94. data/site/build/site/en/skin/images/current.gif +0 -0
  95. data/site/build/site/en/skin/images/error.png +0 -0
  96. data/site/build/site/en/skin/images/external-link.gif +0 -0
  97. data/site/build/site/en/skin/images/fix.jpg +0 -0
  98. data/site/build/site/en/skin/images/forrest-credit-logo.png +0 -0
  99. data/site/build/site/en/skin/images/hack.jpg +0 -0
  100. data/site/build/site/en/skin/images/header_white_line.gif +0 -0
  101. data/site/build/site/en/skin/images/info.png +0 -0
  102. data/site/build/site/en/skin/images/instruction_arrow.png +0 -0
  103. data/site/build/site/en/skin/images/label.gif +0 -0
  104. data/site/build/site/en/skin/images/page.gif +0 -0
  105. data/site/build/site/en/skin/images/pdfdoc.gif +0 -0
  106. data/site/build/site/en/skin/images/poddoc.png +0 -0
  107. data/site/build/site/en/skin/images/printer.gif +0 -0
  108. data/site/build/site/en/skin/images/rc-b-l-15-1body-2menu-3menu.png +0 -0
  109. data/site/build/site/en/skin/images/rc-b-r-15-1body-2menu-3menu.png +0 -0
  110. data/site/build/site/en/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  111. data/site/build/site/en/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png +0 -0
  112. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png +0 -0
  113. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  114. data/site/build/site/en/skin/images/rc-t-r-15-1body-2menu-3menu.png +0 -0
  115. data/site/build/site/en/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png +0 -0
  116. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  117. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  118. data/site/build/site/en/skin/images/remove.jpg +0 -0
  119. data/site/build/site/en/skin/images/rss.png +0 -0
  120. data/site/build/site/en/skin/images/spacer.gif +0 -0
  121. data/site/build/site/en/skin/images/success.png +0 -0
  122. data/site/build/site/en/skin/images/txtdoc.png +0 -0
  123. data/site/build/site/en/skin/images/update.jpg +0 -0
  124. data/site/build/site/en/skin/images/valid-html401.png +0 -0
  125. data/site/build/site/en/skin/images/vcss.png +0 -0
  126. data/site/build/site/en/skin/images/warning.png +0 -0
  127. data/site/build/site/en/skin/images/xmldoc.gif +0 -0
  128. data/site/build/site/en/skin/menu.js +0 -48
  129. data/site/build/site/en/skin/note.txt +0 -50
  130. data/site/build/site/en/skin/print.css +0 -54
  131. data/site/build/site/en/skin/profile.css +0 -163
  132. data/site/build/site/en/skin/prototype.js +0 -1257
  133. data/site/build/site/en/skin/screen.css +0 -587
  134. data/site/build/site/en/svn.html +0 -223
  135. data/site/build/site/en/svn.pdf +0 -239
  136. data/site/build/site/en/wholesite.pdf +0 -1686
  137. data/site/build/tmp/brokenlinks.xml +0 -2
  138. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.data +0 -0
  139. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.index +0 -0
  140. data/test/decision_tree/id3_test.rb +0 -209
@@ -1,151 +0,0 @@
1
- %PDF-1.3
2
- %����
3
- 4 0 obj
4
- << /Type /Info
5
- /Producer (FOP 0.20.5) >>
6
- endobj
7
- 5 0 obj
8
- << /Length 470 /Filter [ /ASCII85Decode /FlateDecode ]
9
- >>
10
- stream
11
- Gas1\_,>n>&A@ZMlO=B#8Os,/*+rGF%c10&l@IB6R6dc#lM1*?dPdd[_L[-IH+TPobIRrpGmoo\$q22pku.a&RXbAZ?NSpA9,L-<P!\[C:Z4nVW`GB7gIm@$8B5tR\j<d,C1LC;kH0*uJH"2K41&6R]2VJM,;2mKSTR2,f>4oqlIru-3mt0I]Xm4_m"_i^hWlV,Z7^/!K\Gb;.WEZE8XZ]"FV.%p7hf7$fE)?UM]FU<`//%Ajeap&n0o(F[Blo_S5_H6:\cs]4O6Oee/f^fRBZLCJ,66j@d*gU\N[Ig\N\Skd)Ua54r-T44Nd7Gi6,Lk7i;fT_:bCg#,D3jO[oU@nao(;&,3gjJp4PkB&j(&,WIJV!$fWP9;mL??p-)!4j=_:PR>FDSL.JtVM6Wkr%PIHIeTsEoBIpQ1ZcOuMQq-a;<gXD%d-H!g$P>?eTsH88aHVgge7Sp\&_k@#I!mH[f~>
12
- endstream
13
- endobj
14
- 6 0 obj
15
- << /Type /Page
16
- /Parent 1 0 R
17
- /MediaBox [ 0 0 612 792 ]
18
- /Resources 3 0 R
19
- /Contents 5 0 R
20
- /Annots 7 0 R
21
- >>
22
- endobj
23
- 7 0 obj
24
- [
25
- 8 0 R
26
- ]
27
- endobj
28
- 8 0 obj
29
- << /Type /Annot
30
- /Subtype /Link
31
- /Rect [ 102.0 519.166 435.272 507.166 ]
32
- /C [ 0 0 0 ]
33
- /Border [ 0 0 0 ]
34
- /A 9 0 R
35
- /H /I
36
- >>
37
- endobj
38
- 10 0 obj
39
- << /Length 435 /Filter [ /ASCII85Decode /FlateDecode ]
40
- >>
41
- stream
42
- Garo>9i&Y\%#46H'g@Yq6BWZg]%_rV&gokh@iW'3/WiXeZ3&ap-XAsl%;;T\YFSdDr-FcmgOsqc7TC-DaG8u>`/HI=.2fit2=Zn]as.5L_M119AO<P$)L-<GaTr9@3O&!nBWoQ,*1oOf%PJJjY@&hTD'fWt]?G+t>%#X@[4M`PgN%'aRoLM`s4eSk9ef>4oR@X"eTY.qkmfNH1`s,$CQ+lPpJp=Engc![!DS*<Z6AP56nG8l"uHiu,&Y6B@C2o:Sr)>e6_QjcFAFb>k4:C^_u3XY1ChMJ'>)b,ne/CeJRIEX36jA2W\^2CTc1tXhJn!)()=h$R0[7nNUE\7E;9TF1fho5NM/gTWCD6Pj-YSW1G[1@\".E:rR&7TXT^D<<GS9f.`%KAok]'E.b#t]]e'b^=;1pr;r^a&gOo0+G"6O)5;V-*kl~>
43
- endstream
44
- endobj
45
- 11 0 obj
46
- << /Type /Page
47
- /Parent 1 0 R
48
- /MediaBox [ 0 0 612 792 ]
49
- /Resources 3 0 R
50
- /Contents 10 0 R
51
- >>
52
- endobj
53
- 13 0 obj
54
- <<
55
- /Title (\376\377\0\61\0\40\0\101\0\162\0\164\0\151\0\146\0\151\0\143\0\151\0\141\0\154\0\40\0\151\0\156\0\164\0\145\0\154\0\154\0\151\0\147\0\145\0\156\0\143\0\145\0\40\0\146\0\157\0\162\0\40\0\162\0\165\0\142\0\171\0\40\0\55\0\40\0\141\0\151\0\64\0\162\0\40\0\55\0\40\0\144\0\157\0\167\0\156\0\154\0\157\0\141\0\144\0\40\0\160\0\141\0\147\0\145\0\40\0\141\0\164\0\40\0\122\0\165\0\142\0\171\0\106\0\157\0\162\0\147\0\145)
56
- /Parent 12 0 R
57
- /A 9 0 R
58
- >> endobj
59
- 14 0 obj
60
- << /Type /Font
61
- /Subtype /Type1
62
- /Name /F3
63
- /BaseFont /Helvetica-Bold
64
- /Encoding /WinAnsiEncoding >>
65
- endobj
66
- 15 0 obj
67
- << /Type /Font
68
- /Subtype /Type1
69
- /Name /F5
70
- /BaseFont /Times-Roman
71
- /Encoding /WinAnsiEncoding >>
72
- endobj
73
- 16 0 obj
74
- << /Type /Font
75
- /Subtype /Type1
76
- /Name /F1
77
- /BaseFont /Helvetica
78
- /Encoding /WinAnsiEncoding >>
79
- endobj
80
- 17 0 obj
81
- << /Type /Font
82
- /Subtype /Type1
83
- /Name /F2
84
- /BaseFont /Helvetica-Oblique
85
- /Encoding /WinAnsiEncoding >>
86
- endobj
87
- 18 0 obj
88
- << /Type /Font
89
- /Subtype /Type1
90
- /Name /F7
91
- /BaseFont /Times-Bold
92
- /Encoding /WinAnsiEncoding >>
93
- endobj
94
- 1 0 obj
95
- << /Type /Pages
96
- /Count 2
97
- /Kids [6 0 R 11 0 R ] >>
98
- endobj
99
- 2 0 obj
100
- << /Type /Catalog
101
- /Pages 1 0 R
102
- /Outlines 12 0 R
103
- /PageMode /UseOutlines
104
- >>
105
- endobj
106
- 3 0 obj
107
- <<
108
- /Font << /F3 14 0 R /F5 15 0 R /F1 16 0 R /F2 17 0 R /F7 18 0 R >>
109
- /ProcSet [ /PDF /ImageC /Text ] >>
110
- endobj
111
- 9 0 obj
112
- <<
113
- /S /GoTo
114
- /D [11 0 R /XYZ 85.0 659.0 null]
115
- >>
116
- endobj
117
- 12 0 obj
118
- <<
119
- /First 13 0 R
120
- /Last 13 0 R
121
- >> endobj
122
- xref
123
- 0 19
124
- 0000000000 65535 f
125
- 0000002575 00000 n
126
- 0000002640 00000 n
127
- 0000002732 00000 n
128
- 0000000015 00000 n
129
- 0000000071 00000 n
130
- 0000000632 00000 n
131
- 0000000752 00000 n
132
- 0000000777 00000 n
133
- 0000002855 00000 n
134
- 0000000912 00000 n
135
- 0000001439 00000 n
136
- 0000002918 00000 n
137
- 0000001547 00000 n
138
- 0000002019 00000 n
139
- 0000002132 00000 n
140
- 0000002242 00000 n
141
- 0000002350 00000 n
142
- 0000002466 00000 n
143
- trailer
144
- <<
145
- /Size 19
146
- /Root 2 0 R
147
- /Info 4 0 R
148
- >>
149
- startxref
150
- 2969
151
- %%EOF
@@ -1,564 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
- <html>
3
- <head>
4
- <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
- <meta content="Apache Forrest" name="Generator">
6
- <meta name="Forrest-version" content="0.8">
7
- <meta name="Forrest-skin-name" content="pelt">
8
- <title>Genetics Algorithms in Ruby :: ai4r</title>
9
- <link type="text/css" href="skin/basic.css" rel="stylesheet">
10
- <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
11
- <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
12
- <link type="text/css" href="skin/profile.css" rel="stylesheet">
13
- <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
14
- <link rel="shortcut icon" href="">
15
- </head>
16
- <body onload="init()">
17
- <script type="text/javascript">ndeSetTextSize();</script>
18
- <div id="top">
19
- <!--+
20
- |header
21
- +-->
22
- <div class="header">
23
- <!--+
24
- |start group logo
25
- +-->
26
- <!--+
27
- |end group logo
28
- +-->
29
- <!--+
30
- |start Project Logo
31
- +-->
32
- <div class="projectlogoA1">
33
- <a href="http://ai4r.rubyforge.org/"><img class="logoImage" alt="ai4r" src="images/ai4r-logo.png" title="Artificial Intelligence for Ruby"></a>
34
- </div>
35
- <!--+
36
- |end Project Logo
37
- +-->
38
- <!--+
39
- |start Search
40
- +-->
41
- <div class="searchbox">
42
- <div class="roundtopsmall">
43
- <form target="_top" action="http://www.google.com/custom" method="get">
44
- <input value="ai4r.rubyforge.org;raa.ruby-lang.org;rubyforge.org" name="domains" type="hidden"><label style="display: none" for="sbi">Enter your search terms</label><input id="sbi" value="" maxlength="255" size="31" name="q" type="text"><label style="display: none" for="sbb">Submit search form</label><input id="sbb" value="Search" name="sa" type="submit"><span style="display:none"><input id="ss0" value="" name="sitesearch" style="display=none" type="radio"><input id="ss1" checked value="ai4r.rubyforge.org" name="sitesearch" style="display=none" type="radio"><input id="ss2" value="raa.ruby-lang.org" name="sitesearch" style="display=none" type="radio"><input id="ss3" value="rubyforge.org" name="sitesearch" style="display=none" type="radio"></span><input value="pub-2578934938711895" name="client" type="hidden"><input value="1" name="forid" type="hidden"><input value="ISO-8859-1" name="ie" type="hidden"><input value="ISO-8859-1" name="oe" type="hidden"><input value="active" name="safe" type="hidden"><input value="0000" name="flav" type="hidden"><input value="XEZZoGuMPMQqvUG_" name="sig" type="hidden"><input value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:50;LW:78;L:http://ai4r.rubyforge.org/images/ai4r-logo.png;S:http://ai4r.rubyforge.org/;FORID:1" name="cof" type="hidden"><input value="en" name="hl" type="hidden">
45
- </form>
46
- </div>
47
- </div>
48
- <!--+
49
- |end search
50
- +-->
51
- <!--+
52
- |start Tabs
53
- +-->
54
- <ul id="tabs">
55
- <li class="current">
56
- <a class="selected" href="index.html">Home</a>
57
- </li>
58
- </ul>
59
- <!--+
60
- |end Tabs
61
- +-->
62
- </div>
63
- </div>
64
- <div id="main">
65
- <div id="publishedStrip">
66
- <!--+
67
- |start Subtabs
68
- +-->
69
- <div id="level2tabs"></div>
70
- <!--+
71
- |end Endtabs
72
- +-->
73
- <script type="text/javascript"><!--
74
- document.write("Last Published: " + document.lastModified);
75
- // --></script>
76
- </div>
77
- <!--+
78
- |breadtrail
79
- +-->
80
- <div class="breadtrail">
81
-
82
- &nbsp;
83
- </div>
84
- <!--+
85
- |start Menu, mainarea
86
- +-->
87
- <!--+
88
- |start Menu
89
- +-->
90
- <div id="menu">
91
- <div onclick="SwitchMenu('menu_selected_1.1', 'skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Home</div>
92
- <div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
93
- <div class="menuitem">
94
- <a href="index.html" title="ai4r - Artificial Intelligence for Ruby">Index</a>
95
- </div>
96
- <div class="menupage">
97
- <div class="menupagetitle">Genetic Algorithms</div>
98
- </div>
99
- <div class="menuitem">
100
- <a href="machineLearning.html" title="ID3 Decision Trees in ruby">Machine Learning</a>
101
- </div>
102
- <div class="menuitem">
103
- <a href="neuralNetworks.html" title="Backpropagation Neural Network in ruby">Neural Networks</a>
104
- </div>
105
- <div class="menuitem">
106
- <a href="downloads.html" title="ai4r - Download Files">Downloads</a>
107
- </div>
108
- <div class="menuitem">
109
- <a href="svn.html" title="ai4r Subversion repository">Subversion (svn)</a>
110
- </div>
111
- <div class="menuitem">
112
- <a href="wholesite.pdf">ai4r project PDF</a>
113
- </div>
114
- </div>
115
- <div id="credit">
116
- <script type="text/javascript">
117
- google_ad_client = "pub-2578934938711895";
118
- google_ad_slot = "6111091580";
119
- google_ad_width = 125;
120
- google_ad_height = 125;
121
- </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
122
- <hr>
123
- </div>
124
- <div id="roundbottom">
125
- <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
126
- <!--+
127
- |alternative credits
128
- +-->
129
- <div id="credit2"></div>
130
- </div>
131
- <!--+
132
- |end Menu
133
- +-->
134
- <!--+
135
- |start content
136
- +-->
137
- <div id="content">
138
- <div title="Portable Document Format" class="pdflink">
139
- <a class="dida" href="geneticAlgorithms.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
140
- PDF</a>
141
- </div>
142
- <h1>Genetics Algorithms in Ruby :: ai4r</h1>
143
- <div id="minitoc-area">
144
- <ul class="minitoc">
145
- <li>
146
- <a href="#Introduction">Introduction to Genetics Algorithms in Ruby</a>
147
- </li>
148
- <li>
149
- <a href="#how-to-run">How to use it</a>
150
- </li>
151
- <li>
152
- <a href="#Example">The European Rock Tour Problem (Also known as the Travelling salesman problem)</a>
153
- </li>
154
- <li>
155
- <a href="#Results">Results of using Genetic Algorithms to the The European Rock Tour Problem (or Travelling salesman problem)</a>
156
- </li>
157
- <li>
158
- <a href="#chromosome-impl">Implementation of Chromosome class for the Travelling salesman problem</a>
159
- <ul class="minitoc">
160
- <li>
161
- <a href="#chromosome-impl-data">Data representation</a>
162
- </li>
163
- <li>
164
- <a href="#chromosome-impl-fitness">Fitness function</a>
165
- </li>
166
- <li>
167
- <a href="#chromosome-impl-reproduce">Reproduce function</a>
168
- </li>
169
- <li>
170
- <a href="#chromosome-impl-mutation">Mutation function</a>
171
- </li>
172
- <li>
173
- <a href="#chromosome-impl-seed">Seed function</a>
174
- </li>
175
- </ul>
176
- </li>
177
- <li>
178
- <a href="#search-impl">Implementation of GeneticSearch</a>
179
- <ul class="minitoc">
180
- <li>
181
- <a href="#search-impl-init">Initialize the search</a>
182
- </li>
183
- <li>
184
- <a href="#search-impl-run">Run method</a>
185
- </li>
186
- <li>
187
- <a href="#search-impl-selection">Selection</a>
188
- </li>
189
- <li>
190
- <a href="#search-impl-reproduction">Reproduction</a>
191
- </li>
192
- </ul>
193
- </li>
194
- <li>
195
- <a href="#example-run">How to run the example</a>
196
- </li>
197
- <li>
198
- <a href="#more-genetic-run">More about Genetic Algorithms and the Travelling salesman problem</a>
199
- </li>
200
- </ul>
201
- </div>
202
-
203
- <a name="N1000C"></a><a name="Introduction"></a>
204
- <h2 class="boxed">Introduction to Genetics Algorithms in Ruby</h2>
205
- <div class="section">
206
- <p>The GeneticAlgorithm module implements the GeneticSearch and Chromosome classes. The GeneticSearch is a generic class, and can be used to solved any kind of problems. The GeneticSearch class performs a stochastic search
207
- of the solution of a given problem. It uses the following pseudocode:
208
- </p>
209
- <ol>
210
-
211
- <li>Choose initial population</li>
212
-
213
- <li>Evaluate the fitness of each individual in the population</li>
214
-
215
- <li>Repeat as many times as generations we allow
216
- <ol>
217
-
218
- <li>Select randomly best-ranking individuals to reproduce</li>
219
-
220
- <li>Breed new generation through crossover and mutation (genetic operations) and give birth to offspring</li>
221
-
222
- <li>Evaluate the individual fitnesses of the offspring</li>
223
-
224
- <li>Replace worst ranked part of population with offspring</li>
225
-
226
- </ol>
227
-
228
- </li>
229
-
230
- </ol>
231
- <p>The Chromosome is "problem specific". Ai4r built-in Chromosomeclass was designed to model the <a href="http://en.wikipedia.org/wiki/Traveling_salesman_problem" title="Link to Wikipedia">Travelling salesman problem</a>. You have to provide a matrix with the cost of traveling from one point to another (array of arrays of float values). If you want to solve other type of problem, you will have to modify the Chromosome class, by overwriting its fitness, reproduce, and mutate functions, to model you specific problem.</p>
232
- </div>
233
-
234
-
235
- <a name="N10039"></a><a name="how-to-run"></a>
236
- <h2 class="boxed">How to use it</h2>
237
- <div class="section">
238
- <pre class="code">
239
-
240
- #Cost of traveling from one point to another. E.g. Travelling from Node 0 to Node 2 costs 5.
241
- data_set = [ [ 0, 10, 5],
242
- [ 6, 0, 4],
243
- [25, 4, 0]
244
- ]
245
-
246
- GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
247
-
248
- search = GeneticAlgorithm::GeneticSearch.new(10, 20)
249
- result = search.run
250
- puts "Result cost: #{result.fitness}"
251
- puts "Result nodes: #{result.data.inspect}"
252
-
253
- </pre>
254
- </div>
255
-
256
-
257
- <a name="N10044"></a><a name="Example"></a>
258
- <h2 class="boxed">The European Rock Tour Problem (Also known as the Travelling salesman problem)</h2>
259
- <div class="section">
260
- <p>An ageing rock band was planning its (hopefully) last european tour. They were planning to visite 15 european cities: Barcelona, Berlin, Brussels, Dublin, Hamburg, Kiev, London, Madrid, Milan, Moscow, Munich, Paris, Rome, Vienna, and Warsaw.</p>
261
- <p>
262
- <img alt="European Tour" src="images/europe2.png"></p>
263
- <p>They start planning the trip, when they realize that they could save a lot of money, if they ordered the cities to minimize the traveling cost. So they decided to try all possible combinations. The sat in front of the computer, visited they favorite traveling site, and started typing. 53 hours and several liters of coffee later, they realized it was a little bit more complicated than what they expected. They called their drummer (who was on vacations) and explained the problem to him. Fortunately, their drummer had a Master in Computer Science degree.</p>
264
- <p>
265
- <em><strong>Drummer</strong> &ndash; Boys, if you continue, you will have to try 1,307,674,368,000 combinations. You are in front of a NP Problem.</em>
266
-
267
- </p>
268
- <p>
269
- <em><strong>Band member #1</strong> &ndash; Oh man! So it is going to take us all day!</em>
270
-
271
- </p>
272
- <p>
273
- <em><strong>Band member #2</strong> &ndash; And maybe more, 'cause this internet connection sucks...</em>
274
-
275
- </p>
276
- <p>
277
- <em><strong>Drummer</strong> &ndash; err... yes, it would take a while. But don't worry, I am sure we can get to a good solution using stochastic search algorithms applied to this problem..</em>
278
-
279
- </p>
280
- <p>
281
- <em><strong>Band</strong> &ndash; (Silence)</em>
282
-
283
- </p>
284
- <p>
285
- <em><strong>Drummer</strong> &ndash; .. that is, we are going to move from solution to solution in the space of candidate solutions, using techniques similar to what nature use for evolution, these are known as genetic algorithms.</em>
286
-
287
- </p>
288
- <p>
289
- <em><strong>Band</strong> &ndash; (Silence)</em>
290
-
291
- </p>
292
- <p>
293
- <em><strong>Drummer</strong> - ... What I mean is, we will pick some of them randomly, leave the ugly ones behind, and mate with the good looking ones...</em>
294
-
295
- </p>
296
- <p>
297
- <em><strong>Band</strong> &ndash; YEAH! THAT'S THE MAN! LET'S DO IT!</em>
298
-
299
- </p>
300
- <p>I forgot to tell another restriction of this problem: This band is really bad (What did you expect? Their drummer is a computer geek!) so once they visited a city, they cannot go back there.
301
- </p>
302
- </div>
303
-
304
-
305
-
306
- <a name="N10098"></a><a name="Results"></a>
307
- <h2 class="boxed">Results of using Genetic Algorithms to the The European Rock Tour Problem (or Travelling salesman problem)</h2>
308
- <div class="section">
309
- <p>The cost of 3 randomly selected tours:</p>
310
- <ul>
311
-
312
- <li>$17486.01 : Madrid Vienna Moscow Berlin Brussels Munich Milan Barcelona London Hamburg Warsaw Dublin Kiev Paris Rome</li>
313
-
314
- <li>$20198.92 : London Rome Brussels Kiev Hamburg Warsaw Barcelona Paris Munich Dublin Vienna Moscow Madrid Milan Berlin</li>
315
-
316
- <li>$17799.34 : Madrid Milan Kiev Vienna Warsaw London Barcelona Hamburg Paris Munich Dublin Berlin Moscow Rome Brussels</li>
317
-
318
- </ul>
319
- <p>3 tours obtained with an initial population of 800, and after 100 generations:</p>
320
- <ul>
321
-
322
- <li>$7611.99 : Moscow Kiev Warsaw Hamburg Berlin Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin</li>
323
-
324
- <li>$7596.74 : Moscow Kiev Warsaw Berlin Hamburg Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin (See Image)</li>
325
-
326
- <li>$7641.61 : Madrid Barcelona Rome Milan Paris Dublin London Brussels Hamburg Berlin Vienna Munich Warsaw Kiev Moscow</li>
327
-
328
- </ul>
329
- <p>
330
- <img alt="Best tour result using Genetic Algorithms in ruby" src="images/europe3.png"></p>
331
- <p>The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you
332
- want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.</p>
333
- </div>
334
-
335
-
336
- <a name="N100C5"></a><a name="chromosome-impl"></a>
337
- <h2 class="boxed">Implementation of Chromosome class for the Travelling salesman problem</h2>
338
- <div class="section">
339
- <p>Although the GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms, the Chromosome class is problem specific.</p>
340
- <a name="N100CE"></a><a name="chromosome-impl-data"></a>
341
- <h3 class="boxed">Data representation</h3>
342
- <p>Each chromosome must represent a posible solution for the problem. This class conatins an array
343
- with the list of visited nodes (cities of the tour). The size of the tour is obtained automatically from the traveling costs matrix. You have to assign the costs matrix BEFORE you run the genetic search. The following costs matrix could be used to solve the problem with only 3 cities:</p>
344
- <pre class="code">
345
-
346
- data_set = [ [ 0, 10, 5],
347
- [ 6, 0, 4],
348
- [25, 4, 0]
349
- ]
350
- GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
351
-
352
- </pre>
353
- <a name="N100DC"></a><a name="chromosome-impl-fitness"></a>
354
- <h3 class="boxed">Fitness function</h3>
355
- <p>The fitness function quantifies the optimality of a solution (that is, a chromosome) in a genetic algorithm so that that particular chromosome may be ranked against all the other chromosomes.
356
- Optimal chromosomes, or at least chromosomes which are more optimal, are allowed to breed and mix their datasets by any of several techniques, producing a new generation that will (hopefully) be even better.</p>
357
- <p>The fitness function will return the complete tour cost represented by the chromosome, multiplied by -1.
358
- For example:</p>
359
- <pre class="code">
360
-
361
- data_set = [ [ 0, 10, 5],
362
- [ 6, 0, 4],
363
- [25, 4, 0]
364
- ]
365
- GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
366
- chromosome = GeneticAlgorithm::Chromosome.new([0, 2, 1])
367
- chromosome.fitness
368
- # =&gt; -9
369
-
370
- </pre>
371
- <p>That is: From 0 to 2 costs 5. From 2 to 1 costs 4. Total cost is 9.</p>
372
- <a name="N100F0"></a><a name="chromosome-impl-reproduce"></a>
373
- <h3 class="boxed">Reproduce function</h3>
374
- <p>Reproduction 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.</p>
375
- <p>
376
- <img alt="Edge recombination" src="images/ero.gif"></p>
377
- <p>The previous image was taken from the wikipedia, so hail to the author: Koala man (not me).</p>
378
- <a name="N10102"></a><a name="chromosome-impl-mutation"></a>
379
- <h3 class="boxed">Mutation function</h3>
380
- <p>Mutation 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.</p>
381
- <pre class="code">
382
-
383
- def self.mutate(chromosome)
384
- if chromosome.normalized_fitness &amp;&amp; rand &lt; ((1 - chromosome.normalized_fitness) * 0.3)
385
- data = chromosome.data
386
- index = rand(data.length-1)
387
- data[index], data[index+1] = data[index+1], data[index]
388
- chromosome.data = data
389
- @fitness = nil
390
- end
391
- end
392
-
393
- </pre>
394
- <a name="N10110"></a><a name="chromosome-impl-seed"></a>
395
- <h3 class="boxed">Seed function</h3>
396
- <p>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).</p>
397
- <pre class="code">
398
-
399
- def self.seed
400
- data_size = @@costs[0].length
401
- available = []
402
- 0.upto(data_size-1) { |n| available &lt;&lt; n }
403
- seed = []
404
- while available.length &gt; 0 do
405
- index = rand(available.length)
406
- seed &lt;&lt; available.delete_at(index)
407
- end
408
- return Chromosome.new(seed)
409
- end
410
-
411
- </pre>
412
- </div>
413
-
414
-
415
- <a name="N1011F"></a><a name="search-impl"></a>
416
- <h2 class="boxed">Implementation of GeneticSearch</h2>
417
- <div class="section">
418
- <p>The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you
419
- want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.</p>
420
- <a name="N10128"></a><a name="search-impl-init"></a>
421
- <h3 class="boxed">Initialize the search</h3>
422
- <p>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.</p>
423
- <pre class="code">
424
-
425
- search = GeneticAlgorithm::GeneticSearch.new(10, 20)
426
- result = search.run
427
-
428
- </pre>
429
- <a name="N10136"></a><a name="search-impl-run"></a>
430
- <h3 class="boxed">Run method</h3>
431
- <p>Once you initialize an instance of GeneticSearch class, you can perform the search executing the run method.
432
- This method will:</p>
433
- <ol>
434
-
435
- <li>Choose initial population</li>
436
-
437
- <li>Evaluate the fitness of each individual in the population</li>
438
-
439
- <li>Repeat as many times as generations we allow
440
- <ol>
441
-
442
- <li>Select randomly the best-ranking individuals to reproduce</li>
443
-
444
- <li>Breed new generation through crossover and mutation (genetic operations) and give birth to offspring</li>
445
-
446
- <li>Evaluate the individual fitnesses of the offspring</li>
447
-
448
- <li>Replace worst ranked part of population with offspring</li>
449
-
450
- </ol>
451
-
452
- </li>
453
-
454
- </ol>
455
- <a name="N1015B"></a><a name="search-impl-selection"></a>
456
- <h3 class="boxed">Selection</h3>
457
- <p>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.</p>
458
- <ol>
459
-
460
- <li>The fitness function is evaluated for each individual, providing fitness values</li>
461
-
462
- <li>The population is sorted by descending fitness values.</li>
463
-
464
- <li>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.</li>
465
-
466
- <li> A random number R is chosen. R is between 0 and the accumulated normalized value (all the normalized fitness values added togheter).</li>
467
-
468
- <li>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.</li>
469
-
470
- <li>We repeat steps 4 and 5, 2/3 times the population size.</li>
471
-
472
- </ol>
473
- <p>
474
- <img alt="Edge recombination" src="images/fitness.png"></p>
475
- <p>The previous image was taken from the wikipedia, so hail to the author: Simon Hatthon.</p>
476
- <a name="N10182"></a><a name="search-impl-reproduction"></a>
477
- <h3 class="boxed">Reproduction</h3>
478
- <p>The reproduction function combines each pair of selected chromosomes using the method Chromosome.reproduce.</p>
479
- <p>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: </p>
480
- <pre class="code">
481
-
482
- rand &lt; ((1 - chromosome.normalized_fitness) * 0.4)
483
-
484
- </pre>
485
- </div>
486
-
487
-
488
-
489
- <a name="N10194"></a><a name="example-run"></a>
490
- <h2 class="boxed">How to run the example</h2>
491
- <div class="section">
492
- <p>You can run the example with "ruby genetic_algorithm_example.rb". The genetic_algorithm_example.rb file
493
- contains:</p>
494
- <pre class="code">
495
-
496
- require File.dirname(__FILE__) + '/../../lib/genetic_algorithm/genetic_algorithm'
497
- require 'csv'
498
-
499
- # Load data from data_set.csv
500
- data_set = []
501
- CSV::Reader.parse(File.open("#{File.dirname(__FILE__)}/travel_cost.csv", 'r')) do |row|
502
- data_set &lt;&lt; row
503
- end
504
- data_labels = data_set.shift
505
- data_set.collect! do |column|
506
- column.collect { |element| element.to_f}
507
- end
508
-
509
- GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
510
-
511
- puts "Beginning genetic search, please wait... "
512
- search = GeneticAlgorithm::GeneticSearch.new(800, 100)
513
- result = search.run
514
- puts "Result cost: #{result.fitness}"
515
- puts "Result tour: "
516
- result.data.each { |c| print " #{data_labels[c]}"}
517
-
518
- </pre>
519
- </div>
520
-
521
-
522
- <a name="N101A2"></a><a name="more-genetic-run"></a>
523
- <h2 class="boxed">More about Genetic Algorithms and the Travelling salesman problem</h2>
524
- <div class="section">
525
- <p>
526
- <a href="http://en.wikipedia.org/wiki/Traveling_salesman_problem" title="Link to Wikipedia">Travelling salesman problem at Wikipedia</a>
527
- </p>
528
- <p>
529
- <a href="http://en.wikipedia.org/wiki/Genetic_algorithm" title="Link to Wikipedia">Genetic Algorithms at Wikipedia</a>
530
- </p>
531
- </div>
532
-
533
- </div>
534
- <!--+
535
- |end content
536
- +-->
537
- <div class="clearboth">&nbsp;</div>
538
- </div>
539
- <div id="footer">
540
- <!--+
541
- |start bottomstrip
542
- +-->
543
- <div class="lastmodified">
544
- <script type="text/javascript"><!--
545
- document.write("Last Published: " + document.lastModified);
546
- // --></script>
547
- </div>
548
- <div class="copyright">
549
- Copyright &copy;
550
- 2007-2008 Sergio Fierens</div>
551
- <div class="host">
552
- <a href="http://rubyforge.org/projects/ai4r/"><img class="logoImage" alt="" src="images/rubyforge.png"></a>
553
- </div>
554
- <!--+
555
- |end bottomstrip
556
- +-->
557
- </div>
558
- <script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script><script type="text/javascript">
559
- var pageTracker = _gat._getTracker("UA-3234625-1");
560
- pageTracker._initData();
561
- pageTracker._trackPageview();
562
- </script>
563
- </body>
564
- </html>