Feellgood
log-stats.h
1 
16 #include <cmath>
17 
18 class LogStats
19  {
20 public:
22  void add(double x)
23  {
24  x = std::log(x);
25  n += 1;
26  double delta1 = x - m;
27  m += delta1 / n;
28  double delta2 = x - m;
29  s += delta1 * delta2;
30  }
31 
33  long count() const { return n; }
34 
43  double mean() const { return std::exp(m); }
44 
55  double stddev() const { return std::sqrt(s / n); }
56 
57 private:
58  long n = 0;
59  double m = 0;
60  double s = 0;
61  };
Record running statistics on a logarithmic scale.
Definition: log-stats.h:19
double m
Definition: log-stats.h:59
double mean() const
Definition: log-stats.h:43
long count() const
Definition: log-stats.h:33
double s
Definition: log-stats.h:60
double stddev() const
Definition: log-stats.h:55
void add(double x)
Definition: log-stats.h:22
long n
Definition: log-stats.h:58