ai4r 1.3 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/README.rdoc +6 -12
  2. data/examples/neural_network/backpropagation_example.rb +18 -16
  3. data/examples/neural_network/xor_example.rb +30 -20
  4. data/lib/ai4r/classifiers/classifier.rb +15 -4
  5. data/lib/ai4r/classifiers/id3.rb +31 -31
  6. data/lib/ai4r/clusterers/clusterer.rb +5 -24
  7. data/lib/ai4r/clusterers/k_means.rb +7 -38
  8. data/lib/ai4r/data/data_set.rb +4 -2
  9. data/lib/ai4r/data/parameterizable.rb +64 -0
  10. data/lib/ai4r/neural_network/backpropagation.rb +233 -210
  11. data/site/build/site/en/downloads.html +3 -3
  12. data/site/build/site/en/geneticAlgorithms.html +3 -3
  13. data/site/build/site/en/index.html +32 -15
  14. data/site/build/site/en/index.pdf +126 -100
  15. data/site/build/site/en/linkmap.html +7 -9
  16. data/site/build/site/en/linkmap.pdf +12 -12
  17. data/site/build/site/en/machineLearning.html +7 -6
  18. data/site/build/site/en/machineLearning.pdf +29 -29
  19. data/site/build/site/en/neuralNetworks.html +164 -127
  20. data/site/build/site/en/neuralNetworks.pdf +267 -200
  21. data/site/build/site/en/svn.html +4 -4
  22. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.data +0 -0
  23. data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.index +0 -0
  24. data/site/build/tmp/projfilters.properties +1 -1
  25. data/site/build/webapp/WEB-INF/logs/core.log +670 -489
  26. data/site/build/webapp/WEB-INF/logs/error.log +213 -364
  27. data/site/build/webapp/WEB-INF/logs/sitemap.log +0 -368
  28. data/site/src/documentation/content/xdocs/index.xml +1 -1
  29. data/site/src/documentation/content/xdocs/neuralNetworks.xml +118 -90
  30. data/site/src/documentation/content/xdocs/site.xml +2 -3
  31. data/test/neural_network/backpropagation_test.rb +23 -0
  32. metadata +5 -7
  33. data/site/build/site/en/forum.html +0 -197
  34. data/site/build/site/en/forum.pdf +0 -151
  35. data/site/build/site/en/wholesite.pdf +0 -1915
@@ -115,13 +115,13 @@ document.write("Last Published: " + document.lastModified);
115
115
  <a href="http://forum.jadeferret.com/viewforum.php?f=3" title="Ai4r Forum">Forum</a>
116
116
  </div>
117
117
  <div class="menuitem">
118
- <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
118
+ <a href="svn.html" title="ai4r Subversion repository">Source Code repository</a>
119
119
  </div>
120
120
  <div class="menuitem">
121
- <a href="svn.html" title="ai4r Subversion repository">Source Code repository</a>
121
+ <a href="http://wiki.jadeferret.com/Category:AI4R" title="ai4r wiki with How-to guides and more documentation">AI4R Wiki</a>
122
122
  </div>
123
123
  <div class="menuitem">
124
- <a href="wholesite.pdf">ai4r project PDF</a>
124
+ <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
125
125
  </div>
126
126
  </div>
127
127
  <div id="credit">
@@ -208,23 +208,21 @@ google_ad_height = 125;
208
208
 
209
209
  <ul>
210
210
  <li>
211
- <a href="http://ai4r.rubyforge.org/rdoc/index.html">API doc (Rdoc)</a>&nbsp;&nbsp;___________________&nbsp;&nbsp;<em>rdoc</em>&nbsp;: Ai4 RDoc docs</li>
211
+ <a href="svn.html">Source Code repository</a>&nbsp;&nbsp;___________________&nbsp;&nbsp;<em>svn</em>&nbsp;: ai4r Subversion repository</li>
212
212
  </ul>
213
213
 
214
214
  <ul>
215
215
  <li>
