-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsp.py
More file actions
22 lines (17 loc) · 657 Bytes
/
sp.py
File metadata and controls
22 lines (17 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""infection model following shortest path"""
import numpy as np
from ic import simulate_cascade
def gen_cascade(g, source=None, fraction=0.5):
source, infection_times, tree = simulate_cascade(
g, 1.0, source=source, return_tree=True)
t = 1
while (np.count_nonzero(infection_times <= t) / g.num_vertices()) <= fraction:
t += 1
infection_times[infection_times > t] = -1
filtered_nodes = np.nonzero(infection_times == -1)[0]
vfilt = tree.new_vertex_property('bool')
vfilt.a = True
for n in filtered_nodes:
vfilt[n] = False
tree.set_vertex_filter(vfilt)
return source, infection_times, tree