X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/df659008699fecbb4fe12bed55e6fb5beafbaaa4..250c00b20a41a9ebb1d1039eaa4ec96f9fa4eb7b:/statistics.h?ds=inline diff --git a/statistics.h b/statistics.h index 7e3fb2e..78f93e3 100644 --- a/statistics.h +++ b/statistics.h @@ -2,12 +2,14 @@ #define STATISTICS_H #include <cmath> -#include <vector> +#include <limits> class statistics { public: statistics() : count(0) + , min(std::numeric_limits<double>::infinity()) + , max(-std::numeric_limits<double>::infinity()) , sum(0.0) , mean(0.0) , sqdiff_sum(0.0) @@ -16,19 +18,27 @@ public: void push(double x) { double delta = x - mean; ++count; + if (x < min) + min = x; + if (x > max) + max = x; sum += x; mean = sum / count; sqdiff_sum += delta * (x - mean); } - unsigned get_count() const { return count; } - double get_sum() const { return sum; } - double get_mean() const { return mean; } - double get_variance() const { return sqdiff_sum / count; } - double get_stddev() const { return sqrt(get_variance()); } + unsigned get_count() const { return count; } + double get_min() const { return min; } + double get_max() const { return max; } + double get_sum() const { return sum; } + double get_mean() const { return mean; } + double get_variance() const { return sqdiff_sum / count; } + double get_stddev() const { return std::sqrt(get_variance()); } private: int count; + double min; // min of x_i + double max; // max of x_i double sum; // sum of x_i double mean; // mean of x_i double sqdiff_sum; // sum of (x_i - mean)^2