216
- <a href="svn.html">Source Code repository</a>&nbsp;&nbsp;___________________&nbsp;&nbsp;<em>svn</em>&nbsp;: ai4r Subversion repository</li>
216
+ <a class="external" href="http://wiki.jadeferret.com/Category:AI4R">AI4R Wiki</a>&nbsp;&nbsp;___________________&nbsp;&nbsp;<em>wiki</em>&nbsp;: ai4r wiki with How-to guides and more documentation</li>
217
217
  </ul>
218
218
 
219
219
  <ul>
220
220
  <li>
221
- <a href="wholesite.pdf">ai4r project PDF</a>&nbsp;&nbsp;___________________&nbsp;&nbsp;<em>ai4r_site_pdf</em>
222
- </li>
223
- </ul>
221
+ <a href="http://ai4r.rubyforge.org/rdoc/index.html">API doc (Rdoc)</a>&nbsp;&nbsp;___________________&nbsp;&nbsp;<em>rdoc</em>&nbsp;: Ai4 RDoc docs</li>
222
+ </ul>
224
223
 
225
224
  </ul>
226
225
  </ul>
227
-
228
226
 
229
227
  </ul>
230
228
  </ul>
@@ -5,10 +5,10 @@
5
5
  /Producer (FOP 0.20.5) >>
6
6
  endobj
7
7
  5 0 obj
8
- << /Length 1145 /Filter [ /ASCII85Decode /FlateDecode ]
8
+ << /Length 1206 /Filter [ /ASCII85Decode /FlateDecode ]
9
9
  >>
10
10
  stream
11
- Gat=+fi$QY'Re;/p^q+qX2XYH>9K^N6Q&MeeoVbL<ZDjp8nEe>mjm-a,ag&J9kUE-N:&_#kUuSZD")S+*TXcHR4SZ:r\#,h-Q>;UaFDQnl94#,0(qYF[W[+j9j'p2SI6-bo#]Q*/"YA_7W$B/7BSf:9=;Lr77E-74El69ZWi8[*/Id/"-*M8lN=>ES#odq]--d11OU:Ejc2WB[#j[d>#AiVI(dX9V<sL@\)JU^O=C^>XMd#r[Xu'qma/hA6uE_,\Bba2-\@&FQA,+Lp%HeQbS(VTJ-P`3j3PQ4s1o^"aRsu1?Q5Z/!V1"1*cquJ3+"r'7fJs^Bl?=8jC/glro41><i7AAo`d_Q[tW8+8Ej>c:)IK_aYNs"ld<i]926?#k+PF"ES=XO=Vkg5'GXiXKZ1LUS&cepF-b2td;j0I`K%`"Lp4uKR3UZ3no;9dn,?<3QPW,k@QJNmLcDA9U/SRIMsEt`H]&_pN?/;jAri_"gFkRe1Z&SI9^T(`7LL]ZBi=(2(T^fBHaEFMmm[mE@C$_>pMOP::`sO81`]hE/d0#%Uc]9gPWp23^>BW>/WSV-Wu)>KAaq!?<ijYGlAilY?q&XR0A6"aBS*Bk']n)P(6iS0S`:Knj8_4dq.,.Y$mV4FP&X3cR@s2eAHTkS*qsb,o\-gQ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GHrPD;RIP"%R,k1"Mq7:!YXa^59J)-]W(R+SCm!j0cW9uipS_YZJ%jK0/OD$X,H4gWDanW2J=t@B]!^8TMd9[/U+.i)UL4\<su*>=O<!aN#UKP"f;6'2F*eonWgQ"XGsD_^2ia+4j-eU]kSm+h1KCmDUAIXP:3e>T,%k`88$n(RQ^*Bhk`ak/\)k[rP!g\q19jXljsR(>*h@rVk5<9@B$tP@H;d5B;>kW*&IJ_,C+;$I$e%lI9;KG-@rMYQ<^fIoI_uMKE\Rt4J(e(lElP4]uUJ)DM>_[]T&Z&7^\5MHJknZgX6PW%85%g=#UI=hBuA09`!%CEG/\DF8Lp.AqTFrcCKDtT3eH5Nf4Y='I0RBapdHt:&m</dsMncCX@R`1RjmAlG=BmJW9BW4*5+%gthU3H]:se_3qam<a0eGoh'7A(G3fp(.0_q;U&P*ilnHD`J'F"3R?DO?1[dqd0X6DlCY5bRX\OEY-d_DENe`LbK3)kYeQT1kb<iOk8mH$L=fgA=.D2:(FEAJpE8M`HM1_GVWo6/&4Ct8e-2O%J<,L6W4/1CT3ZYZ0r2P\qmT[dU4=(V0rS2"1%>nCPA&lp_ftR$'jIXZ=c\A(D'8m'D*:]m0WsdhUOq(A++!'jRN%<s,o)"M^?9(,N?5P`Ct__U6??Lhr<lH0??l~>
12
12
  endstream
