-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathMetric.h
101 lines (87 loc) · 2.3 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
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
/*
* Metric.h
*
* Created on: Mar 17, 2015
* Author: mszhang
*/
#ifndef SRC_METRIC_H_
#define SRC_METRIC_H_
#include "IO.h"
using namespace std;
class 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;
}
}
void loadModel(LStream &inf) {
ReadBinary(inf, overall_label_count);
ReadBinary(inf, correct_label_count);
ReadBinary(inf, predicated_label_count);
// cout << overall_label_count << correct_label_count << predicated_label_count <<endl;
}
void writeModel(LStream &outf) {
WriteBinary(outf, overall_label_count);
WriteBinary(outf, correct_label_count);
WriteBinary(outf, predicated_label_count);
// cout << overall_label_count << correct_label_count << predicated_label_count <<endl;
}
};
#endif /* SRC_EXAMPLE_H_ */