Daley-Kendall Model
Fake News Spreading
The Daley-Kendall model uses three states:
- Ignorant (I): has not heard the rumor
- Spreader (S): actively spreading
- Stifler (R): no longer spreading
At each step:
- Ignorant nodes become spreaders with probability \(\beta\) per spreader neighbor.
- Spreader nodes become stiflers with probability \(\gamma\) when they contact another spreader or stifler.
Load a real graph
Download the Facebook edge list from SNAP and load it with pandas.
import pandas as pd
import networkx as nx
facebook = pd.read_csv(
"./data/facebook_combined.txt.gz",
compression="gzip",
sep=" ",
names=["start_node", "end_node"],
)
G = nx.from_pandas_edgelist(facebook, "start_node", "end_node")Implement Daley-Kendall transitions
Reuse the simulation framework from session 8 and replace the transition rule.
def state_transition(G, current_state, gamma=0.1, beta=0.2):
next_state = current_state.copy()
for node in G.nodes:
state = current_state[node]
if state == "I":
# TODO: if any neighbor is a spreader, become S with prob beta
pass
elif state == "S":
# TODO: if any neighbor is S or R, become R with prob gamma
pass
return next_state
Hint: Transition rule (click to expand)
import random
def state_transition(G, current_state, gamma=0.1, beta=0.2):
next_state = current_state.copy()
for node in G.nodes:
state = current_state[node]
if state == "I":
for neighbor in G.neighbors(node):
if current_state[neighbor] == "S" and random.random() < beta:
next_state[node] = "S"
break
elif state == "S":
for neighbor in G.neighbors(node):
if current_state[neighbor] in ("S", "R") and random.random() < gamma:
next_state[node] = "R"
break
return next_stateExtra challenges
- Add key press controls (SPACE to pause, ENTER to reset).
- Add sliders for \(\beta\) and \(\gamma\).
- Implement network attacks by forcing high-centrality nodes to stifle.
Reference code: amlab/networkx_data/simulation.py.