forked from aau-ros/FREVO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreeLayerNetwork.template
62 lines (54 loc) · 1.73 KB
/
ThreeLayerNetwork.template
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
group ThreeLayerNetwork;
getOutputDeclaration(stepnumber,inputnodes,outputsize,outputnodes,nodes,biases,weights) ::= <<
float bias[<nodes>]={<biases:{bia|<bia>f}; separator=", ">};
float weight[<nodes>][<nodes>]={<weights:{wei|{<wei:{we|<we>f}; separator=", ">}}; separator=", ">};
float netOutput[<outputsize>];
float sigmoidActivate(float x) {
float y=(float)(1.0f / (1.0f + exp(-x)));
return y;
}
Result getStep(float netInput[], long inputsize){
long i;
long j;
float activation [<nodes>];
for (i=0L; i \< <nodes>L; i=i+1){
activation[i]=0.0f;
}
for (i=0L; i \< inputsize; i=i+1) {
netOutput[i]=netInput[i];
}
for (i=<inputnodes>L; i \< (<nodes>L-<outputnodes>L); i=i+1) {
float sumValue=0.0f;
for (j=0L; j \< <inputnodes>L; j=j+1) {
sumValue=sumValue+weight[j][i]*netOutput[j];
}
activation[i]=bias[i]+sumValue;
netOutput[i]=sigmoidActivate(activation[i]);
}
for (i=(<nodes>L-<outputnodes>L); i\< <nodes>L; i=i+1) {
float sumValue=0.0f;
for (j=<inputnodes>L; j \< (<nodes>L-<outputnodes>L); j=j+1) {
sumValue=sumValue+weight[j][i]*netOutput[j];
}
activation[i]=bias[i]+sumValue;
netOutput[i]=sigmoidActivate(activation[i]);
}
float outputVector [<outputnodes>];
for (i = (<nodes>L - <outputnodes>L); i \< <nodes>L; i=i+1) {
j = i - (<nodes>L - <outputnodes>L);
outputVector[j]=netOutput[i];
}
Result r(outputVector,<outputnodes>L);
return r;
}
Result getOutput(float netInput[], long inputsize){
long i;
for (i=0L; i \< <outputsize>L; i=i+1) {
netOutput[i]=0;
}
for (i=0L; i \< <stepnumber>L - 1; i=i+1) {
getStep(netInput, inputsize);
}
return getStep(netInput, inputsize);
}
>>