Daley-Kendall Model

Fake News Spreading

The Daley-Kendall model uses three states:

At each step:

Figure 1: Daley-Kendall: example graph with states I, S, R.

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")

Download: https://snap.stanford.edu/data/ego-Facebook.html

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
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_state

Extra 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.