-
Notifications
You must be signed in to change notification settings - Fork 3
/
Metric.h
74 lines (58 loc) · 1.94 KB
/
Metric.h
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
/*
* Metric.h
*
* Created on: Mar 17, 2015
* Author: mszhang
*/
#ifndef SRC_METRIC_H_
#define SRC_METRIC_H_
using namespace std;
struct Metric {
public:
int overall_label_count;
int correct_label_count;
int predicated_label_count;
public:
Metric() {
overall_label_count = 0;
correct_label_count = 0;
predicated_label_count = 0;
}
~Metric() {}
void reset() {
overall_label_count = 0;
correct_label_count = 0;
predicated_label_count = 0;
}
bool bIdentical() {
if (predicated_label_count == 0) {
if (overall_label_count == correct_label_count) {
return true;
}
return false;
} else {
if (overall_label_count == correct_label_count && predicated_label_count == correct_label_count) {
return true;
}
return false;
}
}
double getAccuracy() {
if (predicated_label_count == 0) {
return correct_label_count*1.0 / overall_label_count;
} else {
return correct_label_count*2.0 / (overall_label_count + predicated_label_count);
}
}
void print() {
if (predicated_label_count == 0) {
std::cout << "Accuracy:\tP=" << correct_label_count << "/" << overall_label_count
<< "=" << correct_label_count*1.0 / overall_label_count << std::endl;
} else {
std::cout << "Recall:\tP=" << correct_label_count << "/" << overall_label_count << "=" << correct_label_count*1.0 / overall_label_count
<< ", " << "Accuracy:\tP=" << correct_label_count << "/" << predicated_label_count << "=" << correct_label_count*1.0 / predicated_label_count
<< ", " << "Fmeasure:\t" << correct_label_count*2.0 / (overall_label_count + predicated_label_count) << std::endl;
}
}
};
#endif /* SRC_EXAMPLE_H_ */