3 #include <tr1/functional>
6 #include "statistics.h"
8 statistics::statistics()
13 void statistics::reset()
19 void statistics::push(double val)
21 values.push_back(val);
25 size_t statistics::get_count()
30 double statistics::get_sum()
36 double statistics::get_avg()
42 double statistics::get_stddev()
48 void statistics::update()
55 avg = stddev = 0.0 / 0.0;
59 using std::tr1::placeholders::_1;
61 unsigned n = values.size();
62 sum = std::accumulate(values.begin(), values.end(), 0.0);
65 std::vector<double> diff(values);
66 std::transform(diff.begin(), diff.end(), diff.begin(),
67 bind(std::minus<double>(), _1, avg));
68 double epsilon = std::accumulate(diff.begin(), diff.end(), 0.0);
69 double square_sum = std::inner_product(diff.begin(), diff.end(),
71 double variance = (square_sum - (epsilon * epsilon) / n) / n;
72 stddev = sqrt(variance);