Blame view

src/ExternLib/StatisticProcesses/MinMaxMeanStatistic.hh 30.8 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * MinMaxMeanStatistic.hh
 *
 *  Created on: 04 nov. 2014
 *      Author: AKKA
 */

#ifndef MINMAXMEANSTATISTIC_HH_
#define MINMAXMEANSTATISTIC_HH_

#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "VisitorOfParamData.hh"
#include "StatisticData.hh"
#include "StatisticOperation.hh"
#include "StatisticProcess.hh"
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
17
#include <math.h>
fbe3c2bb   Benjamin Renard   First commit
18
19
20
21

#include "TimeInterval.hh"

namespace AMDA {
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
22
23
24
25
26
27
28
29
30
    namespace Statistic {
        namespace MinMaxMean {

            using namespace AMDA::Parameters;

            typedef enum {
                FT_MIN,
                FT_MAX,
                FT_MEAN,
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
31
                FT_RMS,
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
32
                FT_MEDIAN,
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
33
                FT_VARIANCE,
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
34
35
                FT_SKEWNESS,
                FT_KURTOSIS,
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
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
            } FUNC_TYPE;

            template<typename TParamData, typename TResultData>
            class MinMaxMeanStatisticOperation : public StatisticOperation<TResultData> {
            public:
                /**
                 * @brief  Element type of paramData
                 */
                typedef typename TParamData::ElementType ElementType;

                MinMaxMeanStatisticOperation(StatisticProcess& process,
                        TimeIntervalListSPtr pTimeIntervalList, TParamData &param, FUNC_TYPE funcType) :
                StatisticOperation<TResultData>(process),
                _paramInput(param), _timeIntervalList(pTimeIntervalList),
                _currentTimeInterval(_timeIntervalList->begin()),
                _funcType(funcType), _dimDef("unknown") {
                    resetData(StatisticOperation<TResultData>::_resultData);
                }

                virtual ~MinMaxMeanStatisticOperation(void) {
                }

                virtual void compute(ParamDataIndexInfo &pParamDataIndexInfo) {
                    for (unsigned int index = pParamDataIndexInfo._startIndex;
                            index < pParamDataIndexInfo._startIndex
                            + pParamDataIndexInfo._nbDataToProcess;
                            index++) {
                        _val = _paramInput.get(index);
                        switch (_funcType) {
                            case FT_MIN:
                                computeMin(_val);
                                break;
                            case FT_MAX:
                                computeMax(_val);
                                break;
                            case FT_MEAN:
                                addForMean(_val);
                                break;
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
74
75
76
                            case FT_RMS:
                                addForRMS(_val);
                                break;
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
77
                            case FT_MEDIAN:
8b82976b   Hacene SI HADJ MOHAND   correcting stats
78
                                addForMean(_val);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
79
80
81
                                generateVector(_val);
                                break;
                            case FT_VARIANCE:
4b695af7   Hacene SI HADJ MOHAND   tested ok
82
                                addForMean(_val);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
83
84
                                generateVector(_val);
                                break;
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
85
                            case FT_SKEWNESS:
4b695af7   Hacene SI HADJ MOHAND   tested ok
86
                                addForMean(_val);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
87
88
89
                                generateVector(_val);
                                break;
                            case FT_KURTOSIS:
4b695af7   Hacene SI HADJ MOHAND   tested ok
90
                                addForMean(_val);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
91
92
                                generateVector(_val);
                                break;
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
93
94
95
96
97
                        }
                    }
                }

