Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JQuantile_t.hh
Go to the documentation of this file.
1#ifndef __JMATH__JQUANTILE_T__
2#define __JMATH__JQUANTILE_T__
3
4#include <vector>
5#include <algorithm>
6#include <numeric>
7
8#include "JLang/JException.hh"
9
10/**
11 * \author mdejong
12 */
13namespace JMATH {}
14namespace JPP { using namespace JMATH; }
15
16namespace JMATH {
17
19
20 /**
21 * Auxiliary data structure for average.
22 *
23 * The determination of the average should be independent of the order of the input values.
24 */
25 struct JQuantile_t {
26 /**
27 * Default constructor.
28 */
30 {
31 reset();
32 }
33
34
35 /**
36 * Reset.
37 */
38 void reset()
39 {
40 buffer.clear();
41 }
42
43
44 /**
45 * Put value.
46 *
47 * \param x value
48 */
49 void put(const double x)
50 {
51 buffer.push_back(x);
52 }
53
54
55 /**
56 * Get mean value.
57 *
58 * \return mean value
59 */
60 double getMean() const
61 {
62 using namespace std;
63
64 if (!buffer.empty()) {
65
66 sort(buffer.begin(), buffer.end());
67
68 return accumulate(buffer.begin(), buffer.end(), 0.0) / buffer.size();
69 }
70
71 THROW(JDivisionByZero, "JQuantile_t::getMean()");
72 }
73
74
75 /**
76 * Get mean value.
77 *
78 * \param value default value
79 * \return mean value
80 */
81 double getMean(const double value) const
82 {
83 if (!buffer.empty())
84 return getMean();
85 else
86 return value;
87 }
88
89 private:
91 };
92}
93
94#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for division by zero.
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for average.
void put(const double x)
Put value.
JQuantile_t()
Default constructor.
double getMean(const double value) const
Get mean value.
std::vector< double > buffer
void reset()
Reset.
double getMean() const
Get mean value.