Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
41 lines (33 loc) · 1.24 KB

File metadata and controls

41 lines (33 loc) · 1.24 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""continous-time independent cascade model"""
import numpy as np
import random
from graph_tool.all import shortest_distance
from utils import edges2graph
from feasibility import is_arborescence
def gen_cascade(g, scale=1.0, source=None, stop_fraction=0.5, return_tree=True):
rands = np.random.exponential(scale, g.num_edges())
delays = g.new_edge_property('float')
delays.set_2d_array(rands)
if source is None:
source = random.choice(np.arange(g.num_vertices()))
dist, pred = shortest_distance(g, source=source, weights=delays, pred_map=True)
q = stop_fraction * 100
percentile = np.percentile(dist.a, q)
infected_nodes = np.nonzero(dist.a <= percentile)[0]
uninfected_nodes = np.nonzero(dist.a > percentile)[0]
infection_times = np.array(dist.a)
infection_times[uninfected_nodes] = -1
rets = (source, infection_times)
if return_tree:
tree_edges = set()
for n in infected_nodes:
c = n
while pred[c] != c:
edge = ((pred[c], c))
if edge not in tree_edges:
tree_edges.add(edge)
else:
break
tree = edges2graph(g, tree_edges)
rets += (tree, )
return rets
Morty Proxy This is a proxified and sanitized view of the page, visit original site.