                virtual void finalizeCompute(void) {
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
98
                    if (_funcType == FT_MEAN)
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
99
                        finalizeMeanResult(StatisticOperation<TResultData>::_resultData);
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
100
101
                    if (_funcType == FT_RMS)
                        finalizeRMSResult(StatisticOperation<TResultData>::_resultData);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
102
103
                    if (_funcType == FT_MEDIAN)
                        finalizeMedianResult(StatisticOperation<TResultData>::_resultData);
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
104
                    if (_funcType == FT_VARIANCE) {
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
105
                        finalizeMeanResult(StatisticOperation<TResultData>::_resultData);
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
106
107
                        finalizeVarianceResult(StatisticOperation<TResultData>::_resultData);
                    } else if (_funcType == FT_SKEWNESS) {
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
108
                        finalizeMeanResult(StatisticOperation<TResultData>::_resultData);
4b695af7   Hacene SI HADJ MOHAND   tested ok
109
                        finalizeVarianceResult(StatisticOperation<TResultData>::_resultData);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
110
                        finalizeSkewnessResult(StatisticOperation<TResultData>::_resultData);
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
111
                    } else if (_funcType == FT_KURTOSIS) {
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
112
                        finalizeMeanResult(StatisticOperation<TResultData>::_resultData);
4b695af7   Hacene SI HADJ MOHAND   tested ok
113
                        finalizeVarianceResult(StatisticOperation<TResultData>::_resultData);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
114
115
                        finalizeKurtosisResult(StatisticOperation<TResultData>::_resultData);
                    }
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
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
                }

                virtual void reset() {
                    StatisticOperation<TResultData>::reset();
                    resetData(StatisticOperation<TResultData>::_resultData);
                }

                /**
                 * @brief Get the result dimensiond efinition.
                 */
                virtual std::string getResultDimDefinition(bool /* forCoverage */) {
                    return _dimDef.str();
                }

            private:

                template<typename Type>
                void resetData(Type &a) {
                    a._result << NotANumber();
                    a._nbDataProcessed = 0;
                }

                template<typename Type>
                void resetData(std::vector<Type> &a) {
                    a.clear();
                }

                template<typename Type>
                void computeMin(Type &a) {
                    _dimDef.str("1");

                    if (isNAN(a))
                        return;

                    if (isNAN(StatisticOperation<TResultData>::_resultData._result))
                        StatisticOperation<TResultData>::_resultData._result = a;
                    else if (a < StatisticOperation<TResultData>::_resultData._result)
                        StatisticOperation<TResultData>::_resultData._result = a;
                    ++StatisticOperation<TResultData>::_resultData._nbDataProcessed;
                }

                template<typename Type>
                void computeMin(std::vector<Type> &a) {
                    if (StatisticOperation<TResultData>::_resultData.empty()) {
                        _dimDef.str("");
                        _dimDef << a.size();
                        for (unsigned int i = 0; i < a.size(); ++i) {
                            StatisticDataScalar<Type> data;
                            resetData(data);
                            data._result = a[i];
                            if (!isNAN(a))
                                ++data._nbDataProcessed;
                            StatisticOperation<TResultData>::_resultData.push_back(data);
                        }
                        return;
                    }

                    for (unsigned int i = 0; i < StatisticOperation<TResultData>::_resultData.size(); ++i) {
                        if (isNAN(a[i]))
                            continue;

                        if (isNAN(StatisticOperation<TResultData>::_resultData[i]._result))
                            StatisticOperation<TResultData>::_resultData[i]._result = a[i];
                        else if (a[i] < StatisticOperation<TResultData>::_resultData[i]._result)
                            StatisticOperation<TResultData>::_resultData[i]._result = a[i];
                        ++StatisticOperation<TResultData>::_resultData[i]._nbDataProcessed;
                    }
                }

                template<typename Type>
                void computeMax(Type &a) {
                    _dimDef.str("1");

                    if (isNAN(a))
                        return;

                    if (isNAN(StatisticOperation<TResultData>::_resultData._result))
                        StatisticOperation<TResultData>::_resultData._result = a;
                    else if (a > StatisticOperation<TResultData>::_resultData._result)
                        StatisticOperation<TResultData>::_resultData._result = a;
                    ++StatisticOperation<TResultData>::_resultData._nbDataProcessed;
                }

                template<typename Type>
                void computeMax(std::vector<Type> &a) {
                    if (StatisticOperation<TResultData>::_resultData.empty()) {
                        _dimDef.str("");
                        _dimDef << a.size();

                        for (unsigned int i = 0; i < a.size(); ++i) {
                            StatisticDataScalar<Type> data;
                            resetData(data);
                            data._result = a[i];
                            if (!isNAN(a))
                                ++data._nbDataProcessed;
                            StatisticOperation<TResultData>::_resultData.push_back(data);
                        }
                        return;
                    }

                    for (unsigned int i = 0; i < StatisticOperation<TResultData>::_resultData.size(); ++i) {
                        if (isNAN(a[i]))
                            continue;

                        if (isNAN(StatisticOperation<TResultData>::_resultData[i]._result))
                            StatisticOperation<TResultData>::_resultData[i]._result = a[i];
                        else if (a[i] > StatisticOperation<TResultData>::_resultData[i]._result)
                            StatisticOperation<TResultData>::_resultData[i]._result = a[i];
                        ++StatisticOperation<TResultData>::_resultData[i]._nbDataProcessed;
                    }
                }

