ai4r 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/README.rdoc +48 -0
  2. data/examples/decision_trees/data_set.csv +121 -0
  3. data/examples/decision_trees/id3_example.rb +31 -0
  4. data/examples/decision_trees/results.txt +29 -0
  5. data/examples/genetic_algorithm/genetic_algorithm_example.rb +39 -0
  6. data/examples/genetic_algorithm/travel_cost.csv +16 -0
  7. data/examples/neural_network/backpropagation_example.rb +65 -0
  8. data/examples/neural_network/patterns_with_base_noise.rb +68 -0
  9. data/examples/neural_network/patterns_with_noise.rb +66 -0
  10. data/examples/neural_network/training_patterns.rb +68 -0
  11. data/lib/decision_tree/id3.rb +354 -0
  12. data/lib/genetic_algorithm/genetic_algorithm.rb +268 -0
  13. data/lib/neural_network/backpropagation.rb +259 -0
  14. data/site/build/site/en/broken-links.xml +2 -0
  15. data/site/build/site/en/downloads.html +187 -0
  16. data/site/build/site/en/downloads.pdf +151 -0
  17. data/site/build/site/en/geneticAlgorithms.html +564 -0
  18. data/site/build/site/en/geneticAlgorithms.pdf +911 -0
  19. data/site/build/site/en/images/ai4r-logo.png +0 -0
  20. data/site/build/site/en/images/built-with-forrest-button.png +0 -0
  21. data/site/build/site/en/images/c.png +0 -0
  22. data/site/build/site/en/images/c_wbn.png +0 -0
  23. data/site/build/site/en/images/c_wn.png +0 -0
  24. data/site/build/site/en/images/ero.gif +0 -0
  25. data/site/build/site/en/images/europe2.png +0 -0
  26. data/site/build/site/en/images/europe3.png +0 -0
  27. data/site/build/site/en/images/fitness.png +0 -0
  28. data/site/build/site/en/images/instruction_arrow.png +0 -0
  29. data/site/build/site/en/images/my_email.png +0 -0
  30. data/site/build/site/en/images/rubyforge.png +0 -0
  31. data/site/build/site/en/images/s.png +0 -0
  32. data/site/build/site/en/images/s_wbn.png +0 -0
  33. data/site/build/site/en/images/s_wn.png +0 -0
  34. data/site/build/site/en/images/sigmoid.png +0 -0
  35. data/site/build/site/en/images/t.png +0 -0
  36. data/site/build/site/en/images/t_wbn.png +0 -0
  37. data/site/build/site/en/images/t_wn.png +0 -0
  38. data/site/build/site/en/index.html +258 -0
  39. data/site/build/site/en/index.pdf +306 -0
  40. data/site/build/site/en/linkmap.html +231 -0
  41. data/site/build/site/en/linkmap.pdf +94 -0
  42. data/site/build/site/en/locationmap.xml +72 -0
  43. data/site/build/site/en/machineLearning.html +325 -0
  44. data/site/build/site/en/machineLearning.pdf +337 -0
  45. data/site/build/site/en/neuralNetworks.html +446 -0
  46. data/site/build/site/en/neuralNetworks.pdf +604 -0
  47. data/site/build/site/en/skin/CommonMessages_de.xml +23 -0
  48. data/site/build/site/en/skin/CommonMessages_en_US.xml +23 -0
  49. data/site/build/site/en/skin/CommonMessages_es.xml +23 -0
  50. data/site/build/site/en/skin/CommonMessages_fr.xml +23 -0
  51. data/site/build/site/en/skin/basic.css +166 -0
  52. data/site/build/site/en/skin/breadcrumbs-optimized.js +90 -0
  53. data/site/build/site/en/skin/breadcrumbs.js +237 -0
  54. data/site/build/site/en/skin/fontsize.js +166 -0
  55. data/site/build/site/en/skin/getBlank.js +40 -0
  56. data/site/build/site/en/skin/getMenu.js +45 -0
  57. data/site/build/site/en/skin/images/README.txt +1 -0
  58. data/site/build/site/en/skin/images/add.jpg +0 -0
  59. data/site/build/site/en/skin/images/built-with-forrest-button.png +0 -0
  60. data/site/build/site/en/skin/images/chapter.gif +0 -0
  61. data/site/build/site/en/skin/images/chapter_open.gif +0 -0
  62. data/site/build/site/en/skin/images/current.gif +0 -0
  63. data/site/build/site/en/skin/images/error.png +0 -0
  64. data/site/build/site/en/skin/images/external-link.gif +0 -0
  65. data/site/build/site/en/skin/images/fix.jpg +0 -0
  66. data/site/build/site/en/skin/images/forrest-credit-logo.png +0 -0
  67. data/site/build/site/en/skin/images/hack.jpg +0 -0
  68. data/site/build/site/en/skin/images/header_white_line.gif +0 -0
  69. data/site/build/site/en/skin/images/info.png +0 -0
  70. data/site/build/site/en/skin/images/instruction_arrow.png +0 -0
  71. data/site/build/site/en/skin/images/label.gif +0 -0
  72. data/site/build/site/en/skin/images/page.gif +0 -0
  73. data/site/build/site/en/skin/images/pdfdoc.gif +0 -0
  74. data/site/build/site/en/skin/images/poddoc.png +0 -0
  75. data/site/build/site/en/skin/images/printer.gif +0 -0
  76. data/site/build/site/en/skin/images/rc-b-l-15-1body-2menu-3menu.png +0 -0
  77. data/site/build/site/en/skin/images/rc-b-r-15-1body-2menu-3menu.png +0 -0
  78. data/site/build/site/en/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  79. data/site/build/site/en/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png +0 -0
  80. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png +0 -0
  81. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  82. data/site/build/site/en/skin/images/rc-t-r-15-1body-2menu-3menu.png +0 -0
  83. data/site/build/site/en/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png +0 -0
  84. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  85. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  86. data/site/build/site/en/skin/images/remove.jpg +0 -0
  87. data/site/build/site/en/skin/images/rss.png +0 -0
  88. data/site/build/site/en/skin/images/spacer.gif +0 -0
  89. data/site/build/site/en/skin/images/success.png +0 -0
  90. data/site/build/site/en/skin/images/txtdoc.png +0 -0
  91. data/site/build/site/en/skin/images/update.jpg +0 -0
  92. data/site/build/site/en/skin/images/valid-html401.png +0 -0
  93. data/site/build/site/en/skin/images/vcss.png +0 -0
  94. data/site/build/site/en/skin/images/warning.png +0 -0
  95. data/site/build/site/en/skin/images/xmldoc.gif +0 -0
  96. data/site/build/site/en/skin/menu.js +48 -0
  97. data/site/build/site/en/skin/note.txt +50 -0
  98. data/site/build/site/en/skin/print.css +54 -0
  99. data/site/build/site/en/skin/profile.css +163 -0
  100. data/site/build/site/en/skin/prototype.js +1257 -0
  101. data/site/build/site/en/skin/screen.css +587 -0
  102. data/site/build/site/en/svn.html +223 -0
  103. data/site/build/site/en/svn.pdf +239 -0
  104. data/site/build/site/en/wholesite.pdf +1686 -0
  105. data/site/build/tmp/brokenlinks.xml +2 -0
  106. data/site/build/tmp/build-info.xml +5 -0
  107. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.data +0 -0
  108. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.index +0 -0
  109. data/site/build/tmp/input.xmap +32 -0
  110. data/site/build/tmp/internal.xmap +32 -0
  111. data/site/build/tmp/locationmap.xml +29 -0
  112. data/site/build/tmp/output.xmap +38 -0
  113. data/site/build/tmp/pluginlist2fetchbuild.xml +144 -0
  114. data/site/build/tmp/plugins-1.xml +212 -0
  115. data/site/build/tmp/plugins-2.xml +347 -0
  116. data/site/build/tmp/projfilters.properties +41 -0
  117. data/site/build/tmp/resources.xmap +32 -0
  118. data/site/build/webapp/WEB-INF/logs/access.log +0 -0
  119. data/site/build/webapp/WEB-INF/logs/core.log +788 -0
  120. data/site/build/webapp/WEB-INF/logs/debug.log +0 -0
  121. data/site/build/webapp/WEB-INF/logs/error.log +248 -0
  122. data/site/build/webapp/WEB-INF/logs/flow.log +0 -0
  123. data/site/build/webapp/WEB-INF/logs/idgen.log +0 -0
  124. data/site/build/webapp/WEB-INF/logs/linkrewriter.log +0 -0
  125. data/site/build/webapp/WEB-INF/logs/locationmap.log +0 -0
  126. data/site/build/webapp/WEB-INF/logs/sitemap.log +0 -0
  127. data/site/build/webapp/WEB-INF/logs/xmlform.log +0 -0
  128. data/site/forrest.properties +152 -0
  129. data/site/forrest.properties.dispatcher.properties +25 -0
  130. data/site/forrest.properties.xml +29 -0
  131. data/site/src/documentation/README.txt +7 -0
  132. data/site/src/documentation/classes/CatalogManager.properties +62 -0
  133. data/site/src/documentation/content/locationmap.xml +72 -0
  134. data/site/src/documentation/content/xdocs/downloads.html +9 -0
  135. data/site/src/documentation/content/xdocs/geneticAlgorithms.xml +280 -0
  136. data/site/src/documentation/content/xdocs/index.xml +73 -0
  137. data/site/src/documentation/content/xdocs/machineLearning.xml +129 -0
  138. data/site/src/documentation/content/xdocs/neuralNetworks.xml +218 -0
  139. data/site/src/documentation/content/xdocs/site.xml +51 -0
  140. data/site/src/documentation/content/xdocs/svn.xml +31 -0
  141. data/site/src/documentation/content/xdocs/tabs.xml +35 -0
  142. data/site/src/documentation/resources/images/ai4r-logo.png +0 -0
  143. data/site/src/documentation/resources/images/c.png +0 -0
  144. data/site/src/documentation/resources/images/c_wbn.png +0 -0
  145. data/site/src/documentation/resources/images/c_wn.png +0 -0
  146. data/site/src/documentation/resources/images/ellipse-2.svg +30 -0
  147. data/site/src/documentation/resources/images/ero.gif +0 -0
  148. data/site/src/documentation/resources/images/europe2.png +0 -0
  149. data/site/src/documentation/resources/images/europe3.png +0 -0
  150. data/site/src/documentation/resources/images/fitness.png +0 -0
  151. data/site/src/documentation/resources/images/icon-a.png +0 -0
  152. data/site/src/documentation/resources/images/icon-b.png +0 -0
  153. data/site/src/documentation/resources/images/icon.png +0 -0
  154. data/site/src/documentation/resources/images/my_email.png +0 -0
  155. data/site/src/documentation/resources/images/project-logo.png +0 -0
  156. data/site/src/documentation/resources/images/rubyforge.png +0 -0
  157. data/site/src/documentation/resources/images/s.png +0 -0
  158. data/site/src/documentation/resources/images/s_wbn.png +0 -0
  159. data/site/src/documentation/resources/images/s_wn.png +0 -0
  160. data/site/src/documentation/resources/images/sigmoid.png +0 -0
  161. data/site/src/documentation/resources/images/sub-dir/icon-c.png +0 -0
  162. data/site/src/documentation/resources/images/t.png +0 -0
  163. data/site/src/documentation/resources/images/t_wbn.png +0 -0
  164. data/site/src/documentation/resources/images/t_wn.png +0 -0
  165. data/site/src/documentation/resources/schema/catalog.xcat +29 -0
  166. data/site/src/documentation/resources/schema/hello-v10.dtd +51 -0
  167. data/site/src/documentation/resources/schema/symbols-project-v10.ent +26 -0
  168. data/site/src/documentation/resources/stylesheets/hello2document.xsl +33 -0
  169. data/site/src/documentation/sitemap.xmap +66 -0
  170. data/site/src/documentation/skinconf.xml +418 -0
  171. data/site/src/documentation/translations/langcode.xml +29 -0
  172. data/site/src/documentation/translations/languages_de.xml +24 -0
  173. data/site/src/documentation/translations/languages_en.xml +24 -0
  174. data/site/src/documentation/translations/languages_es.xml +22 -0
  175. data/site/src/documentation/translations/languages_fr.xml +24 -0
  176. data/site/src/documentation/translations/languages_nl.xml +24 -0
  177. data/site/src/documentation/translations/menu.xml +33 -0
  178. data/site/src/documentation/translations/menu_af.xml +33 -0
  179. data/site/src/documentation/translations/menu_de.xml +33 -0
  180. data/site/src/documentation/translations/menu_es.xml +33 -0
  181. data/site/src/documentation/translations/menu_fr.xml +33 -0
  182. data/site/src/documentation/translations/menu_it.xml +33 -0
  183. data/site/src/documentation/translations/menu_nl.xml +33 -0
  184. data/site/src/documentation/translations/menu_no.xml +33 -0
  185. data/site/src/documentation/translations/menu_ru.xml +33 -0
  186. data/site/src/documentation/translations/menu_sk.xml +33 -0
  187. data/site/src/documentation/translations/tabs.xml +22 -0
  188. data/site/src/documentation/translations/tabs_de.xml +22 -0
  189. data/site/src/documentation/translations/tabs_es.xml +22 -0
  190. data/site/src/documentation/translations/tabs_fr.xml +22 -0
  191. data/site/src/documentation/translations/tabs_nl.xml +22 -0
  192. data/test/decision_tree/id3_test.rb +209 -0
  193. data/test/genetic_algorithm/chromosome_test.rb +55 -0
  194. data/test/genetic_algorithm/genetic_algorithm_test.rb +78 -0
  195. data/test/neural_network/backpropagation_test.rb +44 -0
  196. metadata +274 -0