13
13
  endobj
14
14
  6 0 obj
@@ -72,17 +72,17 @@ endobj
72
72
  xref
73
73
  0 12
74
74
  0000000000 65535 f
75
- 0000001969 00000 n
76
- 0000002027 00000 n
77
- 0000002077 00000 n
75
+ 0000002030 00000 n
76
+ 0000002088 00000 n
77
+ 0000002138 00000 n
78
78
  0000000015 00000 n
79
79
  0000000071 00000 n
80
- 0000001308 00000 n
81
- 0000001414 00000 n
82
- 0000001526 00000 n
83
- 0000001635 00000 n
84
- 0000001745 00000 n
85
- 0000001853 00000 n
80
+ 0000001369 00000 n
81
+ 0000001475 00000 n
82
+ 0000001587 00000 n
83
+ 0000001696 00000 n
84
+ 0000001806 00000 n
85
+ 0000001914 00000 n
86
86
  trailer
87
87
  <<
88
88
  /Size 12
@@ -90,5 +90,5 @@ trailer
90
90
  /Info 4 0 R
91
91
  >>
92
92
  startxref
93
- 2197
93
+ 2258
94
94
  %%EOF
@@ -115,13 +115,13 @@ document.write("Last Published: " + document.lastModified);
115
115
  <a href="http://forum.jadeferret.com/viewforum.php?f=3" title="Ai4r Forum">Forum</a>
116
116
  </div>
117
117
  <div class="menuitem">
118
- <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
118
+ <a href="svn.html" title="ai4r Subversion repository">Source Code repository</a>
119
119
  </div>
120
120
  <div class="menuitem">
121
- <a href="svn.html" title="ai4r Subversion repository">Source Code repository</a>
121
+ <a href="http://wiki.jadeferret.com/Category:AI4R" title="ai4r wiki with How-to guides and more documentation">AI4R Wiki</a>
122
122
  </div>
123
123
  <div class="menuitem">
124
- <a href="wholesite.pdf">ai4r project PDF</a>
124
+ <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
125
125
  </div>
126
126
  </div>
127
127
  <div id="credit">
@@ -229,7 +229,7 @@ The only information that you have is a collection of examples, provided by a ma
229
229
  and identify new posible marketing targets:</p>
230
230
  <pre class="code">
231
231
 
232
- id3.to_s
232
+ id3.get_rules
233
233
  # =&gt; if age_range=='&lt;30' then marketing_target='Y'
234
234
  elsif age_range=='[30-50)' and city=='Chicago' then marketing_target='Y'
235
235
  elsif age_range=='[30-50)' and city=='New York' then marketing_target='N'
@@ -277,7 +277,8 @@ id3.eval(['New York', '&lt;30', 'M'])
277
277
  # =&gt; 'Y'
278
278
  </pre>
279
279
  <p>
280
- But instead of going through the tree every time, you can take advantage of the fact that the method "to_s" generates proper ruby code!
280
+ But instead of going through the tree every time, you can take advantage of the
281
+ fact that the method "get_rules" generates proper ruby code!
281
282
  </p>
282
283
  <pre class="code">
283
284
 
@@ -286,7 +287,7 @@ But instead of going through the tree every time, you can take advantage of the
286
287
  city = 'New York'
287
288
  gender = 'M'
288
289
  marketing_target = nil
289
- eval id3.to_s
290
+ eval id3.get_rules
290
291
  puts marketing_target
291
292
  # =&gt; 'Y'
292
293
  </pre>
