Commit 4b695af7e7d9f7a89f094c23b511f8ede40d5c90

Authored by Hacene SI HADJ MOHAND
1 parent 1d0339b8

tested ok

src/ExternLib/StatisticProcesses/AMDAPlugin.cc
... ... @@ -52,6 +52,8 @@ DESCRIPTION
52 52 #include "PluginManager.hh"
53 53 #include "MinMaxMeanStatisticProcess.hh"
54 54 #include "MinVarStatisticProcess.hh"
  55 +#include "CountStatisticProcess.hh"
  56 +#include "CountStatistic.hh"
55 57  
56 58 using namespace AMDA::Parameters;
57 59  
... ... @@ -102,4 +104,10 @@ extern "C" void registerPlugin(AMDA::Plugins::PluginManager & /*pm*/)
102 104  
103 105 StatisticProcessFactory factKurtosisProcess = boost::factory<AMDA::Statistic::MinMaxMean::KurtosisStatisticProcess*>();
104 106 ServicesServer::getInstance()->addStatisticProcessFactory("kurtosis", factKurtosisProcess);
  107 +
  108 + StatisticProcessFactory factCountProcess = boost::factory<AMDA::Statistic::Count::CountStatisticProcess*>();
  109 + ServicesServer::getInstance()->addStatisticProcessFactory("count", factCountProcess);
  110 +
  111 + StatisticProcessFactory factCountNotNanProcess = boost::factory<AMDA::Statistic::Count::CountNotNanStatisticProcess*>();
  112 + ServicesServer::getInstance()->addStatisticProcessFactory("countNotNan", factCountNotNanProcess);
