forked from chonyy/PageRank-HITS-SimRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
33 lines (24 loc) · 880 Bytes
/
test.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
import networkx as nx
import numpy as np
from numpy import array
import matplotlib.pyplot as plt
with open('./dataset/HITS.txt') as f:
lines = f.readlines()
G = nx.DiGraph()
for line in lines:
t = tuple(line.strip().split(','))
G.add_edge(*t)
h, a = nx.hits(G, max_iter=100)
h = dict(sorted(h.items(), key=lambda x: x[0]))
a = dict(sorted(a.items(), key=lambda x: x[0]))
print(np.round(list(a.values()), 3))
print(np.round(list(h.values()), 3))
pr = nx.pagerank(G)
pr = dict(sorted(pr.items(), key=lambda x: x[0]))
print(np.round(list(pr.values()), 3))
sim = nx.simrank_similarity(G)
lol = [[sim[u][v] for v in sorted(sim[u])] for u in sorted(sim)]
sim_array = np.round(array(lol), 3)
print(sim_array)
nx.draw(G, with_labels=True, node_size=2000, edge_color='#eb4034', width=3, font_size=16, font_weight=500, arrowsize=20, alpha=0.8)
plt.savefig("graph.png")