21 #ifndef mia_core_statistics_hh 22 #define mia_core_statistics_hh 77 double median(std::vector<double>& buf)
const;
87 double n = data.size();
88 for (
auto i = data.begin(); i != data.end(); ++i) {
96 result.first = sum / n;
98 result.second = sqrt((sum2 - result.first * sum) / (n - 1));
103 template <
typename T>
106 std::vector<double> buffer(data.size());
107 copy(data.begin(), data.end(), buffer.begin());
110 result.first = median(buffer);
112 transform(buffer.begin(), buffer.end(), buffer.begin(),
113 [&result](
double x) {
return fabs(x - result.first);});
114 result.second = median(buffer);
118 double FMedianMAD::median(std::vector<double>& buf)
const 123 if (buf.size() & 1) {
124 auto i = buf.begin() + (buf.size() - 1) / 2;
125 std::nth_element(buf.begin(), i, buf.end());
128 auto i1 = buf.begin() + buf.size() / 2 - 1;
129 auto i2 = buf.begin() + buf.size() / 2;
130 std::nth_element(buf.begin(), i1, buf.end());
131 std::nth_element(buf.begin(), i2, buf.end());
132 return (*i1 + *i2) / 2.0;
Functor to be called by mia::filter to evaluate mean and variance of a series of data.
base class for all filer type functors.
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
double fabs(const T3DVector< T > &t)
A way to get the norm of a T3DVector using faba syntax.
TFilter< std::pair< double, double > >::result_type result_type
result_type operator()(const T &data) const
#define NS_MIA_END
conveniance define to end the mia namespace