/* * SkewFunc.hh * * Created on: Jun 23, 2018 * Author: benjamin */ #ifndef SKEWFUNC_HH_ #define SKEWFUNC_HH_ #include "AbstractFunc.hh" #include "Toolbox.hh" namespace AMDA { namespace Parameters { namespace StatisticFunctions { template OutputElemType computeSkew(std::list>& mem, OutputElemType& nanVal) { OutputElemType result = nanVal; if (mem.empty()) { return result; } result << ElemNull(); OutputElemType mean = result; int n = 0; for (auto val : mem) { if (isNAN(val.second)) continue; mean = mean+val.second; ++n; } if (n == 0) { result << NotANumber(); return result; } mean = 1./n*mean; OutputElemType m3 = result; OutputElemType m2 = result; for (auto val : mem) { m3 = m3 + StatisticFunctions::pow((val.second - mean),3); m2 = m2 + StatisticFunctions::square((val.second - mean)); } m3 = 1./n*m3; m2 = 1./n*m2; result = StatisticFunctions::div(m3,StatisticFunctions::pow(m2,1.5)); return result; } /** * @class SkewFunc * @brief * @details This class implements AbstractFunc. */ template class SkewFunc : public ClassicAbstractFunc { public: /** * @brief Constructor. */ SkewFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec& paramInput, double windowtime) : ClassicAbstractFunc(pProcess, pTimeIntervalList, paramInput, windowtime) { } virtual ~SkewFunc() { } OutputElemType compute() { return computeSkew(ClassicAbstractFunc::_mem, ClassicAbstractFunc::_nanVal); } }; /** * @class SkewFuncSm * @brief * @details This class implements AbstractFunc. */ template class SkewSmFunc : public SmAbstractFunc { public: /** * @brief Constructor. */ SkewSmFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec& paramInput, double windowtime) : SmAbstractFunc(pProcess, pTimeIntervalList, paramInput, windowtime) { } virtual ~SkewSmFunc() { } OutputElemType compute() { return computeSkew(SmAbstractFunc::_mem, SmAbstractFunc::_nanVal); } }; } /* namespace StatisticFunctions */ } /* namespace Parameters */ } /* namespace AMDA */ #endif /* SKEWFUNC_HH_ */