-
Notifications
You must be signed in to change notification settings - Fork 1
/
Submission.cpp
73 lines (49 loc) · 1.91 KB
/
Submission.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
#include "stdafx.h"
#include "LabelVector.h"
#include "Submission.h"
Submission::Submission(LabelVector& labelVector, double scale) {
constexpr double e = 2.7182818;
auto erf = [](double x) {return x <= 2.2 ? 0.1*x*(4.4-x) : 0.5;};
for (auto label: labelVector.labels) {
Label& l = label.second;
systoleCDFs .emplace(l.id, array<double, volumeMax+1>());
diastoleCDFs.emplace(l.id, array<double, volumeMax+1>());
for (int i = 0; i <= volumeMax; ++i) {
//systoleCDFs [l.id][i] = i < l.systole ? 0.5-erf((l.systole -i)*scale) : 0.5+erf((i-l.systole )*scale);
//diastoleCDFs[l.id][i] = i < l.diastole ? 0.5-erf((l.diastole-i)*scale) : 0.5+erf((i-l.diastole)*scale);
systoleCDFs [l.id][i] = 1/(1 + pow(e, scale*(i-l.systole)));
diastoleCDFs[l.id][i] = 1/(1 + pow(e, scale*(i-l.diastole)));
}
}
}
Submission
Submission::write(string filePath) {
ofstream submission(filePath);
// Write submission header
submission << "Id";
for (int i = 0; i <= volumeMax; ++i)
submission << ",P" << i;
// Write results
for (auto i: systoleCDFs) {
int id = i.first;
submission << endl << id << "_Systole";
for (int i = 0; i <= volumeMax; ++i)
submission << "," << systoleCDFs[id][i];
submission << endl << id << "_Diastole";
for (int i = 0; i <= volumeMax; ++i)
submission << "," << diastoleCDFs[id][i];
}
return *this;
}
double
Submission::evaluateAgainst(LabelVector& labelVector) {
double crps = 0;
for (auto e: labelVector.labels) {
auto& label = e.second;
for (int i = 0; i <= volumeMax; ++i)
crps += square(systoleCDFs[label.id][i] - (i >= label.systole ? 1 : 0));
for (int i = 0; i <= volumeMax; ++i)
crps += square(diastoleCDFs[label.id][i] - (i >= label.diastole ? 1 : 0));
}
return crps/(2*labelVector.labels.size()*volumeMax);
}