-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathROCCurve.cpp
54 lines (49 loc) · 1.54 KB
/
ROCCurve.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
#include "ROCCurve.hpp"
void ROCCurve::plotCurve(const std::string& fileName, int iter)
{
DoubleVec FPRList;
DoubleVec CDRList;
auto start = std::chrono::system_clock::now();
std::string progress;
for(int theta = 0; theta != 101; ++theta){
double thresh = theta * 0.01;
examData.clear();
for(int i = 0; i != iter; ++i){
stat->reset();
recognition(thresh);
}
FPRList.push_back(FPR());
CDRList.push_back(CDR());
std::cout << theta + 1 << "終了" << std::endl;
}
auto end = std::chrono::system_clock::now();
auto sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
std::cout << "処理時間: " << sec << " [sec]" << std::endl;
writeToTSV(fileName, FPRList, CDRList);
}
void ROCCurve::recognition(double thresh)
{
bool result = stat->calculate() > thresh;
const IntVec& xVec = stat->getXVec();
IntVec correct = {1, 1};
if(xVec == correct) examData.detected(result);
else examData.notDetected(result);
}
double ROCCurve::FPR()
{
return static_cast<double>(examData.FP) / static_cast<double>(examData.notX11);
}
double ROCCurve::CDR()
{
return static_cast<double>(examData.CD) / static_cast<double>(examData.x11);
}
void ROCCurve::writeToTSV(const std::string& fileName,
const DoubleVec& FPRList, const DoubleVec& CDRList)
{
std::ofstream ofs(fileName);
if(!ofs) return;
if(FPRList.empty() || FPRList.size() != CDRList.size()) return;
for(size_t i = 0; i != FPRList.size(); ++i){
ofs << FPRList[i] << "," << CDRList[i] << std::endl;
}
}