-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
BenchmarkMath.js
144 lines (124 loc) · 4.2 KB
/
BenchmarkMath.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
class BenchmarkMath {
// Taken from Perffarm/perfsite/benchmarks.php
/*
* We need to calculate the standard deviation as part of the
* statistical tests for benchmarks so this support funciton
* is provided to ensure we are consistant.
*/
static stddev( scores ) {
/* Make sure we are working with floating point
* numbers.
*/
//There is also a minor check here that makes sure that
//we dont include NULL scores in the sd calculations.
//We wont need this when the annotation tool is being used
//as this should catch all 'bad' data.
//This is only partially correct anyway because there are no checks
//within the ci functions and so the data will still be wrong
//and include NULL data.
if (scores !== null) {
let bad_data = 0;
let scores_sum = 0;
scores.forEach((x) => {
if (x === null) {
bad_data++
} else {
scores_sum += x;
}
});
let count = scores.length - bad_data;
if (count === 0 || scores_sum === 0) {
return null;
}
let mean = scores_sum / count;
let sum = 0;
scores.forEach((x) => {
if (x !== null) {
sum += (x - mean)**2
}
});
if (sum !== 0 && count !== 0) {
let stddev = Math.sqrt(sum / (count - 1));
return stddev;
} else {
return null;
}
} else {
return null;
}
}
// Taken from Perffarm/perfsite/benchmarks.php
/*
* This function calculates the confidence interval of a set
* of results. We are limited to testing for 5%
* convergence.
*/
static confidence_interval ( scores ) {
let scores_sum = 0;
scores.forEach((x) => {
if (x !== null) {
scores_sum += x;
}
});
// First get the std deviation and other
// useful values as floats.
if (scores_sum !== 0) {
let stddev = this.stddev(scores);
let count = scores.length;
let mean = scores_sum / count;
// Do the convergence calculations.
let ci = stddev * this.t_dist05( count - 1 );
ci /= mean;
ci /= Math.sqrt(count);
return ci;
} else {
return 0;
}
}
// Taken from Perffarm/perfsite/benchmarks.php
/*
* This is a lookup function for the t-distribution.
* It is based on the statistical tests code Dave
* Siegwart wrote for RAJ.
* It only does probability of 0.05.
*/
static t_dist05( N ) {
// Constants for t-dist calculations.
let Student_t_05 = [
-1.0,
12.706, 4.303, 3.182, 2.776, 2.571,
2.447, 2.365, 2.306, 2.262, 2.228,
2.201, 2.179, 2.160, 2.145, 2.131,
2.120, 2.110, 2.101, 2.093, 2.086,
2.080, 2.074, 2.069, 2.064, 2.060,
2.056, 2.052, 2.048, 2.045, 2.042
];
let Student_t_05_40 = 2.021;
let Student_t_05_60 = 2.000;
let Student_t_05_120 = 1.98;
let Student_t_05_2000 = 1.96;
let P = 0.0;
if (N <= 30) {
P = Student_t_05[N];
} else if (N <= 40) {
P = this.interp(Student_t_05[30], Student_t_05_40, 30, 40, N);
} else if (N <= 60) {
P = this.interp(Student_t_05_40 , Student_t_05_60, 40, 60, N);
} else if (N <= 120) {
P = this.interp(Student_t_05_60, Student_t_05_120, 60, 120, N);
} else if (N <= 2000) {
P = this.interp(Student_t_05_120, Student_t_05_2000, 120, 2000, N);
} else {
P = Student_t_05_2000;
}
return P;
}
// Taken from Perffarm/perfsite/benchmarks.php
// Support function for t_dist05
static interp( a, b, aN, bN, N ) {
let mu = (N - aN) / (bN - aN);
let v = mu * (b - a) + a;
return v;
}
}
export default BenchmarkMath;