                template<typename Type>
                void addForMean(Type &a) {
                    _dimDef.str("1");

                    if (isNAN(a))
                        return;

                    if (isNAN(StatisticOperation<TResultData>::_resultData._result))
                        StatisticOperation<TResultData>::_resultData._result = a;
                    else
                        StatisticOperation<TResultData>::_resultData._result = StatisticOperation<TResultData>::_resultData._result + a;
                    ++StatisticOperation<TResultData>::_resultData._nbDataProcessed;
                }

                template<typename Type>
                void addForMean(std::vector<Type> &a) {
                    if (StatisticOperation<TResultData>::_resultData.empty()) {
                        _dimDef.str("");
                        _dimDef << a.size();

                        for (unsigned int i = 0; i < a.size(); ++i) {
                            StatisticDataScalar<Type> data;
                            resetData(data);
                            data._result = a[i];
                            if (!isNAN(a))
                                ++data._nbDataProcessed;
                            StatisticOperation<TResultData>::_resultData.push_back(data);
                        }
                        return;
                    }

                    for (unsigned int i = 0; i < StatisticOperation<TResultData>::_resultData.size(); ++i) {
                        if (isNAN(a[i]))
                            continue;

                        if (isNAN(StatisticOperation<TResultData>::_resultData[i]._result))
                            StatisticOperation<TResultData>::_resultData[i]._result = a[i];
                        else
                            StatisticOperation<TResultData>::_resultData[i]._result = StatisticOperation<TResultData>::_resultData[i]._result + a[i];
                        ++StatisticOperation<TResultData>::_resultData[i]._nbDataProcessed;
                    }
                }

                template<typename Type>
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
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
                void addForRMS(Type &a) {
                    _dimDef.str("1");

                    if (isNAN(a))
                        return;

                    if (isNAN(StatisticOperation<TResultData>::_resultData._result))
                        StatisticOperation<TResultData>::_resultData._result = a * a;
                    else
                        StatisticOperation<TResultData>::_resultData._result = StatisticOperation<TResultData>::_resultData._result + a*a;
                    ++StatisticOperation<TResultData>::_resultData._nbDataProcessed;
                }

                template<typename Type>
                void addForRMS(std::vector<Type> &a) {
                    if (StatisticOperation<TResultData>::_resultData.empty()) {
                        _dimDef.str("");
                        _dimDef << a.size();

                        for (unsigned int i = 0; i < a.size(); ++i) {
                            StatisticDataScalar<Type> data;
                            resetData(data);
                            data._result = a[i] * a[i];
                            if (!isNAN(a))
                                ++data._nbDataProcessed;
                            StatisticOperation<TResultData>::_resultData.push_back(data);
                        }
                        return;
                    }

                    for (unsigned int i = 0; i < StatisticOperation<TResultData>::_resultData.size(); ++i) {
                        if (isNAN(a[i]))
                            continue;

                        if (isNAN(StatisticOperation<TResultData>::_resultData[i]._result))
                            StatisticOperation<TResultData>::_resultData[i]._result = a[i] * a[i];
                        else
                            StatisticOperation<TResultData>::_resultData[i]._result = StatisticOperation<TResultData>::_resultData[i]._result + a[i] * a[i];
                        ++StatisticOperation<TResultData>::_resultData[i]._nbDataProcessed;
                    }
                }

                template<typename Type>
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
315
316
317
318
319
320
321
                void generateVector(Type &a) {
                    _dimDef.str("1");
                    if (isNAN(a))
                        return;
                    if (isNAN(StatisticOperation<TResultData>::_resultData._result))
                        StatisticOperation<TResultData>::_resultData._result = a;
                    _dataList.push_back(a);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
                }

