-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.h
144 lines (123 loc) · 3.47 KB
/
generate.h
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
#include "PathAlgorithm.h"
int randInt(int lower, int upper) {
int num = (rand() % (upper - lower + 1)) + lower;
return num;
}
void createConnections() {
//inputs randomly connected to left half of recurrent
for(int i=0;i<IN_NUM;i++) {
for(int j=0;j<REC_NUM;j++) {
if((j%REC_X)<REC_X/2) {
int rnd=randInt(0, 10);
if(rnd==0)
win[i][j]=1.5f;
}
}
}
//outputs randomly connected to right half of recurrent
for(int i=0;i<OUT_NUM;i++) {
for(int j=0;j<REC_NUM;j++) {
if((j%REC_X)<REC_X/2) {
int rnd=randInt(0, 10);
if(rnd==0)
//printf("this\n");
wout[j][i]=1.5f;
}
}
}
for(int i=0;i<REC_NUM;i++) {
//feedforward
/*
if((i-REC_X+1)%REC_X!=0) {
if(i-REC_X>=0) {
wrec[i][i-REC_X+1]=1.5f;
if((i-REC_X+2)%REC_X!=0)
wrec[i][i-REC_X+2]=1.5f;
//printf("%d->%d ", i, i-REC_X+1);
}
wrec[i][i+1]=1.5f;
//printf("%d->%d ", i, i+1);
if(i+REC_X<REC_NUM) {
wrec[i][i+REC_X+1]=1.5f;
if((i+REC_X+1)<REC_NUM && (i+REC_X+2)%REC_X!=0)
wrec[i][i+REC_X+2]=1.5f;
//printf("%d->%d\n", i, i+REC_X+1);
} else {}
//printf("\n");
}
*/
//recurrent
// TODO: inefficient ... adjacency matrix would be better
for(int j=0;j<REC_NUM;j++) {
if(j!=i) {
int a=randInt(0, 50);
if(a==10) {
wrec[i][j]=1.5f;
}
}
}
}
//for association training
/* wrec[28][37]=6.5f; */
/* wrec[28][29]=6.5f; */
/* wrec[38][31]=6.5f; */
//if paths are artificially strengthened
if(pretrained) {
//find path from 0->0
findPath(outputs[0], 1, 0);
adjustOutgoing(0);
//find path from 1->1
findPath(outputs[1], 1, 1);
adjustOutgoing(1);
}
}
void createNerves() {
int count=0;
neurons=malloc(REC_NUM*sizeof(Nerve*));
for(int i=0;i<REC_Y;i++) {
for(int j=0;j<REC_X;j++) {
Nerve* new=malloc(sizeof(Nerve));
new->x=j*25-150;
new->y=i*25-230;
new->id=count;
new->potential=0;
new->neuronType=1;
new->desensitize=1.f;
int type=randInt(0, 2);
if(type==0) {
new->neuronType=-1;
}
new->receptorType=1;
int receptor=randInt(0, 1);
if(receptor==0)
new->receptorType=-1;
neurons[count]=new;
count++;
}
}
inputs=malloc(IN_NUM*sizeof(Nerve*));
for(int i=0;i<IN_NUM;i++) {
Nerve* new=malloc(sizeof(Nerve));
new->x=-250;
new->y=i*200-100;
new->id=i;
new->potential=0;
new->neuronType=1;
new->receptorType=1;
new->desensitize=1.f;
inputs[i]=new;
}
outputs=malloc(OUT_NUM*sizeof(Nerve*));
for(int i=0;i<OUT_NUM;i++) {
Nerve* new=malloc(sizeof(Nerve));
new->x=400;
new->y=i*200-100;
new->id=i;
new->potential=0;
new->neuronType=1;
new->receptorType=1;
new->desensitize=1.f;
outputs[i]=new;
}
createConnections();
}