forked from FrevoProject/FREVO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FullyMeshedNet.template
88 lines (74 loc) · 2.17 KB
/
FullyMeshedNet.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
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
group FullyMeshedNet;
getOutputDeclaration(randomsource,randombiases,seed,iterations,inputnodes,outputsize,outputnodes,nodes,activationmode,biases,weights) ::= <<
float bias[<nodes>]={<biases:{bia|<bia>f}; separator=", ">};
float randombias[<nodes>]={<randombiases:{bia|<bia>f}; separator=", ">};
float weight[<nodes>][<nodes>]={<weights:{wei|{<wei:{we|<we>f}; separator=", ">}}; separator=", ">};
float netOutput[<outputsize>];
long long int seed=<seed>LL;
long nextValue(){
seed=(seed*25214903917LL+11) & ((1 \<\< 48) - 1);
return (long)(seed \>\> 22);
}
float nextDouble(){
return ((((long long int)nextValue() \<\< 27) + nextValue()) / (float)(1 \<\< 53));
}
float rand_range(float border){
float val = (float)(nextDouble()*2.0*border-border);
return val;
}
float sigmoidActivate(float x) {
float y=(float)(1.0f / (1.0f + exp(-x)));
return y;
}
float linearActivate(float x){
if (x \>= 1)
{return 1;}
else {
if (x \<= 0)
{return 0;}
else
{return x;}
}
}
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; i=i+1) {
float sumValue=0.0f;
for (j=0L; j \< <nodes>L; j=j+1) {
sumValue=sumValue+weight[j][i]*netOutput[j];
}
activation[i]=bias[i]+sumValue;
if (<randomsource>){
activation[i]=activation[i]+rand_range(randombias[i]);
}
}
float outputVector [<outputnodes>];
for (i = <inputnodes>L; i \< <nodes>L; i=i+1) {
netOutput[i]=<activationmode>(activation[i]);
}
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 \< <iterations>L - 1; i=i+1) {
getStep(netInput,inputsize);
}
return getStep(netInput,inputsize);
}
>>