ai4r 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/README.rdoc +12 -25
  2. data/examples/decision_trees/id3_example.rb +6 -9
  3. data/examples/decision_trees/results.txt +2 -0
  4. data/examples/genetic_algorithm/genetic_algorithm_example.rb +11 -13
  5. data/examples/neural_network/xor_example.rb +25 -0
  6. data/lib/ai4r.rb +10 -0
  7. data/lib/ai4r/classifiers/classifier.rb +46 -0
  8. data/lib/ai4r/classifiers/id3.rb +27 -58
  9. data/lib/ai4r/classifiers/one_r.rb +19 -58
  10. data/lib/ai4r/classifiers/prism.rb +21 -57
  11. data/lib/ai4r/classifiers/zero_r.rb +16 -48
  12. data/lib/ai4r/clusterers/bisecting_k_means.rb +115 -0
  13. data/lib/ai4r/clusterers/clusterer.rb +55 -0
  14. data/lib/ai4r/clusterers/k_means.rb +164 -0
  15. data/lib/ai4r/data/data_set.rb +250 -0
  16. data/lib/ai4r/genetic_algorithm/genetic_algorithm.rb +19 -19
  17. data/lib/ai4r/neural_network/backpropagation.rb +23 -24
  18. data/site/build/site/en/broken-links.xml +2 -0
  19. data/site/build/site/en/downloads.html +200 -0
  20. data/site/build/site/en/downloads.pdf +151 -0
  21. data/site/build/site/en/forum.html +197 -0
  22. data/site/build/site/en/forum.pdf +151 -0
  23. data/site/build/site/en/geneticAlgorithms.html +591 -0
  24. data/site/build/site/en/geneticAlgorithms.pdf +934 -0
  25. data/site/build/site/en/images/ai4r-logo.png +0 -0
  26. data/site/build/site/en/images/built-with-forrest-button.png +0 -0
  27. data/site/build/site/en/images/c.png +0 -0
  28. data/site/build/site/en/images/c_wbn.png +0 -0
  29. data/site/build/site/en/images/c_wn.png +0 -0
  30. data/site/build/site/en/images/ero.gif +0 -0
  31. data/site/build/site/en/images/europe2.png +0 -0
  32. data/site/build/site/en/images/europe3.png +0 -0
  33. data/site/build/site/en/images/fitness.png +0 -0
  34. data/site/build/site/en/images/genetic_algorithms_example.png +0 -0
  35. data/site/build/site/en/images/instruction_arrow.png +0 -0
  36. data/site/build/site/en/images/jadeferret.png +0 -0
  37. data/site/build/site/en/images/my_email.png +0 -0
  38. data/site/build/site/en/images/neural_network_example.png +0 -0
  39. data/site/build/site/en/images/rubyforge.png +0 -0
  40. data/site/build/site/en/images/s.png +0 -0
  41. data/site/build/site/en/images/s_wbn.png +0 -0
  42. data/site/build/site/en/images/s_wn.png +0 -0
  43. data/site/build/site/en/images/sigmoid.png +0 -0
  44. data/site/build/site/en/images/t.png +0 -0
  45. data/site/build/site/en/images/t_wbn.png +0 -0
  46. data/site/build/site/en/images/t_wn.png +0 -0
  47. data/site/build/site/en/index.html +336 -0
  48. data/site/build/site/en/index.pdf +508 -0
  49. data/site/build/site/en/linkmap.html +263 -0
  50. data/site/build/site/en/linkmap.pdf +94 -0
  51. data/site/build/site/en/locationmap.xml +72 -0
  52. data/site/build/site/en/machineLearning.html +339 -0
  53. data/site/build/site/en/machineLearning.pdf +337 -0
  54. data/site/build/site/en/neuralNetworks.html +484 -0
  55. data/site/build/site/en/neuralNetworks.pdf +604 -0
  56. data/site/build/site/en/skin/CommonMessages_de.xml +23 -0
  57. data/site/build/site/en/skin/CommonMessages_en_US.xml +23 -0
  58. data/site/build/site/en/skin/CommonMessages_es.xml +23 -0
  59. data/site/build/site/en/skin/CommonMessages_fr.xml +23 -0
  60. data/site/build/site/en/skin/basic.css +166 -0
  61. data/site/build/site/en/skin/breadcrumbs-optimized.js +90 -0
  62. data/site/build/site/en/skin/breadcrumbs.js +237 -0
  63. data/site/build/site/en/skin/fontsize.js +166 -0
  64. data/site/build/site/en/skin/getBlank.js +40 -0
  65. data/site/build/site/en/skin/getMenu.js +45 -0
  66. data/site/build/site/en/skin/images/README.txt +1 -0
  67. data/site/build/site/en/skin/images/add.jpg +0 -0
  68. data/site/build/site/en/skin/images/built-with-forrest-button.png +0 -0
  69. data/site/build/site/en/skin/images/chapter.gif +0 -0
  70. data/site/build/site/en/skin/images/chapter_open.gif +0 -0
  71. data/site/build/site/en/skin/images/current.gif +0 -0
  72. data/site/build/site/en/skin/images/error.png +0 -0
  73. data/site/build/site/en/skin/images/external-link.gif +0 -0
  74. data/site/build/site/en/skin/images/fix.jpg +0 -0
  75. data/site/build/site/en/skin/images/forrest-credit-logo.png +0 -0
  76. data/site/build/site/en/skin/images/hack.jpg +0 -0
  77. data/site/build/site/en/skin/images/header_white_line.gif +0 -0
  78. data/site/build/site/en/skin/images/info.png +0 -0
  79. data/site/build/site/en/skin/images/instruction_arrow.png +0 -0
  80. data/site/build/site/en/skin/images/label.gif +0 -0
  81. data/site/build/site/en/skin/images/page.gif +0 -0
  82. data/site/build/site/en/skin/images/pdfdoc.gif +0 -0
  83. data/site/build/site/en/skin/images/poddoc.png +0 -0
  84. data/site/build/site/en/skin/images/printer.gif +0 -0
  85. data/site/build/site/en/skin/images/rc-b-l-15-1body-2menu-3menu.png +0 -0
  86. data/site/build/site/en/skin/images/rc-b-r-15-1body-2menu-3menu.png +0 -0
  87. data/site/build/site/en/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  88. data/site/build/site/en/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png +0 -0
  89. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png +0 -0
  90. data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  91. data/site/build/site/en/skin/images/rc-t-r-15-1body-2menu-3menu.png +0 -0
  92. data/site/build/site/en/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png +0 -0
  93. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png +0 -0
  94. data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png +0 -0
  95. data/site/build/site/en/skin/images/remove.jpg +0 -0
  96. data/site/build/site/en/skin/images/rss.png +0 -0
  97. data/site/build/site/en/skin/images/spacer.gif +0 -0
  98. data/site/build/site/en/skin/images/success.png +0 -0
  99. data/site/build/site/en/skin/images/txtdoc.png +0 -0
  100. data/site/build/site/en/skin/images/update.jpg +0 -0
  101. data/site/build/site/en/skin/images/valid-html401.png +0 -0
  102. data/site/build/site/en/skin/images/vcss.png +0 -0
  103. data/site/build/site/en/skin/images/warning.png +0 -0
  104. data/site/build/site/en/skin/images/xmldoc.gif +0 -0
  105. data/site/build/site/en/skin/menu.js +48 -0
  106. data/site/build/site/en/skin/note.txt +50 -0
  107. data/site/build/site/en/skin/print.css +54 -0
  108. data/site/build/site/en/skin/profile.css +163 -0
  109. data/site/build/site/en/skin/prototype.js +1257 -0
  110. data/site/build/site/en/skin/screen.css +587 -0
  111. data/site/build/site/en/svn.html +252 -0
  112. data/site/build/site/en/svn.pdf +306 -0
  113. data/site/build/site/en/wholesite.pdf +1915 -0
  114. data/site/build/tmp/brokenlinks.xml +2 -0
  115. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.data +0 -0
  116. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.index +0 -0
  117. data/site/build/tmp/locationmap.xml +14 -14
  118. data/site/build/tmp/output.xmap +23 -23
  119. data/site/build/tmp/pluginlist2fetchbuild.xml +144 -144
  120. data/site/build/tmp/projfilters.properties +41 -41
  121. data/site/build/webapp/WEB-INF/logs/core.log +593 -679
  122. data/site/build/webapp/WEB-INF/logs/error.log +362 -279
  123. data/site/build/webapp/WEB-INF/logs/sitemap.log +368 -1015
  124. data/site/src/documentation/content/xdocs/index.xml +18 -10
  125. data/site/src/documentation/content/xdocs/machineLearning.xml +4 -3
  126. data/site/src/documentation/content/xdocs/site.xml +2 -1
  127. data/site/src/documentation/resources/images/sigmoid.png +0 -0
  128. data/test/classifiers/id3_test.rb +45 -44
  129. data/test/classifiers/one_r_test.rb +19 -17
  130. data/test/classifiers/prism_test.rb +22 -20
  131. data/test/classifiers/zero_r_test.rb +15 -12
  132. data/test/clusterers/bisecting_k_means_test.rb +59 -0
  133. data/test/clusterers/k_means_test.rb +93 -0
  134. data/test/data/data_set_test.rb +92 -0
  135. metadata +252 -128
  136. data/lib/ai4r/classifiers/classifier_helper.rb +0 -54
  137. data/site/src/documentation/content/xdocs/forum.html +0 -9
  138. data/site/src/documentation/resources/images/Thumbs.db +0 -0
  139. data/site/src/documentation/resources/images/sub-dir/Thumbs.db +0 -0