105 113 }
... ...
src/ExternLib/StatisticProcesses/CountStatistic.hh 0 → 100644
... ... @@ -0,0 +1,329 @@
  1 +
  2 +/*
  3 + * File: CountStatistic.hh
  4 + * Author: AKKA
  5 + *
  6 + * Created on December 20, 2019, 1:44 PM
  7 + */
  8 +
  9 +#ifndef COUNTSTATISTIC_HH
  10 +#define COUNTSTATISTIC_HH
  11 +
  12 +#include "ParamData.hh"
  13 +#include "DataTypeMath.hh"
  14 +#include "VisitorOfParamData.hh"
  15 +#include "StatisticData.hh"
  16 +#include "StatisticOperation.hh"
  17 +#include "StatisticProcess.hh"
  18 +#include <math.h>
  19 +#include "TimeInterval.hh"
  20 +
  21 +namespace AMDA {
  22 + namespace Statistic {
  23 + namespace Count {
  24 +
  25 + using namespace AMDA::Parameters;
  26 +
  27 + typedef enum {
  28 + FT_COUNT,
  29 + FT_COUNT_NOT_NAN
  30 + } COUNT_FUNC_TYPE;
  31 +
  32 + template <typename TParamData, typename TResultData>
  33 + class CountStatisticOperation : public StatisticOperation<TResultData> {
  34 + public:
  35 + typedef typename TParamData::ElementType ElementType;
  36 +
  37 + CountStatisticOperation(StatisticProcess& process,
  38 + TimeIntervalListSPtr pTimeIntervalList, TParamData &param, COUNT_FUNC_TYPE funcType) :
  39 + StatisticOperation<TResultData>(process),
  40 + _paramInput(param), _timeIntervalList(pTimeIntervalList),
  41 + _currentTimeInterval(_timeIntervalList->begin()),
  42 + _funcType(funcType), _dimDef("unknown") {
  43 + resetData(StatisticOperation<TResultData>::_resultData);
  44 + }
  45 +
  46 + virtual ~CountStatisticOperation(void) {
  47 + }
  48 +
  49 + virtual void compute(ParamDataIndexInfo &pParamDataIndexInfo) {
  50 + for (unsigned int index = pParamDataIndexInfo._startIndex;
  51 + index < pParamDataIndexInfo._startIndex
  52 + + pParamDataIndexInfo._nbDataToProcess;
  53 + index++) {
  54 + _val = _paramInput.get(index);
  55 + switch (_funcType) {
  56 + case FT_COUNT:
  57 + count(_val);
  58 + break;
  59 + case FT_COUNT_NOT_NAN:
  60 + count(_val, "NotNan");
  61 + break;
  62 + }
  63 + }
  64 + }
  65 +
  66 + virtual void finalizeCompute(void) {
  67 + if (_funcType == FT_COUNT || _funcType == FT_COUNT_NOT_NAN) {
  68 + finalizeCountResult(StatisticOperation<TResultData>::_resultData);
  69 + }
  70 + }
  71 +
  72 + virtual std::string getResultDimDefinition(bool /* forCoverage */) {
  73 + return _dimDef.str();
  74 + }
  75 +
  76 + virtual void reset() {
  77 + StatisticOperation<TResultData>::reset();
  78 + resetData(StatisticOperation<TResultData>::_resultData);
  79 + }
  80 + private:
  81 +
  82 + template<typename Type>
  83 + void resetData(Type &a) {
  84 + a._result << NotANumber();
  85 + a._nbDataProcessed = 0;
  86 + }
  87 +
  88 + template<typename Type>
  89 + void resetData(std::vector<Type> &a) {
  90 + a.clear();
  91 + }
  92 +
  93 + template<typename Type>
  94 + void count(Type &a, std::string mode = " ") {
  95 + _dimDef.str("1");
  96 + if (mode == "NotNan" && isNAN(a))
  97 + return;
  98 + ++StatisticOperation<TResultData>::_resultData._nbDataProcessed;
  99 + }
  100 +
  101 + template<typename Type>
  102 + void count(std::vector<Type> &a, std::string mode = " ") {
  103 + if (StatisticOperation<TResultData>::_resultData.empty()) {
  104 + _dimDef.str("");
  105 + _dimDef << a.size();
  106 + for (unsigned int i = 0; i < a.size(); ++i) {
  107 + StatisticDataScalar<int> data;
  108 + resetData(data);
  109 + if (!isNAN(a[i]) || mode == " ")
  110 + ++data._nbDataProcessed;
  111 + StatisticOperation<TResultData>::_resultData.push_back(data);
  112 + }
  113 + return;
  114 + }
  115 + for (unsigned int i = 0; i < StatisticOperation<TResultData>::_resultData.size(); ++i) {
  116 + if (isNAN(a[i]) && mode == "NotNan")
  117 + continue;
  118 + ++StatisticOperation<TResultData>::_resultData[i]._nbDataProcessed;
  119 + }
  120 + }
  121 +
  122 + template<typename Type>
  123 + void finalizeCountResult(Type &a) {
  124 + if (!isNAN(a._nbDataProcessed))
  125 + a._result = a._nbDataProcessed;
  126 + }
  127 +
  128 + template<typename Type>
  129 + void finalizeCountResult(std::vector<Type> &a) {
  130 + for (int i = 0; i < a.size(); i++)
  131 + finalizeCountResult(a[i]);
  132 + }
  133 +
  134 + /**
  135 + * @brief real ParamData Input
  136 + */
  137 + TParamData& _paramInput;
  138 +
  139 + TimeIntervalListSPtr _timeIntervalList;
  140 +
  141 + TimeIntervalList::iterator _currentTimeInterval;
  142 +
  143 + ElementType _val;
  144 +
  145 + COUNT_FUNC_TYPE _funcType;
  146 +
  147 + std::stringstream _dimDef;
  148 +
  149 + }; //Class Count
  150 +
  151 + class CreateCountStatistic : public VisitorOfParamData {
  152 + public:
  153 +
  154 + CreateCountStatistic(StatisticProcess& pProcess,
  155 + TimeIntervalListSPtr pTimeIntervalList,
  156 + ParamData &paramData, COUNT_FUNC_TYPE type) :
  157 + _process(pProcess), _timeIntervalList(pTimeIntervalList),
  158 + _paramData(paramData), _operation(NULL), _type(type) {
  159 + _paramData.accept(*this);
  160 + }
  161 +
  162 + StatisticOperationBase* getStatisticOperation(void) {
  163 + return _operation;
  164 + }
  165 +
  166 + /**
  167 + * @overload VisitorOfParamData::visit(ParamDataScalaireShort *)
  168 + */
  169 + virtual void visit(ParamDataScalaireShort *) {
  170 + _operation = new CountStatisticOperation<ParamDataScalaireShort, StatisticDataScalar<int>>(_process,
  171 + _timeIntervalList, dynamic_cast<ParamDataScalaireShort &> (_paramData), _type);
  172 + }
  173 +
  174 + /**
  175 + * @overload VisitorOfParamData::visit(ParamDataScalaireFloat *)
  176 + */
  177 + virtual void visit(ParamDataScalaireFloat *) {
  178 + _operation = new CountStatisticOperation<ParamDataScalaireFloat, StatisticDataScalar<int>>(_process,
  179 + _timeIntervalList, dynamic_cast<ParamDataScalaireFloat &> (_paramData), _type);
  180 + }
  181 +
  182 + /**
  183 + * @overload VisitorOfParamData::visit(ParamDataScalaireDouble *)
  184 + */
  185 + virtual void visit(ParamDataScalaireDouble *) {
  186 + _operation = new CountStatisticOperation<ParamDataScalaireDouble, StatisticDataScalar<int>>(_process,
  187 + _timeIntervalList, dynamic_cast<ParamDataScalaireDouble &> (_paramData), _type);
  188 + }
  189 +
  190 + /**
  191 + * @overload VisitorOfParamData::visit(ParamDataScalaireLongDouble *)
  192 + */
  193 + virtual void visit(ParamDataScalaireLongDouble *) {
  194 + _operation = new CountStatisticOperation<ParamDataScalaireLongDouble, StatisticDataScalar<int>>(_process,
  195 + _timeIntervalList, dynamic_cast<ParamDataScalaireLongDouble &> (_paramData), _type);
  196 + }
  197 +
  198 + /**
  199 + * @overload VisitorOfParamData::visit(ParamDataScalaireInt *)
  200 + */
  201 + virtual void visit(ParamDataScalaireInt *) {
  202 + _operation = new CountStatisticOperation<ParamDataScalaireInt, StatisticDataScalar<int>>(_process,
  203 + _timeIntervalList, dynamic_cast<ParamDataScalaireInt &> (_paramData), _type);
  204 + }
  205 +
  206 + /**
  207 + * @overload VisitorOfParamData::visit(ParamDataLogicalData *)
  208 + */
  209 + virtual void visit(ParamDataLogicalData *) {
  210 + BOOST_THROW_EXCEPTION(
  211 + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN)
  212 + << AMDA::ex_msg(
  213 + "CreateStatistic operation not supported"));
  214 + }
  215 +
  216 + /**
  217 + * @overload VisitorOfParamData::visit(ParamDataTab1DShort *)
  218 + */
  219 + virtual void visit(ParamDataTab1DShort *) {
  220 + _operation = new CountStatisticOperation<ParamDataTab1DShort, StatisticDataVector<int>>(_process,
  221 + _timeIntervalList, dynamic_cast<ParamDataTab1DShort &> (_paramData), _type);
  222 + }
  223 +
  224 + /**
  225 + * @overload VisitorOfParamData::visit(ParamDataTab1DFloat *)
  226 + */
  227 + virtual void visit(ParamDataTab1DFloat *) {
  228 + _operation = new CountStatisticOperation<ParamDataTab1DFloat, StatisticDataVector<int>>(_process,
  229 + _timeIntervalList, dynamic_cast<ParamDataTab1DFloat &> (_paramData), _type);
  230 + }
  231 +
  232 + /**
  233 + * @overload VisitorOfParamData::visit(ParamDataTab1DDouble *)
  234 + */
  235 + virtual void visit(ParamDataTab1DDouble *) {
  236 + _operation = new CountStatisticOperation<ParamDataTab1DDouble, StatisticDataVector<int>>(_process,
  237 + _timeIntervalList, dynamic_cast<ParamDataTab1DDouble &> (_paramData), _type);
  238 + }
  239 +
  240 + /**
  241 + * @overload VisitorOfParamData::visit(ParamDataTab1DLongDouble *)
  242 + */
  243 + virtual void visit(ParamDataTab1DLongDouble *) {
  244 + _operation = new CountStatisticOperation<ParamDataTab1DLongDouble, StatisticDataVector<int>>(_process,
  245 + _timeIntervalList, dynamic_cast<ParamDataTab1DLongDouble &> (_paramData), _type);
  246 + }
  247 +
  248 + /**
  249 + * @overload VisitorOfParamData::visit(ParamDataTab1DInt *)
  250 + */
  251 + virtual void visit(ParamDataTab1DInt *) {
  252 + _operation = new CountStatisticOperation<ParamDataTab1DInt, StatisticDataVector<int>>(_process,
  253 + _timeIntervalList, dynamic_cast<ParamDataTab1DInt &> (_paramData), _type);
  254 + }
  255 +
  256 + /**
  257 + * @overload VisitorOfParamData::visit(ParamDataTab1DLogicalData *)
  258 + */
  259 + virtual void visit(ParamDataTab1DLogicalData *) {
  260 + BOOST_THROW_EXCEPTION(
  261 + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN)
  262 + << AMDA::ex_msg(
  263 + "CreateStatistic operation not supported"));
  264 + }
  265 +
  266 + /**
  267 + * @overload VisitorOfParamData::visit(ParamDataTab2DShort *)
  268 + */
  269 + virtual void visit(ParamDataTab2DShort *) {
  270 + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DShort data not supported"));
  271 + }
  272 +
  273 + /**
  274 + * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *)
  275 + */
  276 + virtual void visit(ParamDataTab2DFloat *) {
  277 + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DFloat data not supported"));
  278 + }
  279 +
  280 + /**
  281 + * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *)
  282 + */
  283 + virtual void visit(ParamDataTab2DDouble *) {
  284 + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DDouble data not supported"));
  285 + }
  286 +
  287 + /**
  288 + * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *)
  289 + */
  290 + virtual void visit(ParamDataTab2DLongDouble *) {
  291 + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLongDouble data not supported"));
  292 + }
  293 +
  294 + /**
  295 + * @overload VisitorOfParamData::visit(ParamDataTab2DInt *)
  296 + */
  297 + virtual void visit(ParamDataTab2DInt *) {
  298 + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DInt data not supported"));
  299 + }
  300 +
  301 + /**
  302 + * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *)
  303 + */
  304 + virtual void visit(ParamDataTab2DLogicalData *) {
  305 + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLogicalData data not supported"));
  306 + }
  307 +
  308 + private:
  309 + StatisticProcess& _process;
  310 +
  311 + TimeIntervalListSPtr& _timeIntervalList;
  312 +
  313 + ParamData &_paramData;
  314 +
  315 + StatisticOperationBase *_operation;
  316 +
  317 + COUNT_FUNC_TYPE _type;
  318 +
  319 +
  320 + };
  321 +
  322 + }//Count
  323 + }//STATISTIC
  324 +} //AMDA
  325 +
  326 +
  327 +
  328 +#endif /* COUNTSTATISTIC_HH */
  329 +
