-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
93 lines (63 loc) · 2.06 KB
/
test.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
#include "lpred.cpp"
#include "divide.cpp"
int main(){
double precision = 0;
double AUC = 0;
for(int i=0; i<10; i++){
string net = "BUP";
divide(net);
string train = net + "_train.net";
train = "datasets/BUP_full.net";
string test = net + "_test.net";
set<pair<int, int>> predictedLinks;
int test_size = 0;
string line, val;
Graph *g = new Graph();
unordered_set<int> vertices;
int FIRST_LINE = 1, EDGES = 1;
ifstream f;
f.open(test);
while (getline(f,line)) {
if(FIRST_LINE){
stringstream s(line);
int text[2],i=0;
while (getline (s, val, ' ')){
try{
text[i++] = stoi(val);
}
catch(exception e){}
}
g->setV(text[1]);
FIRST_LINE = 0;
continue;
}
if(line != "*edges" && EDGES == 1)
continue;
else if(EDGES == 1){
EDGES = 0;
continue;
}
stringstream s(line);
int edge[3],i=0;
while (getline(s, val, ' ')){
edge[i++] = stoi(val);
}
vertices.insert({edge[0],edge[1]});
g->addEdge(edge[0],edge[1]);
test_size++;
}
predictedLinks = predictLinks(train, -1.84, test_size);
set<pair<int, int>>::iterator itr;
int correct_predictions = 0;
for(itr = predictedLinks.begin(); itr != predictedLinks.end(); ++itr){
if(g->isEdge(itr->first, itr->second) || g->isEdge(itr->second, itr->first))
correct_predictions++;
}
precision += (double)correct_predictions/test_size;
double accuracy=(correct_predictions+tn)/(correct_predictions+tn+fp+fn);
f.close();
del(net);
}
cout << "Precision: " << precision/10 << "\n";
return 0;
}