@@ -95,10 +95,10 @@ endobj
95
95
  >>
96
96
  endobj
97
97
  20 0 obj
98
- << /Length 1797 /Filter [ /ASCII85Decode /FlateDecode ]
98
+ << /Length 1802 /Filter [ /ASCII85Decode /FlateDecode ]
99
99
  >>
100
100
  stream
101
- Gau0DD/\/e&H;*)Tqrjt!!t0=H7b9]8X^>FdUGk.!C[tFN()JfD98R:AAPkW^=+T.M:?cPL*DnCV!e2Q48O%]3$/\1(f4uKIieoh9l/#E4S[fRoCkW;qS`+Z-*=eqDhHO(]M1N/[p@0(534uOT0B>YQ<IDhRo^]6>pR(r#VDK`NTUDU:s=ZD'\6Cc/ItAh>3!#51Q!DPF?7\?X]oT=fc6e_IZT8:o((_.II#7dF.T/ep[Cp\8]5\V+Vo*u7'_opa29->&'^,@b/@+lTtX/?-]=r>C*E9?nD!H3!ek2,%12W!"lq0!PBFe16e@pr,Cq%q$o*\5,9/dL`\XkjT;g?R>^G!3M*jqH4"KWO+`Z>i;YI/=0PfQDomI(Qh&mtLfVeGp*jts."T2i=?2H=[DuW7"qrE#G$"&_Wqqr4[a7X78Bd67h(.uN4*0-@`+o4K8L.G3Z#aqLC`R<+Q1/HG(kVu!<7U$&M+n\-+dU#L,!si):.YXT23QA^L<4\2!bE'*<[WG=OHS.db6p`,)E[B<md6h_Uo[K!,A@UDA/iSk8n&9#s]'7;a"6@rO"#0[bGWXUI6lMBmjS;#1)AD0=5QaUZp#,'hhgoF]67COp5^PC.!-LVh0ZP:a!1hS*:u<`Z!sEIpa9c+gJTIM7-_MP3=H$"OejWsr\oMp^X\o`G$"+0TFUZ=b$+7H9+3rhreT!1`]%$70oS?D7:Pk43Uf\f)nQ[!t1#3c-+^UjpgC0WWMrYIIWKM\\U&;&ojI]np=ip"19@D!IG!]sZhefd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ge-49U:4o7U!J`0@I@/)a%c].MY/D?&R82'dVJ"(sY.OKi*akYmJ8?U*:EMPfjMRd%Gjn*jWC$coY5soYZPGIdN0To1^fXW@jIjXZ0s?KlNDOo?)cT%9D].a:B3R7L*^o+?QQajUX`XV/)=.F(/>(tf35Ad,Uk81I0jBJc1F2VSHN5S'K%+(!]kj+)4u3A!8W'C&m!_Y?@3L?4`[r/7?0;A*.DPHo\7i,HDZjIN6UI:03Wo#00>HMr@!0'2`g(P,Btu=,ONqhe[X*a9WbTgp(/T[kOqL8]W^iSsCPgbOX4tp=cdC`6DLp3K82Q:@h>4P?cc&T</YSdVI#b:e\\t]-nh_H_RX<s6nq]tMhW!6\^;2Ucg>4!jB5&W@H-K<b5")\JeK?"69;u)=.1L>0@lkn!LQh8Mo_Nrod^3,f4?5R>]^EmB)Gjnpjj;de3X&Mbi@ZH@i+&>Kq7X!/qlZu-(H7Bf?DB(T0>c<DbjS3NpF[ae^q-_1SXbjfe]l40`2ij/irlrr]_J6(jjX:TAuecnIBHNQ"j@=0o*bpJY6\^iIJA_f/`WY*+W.W)>f,]&$<<.hc!ii52@C8b2tR>8MmMukAJW=:#[(phDBHA<8d3`LoVt5NCAYqnX!B@$Iur[]3lPg2AYDHm^G>0-$8NMk*4_pA-&;]NgKj`(O:O2]\5qO<O/bMB/DWFgGd/gH`".aAQatUBJAT$oY,,=?WM(tS\3hY*aBu)tL+*`%9;NonI8\oa8tqE:+^/JUh9-)s^:s]'id_"~>
102
102
  endstream
103
103
  endobj
104
104
  21 0 obj
@@ -288,44 +288,44 @@ endobj
288
288
  xref
289
289
  0 39
290
290
  0000000000 65535 f
291
- 0000009543 00000 n
292
- 0000009622 00000 n
293
- 0000009714 00000 n
291
+ 0000009548 00000 n
292
+ 0000009627 00000 n
293
+ 0000009719 00000 n
294
294
  0000000015 00000 n
295
295
  0000000071 00000 n
296
296
  0000000834 00000 n
297
297
  0000000954 00000 n
298
298
  0000001007 00000 n
299
- 0000009848 00000 n
299
+ 0000009853 00000 n
300
300
  0000001142 00000 n
301
- 0000009911 00000 n
301
+ 0000009916 00000 n
302
302
  0000001278 00000 n
303
- 0000009977 00000 n
303
+ 0000009982 00000 n
304
304
  0000001414 00000 n
305
- 0000010042 00000 n
305
+ 0000010047 00000 n
306
306
  0000001551 00000 n
307
- 0000010108 00000 n
307
+ 0000010113 00000 n
308
308
  0000001688 00000 n
309
309
  0000003674 00000 n
310
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
311
+ 0000005677 00000 n
312
+ 0000005785 00000 n
313
+ 0000006805 00000 n
314
+ 0000006928 00000 n
315
+ 0000006962 00000 n
316
+ 0000007155 00000 n
317
+ 0000010178 00000 n
318
+ 0000007350 00000 n
319
+ 0000007611 00000 n
320
+ 0000008103 00000 n
321
+ 0000008321 00000 n
322
+ 0000008602 00000 n
323
+ 0000008886 00000 n
324
+ 0000008999 00000 n
325
+ 0000009109 00000 n
326
+ 0000009217 00000 n
327
+ 0000009323 00000 n
328
+ 0000009439 00000 n
329
329
  trailer
330
330
  <<
331
331
  /Size 39
@@ -333,5 +333,5 @@ trailer
333
333
  /Info 4 0 R
334
334
  >>
335
335
  startxref
336
- 10224
336
+ 10229
337
337
  %%EOF
@@ -5,7 +5,7 @@
5
5
  <meta content="Apache Forrest" name="Generator">
6
6
  <meta name="Forrest-version" content="0.8">
7
7
  <meta name="Forrest-skin-name" content="pelt">
8
- <title>Backpropagation neural networks in ruby :: ai4r</title>
8
+ <title>OCR example using Backpropagation networks in ruby :: ai4r</title>
9
9
  <link type="text/css" href="skin/basic.css" rel="stylesheet">
10
10
  <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
11
11
  <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
@@ -115,13 +115,13 @@ document.write("Last Published: " + document.lastModified);
115
115
  <a href="http://forum.jadeferret.com/viewforum.php?f=3" title="Ai4r Forum">Forum</a>
116
116
  </div>
117
117
  <div class="menuitem">
118
- <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
118
+ <a href="svn.html" title="ai4r Subversion repository">Source Code repository</a>
119
119
  </div>
120
120
  <div class="menuitem">
121
- <a href="svn.html" title="ai4r Subversion repository">Source Code repository</a>
121
+ <a href="http://wiki.jadeferret.com/Category:AI4R" title="ai4r wiki with How-to guides and more documentation">AI4R Wiki</a>
122
122
  </div>
123
123
  <div class="menuitem">
124
- <a href="wholesite.pdf">ai4r project PDF</a>
124
+ <a href="http://ai4r.rubyforge.org/rdoc/index.html" title="Ai4 RDoc docs">API doc (Rdoc)</a>
125
125
  </div>
126
126
  </div>
127
127
  <div id="credit">
@@ -151,17 +151,20 @@ google_ad_height = 125;
151
151
  <a class="dida" href="neuralNetworks.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
152
152
  PDF</a>
153
153
  </div>
154
- <h1>Backpropagation neural networks in ruby :: ai4r</h1>
154
+ <h1>OCR example using Backpropagation networks in ruby :: ai4r</h1>
155
155
  <div id="minitoc-area">
156
156
  <ul class="minitoc">
157
157
  <li>
158
- <a href="#nn-Introduction">Introduction to Neural Networks in Ruby</a>
158
+ <a href="#nn-Introduction">Introduction to Neural Networks</a>
159
+ </li>
160
+ <li>
161
+ <a href="#nn-example">Modeling the OCR problem using Neural Networks networks</a>
159
162
  </li>
160
163
  <li>
161
- <a href="#nn-HowTo">How to use Backpropagation Neural Networks in Ruby</a>
164
+ <a href="#nn2-example">Implementing a basic OCR application using ruby and AI4R</a>
162
165
  </li>
163
166
  <li>
164
- <a href="#nn-example">OCR example using Backpropagation networks in ruby</a>
167
+ <a href="#nn3-example">Results obtained with the AI4R OCR algorithm</a>
165
168
  </li>
166
169
  <li>
167
170
  <a href="#nn-custom">Customizing your neural network in ai4r</a>
@@ -173,7 +176,7 @@ google_ad_height = 125;
173
176
  </div>
174
177
 
175
178
  <a name="N1000D"></a><a name="nn-Introduction"></a>
176
- <h2 class="boxed">Introduction to Neural Networks in Ruby</h2>
179
+ <h2 class="boxed">Introduction to Neural Networks</h2>
177
180
  <div class="section">
178
181
  <p>
179
182
  The utility of artificial neural network models lies in the fact
@@ -194,31 +197,9 @@ google_ad_height = 125;
194
197
  Rumelhart, Geoffrey E. Hinton and Ronald J. Williams in 1986)
