-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathElaboration.cpp
338 lines (282 loc) · 6.69 KB
/
Elaboration.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#include "Elaboration.h"
#include "Segment.h"
#include "Neuron.h"
//to look for erroneous characters and report as file error in the output
bool ferr=false;
ListElaboration::ListElaboration(){
index=0;
tmp=NULL;
}
void ListElaboration::initList(){
}
//Add a new Elaboration in the list
void ListElaboration::add(Elaboration *f){
tmp=f;
list[index]=f;
//check if a spot is available in the list
if(index==MAX_Elaboration){
cerr<<"No more empty Elaboration slots available\n";
return;
}else {
list[index]=f;
index++;
}
}
void ListElaboration::preCompute(Neuron* n){
preComputeStep(n->getSoma());
ferr = n->ferror;
// starting from the soma compute a single step at a time
for(int i=0;i<index;i++){
list[i]->initialize();
}
}
void ListElaboration::preComputeStep(Segment* t){
for(int i=0;i<index;i++){
//skip duplicate somatic segment
if(t->getId()>0)
list[i]->preComputeStep(t);
}
if (t->getNext1()!=NULL){preComputeStep(t->getNext1());}
if (t->getNext2()!=NULL){preComputeStep(t->getNext2());}
}
void ListElaboration::compute(Neuron* n){
// starting from the soma compute a single step at a time
computeStep(n->getSoma());
}
void ListElaboration::computeStep(Segment* t){
for(int i=0;i<index;i++){
//skip duplicate somatic segment
if(t->getId()>0)
list[i]->computeStep(t);
}
if (t->getNext1()!=NULL){
computeStep(t->getNext1());}
if (t->getNext2()!=NULL){
computeStep(t->getNext2());}
}
void ListElaboration::printDistr(std::string str){
if(ferr)
cout<<"*";
for(int i=0;i<index;i++){
list[i]->printDistr(str);
}
}
void ListElaboration::printDistrDB(std::string str){
//printHEader
static int head=0;
bool flag = false;
int i;
if(head==0){
head++;
//print header as one line at start of file
cout<<"NeuronName ";
for( i=0;i<index;i++){
if(i!=0 )
cout<<" ";
list[i]->printHeader();
}
cout<<"\n";
}
//print extracted data from Neurons
for( i=0;i<index;i++){
if(i!=0 )
cout<<",";
if(flag == false){
if(ferr)
cout<<"*"<<str.c_str()<<",";
else
cout<<str.c_str()<<",";
flag = true;
}
list[i]->printDistrDB();
}
cout<<"\n";
}
void ListElaboration::newNeuron(){
for(int i=0;i<index;i++){
list[i]->newNeuron();
}
}
void ListElaboration::newRealNeuron(){
for(int i=0;i<index;i++){
list[i]->newRealNeuron();
}
}
Elaboration::Elaboration(){};
//for Debug: check the range of input data for distribution
int Distr::minMax(double j){
if(j >= VOID)
return 0;
if(j <= -VOID)
return 0;
if(getMin()==-1 && getMax()==-1){
setMin(j);
setMax(j);
}
if(j>getMax()) setMax(j);
if(j<getMin()) setMin(j);
if(j>MAX && j<MIN){
cerr<< "Exceeded value:"<<j<<"\n";
return 0;
}
return 1;
}
int Single::minMax(double j){
if(j >= VOID)
return 0;
if(j <= -VOID)
return 0;
if (j>120) {
int kkuuu=0;
}
if(validminmax==0){
validminmax=1;
setMin(j);
setMax(j);
} else {
if(j>getMax())
setMax(j);
if(j<getMin())
setMin(j);
}
if(j>MAX && j<MIN){
cerr<< "Exceeded value:"<<j<<"\n";
return 0;
}
return 1;
}
;
//evaluate which bin to use to store the distribution
void Distr::storeValue(double i,double j){
static int OVER=0;
if ((j>=VOID) || (j<=-VOID)|| (i>=VOID)|| (i<=-VOID)) {
return;
}
if(minMax(j)){
int ind=0;
if(direct==0){
ind=(int) (((j-getMin())/widthBins)+0.5);
} else {
ind=(int)j;
}
if(ind>MAX_DATA ){
//error over index
if(OVER==0)
cerr<<"Distrib with index over range allowed!\n";
ind=MAX_DATA-1; OVER=1;
}
//store value
data[tab][ind]+=i;
dataSquare[tab][ind]+=i*i;
counter[tab][ind]++;
//update the number of occupied bin
if(index[tab]<ind)
index[tab]=ind;
//Print Raw Data
if(RAW_elab==1)
cout<<i<<"\t"<<j<<"\n";
} //evaluate index;
}
;
// print distrib for db output: one neuron per line
void Distr::printDistrDB(){
double tot=0;
if(strcmp(a->getName(),b->getName())==0){
cout<<a->getName()<<" Distribution:";
} else {
cout<<a->getName()<<"<"<<a->getLimit()<<"> VS "<<b->getName()<<"<"<<b->getLimit()<<"> :";
}
int min=getMin(),max=getMax();
double width=widthBins;
cout<<","<<b->getName()<<",";
//all print start at one since the bin number is computed and then added 1
for(int i=1;i<=index[tab];i++){
cout<<(min+width*(i-.5))<<",";
}
cout<<a->getName()<<",";
for( int i=1;i<=index[tab];i++){
if(counter[tab][i]==0){
cout<<"0"<<",";
}else {
if(average==0) {
cout<<(data[tab][i])<<","; //counter[tab][i])<<" ";
} else {
cout<<(data[tab][i]/counter[tab][i])<<",";
}
}
cout<<",";
}
cout<<"";
if(average!=0) {
cout<<" StdDev,";
for( int i=1;i<=index[tab];i++){
if(counter[tab][i]==0){
cout<<"0"<<",";
}else if(counter[tab][i]>1){
double numerator = (counter[tab][i]*dataSquare[tab][i])-(data[tab][i]*data[tab][i]);
double denomenator = counter[tab][i]*(counter[tab][i]-1);
double std=(sqrt(numerator/denomenator));
cout<<std<<" ";
}else
cout<<0<<" ";
cout<<",";
}
cout<<",";
}
cerr<<"";
}
;
//fixed the printing for alignment of the functions in double distribution.by sri on 06/20/07
void Distr::printDistr(std::string str){
double tot=0;
int i;
cout<<str.c_str()<<"\t";
if(strcmp(a->getName(),b->getName())==0){
cout<<a->getName()<<" Distribution:";
} else {
cout<<a->getName()<<a->getLimit()<<"<VS>"<<b->getName()<<b->getLimit()<<":";
}
//Print X
int min = (int)getMin(), max = (int)getMax();
double width=widthBins;
cout<<b->getName()<<"\t";
for(i=0;i<=index[tab];i++){
cout<<(min+width*(i+.5))<<"\t";
}
cout<<"\n\t"<<a->getName()<<"\t";
//Print Y
for( i=0;i<=index[tab];i++){
if(counter[tab][i]==0){
cout<<"0"<<" ";
}else {
if(average==0) {
cout<<(data[tab][i])<<" "; //counter[tab][i])<<" ";
} else {
cout<<(data[tab][i]/counter[tab][i])<<" ";
}
}
cout<<"\t";
}
cout<<"\n";
//Print Ystd
if(average!=0) {
cout<<" StdDev\t";
for( i=0;i<=index[tab];i++){
if(counter[tab][i]==0){
cout<<"0"<<" ";
}else {
if(counter[tab][i]>1){
double numerator = (counter[tab][i]*dataSquare[tab][i])-(data[tab][i]*data[tab][i]);
double denomenator = counter[tab][i]*(counter[tab][i]-1);
double std=(sqrt(numerator/denomenator));
cout<<std<<" ";
}
else
cout<<0<<" ";
}
cout<<"\t";
}
cout<<"\n";
}
}
;