-
Notifications
You must be signed in to change notification settings - Fork 3
/
stats.cpp
58 lines (53 loc) · 1005 Bytes
/
stats.cpp
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
51
52
53
54
55
56
57
58
#include "stats.h"
Stats::Stats()
{
clear();
}
void Stats::clear()
{
n = 0;
sum = 0;
sum2 = 0;
minimum = 0;
maximum = 0;
}
void Stats::add(double x)
{
++n;
sum += x;
sum2 += x * x;
if (n == 1)
{
minimum = x;
maximum = x;
}
else{
minimum = min(minimum, x);
maximum = max(maximum, x);
}
}
void Stats::add(Stats s)
{
n += s.n;
sum += s.sum;
sum2 += s.sum2;
if (s.n > 0)
{
if (n == 1)
{
minimum = s.minimum;
maximum = s.maximum;
}
else{
minimum = min(minimum, s.getMin());
maximum = max(maximum, s.getMax());
}
}
}
void Stats::print(int x, int y)
{
QTextStream out(stdout);
out << "Stats for color " << x << " index " << y << " " << n << " entries.\n";
out << "Min " << getMin() << " Max " << getMax() << " mean " << mean() << "\n";
out << "StdDev " << stDev() << " " << rms() << "\n";
}