... ...
src/ExternLib/StatisticProcesses/CountStatisticProcess.cc 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +#include "CountStatisticProcess.hh"
  2 +
  3 +#include "CountStatistic.hh"
  4 +
  5 +namespace AMDA {
  6 + namespace Statistic {
  7 + namespace Count {
  8 +
  9 + CountStatisticProcess::CountStatisticProcess(AMDA::Parameters::Parameter &parameter, const int& index) :
  10 + AMDA::Parameters::StatisticProcess(parameter, false, index) {
  11 + }
  12 +
  13 + CountStatisticProcess::~CountStatisticProcess(void) {
  14 + }
  15 +
  16 + void CountStatisticProcess::createOperation(void) {
  17 + AMDA::Parameters::ParamData *paramInput = _parameter.getParamData(this).get();
  18 + CreateCountStatistic lCreateCountStatistic(*this, _timeIntervalList, *paramInput, COUNT_FUNC_TYPE::FT_COUNT);
  19 + _operation = lCreateCountStatistic.getStatisticOperation();
  20 + }
  21 +
  22 + std::string CountStatisticProcess::getUCD(void) {
  23 + return "stat.count";
  24 + }
  25 +
  26 + CountNotNanStatisticProcess::CountNotNanStatisticProcess(AMDA::Parameters::Parameter &parameter, const int& index) :
  27 + AMDA::Parameters::StatisticProcess(parameter, false, index) {
  28 + }
  29 +
  30 + CountNotNanStatisticProcess::~CountNotNanStatisticProcess(void) {
  31 + }
  32 +
  33 + void CountNotNanStatisticProcess::createOperation(void) {
  34 + AMDA::Parameters::ParamData *paramInput = _parameter.getParamData(this).get();
  35 + CreateCountStatistic lCreateCountStatistic(*this, _timeIntervalList, *paramInput, COUNT_FUNC_TYPE::FT_COUNT_NOT_NAN);
  36 + _operation = lCreateCountStatistic.getStatisticOperation();
  37 + }
  38 +
  39 + std::string CountNotNanStatisticProcess::getUCD(void) {
  40 + return "stat.countNotNan";
  41 + }
  42 +
  43 + }
  44 + }
  45 +}
