Skip to content

Instantly share code, notes, and snippets.

@michaeldorner
Created September 2, 2020 18:37
Show Gist options
  • Save michaeldorner/b375c6a5a3187b9ae43031808afac00f to your computer and use it in GitHub Desktop.
Save michaeldorner/b375c6a5a3187b9ae43031808afac00f to your computer and use it in GitHub Desktop.
Reference implementation for Independent Cascade Model
def diffuse_information(G: nx.MultiGraph, seed: list, beta: float=1.0, case='best_case'):
informed_nodes = {n: None for n in seed}
changed = True
while changed:
for u, v, dt in G.edges(nbunch=informed_nodes, data='diffusion_time'):
changed = False
if informed_nodes[u] == None or informed_nodes[u] < dt[case]: # shall we
if random.random() < beta:
if v not in informed_nodes or dt[case] < informed_nodes[v]:
informed_nodes[v] = dt[case]
changed = True
return informed_nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment