-
Notifications
You must be signed in to change notification settings - Fork 0
/
point12.py
47 lines (37 loc) · 1.31 KB
/
point12.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
import matplotlib.pyplot as plt
import networkx as nx
from util import load_network, load_infection_ranking, build_graph_from_dataset, compute_ranking
graph_dataset = load_network('./data/network.json')
infect_ranking = load_infection_ranking("./data/ranking.json")
graph, unique_nodes = build_graph_from_dataset(graph_dataset)
bets = list(nx.betweenness_centrality(graph).items())
bets = sorted(bets, key=lambda x: x[1], reverse=True)
f_values, RRbs = compute_ranking(infect_ranking, bets)
plt.plot(f_values, RRbs)
plt.ylabel("rRB")
plt.xlabel("f")
plt.show()
# Temporal networks
timestep_dict = dict.fromkeys(list(unique_nodes), 0)
for timestep in graph_dataset:
added_nodes = []
for conn in timestep:
if conn[0] not in added_nodes:
timestep_dict[conn[0]] += 1
added_nodes.append(conn[0])
if conn[1] not in added_nodes:
timestep_dict[conn[1]] += 1
added_nodes.append(conn[1])
timesteps = list(timestep_dict.items())
timesteps = sorted(timesteps, key=lambda x: x[1], reverse=True)
print(timesteps)
f_values, RTs = compute_ranking(infect_ranking, timesteps)
plt.subplot(1, 2, 1)
plt.plot(f_values, RTs)
plt.ylabel("rRT (Temporal Feature)")
plt.xlabel("f")
plt.subplot(1, 2, 2)
plt.plot(f_values, RRbs)
plt.ylabel("rRB (Betweennes")
plt.xlabel("f")
plt.show()