                template<typename Type>
                void generateVector(std::vector<Type> &a) {
                    if (StatisticOperation<TResultData>::_resultData.empty()) {
                        _dimDef.str("");
                        _dimDef << a.size();

                        for (unsigned int i = 0; i < a.size(); ++i) {
                            StatisticDataScalar<Type> data;
                            resetData(data);
                            data._result = a[i];
                            if (!isNAN(a))
                                ++data._nbDataProcessed;
                            StatisticOperation<TResultData>::_resultData.push_back(data);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
337
338
339
340
341
342
343
344
345
346
347
                        }
                    }

                    if (_dataList.empty()) {
                        // init _dataList  
                        for (int i = 0; i < a.size(); i++) {
                            std::vector<Type> vec;
                            if (!isNAN(a))
                                vec.push_back(a[i]);
                            _dataList.push_back(vec);
                            vec.clear();
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
348
349
350
351
352
353
                        }
                    } else {
                        //remplir dataList
                        for (int i = 0; i < a.size(); i++) {
                            if (!isNAN(a[i]))
                                _dataList[i].push_back(a[i]);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
354
355
356
357
358
359
360
                        }
                    }

                }

                template<typename Type>
                void finalizeMeanResult(Type& a) {
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
361
362
                    if (!isNAN(a._result) && a._nbDataProcessed > 0)
                        a._result /= a._nbDataProcessed;
4b695af7   Hacene SI HADJ MOHAND   tested ok
363
                    _mean = a._result;
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
364

65af22fe   Hacene SI HADJ MOHAND   ok for median var...
365
366
367
368
                }

                template<typename Type>
                void finalizeMeanResult(std::vector<Type>& a) {
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
                    for (unsigned int i = 0; i < a.size(); ++i) {
                        if (!isNAN(a[i]._result) && a[i]._nbDataProcessed > 0) {
                            a[i]._result /= a[i]._nbDataProcessed;
                            _mean.push_back(a[i]._result);
                        }
                    }
                }

                template<typename Type>
                void finalizeRMSResult(Type& a) {
                    if (!isNAN(a._result) && a._nbDataProcessed > 0)
                        a._result = sqrt(a._result / a._nbDataProcessed);
                }

                template<typename Type>
                void finalizeRMSResult(std::vector<Type>& a) {
                    for (int i = 0; i < a.size(); i++) {
                        if (!isNAN(a[i]._result) && a[i]._nbDataProcessed > 0)
                            a[i]._result = sqrt(a[i]._result / a[i]._nbDataProcessed);
4b695af7   Hacene SI HADJ MOHAND   tested ok
388
                    }
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
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
                }

                template<typename Type>
                void finalizeMedianResult(Type & a) {
                    std::size_t size = _dataList.size();
                    if (size == 0)
                        return;
                    std::sort(_dataList.begin(), _dataList.end());
                    if (size % 2 == 0) {
                        a._result = (_dataList[size / 2 - 1] + _dataList[size / 2]) / 2;
                    } else {
                        a._result = _dataList[floor(size / 2)];
                    }
                }

                template<typename Type>
                void finalizeMedianResult(std::vector<Type>& a) {
                    for (int i = 0; i < a.size(); i++) {
                        std::size_t size = _dataList[i].size();
                        if (size == 0)
                            return;
                        std::sort(_dataList[i].begin(), _dataList[i].end());
                        if (size % 2 == 0) {
                            a[i]._result = (_dataList[i][size / 2 - 1] + _dataList[i][size / 2]) / 2;
                        } else {
                            a[i]._result = _dataList[i][floor(size / 2)];
                        }
                    }
                }