195
198
  </p>
196
199
  </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
200
 
219
-
220
- <a name="N10025"></a><a name="nn-example"></a>
221
- <h2 class="boxed">OCR example using Backpropagation networks in ruby</h2>
201
+ <a name="N1001A"></a><a name="nn-example"></a>
202
+ <h2 class="boxed">Modeling the OCR problem using Neural Networks networks</h2>
222
203
  <div class="section">
223
204
  <p>
224
205
  Let's imagine that we have to implement a program to identify simple patterns
@@ -228,12 +209,14 @@ google_ad_height = 125;
228
209
  signal).
229
210
  </p>
230
211
  <p>
231
- We can take an example of each pattern to be recognized, and train a
232
- neural network to identify them.
212
+ In order to solve this problem, we can take an example of each pattern
213
+ to be recognized, and train a neural network to identify similar patterns.
214
+ In fact, one of the most popular uses of neural networks in business
215
+ applications is OCR (opticar character recognition)
233
216
  </p>
234
217
  <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
218
+ In our porposed solotion, we create a network with the following
219
+ architecture: 256 input neurons and 3 output neurons. We feed this network
237
220
  with 16x16 matrices (in fact will convert them to vectors of length 256).
238
221
  Each pixel is represented with a number from 0 (white pixel) to 10
