forked from spolavar/L-Measure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElaboration.h
554 lines (458 loc) · 10.7 KB
/
Elaboration.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
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
#ifndef ELABORATION_H
#define ELABORATION_H
#include "Neuron.h"
#include "Segment.h"
#include "Func.h"
#include <string.h>
// MAx # of Elaborationevaluated at the same time
#define MAX_Elaboration 100
#define MAX_NEURON 80000
#define NR_BINS 30
#define MAX_DATA 1000
class Elaboration;
class ListElaboration {
//tot number of cell to be analized
int nrTotCell;
Elaboration* list[MAX_Elaboration];
Elaboration* tmp;
int index;
void initList();
public:
ListElaboration();
void add(Elaboration*f);
//set all initial values
void newNeuron();
//used when Global studies are required
void newRealNeuron();
//compute a single value for neuron n and segment t
void compute(Neuron* n);
//compute standard deviation
virtual void computeDev(Segment * s) {
}
;
void computeStep(Segment * s);
//compute the distribution for Neuron n
void computeDistr(Neuron* n) {
}
;
// compute the distribution over all neuron
void computeOverallDistr();
//print methods: one neuron for line
void printDistr(std::string str);
void printDistrDB() {
}
;
void printDistrDB(std::string str);
void printOverallDistr() {
}
;
//Compute initialization value for following funciotn: ie distribution
void preCompute(Neuron* n);
void preComputeStep(Segment * s);
};
class Elaboration {
protected:
int tab;
int nrNeuron;
public:
//print RawData
int RAW_elab;
Elaboration();
Elaboration(ListElaboration* l) {
(*l).add(this);
tab = -1;
nrNeuron = 0;
}
;
//Required for initialization
void virtual initialize() {
}
;
void virtual preComputeStep(Segment * s) {
}
;
void virtual computeStep(Segment * s) {
}
;
//Compute Standard Deviation
void virtual computeDev(Segment * s) {
}
;
// compute the distribution over all neuron
void virtual computeOverallDistr() {
}
;
void virtual newNeuronLocal() {
}
;
void newNeuron() {
tab++;
nrNeuron = 1;
newNeuronLocal();
}
;
void newRealNeuron() {
nrNeuron++;
}
;
void virtual printHeader() {
}
;
void virtual printDistr(std::string str) {
}
;
void virtual printDistrDB() {
}
;
};
class Single: public Elaboration {
//use to evalua te MEan by stdValue/stdCount
double mValue, mCount;
//used to compute standard deviation
double stdValue, stdCount;
protected:
Func *a;
//Elaboration for precompute value
Func* pre;
//Nr void values returned
int nrVoid[MAX_NEURON];
//SG code added
//Number of virtual compartemtns.
int nrVirtual[MAX_NEURON];
// allow dynamic reconfiguration of the distribution
//store Min/MAx value of parameter stored
double dMin[MAX_NEURON], dMax[MAX_NEURON];
//store min max index in the actual array in.
int min, max, start;
//if average=0, then the output print the value, otherwise value/count
int average;
//used to rescale the distribution: it is dynamically reassanged
void rescale(double x);
double MIN;
double MAX;
double data[MAX_NEURON];
//store nr of good value
int counter[MAX_NEURON];
//store stdValue
double std[MAX_NEURON];
//print Raw data??
int RAW;
//valid minmax: if 0 the values need to be set
int validminmax;
public:
Single(ListElaboration * l, Func *aa, int avg = 1, int rawdata = 0) :
Elaboration(l) {
RAW = rawdata;
average = avg;
stdValue = 0;
stdCount = 0;
mValue = 0;
mCount = 0;
a = aa;
pre = aa->getPreFunc();
start = 1;
for (int j = 0; j < MAX_NEURON; j++) {
validminmax = 0;
dMin[j] = 0;
dMax[j] = 0;
counter[j] = 0;
data[j] = 0;
nrVoid[j] = 0;
nrVirtual[j] = 0;
std[tab] = 0;
}
}
void newNeuronLocal() {
std[tab] = getStd();
reset();
}
void reset() {
mValue = 0;
mCount = 0;
stdValue = 0;
stdCount = 0;
validminmax = 0;
//value exceeding these values will be rejected
MIN = -1000000;
MAX = 1000000;
//local var for storing absolute min/max
min = 10000000;
max = -1000000;
}
int minMax(double i);
virtual void storeValue(double i) {
if (i >= VOID || i <= -VOID) {
nrVoid[tab]++;
if(i == -VOID)
nrVirtual[tab]++;
return;
}
data[tab] += i;
counter[tab]++;
//std
stdValue += (i - getMean()) * (i - getMean());
stdCount++;
if (RAW == 1)
cout << i << "\n";
}
void virtual preComputeStep(Segment * t) {
double d = pre->compute(t);
minMax(d);
preMean(d);
}
;
virtual void preMean(double i) {
if (i >= VOID || i <= -VOID)
return;
mValue += i;
mCount++;
}
double getMean() {
if (mCount != 0) {
return mValue / mCount;
} else if (counter[tab] != 0) {
return data[tab] / counter[tab];
} else {
return 0;
}
}
void initialize() {
a->initialize(getMean());
reset();
}
virtual void computeStep(Segment* t) {
double d = a->compute(t);
minMax(d);
if (t->getType() == -1) {
storeValue(-VOID);
return;
}
storeValue(d);
}
double getStd() {
if (stdCount <= 1)
return 0;
return sqrt(stdValue / (stdCount - 1.0));
}
virtual void printHeader() {
if (strcmp(a->getName(), "N_Class") != 0) {
cout << a->getName() << "TotSum ";
cout << a->getName() << "Min ";
cout << a->getName() << "Avg ";
cout << a->getName() << "Max ";
} else {
cout << "class8";
}
}
virtual void printDistrDB() {
if (strcmp(a->getName(), "N_Class") == 0) {
int i = getMax();
if (i > 10000 || i < -10000)
i = 0;
cout << i;
} else {
double div = nrNeuron - 1;
if (div < 1)
div = 1;
if (data[tab] > 1000000000)
data[tab] = 999999;
cout << data[tab] / div << ","; //tot
double min, max, std;
min = getMin();
max = getMax();
std = getStd();
double m1, m2;
m1 = data[tab] / counter[tab];
m2 = getMean();
if (fabs(m1 - m2) > 1)
cerr << "error computing mean!\n";
if (fabs(min) < 0.000001)
min = 0;
if (fabs(max) < 0.000001)
max = 0;
if (fabs(std) < 0.000001)
std = 0;
if ((min) > 1000000)
min = 999999;
if ((max) > 1000000)
max = 999999;
if ((std) > 1000000)
std = 999999;
cout << min << ",";
cout << getMean() << "," << max;
}
cerr << "";
}
;
virtual void printDistr(std::string str) {
cout << str.c_str() << "\t";
cout << a->getName() << " " << a->getLimit() << "\t";
int div = nrNeuron - 1;
if (div < 1)
div = 1;
// if(a->getName().find("Width") != -1 || a->getName().find("Height") != -1 || a->getName().find("Depth") != -1 )
// {
// cout<<getMax()<<"\t"<<counter[tab];
// }else{
//SG Code fix 07/28/2011
//This piece of the code was put to make the total sum same a max/min/avg
if (strcmp(a->getName(), "Width") == 0
|| strcmp(a->getName(), "Height") == 0 || strcmp(a->getName(),
"Depth") == 0) {
cout << getMax() << "\t" << counter[tab];
} else {
cout << data[tab] << "\t" << counter[tab];
}
cout << "\t(" << (nrVoid[tab]-nrVirtual[tab]) << ")";
cout << "\t" << getMin();
cout << "\t" << getMean() << "\t" << getMax() << "\t" << getStd()
<< " \n";
}
;
void setAverage(int i) {
average = i;
}
double getMin() {
if (counter[tab] == 0)
return 0;
return dMin[tab];
}
double getMax() {
if (counter[tab] == 0)
return 0;
return dMax[tab];
}
void setMin(double j) {
dMin[tab] = j;
}
void setMax(double j) {
dMax[tab] = j;
}
virtual double getValue(Segment* t) {
return 0.0;
}
};
class Distr: public Elaboration {
protected:
//store the two Elaboration : distribution of A VS B
Func *a, *b;
// allow dynamic reconfiguration of the distribution
//store Min/MAx value of parameter stored
double dMin[MAX_NEURON], dMax[MAX_NEURON];
//store min max index in the actual array in.
int min, max, start;
//if average=0, then the output print the value, otherwise value/count
int average;
//if direct=1 the plot is directly in the number of bin (used for integer distribution
int direct;
//used to rescale the distribution: it is dynamically reassanged
void rescale(double x);
//1:then binPar contains the number of bins
//0: binPar contains the witdh of the bins( max # of Bin set by MAX_DATA
int binMode;
double binPar;
//the resulting width of bins
double widthBins;
//store the max number of bin;
int index[MAX_DATA];
//print RawData
int RAW;
double MIN;
double MAX;
double data[MAX_NEURON][MAX_DATA];
double dataSquare[MAX_NEURON][MAX_DATA];
//store counter for computing averages
int counter[MAX_NEURON][MAX_DATA];
public:
Distr(ListElaboration * l, Func *aa, Func *bb = 0, int i = 0,
int directV = 0, int binMode1 = 0, double binPar1 = NR_BINS,
int rawdata = 0) :
Elaboration(l) {
//Setting the raw data flag
RAW_elab = rawdata;
RAW = rawdata;
average = i;
direct = directV;
a = aa;
b = bb;
binMode = binMode1;
binPar = binPar1;
widthBins = 0;
if (b == 0)
b = a;
start = 1;
//reset nrBins : to be computed after prePhase
widthBins = -1;
for (int j = 0; j < MAX_NEURON; j++) {
dMin[j] = -1;
dMax[j] = -1;
index[j] = 0;
for (int i = 0; i < MAX_DATA; i++) {
counter[j][i] = 0;
data[j][i] = 0;
dataSquare[j][i] = 0;
}
}
}
void newNeuronLocal() {
widthBins = 0;
}
int minMax(double i);
virtual void storeValue(double i) {
storeValue(i, i);
}
virtual void storeValue(double i, double j);
void virtual preComputeStep(Segment * t) {
minMax(b->compute(t));
}
;
//compute the number of bins to be used( up to MAX_DATA
double computeWidthBins() {
double width = 0;
if (binMode == 0) {
//to set starting value to zero
double m = getMin();
double M = getMax();
//add 0.01% more on MAx value to include the Max in the last bin!
width = ((M * 0.0001 + M - m) / (binPar));
} else {
width = binPar;
}
return width;
}
void computeStep(Segment* t) {
if (widthBins == 0) {
widthBins = computeWidthBins();
index[tab] = (int) ((getMax() - getMin()) / widthBins);
}
double a1 = a->compute(t);
double b2 = b->compute(t);
if (strcmp(a->getName(), b->getName()) == 0 && b2 < VOID) {
a1 = 1;
}
storeValue(a1, b2);
}
//the same as getMEna, but with a different way of computation
double getAverage();
virtual void printDistr(std::string str);
virtual void printDistrDB();
void setAverage(int i) {
average = i;
}
double getMin() {
return dMin[tab];
}
double getMax() {
return dMax[tab];
}
void setMin(double j) {
dMin[tab] = j;
}
void setMax(double j) {
dMax[tab] = j;
}
virtual double getValue(Segment* t) {
return 0.0;
}
};
#endif