-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevaluate-files.cpp
94 lines (79 loc) · 2.17 KB
/
evaluate-files.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
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cstring>
#include "boost/filesystem.hpp"
#include <fstream>
#include <stdexcept>
/**
* Evaluate input data after post processing
*
* \author: mack
*/
int main(int argc, char **argv) {
std::string processedDir = "data/post_processed";
double rN = 5;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-help") == 0) {
std::cout << "The following parameters are available: \n"
<< "-iPP: The path to the post processed file directory for test data (default: data/post_processed) \n"
<< std::endl;
return 1;
}
if (strcmp(argv[i], "-rN") == 0) {
rN = atof(argv[++i]);
} else if (strcmp(argv[i], "-iPP") == 0) {
processedDir = argv[++i];
}
}
if (!boost::filesystem::exists(processedDir))
std::cout << " The filepath " << processedDir
<< " does not exist. You can specify another directory using input parameter -iPP."
<< std::endl;
boost::filesystem::directory_iterator end_itr_pp;
double tp = 0;
double fp = 0;
double tn = 0;
double fn = 0;
for (boost::filesystem::directory_iterator itr(processedDir);
itr != end_itr_pp; ++itr) {
if (itr->path().leaf().string().find(".xyz") != std::string::npos) {
int correctLabel = 0;
if (itr->path().filename().string().find("berries")
!= std::string::npos) {
correctLabel = 1;
} else if (itr->path().filename().string().find("stem")
!= std::string::npos) {
correctLabel = -1;
}
std::ifstream infile(itr->path().c_str());
if (!infile.good()) {
throw std::invalid_argument(
"There's something wrong with the source file at "
+ itr->path().string());
}
int currentLabel;
while (infile >> currentLabel) {
if (correctLabel == 1) {
if (currentLabel == correctLabel) {
tp++;
} else {
fn++;
}
} else if (correctLabel == -1) {
if (currentLabel == correctLabel) {
tn++;
} else {
fp++;
}
}
}
}
}
double precision = tp / (tp + fp);
double recall = tp / (tp + fn);
std::cout << "precision: " << precision << std::endl;
std::cout << "recall: " << recall << std::endl;
std::cout << "done" << std::endl;
return 1;
}