@@ -0,0 +1,33 @@
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
+ <catalogue xml:lang="sk">
19
+ <message key="About">O programe</message>
20
+ <message key="Index">Zoznám</message>
21
+ <message key="Changes">Zmeny</message>
22
+ <message key="Todo">Úlohy</message>
23
+ <message key="Samples">Príklady</message>
24
+ <message key="Apache document">Apache Document</message>
25
+ <message key="Static content">Statický Obsah</message>
26
+ <message key="Linking">Linking</message>
27
+ <message key="Wiki page">Wiki stránka</message>
28
+ <message key="ihtml page">ihtml stránka</message>
29
+ <message key="ehtml page">ehtml stránka</message>
30
+ <message key="FAQ">Casté Otázky</message>
31
+ <message key="Simplifed Docbook">Simplifed Docbook stránka</message>
32
+ <message key="XSP page">XSP stránka</message>
33
+ </catalogue>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0"?>
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
+ <catalogue xml:lang="en">
19
+ <message key="Home">Home</message>
20
+ <message key="Samples">Samples</message>
21
+ <message key="Apache XML Projects">Apache XML Projects</message>
22
+ </catalogue>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0"?>
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
+ <catalogue xml:lang="de">
19
+ <message key="Home">Home</message>
20
+ <message key="Samples">Beispiele</message>
21
+ <message key="Apache XML Projects">Apache XML Projekte</message>
22
+ </catalogue>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0"?>
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
+ <catalogue xml:lang="es">
19
+ <message key="Home">Inicio</message>
20
+ <message key="Samples">Ejemplos</message>
21
+ <message key="Apache XML Projects">Projectos XML Apache</message>
22
+ </catalogue>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0"?>
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
+ <catalogue xml:lang="fr">
19
+ <message key="Home">Accueil</message>
20
+ <message key="Samples">Exemples</message>
21
+ <message key="Apache XML Projects">Projets Apache XML</message>
22
+ </catalogue>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0"?>
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
+ <catalogue xml:lang="nl">
19
+ <message key="Home">Home</message>
20
+ <message key="Samples">Voorbeelden</message>
21
+ <message key="Apache XML Projects">Apache XML Projecten</message>
22
+ </catalogue>
@@ -0,0 +1,209 @@
1
+ #
2
+ # id3_test.rb
3
+ #
4
+ # This is a unit test file for the ID3 algorithm (Quinlan) implemented
5
+ # in ai4r
6
+ #
7
+ # Author:: Sergio Fierens
8
+ # License:: MPL 1.1
9
+ # Project:: ai4r
10
+ # Url:: http://ai4r.rubyforge.org/
11
+ #
12
+ # You can redistribute it and/or modify it under the terms of
13
+ # the Mozilla Public License version 1.1 as published by the
14
+ # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
15
+ #
16
+
17
+ require File.dirname(__FILE__) + '/../../lib/decision_tree/id3'
18
+ require 'test/unit'
19
+
20
+ DATA_LABELS = [ 'city', 'age_range', 'gender', 'marketing_target' ]
21
+
22
+ DATA_SET = [ ['New York', '<30', 'M', 'Y'],
23
+ ['Chicago', '<30', 'M', 'Y'],
24
+ ['Chicago', '<30', 'F', 'Y'],
25
+ ['New York', '<30', 'M', 'Y'],
26
+ ['New York', '<30', 'M', 'Y'],
27
+ ['Chicago', '[30-50)', 'M', 'Y'],
28
+ ['New York', '[30-50)', 'F', 'N'],
29
+ ['Chicago', '[30-50)', 'F', 'Y'],
30
+ ['New York', '[30-50)', 'F', 'N'],
31
+ ['Chicago', '[50-80]', 'M', 'N'],
32
+ ['New York', '[50-80]', 'F', 'N'],
33
+ ['New York', '[50-80]', 'M', 'N'],
34
+ ['Chicago', '[50-80]', 'M', 'N'],
35
+ ['New York', '[50-80]', 'F', 'N'],
36
+ ['Chicago', '>80', 'F', 'Y']
37
+ ]
38
+
39
+ SPLIT_DATA_SET_BY_CITY = [ [
40
+ ["New York", "<30", "M", "Y"],
41
+ ["New York", "<30", "M", "Y"],
42
+ ["New York", "<30", "M", "Y"],
43
+ ["New York", "[30-50)", "F", "N"],
44
+ ["New York", "[30-50)", "F", "N"],
45
+ ["New York", "[50-80]", "F", "N"],
46
+ ["New York", "[50-80]", "M", "N"],
47
+ ["New York", "[50-80]", "F", "N"]],
48
+ [
49
+ ["Chicago", "<30", "M", "Y"],
50
+ ["Chicago", "<30", "F", "Y"],
51
+ ["Chicago", "[30-50)", "M", "Y"],
52
+ ["Chicago", "[30-50)", "F", "Y"],
53
+ ["Chicago", "[50-80]", "M", "N"],
54
+ ["Chicago", "[50-80]", "M", "N"],
55
+ ["Chicago", ">80", "F", "Y"]]
56
+ ]
57
+
58
+ SPLIT_DATA_SET_BY_AGE = [ [
59
+ ["New York", "<30", "M", "Y"],
60
+ ["Chicago", "<30", "M", "Y"],
61
+ ["Chicago", "<30", "F", "Y"],
62
+ ["New York", "<30", "M", "Y"],
63
+ ["New York", "<30", "M", "Y"]],
64
+ [
65
+ ["Chicago", "[30-50)", "M", "Y"],
66
+ ["New York", "[30-50)", "F", "N"],
67
+ ["Chicago", "[30-50)", "F", "Y"],
68
+ ["New York", "[30-50)", "F", "N"]],
69
+ [
70
+ ["Chicago", "[50-80]", "M", "N"],
71
+ ["New York", "[50-80]", "F", "N"],
72
+ ["New York", "[50-80]", "M", "N"],
73
+ ["Chicago", "[50-80]", "M", "N"],
74
+ ["New York", "[50-80]", "F", "N"]],
75
+ [
76
+ ["Chicago", ">80", "F", "Y"]]
77
+ ]
78
+
79
+ EXPECTED_RULES_STRING =
80
+ "if age_range=='<30' then marketing_target='Y'\n"+
81
+ "elsif age_range=='[30-50)' and city=='Chicago' then marketing_target='Y'\n"+
82
+ "elsif age_range=='[30-50)' and city=='New York' then marketing_target='N'\n"+
83
+ "elsif age_range=='[50-80]' then marketing_target='N'\n"+
84
+ "elsif age_range=='>80' then marketing_target='Y'\n"+
85
+ "else raise 'There was not enough information during training to do a proper induction for this data element' end"
86
+
87
+
88
+ DecisionTree::ID3.send(:public, *DecisionTree::ID3.protected_instance_methods)
89
+ DecisionTree::ID3.send(:public, *DecisionTree::ID3.private_instance_methods)
90
+
91
+ module DecisionTree
92
+
93
+ class ID3Test < Test::Unit::TestCase
94
+
95
+ def test_log2
96
+ assert_equal 1.0, DecisionTree::ID3.log2(2)
97
+ assert_equal 0.0, DecisionTree::ID3.log2(0)
98
+ assert 1.585 - DecisionTree::ID3.log2(3) < 0.001
99
+ end
100
+
101
+ def test_sum
102
+ assert_equal 28, DecisionTree::ID3.sum([5, 0, 22, 1])
103
+ assert_equal 0, DecisionTree::ID3.sum([])
104
+ end
105
+
106
+ def test_data_labels
107
+ id3 = DecisionTree::ID3.new(DATA_SET)
108
+ expected_default = [ 'ATTRIBUTE_1', 'ATTRIBUTE_2', 'ATTRIBUTE_3', 'CATEGORY' ]
109
+ assert_equal(expected_default, id3.data_labels)
110
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
111
+ assert_equal(DATA_LABELS, id3.data_labels)
112
+ end
113
+
114
+ def test_domain
115
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
116
+ expected_domain = [["New York", "Chicago"], ["<30", "[30-50)", "[50-80]", ">80"], ["M", "F"], ["Y", "N"]]
117
+ assert_equal expected_domain, id3.domain(DATA_SET)
118
+ end
119
+
120
+ def test_grid
121
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
122
+ expected_grid = [[3, 5], [5, 2]]
123
+ domain = id3.domain(DATA_SET)
124
+ assert_equal expected_grid, id3.freq_grid(0, DATA_SET, domain)
125
+ expected_grid = [[5, 0], [2, 2], [0, 5], [1, 0]]
126
+ assert_equal expected_grid, id3.freq_grid(1, DATA_SET, domain)
127
+ end
128
+
129
+ def test_entropy
130
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
131
+ expected_entropy = 0.9118
132
+ domain = id3.domain(DATA_SET)
133
+ freq_grid = id3.freq_grid(0, DATA_SET, domain)
134
+ assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
135
+ expected_entropy = 0.2667
136
+ freq_grid = id3.freq_grid(1, DATA_SET, domain)
137
+ assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
138
+ expected_entropy = 0.9688
139
+ freq_grid = id3.freq_grid(2, DATA_SET, domain)
140
+ assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
141
+ end
142
+
143
+ def test_min_entropy_index
144
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
145
+ domain = id3.domain(DATA_SET)
146
+ assert_equal 1, id3.min_entropy_index(DATA_SET, domain)
147
+ assert_equal 0, id3.min_entropy_index(DATA_SET, domain, [1])
148
+ assert_equal 2, id3.min_entropy_index(DATA_SET, domain, [1, 0])
149
+ end
150
+
151
+ def test_split_data_examples
152
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
153
+ domain = id3.domain(DATA_SET)
154
+ res = id3.split_data_examples(DATA_SET, domain, 0)
155
+ assert_equal(SPLIT_DATA_SET_BY_CITY, res)
156
+ res = id3.split_data_examples(DATA_SET, domain, 1)
157
+ assert_equal(SPLIT_DATA_SET_BY_AGE, res)
158
+ end
159
+
160
+ def test_most_freq
161
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
162
+ domain = id3.domain(DATA_SET)
163
+ assert_equal 'Y', id3.most_freq(DATA_SET, domain)
164
+ assert_equal 'Y', id3.most_freq(SPLIT_DATA_SET_BY_AGE[3], domain)
165
+ assert_equal 'N', id3.most_freq(SPLIT_DATA_SET_BY_AGE[2], domain)
166
+ end
167
+
168
+ def test_to_s
169
+ assert_equal [["marketing_target='N'"]], DecisionTree::CategoryNode.new('marketing_target', 'N').get_rules
170
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
171
+ assert_equal EXPECTED_RULES_STRING, id3.to_s
172
+ end
173
+
174
+ def test_eval
175
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
176
+ #if age_range='<30' then marketing_target='Y'
177
+ assert_equal 'Y', id3.eval(['New York', '<30', 'F'])
178
+ assert_equal 'Y', id3.eval(['Chicago', '<30', 'M'])
179
+ #if age_range='[30-50)' and city='Chicago' then marketing_target='Y'
180
+ assert_equal 'Y', id3.eval(['Chicago', '[30-50)', 'F'])
181
+ assert_equal 'Y', id3.eval(['Chicago', '[30-50)', 'M'])
182
+ #if age_range='[30-50)' and city='New York' then marketing_target='N'
183
+ assert_equal 'N', id3.eval(['New York', '[30-50)', 'F'])
184
+ assert_equal 'N', id3.eval(['New York', '[30-50)', 'M'])
185
+ #if age_range='[50-80]' then marketing_target='N'
186
+ assert_equal 'N', id3.eval(['New York', '[50-80]', 'F'])
187
+ assert_equal 'N', id3.eval(['Chicago', '[50-80]', 'M'])
188
+ #if age_range='>80' then marketing_target='Y'
189
+ assert_equal 'Y', id3.eval(['New York', '>80', 'M'])
190
+ assert_equal 'Y', id3.eval(['Chicago', '>80', 'F'])
191
+ end
192
+
193
+ def test_rules_eval
194
+ id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
195
+ #if age_range='<30' then marketing_target='Y'
196
+ age_range = '<30'
197
+ marketing_target = nil
198
+ eval id3.to_s
199
+ assert_equal 'Y', marketing_target
200
+ #if age_range='[30-50)' and city='New York' then marketing_target='N'
201
+ age_range='[30-50)'
202
+ city='New York'
203
+ eval id3.to_s
204
+ assert_equal 'N', marketing_target
205
+ end
206
+ end
207
+
208
+ end
209
+
@@ -0,0 +1,55 @@
1
+ # Author:: Sergio Fierens
2
+ # License:: MPL 1.1
3
+ # Project:: ai4r
4
+ # Url:: http://ai4r.rubyforge.org/
5
+ #
6
+ # You can redistribute it and/or modify it under the terms of
7
+ # the Mozilla Public License version 1.1 as published by the
8
+ # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
+
10
+
11
+ require File.dirname(__FILE__) + '/../../lib/genetic_algorithm/genetic_algorithm'
12
+
13
+ require 'test/unit'
14
+
15
+ module GeneticAlgorithm
16
+
17
+ COST = [
18
+ [ 0, 10, 12, 21, 25, 25, 34, 26, 28, 11],
19
+ [ 10, 0, 12, 21, 19, 21, 18, 12, 22, 11],
20
+ [ 10, 12, 0, 24, 18, 16, 36, 29, 17, 22],
21
+ [ 20, 12, 22, 0, 32, 34, 28, 24, 31, 9],
22
+ [ 23, 20, 19, 31, 0, 25, 29, 25, 31, 28],
23
+ [ 24, 20, 15, 33, 24, 0, 38, 34, 17, 25],
24
+ [ 33, 19, 35, 29, 24, 34, 0, 9, 38, 28],
25
+ [ 25, 13, 28, 25, 25, 34, 9, 0, 33, 19],
26
+ [ 30, 23, 18, 29, 31, 18, 38, 34, 0, 23],
27
+ [ 11, 11, 22, 9, 28, 26, 27, 19, 22, 0]
28
+ ]
29
+
30
+ class ChromosomeTest < Test::Unit::TestCase
31
+
32
+ def test_chromosome_seed
33
+ Chromosome.set_cost_matrix(COST)
34
+ chromosome = Chromosome.seed
35
+ assert_equal [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], chromosome.data.sort
36
+ end
37
+
38
+ def test_fitness
39
+ Chromosome.set_cost_matrix(COST)
40
+ chromosome = Chromosome.new([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
41
+ assert_equal( -206, chromosome.fitness)
42
+ end
43
+
44
+ def test_reproduce
45
+ Chromosome.set_cost_matrix(COST)
46
+ c1 = Chromosome.new([2, 8, 5, 3, 6, 7, 1, 9, 0, 4])
47
+ c2 = Chromosome.new([3, 2, 0, 1, 5, 4, 6, 7, 9, 8])
48
+ c3 = Chromosome.reproduce(c1, c2)
49
+ assert_equal([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], c3.data.sort)
50
+ end
51
+
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,78 @@
1
+ # Author:: Sergio Fierens
2
+ # License:: MPL 1.1
3
+ # Project:: ai4r
4
+ # Url:: http://ai4r.rubyforge.org/
5
+ #
6
+ # You can redistribute it and/or modify it under the terms of
7
+ # the Mozilla Public License version 1.1 as published by the
8
+ # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
+
10
+ require File.dirname(__FILE__) + '/../../lib/genetic_algorithm/genetic_algorithm'
11
+ require 'test/unit'
12
+
13
+ module GeneticAlgorithm
14
+
15
+ COUNTRY = %w"Belgium France Germany Ireland Italy Poland Portugal Spain Sweden UK"
16
+
17
+ # Belgium, France, Germany, Ireland, Italy, Poland, Portugal, Spain, Sweden, UK
18
+ COSTS = [
19
+ [ 0, 10, 12, 21, 25, 25, 34, 26, 28, 11],
20
+ [ 10, 0, 12, 21, 19, 21, 18, 12, 22, 11],
21
+ [ 10, 12, 0, 24, 18, 16, 36, 29, 17, 22],
22
+ [ 20, 12, 22, 0, 32, 34, 28, 24, 31, 9],
23
+ [ 23, 20, 19, 31, 0, 25, 29, 25, 31, 28],
24
+ [ 24, 20, 15, 33, 24, 0, 38, 34, 17, 25],
25
+ [ 33, 19, 35, 29, 24, 34, 0, 9, 38, 28],
26
+ [ 25, 13, 28, 25, 25, 34, 9, 0, 33, 19],
27
+ [ 30, 23, 18, 29, 31, 18, 38, 34, 0, 23],
28
+ [ 11, 11, 22, 9, 28, 26, 27, 19, 22, 0]
29
+ ]
30
+
31
+
32
+ class GeneticAlgorithmTest < Test::Unit::TestCase
33
+
34
+ def test_chromosome_seed
35
+ Chromosome.set_cost_matrix(COSTS)
36
+ chromosome = Chromosome.seed
37
+ assert_equal [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], chromosome.data.sort
38
+ end
39
+
40
+ def test_fitness
41
+ Chromosome.set_cost_matrix(COSTS)
42
+ chromosome = Chromosome.new([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
43
+ assert_equal( -206, chromosome.fitness)
44
+ end
45
+
46
+ def test_selection
47
+ search = GeneticSearch.new(10, 5)
48
+ search.generate_initial_population
49
+ selected = search.selection
50
+ selected.each { |c| assert c!=nil }
51
+ assert_equal 6, selected.length
52
+ assert_equal 1, search.population[0].normalized_fitness
53
+ assert_equal 0, search.population.last.normalized_fitness
54
+ assert_equal 10, search.population.length
55
+ end
56
+
57
+ def test_reproduction
58
+ search = GeneticSearch.new(10, 5)
59
+ search.generate_initial_population
60
+ selected = search.selection
61
+ offsprings = search.reproduction selected
62
+ assert_equal 3, offsprings.length
63
+ end
64
+
65
+ def test_replace_worst_ranked
66
+ search = GeneticSearch.new(10, 5)
67
+ search.generate_initial_population
68
+ selected = search.selection
69
+ offsprings = search.reproduction selected
70
+ search.replace_worst_ranked offsprings
71
+ assert_equal 10, search.population.length
72
+ offsprings.each { |c| assert search.population.include?(c)}
73
+ end
74
+
75
+ end
76
+
77
+
78
+ end