summaryrefslogtreecommitdiff
path: root/graphics/asymptote/statistics.h
blob: a8cca39bf41aeb84faf23c3db55e4fde84d7369e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef __statistics_h__
#define __statistics_h__ 1

namespace utils {

class statistics {
  unsigned int N;
  double A;
  double varL;
  double varH;
public:
  statistics() {clear();}
  void clear() {N=0; A=varL=varH=0.0;}
  double count() {return N;}
  double mean() {return A;}
  void add(double t) {
    ++N;
    double diff=t-A;
    A += diff/N;
    double v=diff*(t-A);
    if(diff < 0.0)
      varL += v;
    else
      varH += v;
  }
  double stdev(double var, double f) {
    double factor=N > f ? f/(N-f) : 0.0;
    return sqrt(var*factor);
  }
  double stdev() {
    return stdev(varL+varH,1.0);
  }
  double stdevL() {
    return stdev(varL,2.0);
  }
  double stdevH() {
    return stdev(varH,2.0);
  }
  void output(const char *text, unsigned int m) {
    std::cout << text << ":\n"
              << m << "\t"
              << A << "\t"
              << stdevL() << "\t"
              << stdevH() << std::endl;
  }
};

}

#endif