-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GST.cpp
226 lines (167 loc) · 3.91 KB
/
GST.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// FILE: GST.cpp
// VERSION: 0.1.4
// PURPOSE: Arduino library for Gold Standard Test metrics
// URL: https://github.com/RobTillaart/GST
// https://en.wikipedia.org/wiki/Sensitivity_and_specificity
// https://en.wikipedia.org/wiki/Confusion_matrix
//
// formula's based upon Wikipedia.
#include "GST.h"
GST::GST()
{
clearAll();
};
///////////////////////////////////////////////////////
//
// INPUT FUNCTIONS
//
void GST::setTruePositive(float v)
{
TP = v;
AP = TP + FN;
};
void GST::setTrueNegative(float v)
{
TN = v;
AN = TN + FP;
};
void GST::setFalsePositive(float v)
{
FP = v;
AN = TN + FP;
};
void GST::setFalseNegative(float v)
{
FN = v;
AP = TP + FN;
};
void GST::clearAll()
{
AP = 0;
AN = 0;
TP = 0;
TN = 0;
FP = 0;
FN = 0;
}
// These are used for updating the test matrix
float GST::addTruePositive(float v)
{
TP += v;
AP = TP + FN;
return TP;
};
float GST::addTrueNegative(float v)
{
TN += v;
AN = TN + FP;
return TN;
};
float GST::addFalsePositive(float v)
{
FP += v;
AN = TN + FP;
return FP;
};
float GST::addFalseNegative(float v)
{
FN += v;
AP = TP + FN;
return FN;
};
///////////////////////////////////////////////////////
//
// OUTPUT FUNCTIONS I
//
float GST::getTruePositive() { return TP; };
float GST::getTrueNegative() { return TN; };
float GST::getFalsePositive() { return FP; };
float GST::getFalseNegative() { return FN; };
float GST::getTotal() { return AP + AN; };
float GST::getActualPositive() { return AP; };
float GST::getActualNegative() { return AN; };
float GST::getTestedPositive() { return TP + FP; };
float GST::getTestedNegative() { return TN + FN; };
float GST::sensitivity() { return TPR(); };
float GST::specificity() { return TNR(); };
float GST::truePositiveRate() { return TPR(); };
float GST::TPR() { return TP / AP; };
float GST::trueNegativeRate() { return TNR(); };
float GST::TNR() { return TN / AN; };
float GST::falseNegativeRate() { return FNR(); };
float GST::FNR() { return FN / AP; };
float GST::falsePositiveRate() { return FPR(); };
float GST::FPR() { return FP / AN; };
///////////////////////////////////////////////////////
//
// OUTPUT FUNCTIONS II
//
float GST::positivePredictiveValue() { return PPV(); };
float GST::PPV() { return TP / (TP + FP); };
float GST::negativePredictiveValue() { return NPV(); };
float GST::NPV() { return TN / (TN + FN); };
float GST::falseDiscoveryRate() { return FDR(); };
float GST::FDR() { return FP / (TP + FP); };
float GST::falseOmissionRate() { return FOR(); };
float GST::FOR() { return FN / (TN + FN); };
float GST::positiveLikelihoodRatio() { return LRplus(); };
float GST::LRplus() { return TPR() / FPR(); };
float GST::negativeLikelihoodRatio() { return LRminus(); };
float GST::LRminus() { return FNR() / TNR(); };
float GST::prevalenceThreshold()
{
return sqrt(FPR()) / (sqrt(TPR()) + sqrt(FPR()));
};
float GST::threatScore()
{
return TP / (TP + FN + FP);
};
float GST::criticalSuccessIndex()
{
return threatScore();
};
float GST::prevalence()
{
return AP / (AP + AN);
};
float GST::accuracy()
{
return (TP + TN) / (AP + AN);
};
float GST::balancedAccuracy()
{
return (TPR() + TNR()) * 0.5;
};
float GST::F1Score()
{
return (2 * TP) / (2 * TP + FP + FN);
};
float GST::MatthewsCorrelationCoefficient() { return MCC(); };
float GST::phi() { return MCC(); };
float GST::MCC()
{
return (TP*TN - FP*FN)/sqrt((TP+FP) * (TP+FN) * (TN+FP) * (TN+FN));
};
float GST::FowlkesMallowsIndex() { return FM(); };
float GST::FM()
{
return sqrt(PPV()*TPR());
};
float GST::BookmakerInformedness() { return BM(); };
float GST::BM()
{
return TPR() + TNR() - 1;
};
float GST::markedness() { return MK(); };
float GST::deltaP() { return MK(); };
float GST::MK()
{
return PPV() + NPV() - 1;
};
float GST::diagnosticOddsRatio() { return DOR(); };
float GST::DOR()
{
return LRplus() / LRminus();
};
// -- END OF FILE --