Example: Modeling Social Influence in a Network
We will simulate how opinions spread in a social network.
The idea is based on the DeGroot model of consensus, where each node in the network updates its opinion based on a weighted average of its neighbors’ opinions.
Problem Setup
- A network of individuals is represented as a graph.
- Each node has an initial opinion (randomized).
- Opinions are updated iteratively using the weighted average of neighboring opinions.
- We will observe how opinions converge over time.
Python Code Implementation
1 | import numpy as np |
Explanation
- Graph Creation:
A random graph is created using the $Erdős–Rényi model$ to simulate a social network. - Initialization:
Each node is assigned a random opinion value between $0$ and $1$. - Opinion Update Rule:
Opinions are updated iteratively as a weighted average of neighbors’ opinions, governed by the adjacency matrix of the graph. - Visualization:
- The convergence of opinions over iterations is plotted.
- The initial and final opinions are visualized on the network.
Results
- Convergence Dynamics:
- The plot of opinion dynamics shows how individual nodes’ opinions evolve and converge over iterations.
- Nodes with many connections (high degree) influence others more strongly.
- Graph Visualization:
- Initial opinions are randomly distributed.
- Final opinions converge to a consensus or remain close to a weighted average of initial opinions depending on the network structure.
This example demonstrates how mathematical sociology models can capture social influence processes using $Python$.