This model demonstrates how to use the Networks Library by simulating two opposite opinions that spread through a network. A simple model of "opinion spread" is used to explore how the structure of a Network can affect its behavior.
The Networks Library allows agents to easily specify their network neighbors in
network_neighbor_ids, and view them as if they were spatial neighbors by accessing
The model of opinion spread in this simulation uses a simple mechanism to determine if an agent will change its opinion. It will adopt the opinion of the majority of its neighbors (including itself in the calculation). The two opinions in this model are represented by an agent's color: blue or green. Opinions are randomly assigned to agents when they are initialized.
As the simulation runs, agents view their network neighbors and adjust their opinion, until the simulation reaches a state of equilibrium. Some types of networks will always converge into complete homogeneity of opinion, while others will allow the two different opinions to spread, but still coexist with one another.
This simulation uses the NetworkX python package to stochastically generate networks. There are three different types of networks built into this simulation. You can select which to initialize using the
network_type parameter in globals.json:
- Erdos-Renyi - "erdos_renyi"
- Watts-Strogatz - "watts_strogatz"
- Barabasi-Albert - "barabasi_albert"
Each network also has corresponding parameters to specify in globals.json which affect the shape of the generated network. You can read more about the different characteristics of these networks in this blog post.
There are three experiments intended for you to use to understand the properties of the different types of networks. These experiments only vary properties which affect the initialization of the network:
- Erdos-Renyi p Sweep - varies the percentage of total edges generated
- Watts-Strogatz p Sweep -varies the percentage of edges rewired
- Barabasi-Albert m Sweep - varies the number of edges attached to each new agent
You can extend this model by writing different heuristics for the "opinion spread" mechanism, or adopting it to entirely different domains, such as cascading electrical grid failures, or viral infection.