-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.cpp
147 lines (125 loc) · 3.16 KB
/
demo.cpp
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
#include "icolearning.h"
#include <cstring>
int trace=0;
void icoLearningWithOneFilter() {
// Two inputs: reflex and predictor
// Just one filter in the filterbank
Icolearning icolearning(2,1);
icolearning.setDebugMessages(true);
icolearning.setLearningRate(0.000001f);
icolearning.setReflex(0.01f,0.6f);
if (trace)
icolearning.setPredictorsAsTraces(50);
else
icolearning.setPredictorsAsBandp(0.01f,0.6f);
icolearning.openDocu("onefilter");
for(int step=0;step<150000;step++) {
if (step%1000==500) {
icolearning.setInput(1,1);
} else {
icolearning.setInput(1,0);
}
if ((step%1000==525)&&(step<100000)) {
icolearning.setInput(0,1);
} else {
icolearning.setInput(0,0);
}
icolearning.prediction(step);
icolearning.writeDocu(step);
}
}
void icoLearningWith10Filters() {
// Two inputs: reflex and predictor
// Just one filter in the filterbank
Icolearning icolearning(2,10);
icolearning.setLearningRate(0.0001f);
icolearning.setDebugMessages(true);
icolearning.setReflex(0.01f,0.6f);
if (trace)
icolearning.setPredictorsAsTraces(50);
else
icolearning.setPredictorsAsBandp(0.1f,0.6f);
icolearning.openDocu("ten_filters");
for(int step=0;step<150000;step++) {
if (step%1000==500) {
icolearning.setInput(1,1);
} else {
icolearning.setInput(1,0);
}
if ((step%1000==525)&&(step<100000)) {
icolearning.setInput(0,1);
} else {
icolearning.setInput(0,0);
}
icolearning.prediction(step);
if (step%10==0) {
icolearning.writeDocu(step);
}
}
}
void stdpWithOneFilter() {
FILE* f=fopen("stdp.dat","wt");
for(int t=-200;t<=200;t++) {
// Two inputs: reflex and predictor
// Just one filter in the filterbank
Icolearning icolearning(2,1);
icolearning.setLearningRate(0.000001f);
icolearning.setReflex(0.01f,0.6f);
if (trace)
icolearning.setPredictorsAsTraces(50);
else
icolearning.setPredictorsAsBandp(0.01f,0.6f);
for(int step=0;step<150000;step++) {
if (step%1000==500) {
icolearning.setInput(1,1);
} else {
icolearning.setInput(1,0);
}
if ((step%1000==(500+t))&&(step<100000)) {
icolearning.setInput(0,1);
} else {
icolearning.setInput(0,0);
}
icolearning.prediction(step);
}
fprintf(f,"%d",t);
for(int i=0;i<icolearning.getNchannels();i++) {
for(int j=0;j<icolearning.getNfilters();j++) {
fprintf(f," %e",
icolearning.getWeight(i,j));
}
}
fprintf(f,"\n");
}
fclose(f);
fprintf(stderr,"\n");
}
int main(int argc, char *argv[]) {
int demoNumber=0;
if (argc < 2) {
fprintf(stderr,"%s <demo number> [-t]\n",argv[0]);
exit(1);
}
demoNumber = atoi(argv[1]);
if (argc > 2) {
if (strcmp(argv[2],"-t") == 0) {
trace = 1;
fprintf(stderr, "Filter responses are traces.\n");
}
}
fprintf(stderr, "Demo #%d\n", demoNumber);
switch (demoNumber) {
case 0:
fprintf(stderr,"ICO learning with one filter in the predictive pathway.\n");
icoLearningWithOneFilter();
break;
case 1:
fprintf(stderr,"STDP curve calc for ICO learning with one filter in the predictive pathway.\n");
stdpWithOneFilter();
break;
case 10:
fprintf(stderr,"ICO learning with ten filters in the predictive pathway.\n");
icoLearningWith10Filters();
break;
}
}