Welcome back! In our previous lesson, we established the crucial theoretical distinction between simple and complex contagions. We saw that simple information can spread through a single contact, while complex behaviors require social reinforcement from multiple sources.
Today, we will put that theory into practice. Our goal is to model how a piece of simple information—like a bit of news, a scheduling change, or a fun fact—actually diffuses through a vee network. We will move from concepts to a concrete simulation, which should feel familiar given your background in stochastic processes and simulations. We will build a model of the vee, introduce an idea to one person, and watch how it probabilistically spreads to the others. This will allow us to quantitatively analyze the information flow and the pivotal role of the hinge partner.
The Independent Cascade Model for Simple Contagion
To model the spread of simple information, we will use a classic and intuitive approach called the Independent Cascade (IC) model. The logic is straightforward and aligns perfectly with the definition of simple contagion:
- Seeds: We start with a set of initially "infected" nodes, known as seeds. This is the person or people who first have the information.
- Activation Attempts: In each step, every node that just became infected gets one chance to infect each of its susceptible (uninformed) neighbors.
- Probability: Each of these attempts succeeds with a given probability, p. This 'p' represents the transmissibility of the information—how likely it is to be passed along in a single conversation.
- Process Ends: The cascade continues until a step occurs in which no new nodes are infected.
This model is "independent" because the success of one transmission attempt has no bearing on any other. A partner hearing a piece of news from the hinge is an event independent of their other partner also hearing it.
To see a conceptual overview and a memorable example of this process, you can refer to the following article.
Social Network Analysis: From Graph Theory to Applications with ...
This article provides a brief but clear summary of key information diffusion models.
Focus on the section titled "Information Flow." Read the description of the Independent Cascade model. Then, review the "Game of Thrones" example that follows, including the animated GIF, which shows how a rumor propagates through the network over time.
The Tool for the Job: Building Networks in Python
To run a simulation, we first need a way to represent our vee relationship as a network structure. A powerful and widely used tool for this in Python is the NetworkX library. It allows us to create nodes (representing people) and edges (representing relationships) and then analyze the resulting graph.
The video below is a comprehensive crash course. For our purposes, you only need to understand the absolute basics: how to create a graph, add nodes, and add the edges that connect them.
NetworkX Crash Course - Graph Theory in Python
This "NetworkX Crash Course" from NeuralNine provides a great introduction to the library's fundamental features.
Please watch the first part of the video from the introduction of the library to the end of the section on adding nodes and edges. This will give you all the necessary commands to build our vee network. You can optionally skim the later section on visualization on different layouts, as it can be helpful for 'seeing' the network.
Simulating Simple Diffusion on a Vee Network
Now, let's combine the model and the tool to simulate the spread of news. Our process will follow the logic of a simple contagion simulation, which is clearly laid out in the "Network Analysis" resource, even though it uses a different programming language. We will adapt its principles.
14, Part 2. Social Diffusion Processes | Network Analysis
This resource explains the mechanics of a simple contagion simulation, defining the key components and parameters.
Please read the section titled "Simple Diffusion Models". Focus on understanding the core components of the simulation: starting with initial seeds, probabilistic transmission to neighbors over successive periods, and the parameters that control the process.
Let's apply this. We will simulate the spread of a simple piece of news, like "I just got a promotion at work!", within a vee.
Step 1: Build the Vee Network
First, we create the network structure using NetworkX. Our vee has three individuals: the hinge (H), and two non-hinge partners (P1 and P2). The relationships are between H-P1 and H-P2.
import networkx as nx
import random
# Create an empty graph
G = nx.Graph()
# Add nodes representing the three partners
nodes = ["H", "P1", "P2"]
G.add_nodes_from(nodes)
# Add edges representing the relationships in the vee
edges = [("H", "P1"), ("H", "P2")]
G.add_edges_from(edges)
Step 2: Define the Simulation Logic
Next, we create a function to run the Independent Cascade model. It will take the graph, the initial "seed" node, the transmission probability, and the maximum number of time steps as inputs.
def independent_cascade(graph, seed_node, prob, max_steps):
"""
Simulates the Independent Cascade model.
Returns a list of sets, where each set contains the infected nodes at that time step.
"""
infected_nodes_over_time = []
# Step 0: Initial state
infected_this_step = {seed_node}
infected_nodes_over_time.append(infected_this_step.copy())
newly_infected = {seed_node}
for i in range(max_steps):
# At the start of a new step, the previously newly infected nodes
# are the ones who will try to spread the info.
spreaders = newly_infected.copy()
newly_infected = set()
for spreader in spreaders:
# Look at all neighbors of the current spreader
for neighbor in graph.neighbors(spreader):
# If the neighbor is not already infected
if neighbor not in infected_nodes_over_time[-1]:
# Flip a coin with probability 'prob'
if random.random() < prob:
newly_infected.add(neighbor)
# If no one new was infected, the cascade stops
if not newly_infected:
break
# Update the total set of infected nodes for this step
current_total_infected = infected_nodes_over_time[-1].union(newly_infected)
infected_nodes_over_time.append(current_total_infected)
return infected_nodes_over_time
Step 3: Run and Analyze Scenarios
Now we can explore how information spreads depending on who gets it first. Let's assume a reasonably high probability of transmission, say p = 0.7.
-
Scenario A: The hinge (H) learns the news first.
# Set a seed for reproducibility random.seed(42) # Run the simulation with the Hinge as the seed cascade_A = independent_cascade(G, "H", prob=0.7, max_steps=5) print("Scenario A (Hinge is seed):") for t, infected_set in enumerate(cascade_A): print(f"Time {t}: {sorted(list(infected_set))}")Output:
Scenario A (Hinge is seed): Time 0: ['H'] Time 1: ['H', 'P2'] Time 2: ['H', 'P1', 'P2']In this run, at Time 1, the hinge successfully informs P2. In the next time step, the hinge then successfully informs P1. The information spreads to the entire network in two steps.
-
Scenario B: A non-hinge partner (P1) learns the news first.
# Set a different seed for a new random run random.seed(101) # Run the simulation with P1 as the seed cascade_B = independent_cascade(G, "P1", prob=0.7, max_steps=5) print("\nScenario B (Partner 1 is seed):") for t, infected_set in enumerate(cascade_B): print(f"Time {t}: {sorted(list(infected_set))}")Output:
Scenario B (Partner 1 is seed): Time 0: ['P1'] Time 1: ['H', 'P1'] Time 2: ['H', 'P1', 'P2']Here, the information must flow through the hinge. P1 tells H at Time 1. Then, at Time 2, H tells P2. This highlights the hinge's role as an essential bridge for information. P1 and P2 cannot communicate directly in this structure; all information must pass through H, who holds the position of highest betweenness centrality.
The probabilistic nature means that sometimes, the information might not spread. If we set prob=0.3 and run Scenario B again, the cascade might stop after P1 tells H, leaving P2 uninformed. This models a situation where the hinge simply forgets or doesn't get a chance to pass the news along.
This model, while simple, provides a powerful framework. You could extend it by:
- Adding a "recovery" probability, where individuals might forget the information (as seen in the
simple_contagion_functionfrom the R tutorial). - Assigning different probabilities to different edges to represent that the hinge is more likely to share information with one partner than another.
- Expanding the network to include friends outside the vee to see how information leaks out into the wider social circle.
Conclusion
In this lesson, we have successfully moved from theory to a practical simulation of simple information diffusion.
Key Takeaways:
- The Independent Cascade (IC) model is a standard and intuitive way to simulate simple contagion, where information spreads probabilistically from node to node.
- Using Python's
NetworkXlibrary, we can easily construct a graph representing a vee relationship to serve as the substrate for our simulation.
- The structure of the vee network fundamentally shapes information flow. The hinge partner acts as a crucial broker or bridge, as all information passing between the non-hinge partners must go through them.
- Who learns a piece of news first (the "seed" node) determines the path and speed of its diffusion through the relationship network.
We have focused on simple information, which spreads easily. But what about more complex adoptions, like a new relationship rule or a significant lifestyle change? These require social reinforcement. In our next lesson, we will model this process of complex contagion, shifting from the Independent Cascade model to a threshold-based approach.