59 if (size == 0)
return 0;
60 if (size == 1)
return d[0];
61 if (q <= 0)
return *std::min_element(d, d + size);
62 if (q >= 1)
return *std::max_element(d, d + size);
64 double pos = (size - 1) * q;
65 unsigned int ind = (
unsigned int) pos;
66 double delta = pos - ind;
67 vector<tReal> w(size); std::copy(d, d + size, w.begin());
68 std::nth_element(w.begin(), w.begin() + ind, w.end());
69 tReal i1 = *(w.begin() + ind);
70 tReal i2 = *std::min_element(w.begin() + ind + 1, w.end());
71 return i1 * (1.0 - delta) + i2 * delta;
78 if (size == 0)
return 0;
79 if (size == 1)
return d[0];
80 if (q <= 0)
return *std::min_element(d, d + size);
81 if (q >= 1)
return *std::max_element(d, d + size);
83 double pos = (size - 1) * q;
84 unsigned int ind = (
unsigned int) pos;
85 double delta = pos - ind;
87 std::nth_element(d, d + ind, d+size);
88 tReal i1 = *(d + ind);
89 tReal i2 = *std::min_element(d + ind + 1, d+size);
90 return i1 * (1.0 - delta) + i2 * delta;
static tReal quantile(T *d, const int &size, const tReal &q)
compute a quantile of the distribution
Definition: STAT_Object.h:76
This class is the base class of all statistics package.
Definition: STAT_Object.h:13
static tReal quantile(const T *d, const int &size, const tReal &q)
compute a quantile of the distribution
Definition: STAT_Object.h:58
STAT_Object(void)
create an object
Definition: STAT_Object.cpp:4
virtual ~STAT_Object(void)
destroy an object.
Definition: STAT_Object.cpp:10
this class describes an array
Definition: CORE_Array.h:18
static tReal quantile(const CORE_Array< T > &a, const tReal &q)
compute a quantile of the distribution
Definition: STAT_Object.h:96
abstract base class for most classes.
Definition: CORE_Object.h:30
const T * getValues(tArrayIndex &s) const
get the values of the util vector
Definition: CORE_Array.h:371
const tArrayIndex & getSize() const
return the size of the array
Definition: CORE_Array.h:223
#define tReal
Definition: types.h:18