                template<typename Type>
                void finalizeVarianceResult(Type & a) {
                    if (_dataList.size() == 0)
                        return;
                    double accum = 0.0;
                    std::for_each(std::begin(_dataList), std::end(_dataList), [&](const double d) {
4b695af7   Hacene SI HADJ MOHAND   tested ok
425
                        accum += (d - _mean) * (d - _mean);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
426
                    });
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
427
                    a._result = accum / (_dataList.size());
4b695af7   Hacene SI HADJ MOHAND   tested ok
428
                    _standardDeviation = sqrt(a._result);
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
429
                }
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
430

65af22fe   Hacene SI HADJ MOHAND   ok for median var...
431
432
                template<typename Type>
                void finalizeVarianceResult(std::vector<Type> & a) {
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
433
434
435
436
437
438
439
440
441
                    for (int i = 0; i < a.size(); i++) {
                        if (_dataList[i].size() == 0)
                            return;
                        double accum = 0.0;
                        std::for_each(std::begin(_dataList[i]), std::end(_dataList[i]), [&](const double d) {
                            accum += (d - _mean[i]) * (d - _mean[i]);
                        });
                        a[i]._result = accum / (_dataList[i].size());
                        _standardDeviation.push_back(sqrt(a[i]._result));
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
442
443
444
                    }
                }

1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
445
446
                template<typename Type>
                void finalizeSkewnessResult(Type & a) {
4b695af7   Hacene SI HADJ MOHAND   tested ok
447
448
                    int n = _dataList.size();
                    if (n == 0)
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
449
450
451
                        return;
                    double accum = 0.0;
                    std::for_each(std::begin(_dataList), std::end(_dataList), [&](const double d) {
4b695af7   Hacene SI HADJ MOHAND   tested ok
452
                        accum += (d - _mean) * (d - _mean) * (d - _mean);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
453
                    });
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
454
                    a._result = n / ((double) (n - 1)*(n - 2)) * accum / pow(_standardDeviation, 3);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
455
                }
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
456

1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
457
458
                template<typename Type>
                void finalizeSkewnessResult(std::vector<Type> & a) {
8b82976b   Hacene SI HADJ MOHAND   correcting stats
459
                    for (int i = 0; i < a.size(); i++) { 
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
460
461
462
463
464
465
466
467
                        int n = _dataList[i].size();
                        if (n == 0)
                            return;
                        double accum = 0.0;
                        std::for_each(std::begin(_dataList[i]), std::end(_dataList[i]), [&](const double d) {
                            accum += (d - _mean[i]) * (d - _mean[i]) * (d - _mean[i]);
                        });
                        a[i]._result = n / ((double) (n - 1)*(n - 2)) * accum / pow(_standardDeviation[i], 3);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
468
469
                    }
                }
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
470

1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
471
472
                template<typename Type>
                void finalizeKurtosisResult(Type & a) {
4b695af7   Hacene SI HADJ MOHAND   tested ok
473
474
                    int n = _dataList.size();
                    if (n == 0)
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
475
476
477
                        return;
                    double accum = 0.0;
                    std::for_each(std::begin(_dataList), std::end(_dataList), [&](const double d) {
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
478
                        accum += (d - _mean) * (d - _mean) * (d - _mean) * (d - _mean) / pow(_standardDeviation, 4);
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
479
                    });
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
480
                    a._result = n * (n + 1) / ((double) (n - 1)*(n - 2)*(n - 3)) * accum - 3 * (n - 1)*(n - 1) / ((double) (n - 2)*(n - 3));
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
481
                }
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
482

1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
483
484
                template<typename Type>
                void finalizeKurtosisResult(std::vector<Type> & a) {
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
485
                    for (int i = 0; i < a.size(); i++) {
4b695af7   Hacene SI HADJ MOHAND   tested ok
486
                        int n = _dataList[i].size();
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
487
488
489
490
491
492
493
                        if (n == 0)
                            return;
                        double accum = 0.0;
                        std::for_each(std::begin(_dataList[i]), std::end(_dataList[i]), [&](const double d) {
                            accum += (d - _mean[i]) * (d - _mean[i]) * (d - _mean[i]) * (d - _mean[i]) / pow(_standardDeviation[i], 4);
                        });
                        a[i]._result = n * (n + 1) / ((double) (n - 1)*(n - 2)*(n - 3)) * accum - 3 * (n - 1)*(n - 1) / ((double) (n - 2)*(n - 3));
1d0339b8   Hacene SI HADJ MOHAND   Ok pour skewness ...
494
495
                    }
                }
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
496
497
498
499
500
501
502
503
504
505
506

                /**
                 * @brief real ParamData Input
                 */
                TParamData& _paramInput;

                TimeIntervalListSPtr _timeIntervalList;

                TimeIntervalList::iterator _currentTimeInterval;

                ElementType _val;
6f170ffb   Hacene SI HADJ MOHAND   Ok rms
507
508
509

                ElementType _mean;

4b695af7   Hacene SI HADJ MOHAND   tested ok
510
                ElementType _standardDeviation;
65af22fe   Hacene SI HADJ MOHAND   ok for median var...
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

