-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoc.cpp
More file actions
90 lines (71 loc) · 2.14 KB
/
goc.cpp
File metadata and controls
90 lines (71 loc) · 2.14 KB
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
#include <unordered_map>
#include <set>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <assert.h>
#include "boost/multi_array.hpp"
#include "goc.h"
#include "Network.h"
using namespace std;
GOCDict* loadGOC(Network* net1, Network* net2,
string file1, string file2){
auto anns1 = loadAnnotations(net1,file1);
auto anns2 = loadAnnotations(net2,file2);
int net1Size = net1->nodeToNodeName.size();
int net2Size = net2->nodeToNodeName.size();
GOCDict* toReturn = new GOCDict(boost::extents[net1Size][net2Size]);
for(auto pair1 : anns1){
for(auto pair2 : anns2){
int intersect_size = 0;
set<int>* smaller;
set<int>* larger;
if(pair1.second.size() <= pair2.second.size()){
smaller = &pair1.second;
larger = &pair2.second;
}
else{
smaller = &pair2.second;
larger = &pair1.second;
}
for(auto anno : *smaller){
if(larger->count(anno)){
intersect_size++;
}
}
int union_size = intersect_size + (larger->size() - intersect_size)
+ (smaller->size() - intersect_size);
double toStore = double(intersect_size)/double(union_size);
(*toReturn)[pair1.first][pair2.first] = toStore;
}
}
return toReturn;
}
unordered_map<node, set<int> > loadAnnotations(Network* net, string fp){
ifstream infile(fp);
if(!infile.good()){
throw LineReadException("Failed to load annotations! Check filename.");
}
unordered_map<node,set<int> > toReturn;
string line;
unsigned int count = 0;
while(getline(infile,line)){
istringstream iss(line);
string a;
node u;
iss >> a;
set<int> anns;
int x;
while(iss >> x){
anns.insert(x);
}
u = net->nodeNameToNode[a];
toReturn[u] = anns;
count++;
}
return toReturn;
}