From: Arnaud Giersch Date: Mon, 3 Oct 2011 15:28:29 +0000 (+0200) Subject: Add min and max values in statistics. X-Git-Tag: exp_20120216~24 X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/commitdiff_plain/3d1592bcd7bd39aa4ca37bb93d00cb9b770f70ca?hp=b2361f06c9f703a65c2a5bcd80f026311217e936 Add min and max values in statistics. --- diff --git a/statistics.h b/statistics.h index 28aa913..a12e51f 100644 --- a/statistics.h +++ b/statistics.h @@ -8,6 +8,8 @@ class statistics { public: statistics() : count(0) + , min(std::numeric_limits::infinity()) + , max(-std::numeric_limits::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; } + 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