8 #ifndef ecl_statistics_CUMULATIVE_STATISTICS_HPP_
9 #define ecl_statistics_CUMULATIVE_STATISTICS_HPP_
34 template <
typename T,
typename Enable =
void>
45 void clear() { number_of_data = 0.0; }
55 void push_back(
const T & x)
58 if(number_of_data == 1.0)
60 old_mean = new_mean = x;
65 new_mean = old_mean +
static_cast<T
>(x - old_mean) / number_of_data;
66 new_variance = old_variance +
static_cast<T
>(x - old_mean) *
static_cast<T
>(x - new_mean);
69 old_variance = new_variance;
77 T size()
const {
return number_of_data; }
83 T mean()
const {
return (number_of_data > 0) ? new_mean : 0.0; }
89 T variance()
const {
return ((number_of_data > 1) ? new_variance / (number_of_data - 1) : 0.0); }
93 T old_mean, old_variance;
94 T new_mean, new_variance;