ai4r 1.5 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. data/examples/clusterers/simple_website_clustering.rb +47 -0
  2. data/lib/ai4r.rb +7 -0
  3. data/lib/ai4r/classifiers/hyperpipes.rb +118 -0
  4. data/lib/ai4r/clusterers/average_linkage.rb +22 -23
  5. data/lib/ai4r/clusterers/centroid_linkage.rb +66 -0
  6. data/lib/ai4r/clusterers/complete_linkage.rb +17 -12
  7. data/lib/ai4r/clusterers/diana.rb +139 -0
  8. data/lib/ai4r/clusterers/median_linkage.rb +61 -0
  9. data/lib/ai4r/clusterers/single_linkage.rb +57 -42
  10. data/lib/ai4r/clusterers/ward_linkage.rb +64 -0
  11. data/lib/ai4r/clusterers/weighted_average_linkage.rb +61 -0
  12. data/lib/ai4r/data/constants.rb +18 -0
  13. data/lib/ai4r/data/data_set.rb +5 -3
  14. data/lib/ai4r/data/proximity.rb +18 -0
  15. data/test/clusterers/average_linkage_test.rb +14 -11
  16. data/test/clusterers/bisecting_k_means_test.rb +9 -0
  17. data/test/clusterers/centroid_linkage_test.rb +50 -0
  18. data/test/clusterers/complete_linkage_test.rb +14 -5
  19. data/test/clusterers/diana_test.rb +69 -0
  20. data/test/clusterers/k_means_test.rb +9 -0
  21. data/test/clusterers/median_linkage_test.rb +50 -0
  22. data/test/clusterers/single_linkage_test.rb +15 -6
  23. data/test/clusterers/ward_linkage_test.rb +50 -0
  24. data/test/clusterers/weighted_average_linkage_test.rb +50 -0
  25. data/test/data/data_set_test.rb +14 -0
  26. data/test/data/proximity_test.rb +10 -0
  27. metadata +87 -298
  28. data/site/build/site/en/broken-links.xml +0 -2
  29. data/site/build/site/en/build/tmp/build-info.xml +0 -5
  30. data/site/build/site/en/build/tmp/plugins-1.xml +0 -212
  31. data/site/build/site/en/build/tmp/plugins-2.xml +0 -252
  32. data/site/build/site/en/build/tmp/projfilters.properties +0 -41
  33. data/site/build/site/en/downloads.html +0 -200
  34. data/site/build/site/en/downloads.pdf +0 -151
  35. data/site/build/site/en/geneticAlgorithms.html +0 -591
  36. data/site/build/site/en/geneticAlgorithms.pdf +0 -934
  37. data/site/build/site/en/images/ai4r-logo.png +0 -0
  38. data/site/build/site/en/images/built-with-forrest-button.png +0 -0
  39. data/site/build/site/en/images/c.png +0 -0
  40. data/site/build/site/en/images/c_wbn.png +0 -0
  41. data/site/build/site/en/images/c_wn.png +0 -0
  42. data/site/build/site/en/images/ero.gif +0 -0
  43. data/site/build/site/en/images/europe2.png +0 -0
  44. data/site/build/site/en/images/europe3.png +0 -0
  45. data/site/build/site/en/images/fitness.png +0 -0
  46. data/site/build/site/en/images/genetic_algorithms_example.png +0 -0
  47. data/site/build/site/en/images/instruction_arrow.png +0 -0
  48. data/site/build/site/en/images/jadeferret.png +0 -0
  49. data/site/build/site/en/images/my_email.png +0 -0
  50. data/site/build/site/en/images/neural_network_example.png +0 -0
  51. data/site/build/site/en/images/rubyforge.png +0 -0
  52. data/site/build/site/en/images/s.png +0 -0
  53. data/site/build/site/en/images/s_wbn.png +0 -0
  54. data/site/build/site/en/images/s_wn.png +0 -0
  55. data/site/build/site/en/images/sigmoid.png +0 -0
  56. data/site/build/site/en/images/t.png +0 -0
  57. data/site/build/site/en/images/t_wbn.png +0 -0
  58. data/site/build/site/en/images/t_wn.png +0 -0
  59. data/site/build/site/en/index.html +0 -390
  60. data/site/build/site/en/index.pdf +0 -657
  61. data/site/build/site/en/linkmap.html +0 -261
  62. data/site/build/site/en/linkmap.pdf +0 -94
  63. data/site/build/site/en/locationmap.xml +0 -72
  64. data/site/build/site/en/machineLearning.html +0 -340
  65. data/site/build/site/en/machineLearning.pdf +0 -337
  66. data/site/build/site/en/neuralNetworks.html +0 -521
  67. data/site/build/site/en/neuralNetworks.pdf +0 -671
  68. data/site/build/site/en/skin/CommonMessages_de.xml +0 -23
  69. data/site/build/site/en/skin/CommonMessages_en_US.xml +0 -23
  70. data/site/build/site/en/skin/CommonMessages_es.xml +0 -23
  71. data/site/build/site/en/skin/CommonMessages_fr.xml +0 -23
  72. data/site/build/site/en/skin/basic.css +0 -166
  73. data/site/build/site/en/skin/breadcrumbs-optimized.js +0 -90
  74. data/site/build/site/en/skin/breadcrumbs.js +0 -237
  75. data/site/build/site/en/skin/fontsize.js +0 -166
  76. data/site/build/site/en/skin/getBlank.js +0 -40
  77. data/site/build/site/en/skin/getMenu.js +0 -45
  78. data/site/build/site/en/skin/images/README.txt +0 -1
  79. data/site/build/site/en/skin/images/add.jpg +0 -0
  80. data/site/build/site/en/skin/images/built-with-forrest-button.png +0 -0
  81. data/site/build/site/en/skin/images/chapter.gif +0 -0
  82. data/site/build/site/en/skin/images/chapter_open.gif +0 -0
  83. data/site/build/site/en/skin/images/current.gif +0 -0
  84. data/site/build/site/en/skin/images/error.png +0 -0
  85. data/site/build/site/en/skin/images/external-link.gif +0 -0
  86. data/site/build/site/en/skin/images/fix.jpg +0 -0
  87. data/site/build/site/en/skin/images/forrest-credit-logo.png +0 -0
  88. data/site/build/site/en/skin/images/hack.jpg +0 -0
  89. data/site/build/site/en/skin/images/header_white_line.gif +0 -0
  90. data/site/build/site/en/skin/images/info.png +0 -0
  91. data/site/build/site/en/skin/images/instruction_arrow.png +0 -0
  92. data/site/build/site/en/skin/images/label.gif +0 -0
  93. data/site/build/site/en/skin/images/page.gif +0 -0
  94. data/site/build/site/en/skin/images/pdfdoc.gif +0 -0
  95. data/site/build/site/en/skin/images/poddoc.png +0 -0
  96. data/site/build/site/en/skin/images/printer.gif +0 -0
  97. data/site/build/site/en/skin/images/rc-b-l-15-1body-2menu-3menu.png +0 -0
  98. data/site/build/site/en/skin/images/rc-b-r-15-1body-2menu-3menu.png +0 -0
  99. data/site/build/site/en/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  100. data/site/build/site/en/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png +0 -0
  101. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png +0 -0
  102. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  103. data/site/build/site/en/skin/images/rc-t-r-15-1body-2menu-3menu.png +0 -0
  104. data/site/build/site/en/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png +0 -0
  105. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  106. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  107. data/site/build/site/en/skin/images/remove.jpg +0 -0
  108. data/site/build/site/en/skin/images/rss.png +0 -0
  109. data/site/build/site/en/skin/images/spacer.gif +0 -0
  110. data/site/build/site/en/skin/images/success.png +0 -0
  111. data/site/build/site/en/skin/images/txtdoc.png +0 -0
  112. data/site/build/site/en/skin/images/update.jpg +0 -0
  113. data/site/build/site/en/skin/images/valid-html401.png +0 -0
  114. data/site/build/site/en/skin/images/vcss.png +0 -0
  115. data/site/build/site/en/skin/images/warning.png +0 -0
  116. data/site/build/site/en/skin/images/xmldoc.gif +0 -0
  117. data/site/build/site/en/skin/menu.js +0 -48
  118. data/site/build/site/en/skin/note.txt +0 -50
  119. data/site/build/site/en/skin/print.css +0 -54
  120. data/site/build/site/en/skin/profile.css +0 -163
  121. data/site/build/site/en/skin/prototype.js +0 -1257
  122. data/site/build/site/en/skin/screen.css +0 -587
  123. data/site/build/site/en/sourceCode.html +0 -244
  124. data/site/build/site/en/sourceCode.pdf +0 -278
  125. data/site/build/site/en/svn.html +0 -244
  126. data/site/build/site/en/svn.pdf +0 -278
  127. data/site/build/tmp/brokenlinks.xml +0 -2
  128. data/site/build/tmp/build-info.xml +0 -5
  129. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.data +0 -0
  130. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.index +0 -0
  131. data/site/build/tmp/input.xmap +0 -32
  132. data/site/build/tmp/internal.xmap +0 -32
  133. data/site/build/tmp/locationmap.xml +0 -29
  134. data/site/build/tmp/output.xmap +0 -38
  135. data/site/build/tmp/pluginlist2fetchbuild.xml +0 -144
  136. data/site/build/tmp/plugins-1.xml +0 -201
  137. data/site/build/tmp/plugins-2.xml +0 -401
  138. data/site/build/tmp/projfilters.properties +0 -41
  139. data/site/build/tmp/resources.xmap +0 -32
  140. data/site/build/webapp/WEB-INF/logs/access.log +0 -0
  141. data/site/build/webapp/WEB-INF/logs/core.log +0 -775
  142. data/site/build/webapp/WEB-INF/logs/debug.log +0 -0
  143. data/site/build/webapp/WEB-INF/logs/error.log +0 -213
  144. data/site/build/webapp/WEB-INF/logs/flow.log +0 -0
  145. data/site/build/webapp/WEB-INF/logs/idgen.log +0 -0
  146. data/site/build/webapp/WEB-INF/logs/linkrewriter.log +0 -0
  147. data/site/build/webapp/WEB-INF/logs/locationmap.log +0 -0
  148. data/site/build/webapp/WEB-INF/logs/sitemap.log +0 -0
  149. data/site/build/webapp/WEB-INF/logs/xmlform.log +0 -0
  150. data/site/forrest.properties +0 -152
  151. data/site/forrest.properties.dispatcher.properties +0 -25
  152. data/site/forrest.properties.xml +0 -29
  153. data/site/src/documentation/README.txt +0 -7
  154. data/site/src/documentation/classes/CatalogManager.properties +0 -62
  155. data/site/src/documentation/content/locationmap.xml +0 -72
  156. data/site/src/documentation/content/xdocs/downloads.html +0 -9
  157. data/site/src/documentation/content/xdocs/geneticAlgorithms.xml +0 -294
  158. data/site/src/documentation/content/xdocs/index.xml +0 -129
  159. data/site/src/documentation/content/xdocs/machineLearning.xml +0 -131
  160. data/site/src/documentation/content/xdocs/neuralNetworks.xml +0 -270
  161. data/site/src/documentation/content/xdocs/site.xml +0 -54
  162. data/site/src/documentation/content/xdocs/sourceCode.xml +0 -43
  163. data/site/src/documentation/content/xdocs/tabs.xml +0 -35
  164. data/site/src/documentation/resources/images/ai4r-logo.png +0 -0
  165. data/site/src/documentation/resources/images/c.png +0 -0
  166. data/site/src/documentation/resources/images/c_wbn.png +0 -0
  167. data/site/src/documentation/resources/images/c_wn.png +0 -0
  168. data/site/src/documentation/resources/images/ellipse-2.svg +0 -30
  169. data/site/src/documentation/resources/images/ero.gif +0 -0
  170. data/site/src/documentation/resources/images/europe2.png +0 -0
  171. data/site/src/documentation/resources/images/europe3.png +0 -0
  172. data/site/src/documentation/resources/images/fitness.png +0 -0
  173. data/site/src/documentation/resources/images/genetic_algorithms_example.png +0 -0
  174. data/site/src/documentation/resources/images/icon-a.png +0 -0
  175. data/site/src/documentation/resources/images/icon-b.png +0 -0
  176. data/site/src/documentation/resources/images/icon.png +0 -0
  177. data/site/src/documentation/resources/images/jadeferret.png +0 -0
  178. data/site/src/documentation/resources/images/my_email.png +0 -0
  179. data/site/src/documentation/resources/images/neural_network_example.png +0 -0
  180. data/site/src/documentation/resources/images/project-logo.png +0 -0
  181. data/site/src/documentation/resources/images/rubyforge.png +0 -0
  182. data/site/src/documentation/resources/images/s.png +0 -0
  183. data/site/src/documentation/resources/images/s_wbn.png +0 -0
  184. data/site/src/documentation/resources/images/s_wn.png +0 -0
  185. data/site/src/documentation/resources/images/sigmoid.png +0 -0
  186. data/site/src/documentation/resources/images/sub-dir/icon-c.png +0 -0
  187. data/site/src/documentation/resources/images/t.png +0 -0
  188. data/site/src/documentation/resources/images/t_wbn.png +0 -0
  189. data/site/src/documentation/resources/images/t_wn.png +0 -0
  190. data/site/src/documentation/resources/schema/catalog.xcat +0 -29
  191. data/site/src/documentation/resources/schema/hello-v10.dtd +0 -51
  192. data/site/src/documentation/resources/schema/symbols-project-v10.ent +0 -26
  193. data/site/src/documentation/resources/stylesheets/hello2document.xsl +0 -33
  194. data/site/src/documentation/sitemap.xmap +0 -66
  195. data/site/src/documentation/skinconf.xml +0 -418
  196. data/site/src/documentation/translations/langcode.xml +0 -29
  197. data/site/src/documentation/translations/languages_de.xml +0 -24
  198. data/site/src/documentation/translations/languages_en.xml +0 -24
  199. data/site/src/documentation/translations/languages_es.xml +0 -22
  200. data/site/src/documentation/translations/languages_fr.xml +0 -24
  201. data/site/src/documentation/translations/languages_nl.xml +0 -24
  202. data/site/src/documentation/translations/menu.xml +0 -33
  203. data/site/src/documentation/translations/menu_af.xml +0 -33
  204. data/site/src/documentation/translations/menu_de.xml +0 -33
  205. data/site/src/documentation/translations/menu_es.xml +0 -33
  206. data/site/src/documentation/translations/menu_fr.xml +0 -33
  207. data/site/src/documentation/translations/menu_it.xml +0 -33
  208. data/site/src/documentation/translations/menu_nl.xml +0 -33
  209. data/site/src/documentation/translations/menu_no.xml +0 -33
  210. data/site/src/documentation/translations/menu_ru.xml +0 -33
  211. data/site/src/documentation/translations/menu_sk.xml +0 -33
  212. data/site/src/documentation/translations/tabs.xml +0 -22
  213. data/site/src/documentation/translations/tabs_de.xml +0 -22
  214. data/site/src/documentation/translations/tabs_es.xml +0 -22
  215. data/site/src/documentation/translations/tabs_fr.xml +0 -22
  216. data/site/src/documentation/translations/tabs_nl.xml +0 -22
