OSDN Git Service

d511b3a2b4435b5908a20a661e8582689a527067
[dennco/dennco.git] / Samples / Samples / Sample5_SimplePerceptron.ng / Container / 2 / 2_a.xhtml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4 <head><title>Dennco - test1</title>
5 <link rel="stylesheet" type="text/css" href="dstyle.css" />  
6 </head>
7
8 <body>
9
10 <a define="cell"  name="cell1">
11 <a parameter="cellcode"  href="#PerceptronCellCode"> </a>
12 <a parameter="connection" href="../3/3_a.xhtml#cell1output" receptor="output"></a>
13 </a>
14
15 <a define="cellcode"  name="PerceptronCellCode" type="B">
16 <pre parameter="script"> 
17 <![CDATA[
18
19 var threshold = 0.5;
20
21 var wights = new Array();
22 var correctedWights = new Array();
23 var u0wight = 0;
24 var correctedU0wight = 0;
25 var units = new Array();
26 var learned = false;
27
28 function doInit()
29 {
30         for (var r in this.cell.receptors)
31         {
32                 if (r.match(/^u[0-9][0-9]$/)
33                 {
34                         var index = Number(r.substring(1));
35                         this.units[index] = r;
36                         this.wights[index] = 0;
37                         this.correctedWights[index] = 0;
38                 }
39         }
40 }
41
42 function doTick(time)   
43 {
44         //process for output
45         var sum = 1 * u0wight;  
46         for (var index in units)
47         {
48                 sum += this.cell.receptors[units[index]] * wights[index];
49         }
50         var output = sum < this.threshold ? 0 : 1;
51         this.cell.axonValue  = output;
52         
53         //process for learn 
54         var learn = this.cell.receptors.learn;
55         var exp   = this.cell.receptors.expected;
56         var rate  = this.cell.receptors.learningRate;   
57
58         if (learn == 1)
59         {
60                 if (!this.learned)
61                 {
62                         if (exp != output)
63                         {
64                                 var correctionRate = rate * (exp - output);
65                                 correctedU0wight = u0wight + u0wight * correctionRate;
66                                 for (var index in units)
67                                 {
68                                         correctedWights[index] = wights[index] + (wights[index] * correctionRate);
69                                 }
70                         }
71                         this.learned = true;
72                 }
73         }
74         else
75         {
76                 if (this.learned)
77                 {
78                 
79                 
80                 }
81                 this.learned = false;
82         }
83 }
84 ]]>
85 </pre>
86 </a>
87
88 </body>
89 </html>