-
Notifications
You must be signed in to change notification settings - Fork 71
/
documentation.html
executable file
·965 lines (848 loc) · 42.3 KB
/
documentation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
<html>
<head>
<title>Docs For Class NeuralNetwork</title>
<style type='text/css'>
.php {
padding: 1em;
}
.php-src { font-family: 'Courier New', Courier, monospace; font-weight: normal; }
body
{
color: #000000;
background-color: #ffffff;
background-repeat: repeat-y;
font-family: tahoma, verdana, arial, sans-serif;
font-size: 10pt;
}
a
{
color: #000099;
background-color: transparent;
text-decoration: none;
}
a:hover
{
text-decoration: underline;
}
a.menu
{
color: #ffffff;
background-color: transparent;
}
td
{
font-size: 10pt;
}
td.header_top
{
color: #ffffff;
background-color: #9999cc;
font-size: 16pt;
font-weight: bold;
text-align: right;
padding: 10px;
}
td.header_line
{
color: #ffffff;
background-color: #333366;
}
td.header_menu
{
color: #ffffff;
background-color: #666699;
font-size: 8pt;
text-align: right;
padding: 2px;
padding-right: 5px;
}
td.menu
{
padding: 2px;
padding-left: 5px;
}
td.code_border
{
color: #000000;
background-color: #c0c0c0;
}
td.code
{
color: #000000;
background-color: #f0f0f0;
}
td.type
{
font-style: italic;
}
div.credit
{
font-size: 8pt;
text-align: center;
}
div.package
{
padding-left: 5px;
}
div.tags
{
padding-left: 15px;
}
div.function
{
padding-left: 15px;
}
div.top
{
font-size: 8pt;
}
div.warning
{
color: #ff0000;
background-color: transparent;
}
div.description
{
padding-left: 15px;
}
hr
{
height: 1px;
border-style: solid;
border-color: #c0c0c0;
margin-top: 10px;
margin-bottom: 10px;
}
span.smalllinenumber
{
font-size: 8pt;
}
ul {
margin-left: 0px;
padding-left: 8px;
}
/* Syntax highlighting */
.src-code { background-color: #f5f5f5; border: 1px solid #ccc9a4; padding: 0px; margin : 0px;
font-family: 'Courier New', Courier, monospace; font-weight: normal; }
.src-line { font-family: 'Courier New', Courier, monospace; font-weight: normal; }
.src-comm { color: green; }
.src-id { }
.src-inc { color: #0000FF; }
.src-key { color: #0000FF; }
.src-num { color: #CC0000; }
.src-str { color: #66cccc; }
.src-sym { font-weight: bold; }
.src-var { }
.src-php { font-weight: bold; }
.src-doc { color: #009999 }
.src-doc-close-template { color: #0000FF }
.src-doc-coretag { color: #0099FF; font-weight: bold }
.src-doc-inlinetag { color: #0099FF }
.src-doc-internal { color: #6699cc }
.src-doc-tag { color: #0080CC }
.src-doc-template { color: #0000FF }
.src-doc-type { font-style: italic }
.src-doc-var { font-style: italic }
.tute-tag { color: #009999 }
.tute-attribute-name { color: #0000FF }
.tute-attribute-value { color: #0099FF }
.tute-entity { font-weight: bold; }
.tute-comment { font-style: italic }
.tute-inline-tag { color: #636311; font-weight: bold }
/* tutorial */
.authors { }
.author { font-style: italic; font-weight: bold }
.author-blurb { margin: .5em 0em .5em 2em; font-size: 85%; font-weight: normal; font-style: normal }
.example { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; }
.listing { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; white-space: nowrap; }
.release-info { font-size: 85%; font-style: italic; margin: 1em 0em }
.ref-title-box { }
.ref-title { }
.ref-purpose { font-style: italic; color: #666666 }
.ref-synopsis { }
.title { font-weight: bold; margin: 1em 0em 0em 0em; padding: .25em; border: 2px solid #999999; background-color: #9999CC }
.cmd-synopsis { margin: 1em 0em }
.cmd-title { font-weight: bold }
.toc { margin-left: 2em; padding-left: 0em }
</style>
</head>
<body>
<h1>Class: NeuralNetwork</h1>
<table width="100%" border="0">
<tr><td valign="top">
<h3><a href="#class_details">Class Overview</a></h3>
<pre></pre><br />
<div class="description"><strong>Multi-layer Neural Network in PHP</strong></div><br /><br />
<h4>Author(s):</h4>
<ul>
<li>E. Akerboom</li>
<li><a href="http://www.tremani.nl/">Tremani</a>, <a href="http://maps.google.com/maps?f=q&hl=en&q=delft%2C+the+netherlands&ie=UTF8&t=k&om=1&ll=53.014783%2C4.921875&spn=36.882665%2C110.566406&z=4">Delft</a>, The Netherlands</li>
</ul>
<h4>Version:</h4>
<ul>
<li>1.0</li>
</ul>
</td>
<td valign="top">
<h3><a href="#class_methods">Methods</a></h3>
<ul>
<li><a href="#methodNeuralNetwork">NeuralNetwork</a></li>
<li><a href="#methodactivation">activation</a></li>
<li><a href="#methodaddControlData">addControlData</a></li>
<li><a href="#methodaddTestData">addTestData</a></li>
<li><a href="#methodcalculate">calculate</a></li>
<li><a href="#methodderivative_activation">derivative_activation</a></li>
<li><a href="#methodgetControlDataIDs">getControlDataIDs</a></li>
<li><a href="#methodgetLearningRate">getLearningRate</a></li>
<li><a href="#methodgetMomentum">getMomentum</a></li>
<li><a href="#methodgetRandomWeight">getRandomWeight</a></li>
<li><a href="#methodgetTestDataIDs">getTestDataIDs</a></li>
<li><a href="#methodisVerbose">isVerbose</a></li>
<li><a href="#methodload">load</a></li>
<li><a href="#methodsave">save</a></li>
<li><a href="#methodsetLearningRate">setLearningRate</a></li>
<li><a href="#methodsetMomentum">setMomentum</a></li>
<li><a href="#methodsetVerbose">setVerbose</a></li>
<li><a href="#methodshowWeights">showWeights</a></li>
<li><a href="#methodtrain">train</a></li>
</ul>
</td>
</tr></table>
<hr />
<table width="100%" border="0"><tr>
</tr></table>
<hr />
<a name="class_details"></a>
<h3>Class Details</h3>
<div class="tags">
[line 75]<br />
<strong>Multi-layer Neural Network in PHP</strong><br /><br /><p>Loosely based on source code by <a href="http://www.philbrierley.com">Phil Brierley</a>, that was translated into PHP by 'dspink' in sep 2005</p><p>Algorithm was obtained from the excellent introductory book "<a href="http://www.amazon.com/link/dp/0321204662">Artificial Intelligence - a guide to intelligent systems</a>" by Michael Negnevitsky (ISBN 0-201-71159-1)</p><p><strong>Example: learning the 'XOR'-function</strong> <ol><li><div class="src-line"> <span class="src-inc">require_once</span><span class="src-sym">(</span><span class="src-str">"class_neuralnetwork.php"</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// Create a new neural network with 3 input neurons,</span></div></li>
<li><div class="src-line"> <span class="src-comm">// 4 hidden neurons, and 1 output neuron</span></div></li>
<li><div class="src-line"> <span class="src-var">$n </span>= <span class="src-key">new </span><a href="#methodNeuralNetwork">NeuralNetwork</a><span class="src-sym">(</span><span class="src-num">3</span><span class="src-sym">, </span><span class="src-num">4</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> <span class="src-var">$n</span><span class="src-sym">-></span><a href="#methodsetVerbose">setVerbose</a><span class="src-sym">(</span><span class="src-id">false</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// Add test-data to the network. In this case,</span></div></li>
<li><div class="src-line"> <span class="src-comm">// we want the network to learn the 'XOR'-function.</span></div></li>
<li><div class="src-line"> <span class="src-comm">// The third input-parameter is the 'bias'.</span></div></li>
<li><div class="src-line"> <span class="src-var">$n</span><span class="src-sym">-></span><a href="#methodaddTestData">addTestData</a><span class="src-sym">( </span><span class="src-key">array </span><span class="src-sym">(</span>-<span class="src-num">1</span><span class="src-sym">, </span>-<span class="src-num">1</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-key">array </span><span class="src-sym">(</span>-<span class="src-num">1</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> <span class="src-var">$n</span><span class="src-sym">-></span><a href="#methodaddTestData">addTestData</a><span class="src-sym">( </span><span class="src-key">array </span><span class="src-sym">(</span>-<span class="src-num">1</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-key">array </span><span class="src-sym">( </span><span class="src-num">1</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> <span class="src-var">$n</span><span class="src-sym">-></span><a href="#methodaddTestData">addTestData</a><span class="src-sym">( </span><span class="src-key">array </span><span class="src-sym">( </span><span class="src-num">1</span><span class="src-sym">, </span>-<span class="src-num">1</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-key">array </span><span class="src-sym">( </span><span class="src-num">1</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> <span class="src-var">$n</span><span class="src-sym">-></span><a href="#methodaddTestData">addTestData</a><span class="src-sym">( </span><span class="src-key">array </span><span class="src-sym">( </span><span class="src-num">1</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-key">array </span><span class="src-sym">(</span>-<span class="src-num">1</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// we try training the network for at most $max times</span></div></li>
<li><div class="src-line"> <span class="src-var">$max </span>= <span class="src-num">3</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// train the network in max 1000 epochs, with a max squared error of 0.01</span></div></li>
<li><div class="src-line"> <span class="src-key">while </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-sym">(</span><span class="src-var">$success</span>=<span class="src-var">$n</span><span class="src-sym">-></span><a href="#methodtrain">train</a><span class="src-sym">(</span><span class="src-num">1000</span><span class="src-sym">, </span><span class="src-num">0.01</span><span class="src-sym">)) </span>&& <span class="src-var">$max</span>--><span class="src-num">0</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"> <span class="src-comm">// training failed:</span></div></li>
<li><div class="src-line"> <span class="src-comm">// 1. re-initialize the weights in the network</span></div></li>
<li><div class="src-line"> <span class="src-var">$n</span><span class="src-sym">-></span><span class="src-id">initWeights</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// 2. display message</span></div></li>
<li><div class="src-line"> echo <span class="src-str">"Nothing found...<hr />"</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> <span class="src-sym">}</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// print a message if the network was succesfully trained</span></div></li>
<li><div class="src-line"> <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$success</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"> <span class="src-var">$epochs </span>= <span class="src-var">$n</span><span class="src-sym">-></span><span class="src-id">getEpoch</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> echo <span class="src-str">"</span><span class="src-str"><span class="src-id">Success</span> <span class="src-id">in</span> <span class="src-var">$epochs</span> <span class="src-id">training</span> <span class="src-id">rounds</span>!<<span class="src-id">hr</span> /></span><span class="src-str">"</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> <span class="src-sym">}</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// in any case, we print the output of the neural network</span></div></li>
<li><div class="src-line"> <span class="src-key">for </span><span class="src-sym">(</span><span class="src-var">$i </span>= <span class="src-num">0</span><span class="src-sym">; </span><span class="src-var">$i </span>< <a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$n</span><span class="src-sym">-></span><span class="src-id">trainInputs</span><span class="src-sym">)</span><span class="src-sym">; </span><span class="src-var">$i </span>++<span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"> <span class="src-var">$output </span>= <span class="src-var">$n</span><span class="src-sym">-></span><a href="#methodcalculate">calculate</a><span class="src-sym">(</span><span class="src-var">$n</span><span class="src-sym">-></span><span class="src-id">trainInputs</span><span class="src-sym">[</span><span class="src-var">$i</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> print <span class="src-str">"</span><span class="src-str"><<span class="src-id">br</span> /><span class="src-id">Testset</span> <span class="src-var">$i</span>; </span><span class="src-str">"</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> print <span class="src-str">"expected output = ("</span>.<a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">", "</span><span class="src-sym">, </span><span class="src-var">$n</span><span class="src-sym">-></span><span class="src-id">trainOutput</span><span class="src-sym">[</span><span class="src-var">$i</span><span class="src-sym">]</span><span class="src-sym">)</span>.<span class="src-str">") "</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> print <span class="src-str">"output from neural network = ("</span>.<a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">", "</span><span class="src-sym">, </span><span class="src-var">$output</span><span class="src-sym">)</span>.<span class="src-str">")\n"</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> <span class="src-sym">}</span></div></li>
</ol></p><p>The resulting output could for example be something along the following lines:</p><p><ol><li><div class="src-line"> <span class="src-id">Success in </span><span class="src-num">719 </span><span class="src-id">training rounds</span><span class="src-sym">!</span></div></li>
<li><div class="src-line"> <span class="src-id">Testset </span><span class="src-num">0</span><span class="src-sym">; </span><span class="src-id">expected output </span>= <span class="src-sym">(</span>-<span class="src-num">1</span><span class="src-sym">) </span><span class="src-id">output from neural network </span>= <span class="src-sym">(</span>-<span class="src-num">0.986415991978</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"> <span class="src-id">Testset </span><span class="src-num">1</span><span class="src-sym">; </span><span class="src-id">expected output </span>= <span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">) </span><span class="src-id">output from neural network </span>= <span class="src-sym">(</span><span class="src-num">0.992121412998</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"> <span class="src-id">Testset </span><span class="src-num">2</span><span class="src-sym">; </span><span class="src-id">expected output </span>= <span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">) </span><span class="src-id">output from neural network </span>= <span class="src-sym">(</span><span class="src-num">0.992469534962</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"> <span class="src-id">Testset </span><span class="src-num">3</span><span class="src-sym">; </span><span class="src-id">expected output </span>= <span class="src-sym">(</span>-<span class="src-num">1</span><span class="src-sym">) </span><span class="src-id">output from neural network </span>= <span class="src-sym">(</span>-<span class="src-num">0.990224120384</span><span class="src-sym">)</span></div></li>
</ol></p><p>...which indicates the network has learned the task.</p><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>version:</b> </td><td>1.0</td>
</tr>
<tr>
<td><b>since:</b> </td><td>feb 2007</td>
</tr>
<tr>
<td><b>author:</b> </td><td>E. Akerboom</td>
</tr>
<tr>
<td><b>author:</b> </td><td><a href="http://www.tremani.nl/">Tremani</a>, <a href="http://maps.google.com/maps?f=q&hl=en&q=delft%2C+the+netherlands&ie=UTF8&t=k&om=1&ll=53.014783%2C4.921875&spn=36.882665%2C110.566406&z=4">Delft</a></td>
</tr>
<tr>
<td><b>license:</b> </td><td><a href="http://opensource.org/licenses/bsd-license.php">BSD License</a></td>
</tr>
</table>
</div>
</div><br /><br />
<div class="top">[ <a href="#top">Top</a> ]</div><br />
<hr />
<a name="class_methods"></a>
<h3>Class Methods</h3>
<div class="tags">
<hr />
<a name="methodNeuralNetwork"></a>
<h3>constructor NeuralNetwork <span class="smalllinenumber">[line 124]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>NeuralNetwork NeuralNetwork(
array
$nodecount)</code>
</td></tr></table>
</td></tr></table><br />
Creates a neural network.<br /><br /><p>Example: <ol><li><div class="src-line"> <span class="src-comm">// create a network with 4 input nodes, 10 hidden nodes, and 4 output nodes</span></div></li>
<li><div class="src-line"> <span class="src-var">$n </span>= <span class="src-key">new </span><a href="#methodNeuralNetwork">NeuralNetwork</a><span class="src-sym">(</span><span class="src-num">4</span><span class="src-sym">, </span><span class="src-num">10</span><span class="src-sym">, </span><span class="src-num">4</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// create a network with 4 input nodes, 1 hidden layer with 10 nodes,</span></div></li>
<li><div class="src-line"> <span class="src-comm">// another hidden layer with 10 nodes, and 4 output nodes</span></div></li>
<li><div class="src-line"> <span class="src-var">$n </span>= <span class="src-key">new </span><a href="#methodNeuralNetwork">NeuralNetwork</a><span class="src-sym">(</span><span class="src-num">4</span><span class="src-sym">, </span><span class="src-num">10</span><span class="src-sym">, </span><span class="src-num">10</span><span class="src-sym">, </span><span class="src-num">4</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"> </div></li>
<li><div class="src-line"> <span class="src-comm">// alternative syntax</span></div></li>
<li><div class="src-line"> <span class="src-var">$n </span>= <span class="src-key">new </span><a href="#methodNeuralNetwork">NeuralNetwork</a><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">4</span><span class="src-sym">, </span><span class="src-num">10</span><span class="src-sym">, </span><span class="src-num">10</span><span class="src-sym">, </span><span class="src-num">4</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
</ol></p><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">array </td>
<td><b>$nodecount</b> </td>
<td>The number of nodes in the consecutive layers.</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodactivation"></a>
<h3>method activation <span class="smalllinenumber">[line 234]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>float activation(
float
$value)</code>
</td></tr></table>
</td></tr></table><br />
Implements the standard (default) activation function for backpropagation networks, the 'tanh' activation function.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>The final output of the node</td>
</tr>
</table>
</div>
<br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">float </td>
<td><b>$value</b> </td>
<td>The preliminary output to apply this function to</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodaddControlData"></a>
<h3>method addControlData <span class="smalllinenumber">[line 294]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>void addControlData(
array
$input, array
$output, [int
$id = null])</code>
</td></tr></table>
</td></tr></table><br />
Add a set of control data to the network.<br /><br /><p>This set of data is used to prevent 'overlearning' of the network. The network will stop training if the results obtained for the control data are worsening.</p><p>The data added as control data is not used for training.</p><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">array </td>
<td><b>$input</b> </td>
<td>An input vector</td>
</tr>
<tr>
<td class="type">array </td>
<td><b>$output</b> </td>
<td>The corresponding output</td>
</tr>
<tr>
<td class="type">int </td>
<td><b>$id</b> </td>
<td>(optional) An identifier for this piece of data</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodaddTestData"></a>
<h3>method addTestData <span class="smalllinenumber">[line 259]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>void addTestData(
array
$input, array
$output, [int
$id = null])</code>
</td></tr></table>
</td></tr></table><br />
Add a test vector and its output<br /><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">array </td>
<td><b>$input</b> </td>
<td>An input vector</td>
</tr>
<tr>
<td class="type">array </td>
<td><b>$output</b> </td>
<td>The corresponding output</td>
</tr>
<tr>
<td class="type">int </td>
<td><b>$id</b> </td>
<td>(optional) An identifier for this piece of data</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodcalculate"></a>
<h3>method calculate <span class="smalllinenumber">[line 187]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>mixed calculate(
array
$input)</code>
</td></tr></table>
</td></tr></table><br />
Calculate the output of the neural network for a given input vector<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>The output of the network</td>
</tr>
</table>
</div>
<br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">array </td>
<td><b>$input</b> </td>
<td>The vector to calculate</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodderivative_activation"></a>
<h3>method derivative_activation <span class="smalllinenumber">[line 246]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>$float derivative_activation(
float
$value)</code>
</td></tr></table>
</td></tr></table><br />
Implements the derivative of the activation function. By default, this is the inverse of the 'tanh' activation function: 1.0 - tanh($value)*tanh($value);<br /><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">float </td>
<td><b>$value</b> </td>
<td>'X'</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodgetControlDataIDs"></a>
<h3>method getControlDataIDs <span class="smalllinenumber">[line 313]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>array getControlDataIDs(
)</code>
</td></tr></table>
</td></tr></table><br />
Returns the identifiers of the control data used during the training of the network (if available)<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>An array of identifiers</td>
</tr>
</table>
</div>
<br /><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodgetLearningRate"></a>
<h3>method getLearningRate <span class="smalllinenumber">[line 155]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>float getLearningRate(
int
$layer)</code>
</td></tr></table>
</td></tr></table><br />
Gets the learning rate for a specific layer<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>The learning rate for that layer</td>
</tr>
</table>
</div>
<br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">int </td>
<td><b>$layer</b> </td>
<td>The layer to obtain the learning rate for</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodgetMomentum"></a>
<h3>method getMomentum <span class="smalllinenumber">[line 177]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>float getMomentum(
)</code>
</td></tr></table>
</td></tr></table><br />
Gets the momentum.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>The momentum</td>
</tr>
</table>
</div>
<br /><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodgetRandomWeight"></a>
<h3>method getRandomWeight <span class="smalllinenumber">[line 647]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>float getRandomWeight(
$layer)</code>
</td></tr></table>
</td></tr></table><br />
Gets a random weight between [-0.25 .. 0.25]. Used to initialize the network.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>A random weight</td>
</tr>
</table>
</div>
<br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type"> </td>
<td><b>$layer</b> </td>
<td></td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodgetTestDataIDs"></a>
<h3>method getTestDataIDs <span class="smalllinenumber">[line 277]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>array getTestDataIDs(
)</code>
</td></tr></table>
</td></tr></table><br />
Returns the identifiers of the data used to train the network (if available)<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>An array of identifiers</td>
</tr>
</table>
</div>
<br /><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodisVerbose"></a>
<h3>method isVerbose <span class="smalllinenumber">[line 344]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>boolean isVerbose(
)</code>
</td></tr></table>
</td></tr></table><br />
Returns whether or not the network displays status and error messages.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>'true' if status and error messages are displayed, 'false' otherwise</td>
</tr>
</table>
</div>
<br /><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodload"></a>
<h3>method load <span class="smalllinenumber">[line 355]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>boolean load(
string
$filename)</code>
</td></tr></table>
</td></tr></table><br />
Loads a neural network from a file saved by the 'save()' function. Clears the training and control data added so far.<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>'true' on success, 'false' otherwise</td>
</tr>
</table>
</div>
<br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">string </td>
<td><b>$filename</b> </td>
<td>The filename to load the network from</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodsave"></a>
<h3>method save <span class="smalllinenumber">[line 399]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>boolean save(
string
$filename)</code>
</td></tr></table>
</td></tr></table><br />
Saves a neural network to a file<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>'true' on success, 'false' otherwise</td>
</tr>
</table>
</div>
<br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">string </td>
<td><b>$filename</b> </td>
<td>The filename to save the neural network to</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodsetLearningRate"></a>
<h3>method setLearningRate <span class="smalllinenumber">[line 141]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>void setLearningRate(
array
$learningrate)</code>
</td></tr></table>
</td></tr></table><br />
Sets the learning rate between the different layers.<br /><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">array </td>
<td><b>$learningrate</b> </td>
<td>An array containing the learning rates [range 0.0 - 1.0]. The size of this array is 'layercount - 1'. You might also provide a single number. If that is the case, then this will be the learning rate for the whole network.</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodsetMomentum"></a>
<h3>method setMomentum <span class="smalllinenumber">[line 168]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>void setMomentum(
float
$momentum)</code>
</td></tr></table>
</td></tr></table><br />
Sets the 'momentum' for the learning algorithm. The momentum should accelerate the learning process and help avoid local minima.<br /><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">float </td>
<td><b>$momentum</b> </td>
<td>The momentum. Must be between 0.0 and 1.0; Usually between 0.5 and 0.9</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodsetVerbose"></a>
<h3>method setVerbose <span class="smalllinenumber">[line 335]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>void setVerbose(
boolean
$is_verbose)</code>
</td></tr></table>
</td></tr></table><br />
Determines if the neural network displays status and error messages. By default, it does.<br /><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">boolean </td>
<td><b>$is_verbose</b> </td>
<td>'true' if you want to display status and error messages, 'false' if you don't</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodshowWeights"></a>
<h3>method showWeights <span class="smalllinenumber">[line 322]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>void showWeights(
[boolean
$force = false])</code>
</td></tr></table>
</td></tr></table><br />
Shows the current weights and thresholds<br /><br /><br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">boolean </td>
<td><b>$force</b> </td>
<td>Force the output, even if the network is <a href="#methodsetVerbose">not verbose</a>.</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<hr />
<a name="methodtrain"></a>
<h3>method train <span class="smalllinenumber">[line 424]</span></h3>
<div class="function">
<table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code_border">
<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">
<code>bool train(
[int
$maxEpochs = 500], [float
$maxError = 0.01])</code>
</td></tr></table>
</td></tr></table><br />
Start the training process<br /><br /><br /><br />
<h4>Tags:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>return:</b> </td><td>'true' if the training was successful, 'false' otherwise</td>
</tr>
</table>
</div>
<br /><br />
<h4>Parameters:</h4>
<div class="tags">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="type">int </td>
<td><b>$maxEpochs</b> </td>
<td>The maximum number of epochs</td>
</tr>
<tr>
<td class="type">float </td>
<td><b>$maxError</b> </td>
<td>The maximum squared error in the training data</td>
</tr>
</table>
</div><br />
<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
</div><br />
<div class="credit">
<hr />
Documentation generated by <a href="http://www.phpdoc.org">phpDocumentor 1.3.1</a>
</div>
</td></tr></table>
</body>
</html>