@@ -1,72 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!--
3
- Licensed to the Apache Software Foundation (ASF) under one or more
4
- contributor license agreements. See the NOTICE file distributed with
5
- this work for additional information regarding copyright ownership.
6
- The ASF licenses this file to You under the Apache License, Version 2.0
7
- (the "License"); you may not use this file except in compliance with
8
- the License. You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- -->
18
- <locationmap xmlns="http://apache.org/forrest/locationmap/1.0">
19
- <components>
20
- <matchers default="lm">
21
- <matcher name="lm" src="org.apache.forrest.locationmap.WildcardLocationMapHintMatcher"/>
22
- </matchers>
23
- <!--
24
- * Can contain any sitemap selector with the following syntax. *
25
- <selectors default="exists">
26
- <selector name="exists" logger="sitemap.selector.exists"
27
- src="org.apache.forrest.sourceexists.SourceExistsSelector" />
28
- </selectors>
29
- -->
30
- </components>
31
- <!--
32
- * Can contain a mount statement as a sibling to components and locator *
33
- <mount src="somelocation.xml"/>
34
- -->
35
- <locator>
36
- <!--
37
- * Can contain a mount within a selector where a selector is valid.
38
- <select>
39
- <mount src="somelocation.xml"/>
40
- </select>
41
- -->
42
- <match pattern="project.rewrite.**">
43
- <location src="http://cocoon.apache.org/{1}.html"/>
44
- </match>
45
- <match pattern="project.remote.**.xml">
46
- <location src="http://svn.apache.org/repos/asf/forrest/trunk/main/fresh-site/src/documentation/content/xdocs/{1}.xml"/>
47
- </match>
48
- <!--
49
- * Can use a selector inside a match. *
50
- <match pattern="somepattern/**">
51
- <select>
52
- <location src="first-location-attempted"/>
53
- <location src="second-location-attempted"/>
54
- <location src="third-location-attepted"/>
55
- </select>
56
- </match>
57
- -->
58
- <!--
59
- To locate all your source documents in a slide repository you can do:
60
-
61
- <match pattern="tabs.xml">
62
- <location src="http://127.0.0.1:8080/slide/files/tabs.xml"/>
63
- </match>
64
- <match pattern="site.xml">
65
- <location src="http://127.0.0.1:8080/slide/files/site.xml"/>
66
- </match>
67
- <match pattern="**.xml">
68
- <location src="http://127.0.0.1:8080/slide/files/{1}.xml"/>
69
- </match>
70
- -->
71
- </locator>
72
- </locationmap>
@@ -1,9 +0,0 @@
1
- <html>
2
- <head>
3
- <title>Artificial intelligence for ruby :: ai4r :: download page at RubyForge</title>
4
- </head>
5
- <body>
6
- <h1><a name="intro" />Artificial intelligence for ruby - ai4r - download page at RubyForge</h1>
7
- <iframe width="100%" height="800px" frameborder="0" src="http://rubyforge.org/frs/?group_id=4942" />
8
- </body>
9
- </html>
@@ -1,294 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
3
- <document>
4
- <header>
5
- <title>Genetics Algorithms in Ruby :: ai4r</title>
6
- </header>
7
- <body>
8
- <section id="Example">
9
- <title>The European Rock Tour Problem (Also known as the Travelling salesman problem)</title>
10
- <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>
11
- <p><img src="images/europe2.png" alt="European Tour" /></p>
12
- <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>
13
- <p><em><strong>Drummer</strong> – Boys, if you continue, you will have to try 1,307,674,368,000 combinations. You are in front of a NP Problem.</em>
14
- </p>
15
- <p><em><strong>Band member #1</strong> – Oh man! So it is going to take us all day!</em>
16
- </p>
17
- <p><em><strong>Band member #2</strong> – And maybe more, 'cause this internet connection sucks...</em>
18
- </p>
19
- <p><em><strong>Drummer</strong> – 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>
20
- </p>
21
- <p><em><strong>Band</strong> – (Silence)</em>
22
- </p>
23
- <p><em><strong>Drummer</strong> – .. 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>
24
- </p>
25
- <p><em><strong>Band</strong> – (Silence)</em>
26
- </p>
27
- <p><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>
28
- </p>
29
- <p><em><strong>Band</strong> – YEAH! THAT'S THE MAN! LET'S DO IT!</em>
30
- </p>
31
- <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.
32
- </p>
33
- </section>
34
-
35
- <section id="Introduction">
36
- <title>Introduction to Genetics Algorithms in Ruby</title>
37
- <p>A Genetic Algorithm is a particular class of evolutionary algorithm and stochastic search.
38
- It aims to find the best possible solution in a solution domain, by selecting a simple
39
- set of solutions (chosed randomly or with a simple heuristic), and making it "evolve".
40
- </p>
41
- <p>It works based on the following pseudocode:</p>
42
- <ol>
43
- <li>Choose initial population</li>
44
- <li>Evaluate the fitness of each individual in the population</li>
45
- <li>Repeat as many times as generations we allow
46
- <ol>
47
- <li>Select randomly best-ranking individuals to reproduce</li>
48
- <li>Breed new generation through crossover and mutation (genetic operations) and give birth to offspring</li>
49
- <li>Evaluate the individual fitnesses of the offspring</li>
50
- <li>Replace worst ranked part of population with offspring</li>
51
- </ol>
52
- </li>
53
- </ol>
54
- </section>
55
-
56
- <section id="chromosome-impl">
57
- <title>Implementation of Chromosome class for the Travelling salesman problem</title>
58
- <p>In AI4R, the GeneticAlgorithm module implements the GeneticSearch and Chromosome classes.
59
- GeneticSearch is a generic class, and can be used to solved any kind of problems.
60
- The GeneticSearch class performs a stochastic search following the algorithm mentioned in the
61
- previous section.
62
- </p>
63
- <p>
64
- However, the Chromosome class implementation is problem specific.
65
- Ai4r built-in Chromosomeclass was designed to model the
66
- <a href="http://en.wikipedia.org/wiki/Traveling_salesman_problem" title="Link to Wikipedia">
67
- Travelling salesman problem.
68
- </a>
69
- You have to provide a matrix with the cost of traveling from one point to another
70
- (array of arrays of float values).
71
- If you want to solve other type of problem, you will have to modify the Chromosome class,
72
- by overwriting its fitness, reproduce, and mutate functions, to model you specific problem.
73
- </p>
74
- <section id="chromosome-impl-data">
75
- <title>Data representation</title>
76
- <p>Each chromosome must represent a posible solution for the problem. This class conatins an array
77
- 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>
78
- <source>
79
- <![CDATA[
80
- data_set = [ [ 0, 10, 5],
81
- [ 6, 0, 4],
82
- [25, 4, 0]
83
- ]
84
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
85
- ]]>
86
- </source>
87
- </section>
88
- <section id="chromosome-impl-fitness">
89
- <title>Fitness function</title>
90
- <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.
91
- 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>
92
- <p>The fitness function will return the complete tour cost represented by the chromosome, multiplied by -1.
93
- For example:</p>
94
-
95
- <source>
96
- <![CDATA[
97
- data_set = [ [ 0, 10, 5],
98
- [ 6, 0, 4],
99
- [25, 4, 0]
100
- ]
101
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
102
- chromosome = Ai4r::GeneticAlgorithm::Chromosome.new([0, 2, 1])
103
- chromosome.fitness
104
- # => -9
105
- ]]>
106
- </source>
107
- <p>That is: From 0 to 2 costs 5. From 2 to 1 costs 4. Total cost is 9.</p>
108
- </section>
109
- <section id="chromosome-impl-reproduce">
110
- <title>Reproduce function</title>
111
- <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>
112
- <p><img src="images/ero.gif" alt="Edge recombination" /></p>
113
- <p>The previous image was taken from the wikipedia, so hail to the author: Koala man (not me).</p>
114
- </section>
115
- <section id="chromosome-impl-mutation">
116
- <title>Mutation function</title>
117
- <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>
118
- <source>
119
- <![CDATA[
120
- def self.mutate(chromosome)
121
- if chromosome.normalized_fitness && rand < ((1 - chromosome.normalized_fitness) * 0.3)
122
- data = chromosome.data
123
- index = rand(data.length-1)
124
- data[index], data[index+1] = data[index+1], data[index]
125
- chromosome.data = data
126
- @fitness = nil
127
- end
128
- end
129
- ]]>
130
- </source>
131
- </section>
132
- <section id="chromosome-impl-seed">
133
- <title>Seed function</title>
134
- <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>
135
- <source>
136
- <![CDATA[
137
- def self.seed
138
- data_size = @@costs[0].length
139
- available = []
140
- 0.upto(data_size-1) { |n| available << n }
141
- seed = []
142
- while available.length > 0 do
143
- index = rand(available.length)
144
- seed << available.delete_at(index)
145
- end
146
- return Chromosome.new(seed)
147
- end
148
- ]]>
149
- </source>
150
- </section>
151
- </section>
152
-
153
- <section id="search-impl">
154
- <title>Implementation of GeneticSearch</title>
155
- <p>The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you
156
- want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.</p>
157
-
158
- <section id="search-impl-init">
159
-
160
- <title>Initialize the search</title>
161
- <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>
162
- <source>
163
- <![CDATA[
164
- search = Ai4r::GeneticAlgorithm::GeneticSearch.new(10, 20)
165
- result = search.run
166
- ]]>
167
- </source>
168
- </section>
169
- <section id="search-impl-run">
170
- <title>Run method</title>
171
- <p>Once you initialize an instance of GeneticSearch class, you can perform the search executing the run method.
172
- This method will:</p>
173
- <ol>
174
- <li>Choose initial population</li>
175
- <li>Evaluate the fitness of each individual in the population</li>
176
- <li>Repeat as many times as generations we allow
177
- <ol>
178
- <li>Select randomly the best-ranking individuals to reproduce</li>
179
- <li>Breed new generation through crossover and mutation (genetic operations) and give birth to offspring</li>
180
- <li>Evaluate the individual fitnesses of the offspring</li>
181
- <li>Replace worst ranked part of population with offspring</li>
182
- </ol>
183
- </li>
184
- </ol>
185
- </section>
186
-
187
- <section id="search-impl-selection">
188
- <title>Selection</title>
189
- <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>
190
- <ol>
191
- <li>The fitness function is evaluated for each individual, providing fitness values</li>
192
- <li>The population is sorted by descending fitness values.</li>
193
- <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>
194
- <li> A random number R is chosen. R is between 0 and the accumulated normalized value (all the normalized fitness values added togheter).</li>
195
- <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>
196
- <li>We repeat steps 4 and 5, 2/3 times the population size.</li>
197
- </ol>
198
- <p><img src="images/fitness.png" alt="Edge recombination" /></p>
199
- <p>The previous image was taken from the wikipedia, so hail to the author: Simon Hatthon.</p>
200
- </section>
201
-
202
-
203
- <section id="search-impl-reproduction">
204
- <title>Reproduction</title>
205
- <p>The reproduction function combines each pair of selected chromosomes using the method Chromosome.reproduce.</p>
206
- <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>
207
- <source>
208
- <![CDATA[
209
- rand < ((1 - chromosome.normalized_fitness) * 0.4)
210
- ]]>
211
- </source>
212
- </section>
213
-
214
-
215
- </section>
216
- <section id="how-to-run">
217
- <title>How to use AI4R Genetic Search implementation</title>
218
- <source>
219
- <![CDATA[
220
- #Cost of traveling from one point to another. E.g. Travelling from Node 0 to Node 2 costs 5.
221
- data_set = [ [ 0, 10, 5],
222
- [ 6, 0, 4],
223
- [25, 4, 0]
224
- ]
225
-
226
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
227
-
228
- search = Ai4r::GeneticAlgorithm::GeneticSearch.new(10, 20)
229
- result = search.run
230
- puts "Result cost: #{result.fitness}"
231
- puts "Result nodes: #{result.data.inspect}"
232
- ]]>
233
- </source>
234
- </section>
235
-
236
- <section id="example-run">
237
- <title>How to run the example</title>
238
- <p>You can run the example with "ruby genetic_algorithm_example.rb". The genetic_algorithm_example.rb file
239
- contains:</p>
240
- <source>
241
- <![CDATA[
242
- require "rubygems"
243
- require "ai4r/genetic_algorithm/genetic_algorithm"
244
- require "csv"
245
-
246
- # Load data from data_set.csv
247
- data_set = []
248
- CSV::Reader.parse(File.open("#{File.dirname(__FILE__)}/travel_cost.csv", 'r')) do |row|
249
- data_set << row
250
- end
251
- data_labels = data_set.shift
252
- data_set.collect! do |column|
253
- column.collect { |element| element.to_f}
254
- end
255
-
256
- Ai4r::GeneticAlgorithm::Chromosome.set_cost_matrix(data_set)
257
-
258
- puts "Beginning genetic search, please wait... "
259
- search = Ai4r::GeneticAlgorithm::GeneticSearch.new(800, 100)
260
- result = search.run
261
- puts "Result cost: #{result.fitness}"
262
- puts "Result tour: "
263
- result.data.each { |c| print " #{data_labels[c]}"}
264
- ]]>
265
- </source>
266
-
267
- </section>
268
-
269
- <section id="Results">
270
- <title>Results of using Genetic Algorithms to the The European Rock Tour Problem (or Travelling salesman problem)</title>
271
- <p>The cost of 3 randomly selected tours:</p>
272
- <ul>
273
- <li>$17486.01 : Madrid Vienna Moscow Berlin Brussels Munich Milan Barcelona London Hamburg Warsaw Dublin Kiev Paris Rome</li>
274
- <li>$20198.92 : London Rome Brussels Kiev Hamburg Warsaw Barcelona Paris Munich Dublin Vienna Moscow Madrid Milan Berlin</li>
275
- <li>$17799.34 : Madrid Milan Kiev Vienna Warsaw London Barcelona Hamburg Paris Munich Dublin Berlin Moscow Rome Brussels</li>
276
- </ul>
277
- <p>3 tours obtained with an initial population of 800, and after 100 generations:</p>
278
- <ul>
279
- <li>$7611.99 : Moscow Kiev Warsaw Hamburg Berlin Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin</li>
280
- <li>$7596.74 : Moscow Kiev Warsaw Berlin Hamburg Munich Vienna Milan Rome Barcelona Madrid Paris Brussels London Dublin (See Image)</li>
281
- <li>$7641.61 : Madrid Barcelona Rome Milan Paris Dublin London Brussels Hamburg Berlin Vienna Munich Warsaw Kiev Moscow</li>
282
- </ul>
283
- <p><img src="images/europe3.png" alt="Best tour result using Genetic Algorithms in ruby" /></p>
284
- <p>The GeneticSearch class is an generic class to try to solve any kind of problem using genetic algorithms. If you
285
- want to model another type of problem, you will have to modify the Chromosome class, defining its fitness, mutate, and reproduce functions.</p>
286
- </section>
287
-
288
- <section id="more-genetic-run">
289
- <title>More about Genetic Algorithms and the Travelling salesman problem</title>
290
- <p><a href="http://en.wikipedia.org/wiki/Traveling_salesman_problem" title="Link to Wikipedia">Travelling salesman problem at Wikipedia</a></p>
291
- <p><a href="http://en.wikipedia.org/wiki/Genetic_algorithm" title="Link to Wikipedia">Genetic Algorithms at Wikipedia</a></p>
292
- </section>
293
- </body>
294
- </document>
@@ -1,129 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!--
3
- Licensed to the Apache Software Foundation (ASF) under one or more
4
- contributor license agreements. See the NOTICE file distributed with
5
- this work for additional information regarding copyright ownership.
6
- The ASF licenses this file to You under the Apache License, Version 2.0
7
- (the "License"); you may not use this file except in compliance with
8
- the License. You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- -->
18
- <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
19
- <document>
20
- <header>
21
- <title>AI4R :: Artificial Intelligence for Ruby</title>
22
- </header>
23
- <body>
24
- <section id="Introduction">
25
- <title>Introduction</title>
26
- <p>
27
- AI4R is a collection of ruby algorithms implementations, covering several Artificial
28
- intelligence fields, and simple practical examples using them. It implements:
29
- </p>
30
- <ul>
31
- <li><a href="http://en.wikipedia.org/wiki/Genetic_algorithms">Genetic algorithms</a></li>
32
- <li><a href="http://en.wikipedia.org/wiki/Neural_network">Neural networks (Backpropagation networks)</a></li>
33
- <li><a href="machineLearning.html">Automatic classifiers (Machine Learning)</a>
34
- <ul>
35
- <li><a href="http://en.wikipedia.org/wiki/ID3_algorithm">ID3 (Decision Trees)</a></li>
36
- <li>PRISM (J. Cendrowska, 1987)</li>
37
- <li><a href="http://en.wikipedia.org/wiki/Multilayer_perceptron">Multilayer Perceptron</a></li>
38
- <li><a href="http://en.wikipedia.org/wiki/Association_rule_learning#One-attribute-rule">OneR (AKA One Attribute Rule, 1R)</a></li>
39
- <li><a href="http://en.wikipedia.org/wiki/Association_rule_learning#Zero-attribute-rule">ZeroR</a></li>
40
- </ul>
41
- </li>
42
- <li><a href="http://en.wikipedia.org/wiki/Data_clustering">Data clustering</a>
43
- <ul>
44
- <li><a href="http://en.wikipedia.org/wiki/k_means">K-means algorithm</a></li>
45
- <li><a href="http://en.wikipedia.org/wiki/k_means">Bisecting k-means</a></li>
46
- <li><a href="http://en.wikipedia.org/wiki/Single_linkage_clustering">Single linkage</a></li>
47
- <li><a href="http://en.wikipedia.org/wiki/Cluster_analysis#Agglomerative_hierarchical_clustering">Complete linkage</a></li>
48
- <li><a href="http://en.wikipedia.org/wiki/Cluster_analysis#Agglomerative_hierarchical_clustering">Average linkage</a></li>
49
- </ul>
50
- </li>
51
- </ul>
52
- </section>
53
-
54
- <section id="Examples_offered">
55
- <title>Practical examples</title>
56
- <p>
57
- <strong>Genetic Algorithms</strong><br />
58
- <a href="geneticAlgorithms.html">Optimization of the Travelling salesman problem (NP-hard problem)</a><br />
59
- <a href="geneticAlgorithms.html">
60
- <img src="images/genetic_algorithms_example.png" alt="Genetic Algorithms Example" />
61
- </a>
62
- </p>
63
- <p>
64
- <strong>Neural networks</strong><br />
65
- <a href="neuralNetworks.html">Simple OCR (recognition of visual patterns)</a><br />
66
- <a href="neuralNetworks.html">
67
- <img src="images/neural_network_example.png" alt="Neural Network Example" />
68
- </a>
69
- </p>
70
- <p>
71
- <strong>Automatic classifiers</strong><br />
72
- <a href="machineLearning.html">Automatic identification of relevant marketing targets</a>
73
- </p>
74
-
75
- </section>
76
-
77
- <section id="howtoinstall">
78
- <title>How to install</title>
79
- <p>1. Install the gem:</p>
80
- <source>gem install ai4r</source>
81
- <p>2. Include require statements in your code:</p>
82
- <source>
83
- require "rubygems"
84
- require "ai4r"
85
- </source>
86
- </section>
87
-
88
- <section id="roadmap">
89
- <title>Development Roadmap</title>
90
- <p>
91
- AI4R is an active project. If you are interested about what we are
92
- working on, checkout the
93
- <a href="http://wiki.jadeferret.com/AI4R_RoadMap" title="Ai4r Roadmap">
94
- development roadmap
95
- </a>
96
- </p>
97
- </section>
98
-
99
- <section id="ContactMe">
100
- <title>Contact</title>
101
- <p>
102
- If you have questions or constructive comments about this project,
103
- please post them in the
104
- <a href="http://forum.jadeferret.com/viewforum.php?f=3" title="Ai4r Forum">forum</a>.
105
- I get an email notification when you post, and I do my best to answer as soon as possible.
106
- </p>
107
- <p>
108
- If you do not want to make it public, send it to me:
109
- Sergio Fierens, email address: <img src="images/my_email.png" alt="(sergio (dot) fierens (at) gmail (dot) com)"
110
- title="Sergio Fierens contact email" />. But please, try to post them in the
111
- forum. I get tons of emails and it would be great to make them
112
- public to help everyone.
113
- </p>
114
- <p>
115
- Also, there is an irc channel on Freenode (#AI4R), where developers
116
- discuss the current progress.
117
- </p>
118
- </section>
119
-
120
- <section id="warranty">
121
- <title>Disclaimer Note</title>
122
- <p>
123
- This software is provided "as is" and without any express or implied
124
- warranties, including, without limitation, the implied warranties of
125
- merchantibility and fitness for a particular purpose.
126
- </p>
127
- </section>
128
- </body>
129
- </document>