#ifndef __JMATH__JQUANTILE_T__ #define __JMATH__JQUANTILE_T__ #include #include #include #include "JLang/JException.hh" /** * \author mdejong */ namespace JMATH {} namespace JPP { using namespace JMATH; } namespace JMATH { using JLANG::JDivisionByZero; /** * Auxiliary data structure for average. * * The determination of the average should be independent of the order of the input values. */ struct JQuantile_t { /** * Default constructor. */ JQuantile_t() { reset(); } /** * Reset. */ void reset() { buffer.clear(); } /** * Put value. * * \param x value */ void put(const double x) { buffer.push_back(x); } /** * Get mean value. * * \return mean value */ double getMean() const { using namespace std; if (!buffer.empty()) { sort(buffer.begin(), buffer.end()); return accumulate(buffer.begin(), buffer.end(), 0.0) / buffer.size(); } THROW(JDivisionByZero, "JQuantile_t::getMean()"); } /** * Get mean value. * * \param value default value * \return mean value */ double getMean(const double value) const { if (!buffer.empty()) return getMean(); else return value; } private: mutable std::vector buffer; }; } #endif