-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_good_seed_pairs.py
56 lines (36 loc) · 1.11 KB
/
gen_good_seed_pairs.py
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
# coding: utf-8
"""
generate good seed pairs and dump it into file
a good seed pair (u, v) satisfy:
- there is a negative edge between u and v
- both u and v has at least {threshold} positive degree
the threshold are specified according to th graph:
- word, bitcoin: 5
- ref: 15
- epinions, slashdot, wikiconflict: 20
the resulting number of pairs in each graph:
- word: 8604
- bitcoin: 1323
- ref: 9286
- epinions: 36577
- slashdot: 43373
- wikiconflict: 87971
"""
import sys
import networkx as nx
import pickle as pkl
from tqdm import tqdm
from helpers import pos_graph, neg_graph
graph = sys.argv[1]
threshold = int(sys.argv[2])
g = nx.read_gpickle('graphs/{}.pkl'.format(graph))
pos_g = pos_graph(g)
neg_g = neg_graph(g)
pos_deg = pos_g.degree()
good_pairs = []
for u, v in tqdm(neg_g.edges(), total=neg_g.number_of_edges()):
if pos_deg[u] >= threshold and pos_deg[v] >= threshold:
good_pairs.append((u, v))
print('found {} good pairs from {} candidates'.format(len(good_pairs), neg_g.number_of_edges()))
with open('outputs/{}_good_pairs.pkl'.format(graph), 'wb') as f:
pkl.dump(good_pairs, f)