Created
September 2, 2020 18:37
-
-
Save michaeldorner/b375c6a5a3187b9ae43031808afac00f to your computer and use it in GitHub Desktop.
Reference implementation for Independent Cascade Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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