239
222
  (black pixel). The output of this network if a 3 vector of dimension 3,
@@ -262,81 +245,56 @@ google_ad_height = 125;
262
245
  </tr>
263
246
 
264
247
  </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>
248
+ </div>
249
+
250
+ <a name="N10057"></a><a name="nn2-example"></a>
251
+ <h2 class="boxed">Implementing a basic OCR application using ruby and AI4R</h2>
252
+ <div class="section">
253
+ <p>The code bellow shows the basic steps to use Backpropagation Neural
254
+ Networks in AI4R:</p>
255
+ <pre class="code">
321
256
 
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>
257
+ # Create the network with:
258
+ # 4 inputs
259
+ # 1 hidden layer with 3 neurons
260
+ # 2 outputs
261
+ net = Ai4r::NeuralNetwork::Backpropagation.new([4, 3, 2])
262
+
263
+ # Train the network
264
+ 100.times do |i|
265
+ net.train(example[i], result[i])
266
+ end
267
+
268
+ # Use it: Evaluate data with the trained network
269
+ net.eval([12, 48, 12, 25]) # =&gt; [0.89, 0.04]
270
+
271
+ </pre>
272
+ <p>This is the source code used to elaborate this simple OCR application
273
+ (You can find it inside the AI4R zip file release):</p>
326
274
  <pre class="code">
