forked from rcedgar/syncmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquarts.cpp
81 lines (70 loc) · 1.42 KB
/
quarts.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "myutils.h"
#include "sort.h"
#include "quarts.h"
void GetQuarts(const vector<unsigned> &v, Quarts &Q)
{
const unsigned N = SIZE(v);
Q.Min = 0;
Q.LoQ = 0;
Q.Med = 0;
Q.HiQ = 0;
Q.Max = 0;
Q.Total = 0;
Q.Avg = 0.0;
if (N == 0)
return;
vector<unsigned> v2 = v;
unsigned *vs = v2.data();
QuickSortInPlace(vs, N);
for (unsigned i = 0; i < N; ++i)
Q.Total += vs[i];
float Mean = float(Q.Total)/N;
float Sumd = 0.0f;
for (unsigned i = 0; i < N; ++i)
{
float x = float(vs[i]);
float d = (x - Mean)*(x - Mean);
Sumd += d;
}
Q.Min = vs[0];
Q.LoQ = vs[N/4];
Q.Med = vs[N/2];
Q.HiQ = vs[(3*N)/4];
Q.Max = vs[N-1];
Q.Avg = Mean;
Q.StdDev = sqrt(Sumd/N);
}
void GetQuartsFloat(const vector<float> &v, QuartsFloat &Q)
{
const unsigned N = SIZE(v);
Q.Min = 0.0f;
Q.LoQ = 0.0f;
Q.Med = 0.0f;
Q.HiQ = 0.0f;
Q.Max = 0.0f;
Q.Total = 0.0f;
Q.Avg = 0.0f;
if (N == 0)
return;
vector<float> v2 = v;
float *vs = v2.data();
QuickSortInPlace(vs, N);
for (unsigned i = 0; i < N; ++i)
Q.Total += vs[i];
float Mean = float(Q.Total)/N;
float Sumd = 0.0f;
for (unsigned i = 0; i < N; ++i)
{
float x = vs[i];
float d = (x - Mean)*(x - Mean);
Sumd += d;
}
float StdDev = sqrt(Sumd/N);
Q.Min = vs[0];
Q.LoQ = vs[N/4];
Q.Med = vs[N/2];
Q.HiQ = vs[(3*N)/4];
Q.Max = vs[N-1];
Q.Avg = Mean;
Q.StdDev = StdDev;
}