0 46 \ No newline at end of file
... ...
src/ExternLib/StatisticProcesses/CountStatisticProcess.hh 0 → 100644
... ... @@ -0,0 +1,87 @@
  1 +/*
  2 + * To change this license header, choose License Headers in Project Properties.
  3 + * To change this template file, choose Tools | Templates
  4 + * and open the template in the editor.
  5 + */
  6 +
  7 +/*
  8 + * File: CountStatisticProcess.hh
  9 + * Author: AKKA
  10 + *
  11 + * Created on December 20, 2019, 1:42 PM
  12 + */
  13 +
  14 +#ifndef COUNTSTATISTICPROCESS_HH
  15 +#define COUNTSTATISTICPROCESS_HH
  16 +
  17 +#include "StatisticProcess.hh"
  18 +
  19 +namespace AMDA {
  20 +namespace Statistic {
  21 +namespace Count {
  22 +
  23 +/**
  24 + * @class CountStatisticProcess
  25 + * @brief Process to compute COUNT value
  26 + */
  27 +class CountStatisticProcess : public AMDA::Parameters::StatisticProcess
  28 +{
  29 +public:
  30 + /*
  31 + * @brief constructor
  32 + */
  33 + CountStatisticProcess(AMDA::Parameters::Parameter &parameter, const int& index);
  34 +
  35 + /*
  36 + * @brief destructor
  37 + */
  38 + virtual ~CountStatisticProcess(void);
  39 +
  40 + /*
  41 + * @brief create min statistic operation
  42 + */
  43 + virtual void createOperation(void);
  44 +
  45 + /*
  46 + * @brief get UCD of the process
  47 + */
  48 + std::string getUCD(void);
  49 +};
  50 +
  51 +/**
  52 + * @class CountStatisticProcess
  53 + * @brief Process to compute COUNT value
  54 + */
  55 +class CountNotNanStatisticProcess : public AMDA::Parameters::StatisticProcess
  56 +{
  57 +public:
  58 + /*
  59 + * @brief constructor
  60 + */
  61 + CountNotNanStatisticProcess(AMDA::Parameters::Parameter &parameter, const int& index);
  62 +
  63 + /*
  64 + * @brief destructor
  65 + */
  66 + virtual ~CountNotNanStatisticProcess(void);
  67 +
  68 + /*
  69 + * @brief create min statistic operation
  70 + */
  71 + virtual void createOperation(void);
  72 +
  73 + /*
  74 + * @brief get UCD of the process
  75 + */
  76 + std::string getUCD(void);
  77 +};
  78 +
  79 +
  80 +
  81 +} // Count
  82 +} // Statistic
  83 +} // AMDA
  84 +
  85 +
  86 +#endif /* COUNTSTATISTICPROCESS_HH */
  87 +
... ...
src/ExternLib/StatisticProcesses/MinMaxMeanStatistic.hh
... ... @@ -74,12 +74,15 @@ namespace AMDA {
74 74 generateVector(_val);
75 75 break;
76 76 case FT_VARIANCE:
  77 + addForMean(_val);
77 78 generateVector(_val);
78 79 break;
79 80 case FT_SKEWNESS:
  81 + addForMean(_val);
80 82 generateVector(_val);
81 83 break;
82 84 case FT_KURTOSIS:
  85 + addForMean(_val);
83 86 generateVector(_val);
84 87 break;
85 88 }
... ... @@ -96,9 +99,11 @@ namespace AMDA {
96 99 finalizeVarianceResult(StatisticOperation<TResultData>::_resultData);
97 100 }else if (_funcType == FT_SKEWNESS){
98 101 finalizeMeanResult(StatisticOperation<TResultData>::_resultData);
  102 + finalizeVarianceResult(StatisticOperation<TResultData>::_resultData);
99 103 finalizeSkewnessResult(StatisticOperation<TResultData>::_resultData);
100 104 }else if (_funcType == FT_KURTOSIS){
101 105 finalizeMeanResult(StatisticOperation<TResultData>::_resultData);
  106 + finalizeVarianceResult(StatisticOperation<TResultData>::_resultData);
102 107 finalizeKurtosisResult(StatisticOperation<TResultData>::_resultData);
103 108 }
104 109 }
... ... @@ -306,12 +311,15 @@ namespace AMDA {
306 311 if (a._nbDataProcessed > 0)
307 312 if (!isNAN(a._result))
308 313 a._result /= a._nbDataProcessed;
  314 + _mean = a._result;
309 315 }
310 316  
311 317 template<typename Type>
312 318 void finalizeMeanResult(std::vector<Type>& a) {
313   - for (unsigned int i = 0; i < a.size(); ++i)
314   - finalizeMeanResult(a[i]);
  319 + for (unsigned int i = 0; i < a.size(); ++i){
  320 + a[i]._result /= a[i]._nbDataProcessed;
  321 + _mean.push_back(a[i]._result);
  322 + }
315 323 }
316 324  
317 325 template<typename Type>
... ... @@ -348,9 +356,10 @@ namespace AMDA {
348 356 return;
349 357 double accum = 0.0;
350 358 std::for_each(std::begin(_dataList), std::end(_dataList), [&](const double d) {
351   - accum += (d - a._result) * (d - a._result);
  359 + accum += (d - _mean) * (d - _mean);
352 360 });
353   - a._result = accum/(_dataList.size()-1);
  361 + a._result = accum/(_dataList.size());
  362 + _standardDeviation = sqrt(a._result);
354 363 }
355 364  
356 365 template<typename Type>
... ... @@ -360,57 +369,62 @@ namespace AMDA {
360 369 return;
361 370 double accum = 0.0;
362 371 std::for_each(std::begin(_dataList[i]), std::end(_dataList[i]), [&](const double d) {
363   - accum += (d - a[i]._result) * (d - a[i]._result);
  372 + accum += (d - _mean[i]) * (d - _mean[i]);
364 373 });
365   - a[i]._result = accum/(_dataList[i].size()-1);
  374 + a[i]._result = accum/(_dataList[i].size());
  375 + _standardDeviation.push_back(sqrt(a[i]._result));
366 376 }
367 377 }
368 378  
369 379 template<typename Type>
370 380 void finalizeSkewnessResult(Type & a) {
371   - if (_dataList.size() == 0)
  381 + int n = _dataList.size();
  382 + if (n == 0)
372 383 return;
373 384 double accum = 0.0;
374 385 std::for_each(std::begin(_dataList), std::end(_dataList), [&](const double d) {
375   - accum += (d - a._result) * (d - a._result) * (d - a._result);
  386 + accum += (d - _mean) * (d - _mean) * (d - _mean);
376 387 });
377   - a._result = accum/(_dataList.size()-1);
  388 + a._result = n/((double) (n-1)*(n-2))*accum/pow(_standardDeviation, 3);
378 389 }
379 390  
380 391 template<typename Type>
381 392 void finalizeSkewnessResult(std::vector<Type> & a) {
382 393 for(int i = 0; i < a.size(); i++){
383   - if (_dataList[i].size() == 0)
  394 + int n = _dataList[i].size();
  395 + if (n == 0)
384 396 return;
385 397 double accum = 0.0;
386 398 std::for_each(std::begin(_dataList[i]), std::end(_dataList[i]), [&](const double d) {
387   - accum += (d - a[i]._result) * (d - a[i]._result) * (d - a[i]._result);
  399 + accum += (d - _mean[i]) * (d - _mean[i]) * (d - _mean[i]);
388 400 });
389   - a[i]._result = accum/(_dataList[i].size()-1);
  401 + a[i]._result = n/((double) (n-1)*(n-2))*accum/pow(_standardDeviation[i], 3);
390 402 }
391 403 }
392 404  
393 405 template<typename Type>
394 406 void finalizeKurtosisResult(Type & a) {
395   - if (_dataList.size() == 0)
  407 + int n = _dataList.size();
  408 + if (n == 0)
396 409 return;
397 410 double accum = 0.0;
398 411 std::for_each(std::begin(_dataList), std::end(_dataList), [&](const double d) {
399   - accum += (d - a._result) * (d - a._result) * (d - a._result) * (d - a._result);;
  412 + accum += (d - _mean) * (d - _mean) * (d - _mean) * (d - _mean)/pow(_standardDeviation,4);
400 413 });
401   - a._result = accum/(_dataList.size()-1);
  414 + a._result = n*(n+1)/((double)(n-1)*(n-2)*(n-3))*accum- 3*(n-1)*(n-1)/((double)(n-2)*(n-3));
402 415 }
403 416  
404 417 template<typename Type>
405 418 void finalizeKurtosisResult(std::vector<Type> & a) {
406 419 for(int i = 0; i < a.size(); i++){
407   - if (_dataList[i].size() == 0)
  420 + int n = _dataList[i].size();
  421 + if ( n == 0)
408 422 return;
409 423 double accum = 0.0;
410 424 std::for_each(std::begin(_dataList[i]), std::end(_dataList[i]), [&](const double d) {
411   - accum += (d - a[i]._result) * (d - a[i]._result) * (d - a[i]._result) * (d - a[i]._result);;
  425 + accum += (d - _mean[i]) * (d - _mean[i]) * (d - _mean[i]) * (d - _mean[i])/pow(_standardDeviation[i],4);
412 426 });
413   - a[i]._result = accum/(_dataList[i].size()-1);
  427 + a[i]._result = n*(n+1)/((double)(n-1)*(n-2)*(n-3))*accum- 3*(n-1)*(n-1)/((double)(n-2)*(n-3));
414 428 }
415 429 }
416 430  
... ... @@ -424,6 +438,10 @@ namespace AMDA {
424 438 TimeIntervalList::iterator _currentTimeInterval;
425 439  
426 440 ElementType _val;
  441 +
  442 + ElementType _mean;
  443 +
  444 + ElementType _standardDeviation;
427 445  
428 446 std::vector<ElementType> _dataList;
429 447  
... ...