327
275
 
328
276
  require "rubygems"
329
- require "ai4r/neural_network/backpropagation"
277
+ require "ai4r"
330
278
  require File.dirname(__FILE__) + '/training_patterns'
331
279
  require File.dirname(__FILE__) + '/patterns_with_noise'
332
280
  require File.dirname(__FILE__) + '/patterns_with_base_noise'
333
281
 
334
- net = Ai4r::NeuralNetwork::Backpropagation.new([256, 128, 3])
282
+ # Create a network with 256 inputs, and 3 outputs
283
+ net = Ai4r::NeuralNetwork::Backpropagation.new([256, 3])
335
284
 
285
+ # Load training data
336
286
  tr_input = TRIANGLE.flatten.collect { |input| input.to_f / 10}
337
287
  sq_input = SQUARE.flatten.collect { |input| input.to_f / 10}
338
288
  cr_input = CROSS.flatten.collect { |input| input.to_f / 10}
289
+ # Train the network
290
+ puts "Training the network, please wait."
291
+ 100.times do
292
+ net.train(tr_input, [1,0,0])
293
+ net.train(sq_input, [0,1,0])
294
+ net.train(cr_input, [0,0,1])
295
+ end
339
296
 
297
+ # Load test data with noise
340
298
  tr_with_noise = TRIANGLE_WITH_NOISE.flatten.collect { |input| input.to_f / 10}
341
299
  sq_with_noise = SQUARE_WITH_NOISE.flatten.collect { |input| input.to_f / 10}
342
300
  cr_with_noise = CROSS_WITH_NOISE.flatten.collect { |input| input.to_f / 10}
@@ -345,12 +303,7 @@ tr_with_base_noise = TRIANGLE_WITH_BASE_NOISE.flatten.collect { |input| input.to
345
303
  sq_with_base_noise = SQUARE_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10}
346
304
  cr_with_base_noise = CROSS_WITH_BASE_NOISE.flatten.collect { |input| input.to_f / 10}
347
305
 
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
306
+ # Print the evaluation results
354
307
 
355
308
  def result_label(result)
356
309
  if result[0] &gt; result[1] &amp;&amp; result[0] &gt; result[2]
@@ -377,45 +330,129 @@ puts "#{net.eval(cr_with_base_noise).inspect} =&gt; #{result_label(net.eval(cr_w
377
330
 
378
331
  </pre>
379
332
  </div>
333
+
334
+ <a name="N1006C"></a><a name="nn3-example"></a>
335
+ <h2 class="boxed">Results obtained with the AI4R OCR algorithm</h2>
336
+ <div class="section">
337
+ <p>
338
+ The results we got when we evaluate patterns with our trained network are:
339
+ </p>
340
+ <ul>
341
+
342
+ <li>Evaluating the training patterns with the trained network:
343
+ <ol>
344
+
345
+ <li>
346
+ <img alt="Triangule training example" src="/images/t.png">
347
+ [0.98, 0.03, 0.01] =&gt; TRIANGLE </li>
348
+
349
+ <li>
350
+ <img alt="Square training example" src="/images/s.png">
351
+ [0.00, 0.96, 0.03] =&gt; SQUARE </li>
352
+
353
+ <li>
354
+ <img alt="Cross training example" src="/images/c.png">
355
+ [0.00, 0.00, 0.99] =&gt; CROSS </li>
356
+
357
+ </ol>
358
+
359
+ </li>
360
+
361
+ <li>Evaluating the patterns with random noise with the trained network:
362
+ <ol>
363
+
364
+ <li>
365
+ <img alt="Triangule pattern with random noise" src="/images/t_wn.png"> [0.98, 0.01, 0.01] =&gt; TRIANGLE </li>
366
+
367
+ <li>
368
+ <img alt="Square pattern with random noise" src="/images/s_wn.png"> [0.00, 0.96, 0.02] =&gt; SQUARE </li>
369
+
370
+ <li>
371
+ <img alt="Cross pattern with random noise" src="/images/c_wn.png"> [0.00, 0.00, 0.98] =&gt; CROSS </li>
372
+
373
+ </ol>
374
+
375
+ </li>
376
+
377
+ <li>Evaluating the patterns with line noise with the trained network:
378
+ <ol>
379
+
380
+ <li>
381
+ <img alt="Triangule pattern with line noise" src="/images/t_wbn.png"> [0.62, 0.00, 0.02] =&gt; TRIANGLE </li>
382
+
383
+ <li>
384
+ <img alt="Square pattern with line noise" src="/images/s_wbn.png"> [0.00, 0.75, 0.01] =&gt; SQUARE </li>
385
+
386
+ <li>
387
+ <img alt="Cross pattern with line noise" src="/images/c_wbn.png"> [0.00, 0.00, 0.98] =&gt; CROSS </li>
388
+
389
+ </ol>
390
+
391
+ </li>
392
+
393
+ </ul>
394
+ <p>These results are satisfactory. The network could sucessfully identify
395
+ the patterns despite the noise introduced to them.</p>
396
+ </div>
380
397
 