@@ -0,0 +1,337 @@
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 672 /Filter [ /ASCII85Decode /FlateDecode ]
9
+ >>
10
+ stream
11
+ GauI49lo#B&;KZQ'fs3*X%9O-Rq$-S9JY_Vf!i'mJJ[@GZ)B5%o'blT_2:&e-O4Ark`o1!mGhL@4:?$B+V>;t,hiI'qca;a'EKS_rGaUYk2M3E0MY3J,Msh@[GI3,9Z_XDV![1&'.?eGFb)?`9=mW8Ii"ihK6>k3\t5',,^XcV$kMlqbQ'K0YH2aAjfgeWrATXfE-M0e?SY5&%qFcqXfDB;Z<Nd]%?B&O[SY`@lq\8>0)]c:3eo;_-lMr&hc`.Im^N)EpU)k>5HJ]Dp?>tcEU3r?6</^t/\p2,oU9+VBi!i\e$+1.1(iO\=A4F,98lg=XI%*-"RFLS+],$9Mn6/_=X]:i"+Sg<n%ZG$F5c'Z*2_;$k+"ek/A7l'LW0A(44<1!J>0DF;&=74$HT]JK=,+VL:OSs<M`^PLOSodGRab8*<U="eFNt*),4C5d5V3RqA/*C[*H?Y.JG5KqF+$GW2bIg$LPSBcTie8?H#?R)S8Q%3#BneWJss]C8DI7V2n.6;9Stg#Wia=e^3rf18>?$l/dE=JmWq)l+bH4,rCa$I%=YE87I*cK$V9GCI[:lO3poPOn<r3:DfY!P0?6B*LRFaIl(`A[FcM6$cu6P`Y)6X_%`_8]dU]^h7UXn#F0Y<D#qY,kPM]f;"Wps/]p<\jq2Wk@K-KD[['/~>
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
+ 10 0 R
27
+ 12 0 R
28
+ 14 0 R
29
+ 16 0 R
30
+ ]
31
+ endobj
32
+ 8 0 obj
33
+ << /Type /Annot
34
+ /Subtype /Link
35
+ /Rect [ 102.0 532.666 252.992 520.666 ]
36
+ /C [ 0 0 0 ]
37
+ /Border [ 0 0 0 ]
38
+ /A 9 0 R
39
+ /H /I
40
+ >>
41
+ endobj
42
+ 10 0 obj
43
+ << /Type /Annot
44
+ /Subtype /Link
45
+ /Rect [ 102.0 514.466 442.28 502.466 ]
46
+ /C [ 0 0 0 ]
47
+ /Border [ 0 0 0 ]
48
+ /A 11 0 R
49
+ /H /I
50
+ >>
51
+ endobj
52
+ 12 0 obj
53
+ << /Type /Annot
54
+ /Subtype /Link
55
+ /Rect [ 102.0 496.266 201.32 484.266 ]
56
+ /C [ 0 0 0 ]
57
+ /Border [ 0 0 0 ]
58
+ /A 13 0 R
59
+ /H /I
60
+ >>
61
+ endobj
62
+ 14 0 obj
63
+ << /Type /Annot
64
+ /Subtype /Link
65
+ /Rect [ 102.0 478.066 254.312 466.066 ]
66
+ /C [ 0 0 0 ]
67
+ /Border [ 0 0 0 ]
68
+ /A 15 0 R
69
+ /H /I
70
+ >>
71
+ endobj
72
+ 16 0 obj
73
+ << /Type /Annot
74
+ /Subtype /Link
75
+ /Rect [ 102.0 459.866 276.296 447.866 ]
76
+ /C [ 0 0 0 ]
77
+ /Border [ 0 0 0 ]
78
+ /A 17 0 R
79
+ /H /I
80
+ >>
81
+ endobj
82
+ 18 0 obj
83
+ << /Length 1893 /Filter [ /ASCII85Decode /FlateDecode ]
84
+ >>
85
+ stream
86
+ Gau0D=`<%S&:XAW&GkAjBNUCkY$uU+oL+VGfXBXl+peV1@ViKYkYb=6r;.L;f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 << /Type /Annot
136
+ /Subtype /Link
137
+ /Rect [ 90.0 619.806 259.296 607.806 ]
138
+ /C [ 0 0 0 ]
139
+ /Border [ 0 0 0 ]
140
+ /A << /URI (http://en.wikipedia.org/wiki/Decision_tree)
141
+ /S /URI >>
142
+ /H /I
143
+ >>
144
+ endobj
145
+ 26 0 obj
146
+ << /Type /Annot
147
+ /Subtype /Link
148
+ /Rect [ 262.296 619.806 434.94 607.806 ]
149
+ /C [ 0 0 0 ]
150
+ /Border [ 0 0 0 ]
151
+ /A << /URI (http://en.wikipedia.org/wiki/ID3_algorithm)
152
+ /S /URI >>
153
+ /H /I
154
+ >>
155
+ endobj
156
+ 28 0 obj
157
+ <<
158
+ /Title (\376\377\0\61\0\40\0\111\0\156\0\164\0\162\0\157\0\144\0\165\0\143\0\164\0\151\0\157\0\156\0\40\0\164\0\157\0\40\0\111\0\104\0\63\0\40\0\141\0\154\0\147\0\157\0\162\0\151\0\164\0\150\0\155)
159
+ /Parent 27 0 R
160
+ /Next 29 0 R
161
+ /A 9 0 R
162
+ >> endobj
163
+ 29 0 obj
164
+ <<
165
+ /Title (\376\377\0\62\0\40\0\115\0\141\0\162\0\153\0\145\0\164\0\151\0\156\0\147\0\40\0\164\0\141\0\162\0\147\0\145\0\164\0\40\0\163\0\164\0\162\0\141\0\164\0\145\0\147\0\171\0\40\0\145\0\170\0\141\0\155\0\160\0\154\0\145\0\40\0\165\0\163\0\151\0\156\0\147\0\40\0\111\0\104\0\63\0\40\0\104\0\145\0\143\0\151\0\163\0\151\0\157\0\156\0\40\0\124\0\162\0\145\0\145\0\163\0\40\0\151\0\156\0\40\0\122\0\165\0\142\0\171)
166
+ /Parent 27 0 R
167
+ /Prev 28 0 R
168
+ /Next 30 0 R
169
+ /A 11 0 R
170
+ >> endobj
171
+ 30 0 obj
172
+ <<
173
+ /Title (\376\377\0\63\0\40\0\102\0\145\0\164\0\164\0\145\0\162\0\40\0\144\0\141\0\164\0\141\0\40\0\154\0\157\0\141\0\144\0\151\0\156\0\147)
174
+ /Parent 27 0 R
175
+ /Prev 29 0 R
176
+ /Next 31 0 R
177
+ /A 13 0 R
178
+ >> endobj
179
+ 31 0 obj
180
+ <<
181
+ /Title (\376\377\0\64\0\40\0\101\0\40\0\147\0\157\0\157\0\144\0\40\0\164\0\151\0\160\0\40\0\146\0\157\0\162\0\40\0\144\0\141\0\164\0\141\0\40\0\145\0\166\0\141\0\154\0\165\0\141\0\164\0\151\0\157\0\156)
182
+ /Parent 27 0 R
183
+ /Prev 30 0 R
184
+ /Next 32 0 R
185
+ /A 15 0 R
186
+ >> endobj
187
+ 32 0 obj
188
+ <<
189
+ /Title (\376\377\0\65\0\40\0\115\0\157\0\162\0\145\0\40\0\141\0\142\0\157\0\165\0\164\0\40\0\111\0\104\0\63\0\40\0\141\0\156\0\144\0\40\0\144\0\145\0\143\0\151\0\163\0\151\0\157\0\156\0\40\0\164\0\162\0\145\0\145\0\163)
190
+ /Parent 27 0 R
191
+ /Prev 31 0 R
192
+ /A 17 0 R
193
+ >> endobj
194
+ 33 0 obj
195
+ << /Type /Font
196
+ /Subtype /Type1
197
+ /Name /F3
198
+ /BaseFont /Helvetica-Bold
199
+ /Encoding /WinAnsiEncoding >>
200
+ endobj
201
+ 34 0 obj
202
+ << /Type /Font
203
+ /Subtype /Type1
204
+ /Name /F5
205
+ /BaseFont /Times-Roman
206
+ /Encoding /WinAnsiEncoding >>
207
+ endobj
208
+ 35 0 obj
209
+ << /Type /Font
210
+ /Subtype /Type1
211
+ /Name /F1
212
+ /BaseFont /Helvetica
213
+ /Encoding /WinAnsiEncoding >>
214
+ endobj
215
+ 36 0 obj
216
+ << /Type /Font
217
+ /Subtype /Type1
218
+ /Name /F9
219
+ /BaseFont /Courier
220
+ /Encoding /WinAnsiEncoding >>
221
+ endobj
222
+ 37 0 obj
223
+ << /Type /Font
224
+ /Subtype /Type1
225
+ /Name /F2
226
+ /BaseFont /Helvetica-Oblique
227
+ /Encoding /WinAnsiEncoding >>
228
+ endobj
229
+ 38 0 obj
230
+ << /Type /Font
231
+ /Subtype /Type1
232
+ /Name /F7
233
+ /BaseFont /Times-Bold
234
+ /Encoding /WinAnsiEncoding >>
235
+ endobj
236
+ 1 0 obj
237
+ << /Type /Pages
238
+ /Count 4
239
+ /Kids [6 0 R 19 0 R 21 0 R 23 0 R ] >>
240
+ endobj
241
+ 2 0 obj
242
+ << /Type /Catalog
243
+ /Pages 1 0 R
244
+ /Outlines 27 0 R
245
+ /PageMode /UseOutlines
246
+ >>
247
+ endobj
248
+ 3 0 obj
249
+ <<
250
+ /Font << /F3 33 0 R /F5 34 0 R /F1 35 0 R /F9 36 0 R /F2 37 0 R /F7 38 0 R >>
251
+ /ProcSet [ /PDF /ImageC /Text ] >>
252
+ endobj
253
+ 9 0 obj
254
+ <<
255
+ /S /GoTo
256
+ /D [19 0 R /XYZ 85.0 659.0 null]
257
+ >>
258
+ endobj
259
+ 11 0 obj
260
+ <<
261
+ /S /GoTo
262
+ /D [19 0 R /XYZ 85.0 519.466 null]
263
+ >>
264
+ endobj
265
+ 13 0 obj
266
+ <<
267
+ /S /GoTo
268
+ /D [21 0 R /XYZ 85.0 501.24 null]
269
+ >>
270
+ endobj
271
+ 15 0 obj
272
+ <<
273
+ /S /GoTo
274
+ /D [21 0 R /XYZ 85.0 337.106 null]
275
+ >>
276
+ endobj
277
+ 17 0 obj
278
+ <<
279
+ /S /GoTo
280
+ /D [23 0 R /XYZ 85.0 649.14 null]
281
+ >>
282
+ endobj
283
+ 27 0 obj
284
+ <<
285
+ /First 28 0 R
286
+ /Last 32 0 R
287
+ >> endobj
288
+ xref
289
+ 0 39
290
+ 0000000000 65535 f
291
+ 0000009543 00000 n
292
+ 0000009622 00000 n
293
+ 0000009714 00000 n
294
+ 0000000015 00000 n
295
+ 0000000071 00000 n
296
+ 0000000834 00000 n
297
+ 0000000954 00000 n
298
+ 0000001007 00000 n
299
+ 0000009848 00000 n
300
+ 0000001142 00000 n
301
+ 0000009911 00000 n
302
+ 0000001278 00000 n
303
+ 0000009977 00000 n
304
+ 0000001414 00000 n
305
+ 0000010042 00000 n
306
+ 0000001551 00000 n
307
+ 0000010108 00000 n
308
+ 0000001688 00000 n
309
+ 0000003674 00000 n
310
+ 0000003782 00000 n
311
+ 0000005672 00000 n
312
+ 0000005780 00000 n
313
+ 0000006800 00000 n
314
+ 0000006923 00000 n
315
+ 0000006957 00000 n
316
+ 0000007150 00000 n
317
+ 0000010173 00000 n
318
+ 0000007345 00000 n
319
+ 0000007606 00000 n
320
+ 0000008098 00000 n
321
+ 0000008316 00000 n
322
+ 0000008597 00000 n
323
+ 0000008881 00000 n
324
+ 0000008994 00000 n
325
+ 0000009104 00000 n
326
+ 0000009212 00000 n
327
+ 0000009318 00000 n
328
+ 0000009434 00000 n
329
+ trailer
330
+ <<
331
+ /Size 39
332
+ /Root 2 0 R
333
+ /Info 4 0 R
334
+ >>
335
+ startxref
336
+ 10224
337
+ %%EOF
@@ -0,0 +1,484 @@
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>Backpropagation neural networks 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
+ <div class="grouplogo">
27
+ <a href="http://www.jadeferret.com"><img class="logoImage" alt="Jade Ferret" src="images/jadeferret.png" title="Jade Ferret"></a>
28
+ </div>
29
+ <!--+
30
+ |end group logo
31
+ +-->
32
+ <!--+
33
+ |start Project Logo
34
+ +-->
35
+ <div class="projectlogo">
36
+ <a href="http://ai4r.rubyforge.org/"><img class="logoImage" alt="ai4r" src="images/ai4r-logo.png" title="AI4R - Artificial Intelligence for Ruby"></a>
37
+ </div>
38
+ <!--+
39
+ |end Project Logo
40
+ +-->
41
+ <!--+
42
+ |start Search
43
+ +-->
44
+ <div class="searchbox">
45
+ <div class="roundtopsmall">
46
+ <form target="_top" action="http://www.google.com/custom" method="get">
47
+ <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">
48
+ </form>
49
+ </div>
50
+ </div>
51
+ <!--+
52
+ |end search
53
+ +-->
54
+ <!--+
55
+ |start Tabs
56
+ +-->
57
+ <ul id="tabs">
58
+ <li class="current">
59
+ <a class="selected" href="index.html">Home</a>
60
+ </li>
61
+ </ul>
62
+ <!--+
63
+ |end Tabs
64
+ +-->
65
+ </div>
66
+ </div>
67
+ <div id="main">
68
+ <div id="publishedStrip">
69
+ <!--+
70
+ |start Subtabs
71
+ +-->
72
+ <div id="level2tabs"></div>
73
+ <!--+
74
+ |end Endtabs
75
+ +-->
76
+ <script type="text/javascript"><!--
77
+ document.write("Last Published: " + document.lastModified);
78
+ // --></script>
79
+ </div>
80
+ <!--+
81
+ |breadtrail
82
+ +-->
83
+ <div class="breadtrail">
84
+
85
+ &nbsp;
86
+ </div>
87
+ <!--+
88
+ |start Menu, mainarea
89
+ +-->
90
+ <!--+
91
+ |start Menu
92
+ +-->
93
+ <div id="menu">
94
+ <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>
95
+ <div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
96
+ <div class="menuitem">
97
+ <a href="index.html" title="ai4r - Artificial Intelligence for Ruby">Index</a>
98
+ </div>
99
+ <div onclick="SwitchMenu('menu_selected_1.1.2', 'skin/')" id="menu_selected_1.1.2Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Practical Examples</div>
100
+ <div id="menu_selected_1.1.2" class="selectedmenuitemgroup" style="display: block;">
101
+ <div class="menuitem">
102
+ <a href="geneticAlgorithms.html" title="Genetic Algorithms in ruby">Genetic Algorithms</a>
103
+ </div>
104
+ <div class="menuitem">
105
+ <a href="machineLearning.html" title="ID3 Decision Trees in ruby">Machine Learning</a>
106
+ </div>
107
+ <div class="menupage">
108
+ <div class="menupagetitle">Neural Networks</div>
109
+ </div>
110
+ </div>
111
+ <div class="menuitem">
112
+ <a href="downloads.html" title="ai4r - Download Files">Downloads</a>
113
+ </div>
114
+ <div class="menuitem">
115
+ <a href="http://forum.jadeferret.com/viewforum.php?f=3" title="Ai4r Forum">Forum</a>
116
+ </div>
117
+ <div class="menuitem">
118
+ <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
119
+ </div>
120
+ <div class="menuitem">
121
+ <a href="svn.html" title="ai4r Subversion repository">Source Code repository</a>
122
+ </div>
123
+ <div class="menuitem">
124
+ <a href="wholesite.pdf">ai4r project PDF</a>
125
+ </div>
126
+ </div>
127
+ <div id="credit">
128
+ <script type="text/javascript">
129
+ google_ad_client = "pub-2578934938711895";
130
+ google_ad_slot = "6111091580";
131
+ google_ad_width = 125;
132
+ google_ad_height = 125;
133
+ </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
134
+ <hr>
135
+ </div>
136
+ <div id="roundbottom">
137
+ <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
138
+ <!--+
139
+ |alternative credits
140
+ +-->
141
+ <div id="credit2"></div>
142
+ </div>
143
+ <!--+
144
+ |end Menu
145
+ +-->
146
+ <!--+
147
+ |start content
148
+ +-->
149
+ <div id="content">
150
+ <div title="Portable Document Format" class="pdflink">
151
+ <a class="dida" href="neuralNetworks.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
152
+ PDF</a>
153
+ </div>
154
+ <h1>Backpropagation neural networks in ruby :: ai4r</h1>
155
+ <div id="minitoc-area">
156
+ <ul class="minitoc">
157
+ <li>
158
+ <a href="#nn-Introduction">Introduction to Neural Networks in Ruby</a>
159
+ </li>
160
+ <li>
161
+ <a href="#nn-HowTo">How to use Backpropagation Neural Networks in Ruby</a>
162
+ </li>
163
+ <li>
164
+ <a href="#nn-example">OCR example using Backpropagation networks in ruby</a>
165
+ </li>
166
+ <li>
167
+ <a href="#nn-custom">Customizing your neural network in ai4r</a>
168
+ </li>
169
+ <li>
170
+ <a href="#nn-more">More about Neural Networks and Backpropagation</a>
171
+ </li>
172
+ </ul>
173
+ </div>
174
+
175
+ <a name="N1000D"></a><a name="nn-Introduction"></a>
176
+ <h2 class="boxed">Introduction to Neural Networks in Ruby</h2>
177
+ <div class="section">
178
+ <p>
179
+ The utility of artificial neural network models lies in the fact
180
+ that they can be used to infer a function from observations. This is
181
+ particularly useful in applications where the complexity of the data
182
+ or task makes the design of such a function by hand impractical.
183
+ Neural Networks are being used in many businesses and applications.
184
+ Their ability to learn by example makes them attractive in environments
185
+ where the business rules are either not well defined or are hard to
186
+ enumerate and define. Many people believe that Neural Networks can
187
+ only solve toy problems. Give them a try, and let you decide if they
188
+ are good enough to solve your needs.
189
+ </p>
190
+ <p>
191
+ In this module you will find an implementation of neural networks
192
+ using the Backpropagation is a supervised learning technique
193
+ (described by Paul Werbos in 1974, and further developed by David E.
194
+ Rumelhart, Geoffrey E. Hinton and Ronald J. Williams in 1986)
195
+ </p>
196
+ </div>
197
+
198
+ <a name="N1001A"></a><a name="nn-HowTo"></a>
199
+ <h2 class="boxed">How to use Backpropagation Neural Networks in Ruby</h2>
200
+ <div class="section">
201
+ <pre class="code">
202
+
203
+ # Create the network
204
+ net = Ai4r::NeuralNetwork::Backpropagation.new([4, 3, 2])
205
+ # 4 inputs
206
+ # 1 hidden layer with 3 neurons
207
+ # 2 outputs
208
+ # Train the network
209
+ 1..upto(100) do |i|
210
+ net.train(example[i], result[i])
211
+ end
212
+
213
+ # Use it: Evaluate data with the trained network
214
+ net.eval([12, 48, 12, 25]) # =&gt; [0.89, 0.04]
215
+
216
+ </pre>
217
+ </div>
218
+
219
+
220
+ <a name="N10025"></a><a name="nn-example"></a>
221
+ <h2 class="boxed">OCR example using Backpropagation networks in ruby</h2>
222
+ <div class="section">
223
+ <p>
224
+ Let's imagine that we have to implement a program to identify simple patterns
225
+ (triangles, squares, crosses, etc). The main problem is that this program must
226
+ be resistant to random noise in the image (pixels with wrong values) and
227
+ line noise (similar to the unwanted direct current that we usually have in a
228
+ signal).
229
+ </p>
230
+ <p>
231
+ We can take an example of each pattern to be recognized, and train a
232
+ neural network to identify them.
233
+ </p>
234
+ <p>
235
+ We create a network with the following architecture: 256 input neurons,
236
+ 128 neurons in a hidden layer, 3 output neurons. We feed this network
237
+ with 16x16 matrices (in fact will convert them to vectors of length 256).
238
+ Each pixel is represented with a number from 0 (white pixel) to 10
239
+ (black pixel). The output of this network if a 3 vector of dimension 3,
240
+ where ideally:
241
+ </p>
242
+ <ul>
243
+
244
+ <li>(1, 0, 0) for triangles</li>
245
+
246
+ <li>(0, 1, 0) for squares</li>
247
+
248
+ <li>(0, 0, 1) for crosses</li>
249
+
250
+ </ul>
251
+ <p>We train our backpropagation neural network using the following examples:</p>
252
+ <table class="ForrestTable" cellspacing="1" cellpadding="4">
253
+
254
+ <caption>Training patterns</caption>
255
+
256
+ <tr>
257
+
258
+ <td colspan="1" rowspan="1"><img alt="Triangule training example" src="/images/t.png"></td>
259
+ <td colspan="1" rowspan="1"><img alt="Square training example" src="/images/s.png"></td>
260
+ <td colspan="1" rowspan="1"><img alt="Cross training example" src="/images/c.png"></td>
261
+
262
+ </tr>
263
+
264
+ </table>
265
+ <p>And we repeat the training 20 times.</p>
266
+ <p>
267
+ The results we got when we evaluate patterns with our trained network are:
268
+ </p>
269
+ <ul>
270
+
271
+ <li>Evaluating the training patterns with the trained network:
272
+ <ol>
273
+
274
+ <li>
275
+ <img alt="Triangule training example" src="/images/t.png">
276
+ [0.98, 0.03, 0.01] =&gt; TRIANGLE </li>
277
+
278
+ <li>
279
+ <img alt="Square training example" src="/images/s.png">
280
+ [0.00, 0.96, 0.03] =&gt; SQUARE </li>
281
+
282
+ <li>
283
+ <img alt="Cross training example" src="/images/c.png">
284
+ [0.00, 0.00, 0.99] =&gt; CROSS </li>
285
+
286
+ </ol>
287
+
288
+ </li>
289
+
290
+ <li>Evaluating the patterns with random noise with the trained network:
291
+ <ol>
292
+
293
+ <li>
294
+ <img alt="Triangule pattern with random noise" src="/images/t_wn.png"> [0.98, 0.01, 0.01] =&gt; TRIANGLE </li>
295
+
296
+ <li>
297
+ <img alt="Square pattern with random noise" src="/images/s_wn.png"> [0.00, 0.96, 0.02] =&gt; SQUARE </li>
298
+
299
+ <li>
300
+ <img alt="Cross pattern with random noise" src="/images/c_wn.png"> [0.00, 0.00, 0.98] =&gt; CROSS </li>
301
+
302
+ </ol>
303
+
304
+ </li>
305
+
306
+ <li>Evaluating the patterns with line noise with the trained network:
307
+ <ol>
308
+
309
+ <li>
310
+ <img alt="Triangule pattern with line noise" src="/images/t_wbn.png"> [0.62, 0.00, 0.02] =&gt; TRIANGLE </li>
311
+
312
+ <li>
313
+ <img alt="Square pattern with line noise" src="/images/s_wbn.png"> [0.00, 0.75, 0.01] =&gt; SQUARE </li>
314
+
315
+ <li>
316
+ <img alt="Cross pattern with line noise" src="/images/c_wbn.png"> [0.00, 0.00, 0.98] =&gt; CROSS </li>
317
+
318
+ </ol>
319
+
320
+ </li>
321
+
322
+ </ul>
323
+ <p>These results are very satisfactory. The network could sucessfully identify the patterns despite the noise introduced to them. In fact, one of the most popular uses of neural networks in business
324
+ applications is OCR (opticar character recognition).</p>
325
+ <p>This is the source code used to elaborate this example (You can find it inside the zip file):</p>
326
+ <pre class="code">
327
+
328
+ require "rubygems"
329
+ require "ai4r/neural_network/backpropagation"
330
+ require File.dirname(__FILE__) + '/training_patterns'
331
+ require File.dirname(__FILE__) + '/patterns_with_noise'
332
+ require File.dirname(__FILE__) + '/patterns_with_base_noise'
333
+
334
+ net = Ai4r::NeuralNetwork::Backpropagation.new([256, 128, 3])
335
+
336
+ tr_input = TRIANGLE.flatten.collect { |input| input.to_f / 10}
337
+ sq_input = SQUARE.flatten.collect { |input| input.to_f / 10}
338
+ cr_input = CROSS.flatten.collect { |input| input.to_f / 10}
339
+
340
+ tr_with_noise = TRIANGLE_WITH_NOISE.flatten.collect { |input| input.to_f / 10}
341
+ sq_with_noise = SQUARE_WITH_NOISE.flatten.collect { |input| input.to_f / 10}
342
+ cr_with_noise = CROSS_WITH_NOISE.flatten.collect { |input| input.to_f / 10}
343
+
344
+ tr_with_base_noise = TRIANGLE_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10}
345
+ sq_with_base_noise = SQUARE_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10}
346
+ cr_with_base_noise = CROSS_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10}
347
+
348
+ puts "Training the network, please wait."
349
+ 20.times do
350
+ net.train(tr_input, [1,0,0])
351
+ net.train(sq_input, [0,1,0])
352
+ net.train(cr_input, [0,0,1])
353
+ end
354
+
355
+ def result_label(result)
356
+ if result[0] &gt; result[1] &amp;&amp; result[0] &gt; result[2]
357
+ "TRIANGLE"
358
+ elsif result[1] &gt; result[2]
359
+ "SQUARE"
360
+ else
361
+ "CROSS"
362
+ end
363
+ end
364
+
365
+ puts "Training Examples"
366
+ puts "#{net.eval(tr_input).inspect} =&gt; #{result_label(net.eval(tr_input))}"
367
+ puts "#{net.eval(sq_input).inspect} =&gt; #{result_label(net.eval(sq_input))}"
368
+ puts "#{net.eval(cr_input).inspect} =&gt; #{result_label(net.eval(cr_input))}"
369
+ puts "Examples with noise"
370
+ puts "#{net.eval(tr_with_noise).inspect} =&gt; #{result_label(net.eval(tr_with_noise))}"
371
+ puts "#{net.eval(sq_with_noise).inspect} =&gt; #{result_label(net.eval(sq_with_noise))}"
372
+ puts "#{net.eval(cr_with_noise).inspect} =&gt; #{result_label(net.eval(cr_with_noise))}"
373
+ puts "Examples with base noise"
374
+ puts "#{net.eval(tr_with_base_noise).inspect} =&gt; #{result_label(net.eval(tr_with_base_noise))}"
375
+ puts "#{net.eval(sq_with_base_noise).inspect} =&gt; #{result_label(net.eval(sq_with_base_noise))}"
376
+ puts "#{net.eval(cr_with_base_noise).inspect} =&gt; #{result_label(net.eval(cr_with_base_noise))}"
377
+
378
+ </pre>
379
+ </div>
380
+
381
+
382
+ <a name="N100C6"></a><a name="nn-custom"></a>
383
+ <h2 class="boxed">Customizing your neural network in ai4r</h2>
384
+ <div class="section">
385
+ <p>Sometime for a given problem, you will have to "play around" with some parameters to
386
+ get to a solution. This parameters are:</p>
387
+ <p>
388
+ <strong>threshold</strong>: A real number which we will call Threshold. Experiments have shown that best values for q are between 0.25 and 1. You can optionally pass this parameter to the initialization method of your network.</p>
389
+ <p>
390
+ <strong>lambda</strong>: The Learning Rate: a real number, usually between 0.05 and 0.25. You can optionally pass this parameter to the initialization method of your network.</p>
391
+ <p>
392
+ <strong>momentum</strong>: A momentum will avoid oscillations during learning, converging to a solution in less iterations. You can optionally pass this parameter to the initialization method of your network.</p>
393
+ <p>
394
+ <strong>transference function</strong>: By default, f(x) = 1/(1 + e^(-x)).
395
+ This function is called "Sigmoid function". You can see it like a
396
+ "smoothed" version of the "Heaviside step function". It will always provide a
397
+ value between 0 and 1. </p>
398
+ <p>
399
+ <img alt="Sigmoid function" src="images/sigmoid.png"></p>
400
+ <p>
401
+ Sometimes you will have better results with f(x) = x. You can change the transference function from the default sigmoidal function to the linear one, overriding Ai4r::NeuralNetwork::Neuron.f and Ai4r::NeuralNetwork::Neuron.f_prime (derived function
402
+ of f):</p>
403
+ <pre class="code">
404
+
405
+ class Ai4r::NeuralNetwork::Neuron
406
+ def self.f(x)
407
+ x
408
+ end
409
+ def self.f_prime(x)
410
+ 1
411
+ end
412
+ end
413
+
414
+ </pre>
415
+ </div>
416
+
417
+
418
+ <a name="N100F0"></a><a name="nn-more"></a>
419
+ <h2 class="boxed">More about Neural Networks and Backpropagation</h2>
420
+ <div class="section">
421
+ <ul>
422
+
423
+ <li>
424
+
425
+ <a class="external" href="http://en.wikipedia.org/wiki/Artificial_neural_network">Wikipedia article on Artificial Neural Networks</a>
426
+
427
+ </li>
428
+
429
+ <li>
430
+
431
+ <a class="external" href="http://en.wikipedia.org/wiki/Backpropagation">Wikipedia article on Backpropagation Algorithm</a>
432
+
433
+ </li>
434
+
435
+ <li>
436
+
437
+ <a class="external" href="http://www.tek271.com/articles/neuralNet/IntoToNeuralNets.html">Neural Networks - An Introduction by Abdul Habra</a>
438
+
439
+ </li>
440
+
441
+ <li>
442
+
443
+ <a class="external" href="http://galaxy.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html">A graphical explanation of the
444
+ backpropagation algorithm by Mariusz Bernacki and Przemysław Włodarczyk</a>
445
+
446
+ </li>
447
+
448
+ </ul>
449
+ </div>
450
+
451
+
452
+ </div>
453
+ <!--+
454
+ |end content
455
+ +-->
456
+ <div class="clearboth">&nbsp;</div>
457
+ </div>
458
+ <div id="footer">
459
+ <!--+
460
+ |start bottomstrip
461
+ +-->
462
+ <div class="lastmodified">
463
+ <script type="text/javascript"><!--
464
+ document.write("Last Published: " + document.lastModified);
465
+ // --></script>
466
+ </div>
467
+ <div class="copyright">
468
+ Copyright &copy;
469
+ 2007-2009 <a href="http://www.jadeferret.com/">Sergio Fierens, Jade Ferret</a>
470
+ </div>
471
+ <div class="host">
472
+ <a href="http://rubyforge.org/projects/ai4r/"><img class="logoImage" alt="" src="images/rubyforge.png"></a>
473
+ </div>
474
+ <!--+
475
+ |end bottomstrip
476
+ +-->
477
+ </div>
478
+ <script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script><script type="text/javascript">
479
+ var pageTracker = _gat._getTracker("UA-3234625-1");
480
+ pageTracker._initData();
481
+ pageTracker._trackPageview();
482
+ </script>
483
+ </body>
484
+ </html>