                std::vector<ElementType> _dataList;

                FUNC_TYPE _funcType;

                std::stringstream _dimDef;
            };

            class CreateMinMaxMeanStatistic : public VisitorOfParamData {
            public:

                /**
                 * @brief constructor
                 */
                CreateMinMaxMeanStatistic(StatisticProcess& pProcess,
                        TimeIntervalListSPtr pTimeIntervalList,
                        ParamData &paramData, FUNC_TYPE type) :
                _process(pProcess), _timeIntervalList(pTimeIntervalList),
                _paramData(paramData), _operation(NULL), _type(type) {
                    _paramData.accept(*this);
                }

                StatisticOperationBase* getStatisticOperation(void) {
                    return _operation;
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireShort *)
                 */
                virtual void visit(ParamDataScalaireShort *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataScalaireShort, StatisticDataScalar<short>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataScalaireShort &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireFloat *)
                 */
                virtual void visit(ParamDataScalaireFloat *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataScalaireFloat, StatisticDataScalar<float>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataScalaireFloat &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireDouble *)
                 */
                virtual void visit(ParamDataScalaireDouble *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataScalaireDouble, StatisticDataScalar<double>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataScalaireDouble &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireLongDouble *)
                 */
                virtual void visit(ParamDataScalaireLongDouble *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataScalaireLongDouble, StatisticDataScalar<long double>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataScalaireLongDouble &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireInt *)
                 */
                virtual void visit(ParamDataScalaireInt *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataScalaireInt, StatisticDataScalar<int>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataScalaireInt &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataLogicalData *)
                 */
                virtual void visit(ParamDataLogicalData *) {
                    BOOST_THROW_EXCEPTION(
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN)
                            << AMDA::ex_msg(
                            "CreateStatistic operation not supported"));
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DShort *)
                 */
                virtual void visit(ParamDataTab1DShort *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataTab1DShort, StatisticDataVector<short>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataTab1DShort &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DFloat *)
                 */
                virtual void visit(ParamDataTab1DFloat *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataTab1DFloat, StatisticDataVector<float>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataTab1DFloat &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DDouble *)
                 */
                virtual void visit(ParamDataTab1DDouble *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataTab1DDouble, StatisticDataVector<double>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataTab1DDouble &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DLongDouble *)
                 */
                virtual void visit(ParamDataTab1DLongDouble *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataTab1DLongDouble, StatisticDataVector<long double>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataTab1DLongDouble &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DInt *)
                 */
                virtual void visit(ParamDataTab1DInt *) {
                    _operation = new MinMaxMeanStatisticOperation<ParamDataTab1DInt, StatisticDataVector<int>>(_process,
                            _timeIntervalList, dynamic_cast<ParamDataTab1DInt &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DLogicalData *)
                 */
                virtual void visit(ParamDataTab1DLogicalData *) {
                    BOOST_THROW_EXCEPTION(
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN)
                            << AMDA::ex_msg(
                            "CreateStatistic operation not supported"));
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DShort *)
                 */
                virtual void visit(ParamDataTab2DShort *) {
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DShort data not supported"));
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *)
                 */
                virtual void visit(ParamDataTab2DFloat *) {
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DFloat data not supported"));
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *)
                 */
                virtual void visit(ParamDataTab2DDouble *) {
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DDouble data not supported"));
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *)
                 */
                virtual void visit(ParamDataTab2DLongDouble *) {
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLongDouble data not supported"));
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DInt *)
                 */
                virtual void visit(ParamDataTab2DInt *) {
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DInt data not supported"));
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *)
                 */
                virtual void visit(ParamDataTab2DLogicalData *) {
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLogicalData data not supported"));
                }

            private:
                StatisticProcess& _process;

                TimeIntervalListSPtr& _timeIntervalList;

                ParamData &_paramData;

                StatisticOperationBase *_operation;

                FUNC_TYPE _type;
            };

        } /* namespace MinMaxMean */
    } /* namespace Statistic */
fbe3c2bb   Benjamin Renard   First commit
693
694
695
} /* namespace AMDA */

#endif /* MINMAXMEANSTATISTIC_HH_ */