-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
134 lines (113 loc) · 3.65 KB
/
main.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
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
namespace STDPFunctionLutor {
// reference: Abbott STDP (2006)
// Returns deltaW
inline
double STDP_Abott(int dt,
double LTPamplitude, double LTDamplitude,
int LTPtimeRange, int LTDtimeRange)
{
double dw;
if ( dt > 0) {
dw = LTPamplitude * exp( -dt / (double)LTPtimeRange );
} else
if ( dt < 0 ) {
dw = LTDamplitude * -exp( dt / (double)LTDtimeRange );
} else
dw = 0;
return dw;
}
//----------------------------------
//
// make_lut()
//
//
//----------------------------------
void make_lut(const char* filename, int tao_start=-50, int tao_end=50,
int ltpX=10, int ltdX=10, double ltpY=1.0f, double ltdY=1.5f) {
FILE* f = fopen(filename, "w+");
fprintf(f, "#ifndef __STDP_FUNCTION_LUT_H__\n"
"#define __STDP_FUNCTION_LUT_H__\n"
"\n"
"// This is an automatically generated file. \n"
"// STDP Function LUTor v1.0 (C) 2014 Sandor Vasas\n"
"\n"
"namespace STDPLut {\n"
"const int STDP_LTP_TAO = %d;//tao_plus of equation; LTP time param\n"
"const int STDP_LTD_TAO = %d;//tao_minus of equation; LTD time param\n"
"const double STDP_LTP_AMPLITUDE = %f;//deltaWeight\n"
"const double STDP_LTD_AMPLITUDE = %f;//deltaWeight\n"
"const int STDP_LTD_LUTSIZE = %d;//msec\n"
"const int STDP_LTP_LUTSIZE = %d;//msec\n"
" \n",
ltpX, ltdX, ltpY, ltdY, -tao_start+1, tao_end+1);
double stdp;
fprintf(f, "// tao = t_pre - t_post\n");
fprintf(f, "const float LTD[] = {\n");
for ( int t = 0; t >= tao_start; --t )
{
stdp = STDP_Abott(t, ltpY, ltdY, ltpX, ltdX);
fprintf(f, " %9.8ff, // tao=%d\n", stdp, -t );
}
fprintf(f, "};\n");
fprintf(f, "// tao = t_post - t_pre\n");
fprintf(f, "const float LTP[] = {\n");
for ( int t = 0; t <= tao_end; ++t )
{
stdp = STDP_Abott(t, ltpY, ltdY, ltpX, ltdX);
fprintf(f, " %9.8ff, // tao=%d\n", stdp, t );
}
fprintf(f, "};\n");
fprintf(f, "}; // eof namespace STDPLutor\n");
fprintf(f, "#endif\n");
fclose(f);
};
};
using namespace STDPFunctionLutor;
int main(int argc, char **argv) {
cout << "===========================================================================" << endl;
std::cout << "Spike-Timing Dependent Plasticity Function Lookup Table Generator v1.0"<<endl<<
"Copyright (C) 2014 Sandor Vasas" << endl <<
"===========================================================================" << endl <<
"Default parameters are:" << endl <<
"ltpX = 10ms, ltdX = 10ms, ltpY = 1.0, ltdY = 1.5" << endl <<
"t E [ -50, 50 ]" << endl <<
"Filename will be STDPLut.h" << endl;
char c;
int ltpx, ltdx;
double ltpy, ltdy;
int tao_start, tao_end;
tao_start = -50;
tao_end = 50;
ltpx = 10; ltdx = 10;
ltpy = 1.0f; ltdy = 1.5f;
while ( c != 'x' && c!= 'X' ) {
cout << "MENU"<<endl;
cout << "D to set default parameters" << endl;
cout << "C to configure"<< endl << "G to generate" << endl << "X to quit." << endl;
cin >> c;
if (c == 'c' || c == 'C' ) {
cout << "(Note: tao = t_post - t_pre)" << endl;
cout << "LTD_TIME_RANGE="; cin >> ltdx;
cout << "LTP_TIME_RANGE="; cin >> ltpx;
cout << "LTD_SCALE_Y="; cin >> ltdy;
cout << "LTP_SCALE_Y="; cin >> ltpy;
cout << "PLOT_FROM_TAO="; cin >> tao_start;
cout << "PLOT_TO_TAO="; cin >> tao_end;
} else
if ( c == 'g' || c == 'G' ) {
make_lut("STDPLut.h", tao_start, tao_end, ltpx, ltdx, ltpy, ltdy);
cout << "LUT generated " << endl;
} else
if ( c == 'd' || c == 'D' ) {
tao_start = -50; tao_end = 50;
ltpx = 10; ltdx = 10;
ltpy = 1.0f; ltdy = 1.5f;
cout << "Parameters set to default" << endl;
}
}
return 0;
}