381
398
 
382
- <a name="N100C6"></a><a name="nn-custom"></a>
399
+ <a name="N100CD"></a><a name="nn-custom"></a>
383
400
  <h2 class="boxed">Customizing your neural network in ai4r</h2>
384
401
  <div class="section">
385
402
  <p>Sometime for a given problem, you will have to "play around" with some parameters to
386
403
  get to a solution. This parameters are:</p>
387
404
  <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>
405
+
406
+ <strong>Learning Rate</strong>: a real number, usually between 0.05
407
+ and 0.25.
408
+ </p>
391
409
  <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>
410
+
411
+ <strong>Momentum</strong>: A momentum will avoid oscillations during
412
+ learning, converging to a solution in less iterations.
413
+ </p>
393
414
  <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
415
+ <strong>Propagation function</strong>: By default, f(x) = 1/(1 + e^(-x)).
416
+ This function is called
417
+ <a class="external" href="http://en.wikipedia.org/wiki/Sigmoid_function">
418
+ Sigmoid function
419
+ </a>. You can see it like a "smoothed" version of the
420
+ <a class="external" href="http://en.wikipedia.org/wiki/Heaviside_step_function">
421
+ Heaviside step function
422
+ </a>. It will always provide a
397
423
  value between 0 and 1. </p>
398
424
  <p>
399
425
  <img alt="Sigmoid function" src="images/sigmoid.png"></p>
400
426
  <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>
427
+ Sometimes you will have better results with f(x) = tanh(x), or even with
428
+ f(x) = x. If you modify the propagation function, you have to supply the
429
+ derivative function too (in terms of the propagation function result).
430
+ </p>
431
+ <p>To customize these parameters in AI4R, you can user the "set_parameters"
432
+ method:</p>
403
433
  <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
-
434
+ net.set_parameters(
435
+ :momentum =&gt; 0.15,
436
+ :learning_rate =&gt; 0.5,
437
+ :propagation_function =&gt; lambda { |x| Math.tanh(x) },
438
+ :derivative_propagation_function =&gt; lambda { |y| 1.0 - y**2 }
439
+ )
440
+ </pre>
441
+ <p>You can also use the attribute accesors:</p>
442
+ <pre class="code">
443
+ net.momentum = 0.15
444
+ net.learning_rate = 0.5
445
+ net.propagation_function = lambda { |x| Math.tanh(x) }
446
+ net.derivative_propagation_function = lambda { |y| 1.0 - y**2 }
414
447
  </pre>
415
448
  </div>
416
-
417
449
 
418
- <a name="N100F0"></a><a name="nn-more"></a>
450
+ <div class="note">
451
+ <div class="label">Note</div>
452
+ <div class="content">Remember to set the custom parameters BEFORE training the network</div>
453
+ </div>
454
+
455
+ <a name="N1010B"></a><a name="nn-more"></a>
419
456
  <h2 class="boxed">More about Neural Networks and Backpropagation</h2>
420
457
  <div class="section">
421
458
  <ul>