Category Archives: Cellular Automata

Modeling the Formation of Opinion Clusters using Cellular Automata

I recently finished a very interesting MOOC by the University of Groningen entitled Decision making in a complex and uncertain World. The course running on the platform Futurelearn was an interdisciplinary introduction to different aspects of complexity theory. Among other topics it introduced the concept of agent based modeling and cellular automata.

One example of how to use these concepts was a model that tried to predict how different opinions are spreading in a society. I was fascinated by how this simple model could explain and model a complex phenomenon like the distribution and formation of opinions in a society. Since I’m a programmer I felt like implementing this model as a simulation in the browser so that it is possible to see what is actually happening when you run it.

In this blog post I will explain what the simulation is about and explain a couple of words about the background. I will conclude with some decisions I had to make for my implementation and finally suggest some takeaways.

The Problem

The simulation models opinion dynamics in a society trying to answer the question:

Why do opinion clusters form?

Or a bit longer:

„What are the mechanisms that lead to the exchange of opinions between individuals in a society?“

The model defines the dynamics of a number of so called cells or agents that simulate humans in a society, but interact more predictably only defined by a restricted set of rules. Some elements of chance are applied as well to be able to more realistically reflect the behavior of a real society.

In 1997 the American political scientist Robert Axelrod proposed a model of “cultural dissemination” to simulate clustering and self-organization of opinions in a society through the interplay of social influence and homophily (both explained below). Because this model is quite simple and well defined I chose it for my implementation.

Cellular Automata

The simulation runs in a “world” represented by a two-dimensional grid of square cells. Each cell has an opinion about each one of a number of so called opinion dimensions ‒ also called features. The amount of opinions each feature can take is restricted ‒ they are called traits.

An example: A feature could be the party that an individual is voting for in the next election and the traits would be the parties available for election. Another feature could be the individual’s preferred hair product ‒ then the traits would be the available brands. Obviously the more features and the more traits there are, the more complex the resulting “opinion space” will be.

Cells can interact with other cells, but only with its neighbors. The model by Robert Axelrod uses so called Von Neumann neighborhoods. Here every cell can only interact with their direct orthogonal neighbors, not with their diagonal neighbors and not with neighbors of neighbors:

sketch of a Von Neumann Neighborhood

For the cells at the borders of the grid we imagine an “invisible bridge” to the cell at the opposite border of the grid, effectively making our world a torus rather than a rectangular plane.

Social Influence and Homophily

How does one cell influence the opinion of another? In the model we use two mechanisms:

1. Social Influence

This concept simply refers to the fact that when individuals interact with each other, their opinions tend to become more similar. Due to the neighborhood we are using only direct neighbor cells will ever directly interact and influence each other.

2. Homophily

Homophily is the second phenomenon that affects when social influence takes effect and when not. It refers to the fact that individuals who are more similar to each other are more likely to interact. In the model this is implemented in a way that the likelihood of one cell influencing each other is determined by the amount of traits they have in common. E.g. if two cells agree on 2 traits out of 3 features, their likelihood to influence each other would be 2/3.

The Simulation

The simulation starts with a random distribution of opinions. That does not necessarily correspond to reality but there needs to be a starting point.

In each step of the simulation two neighbors A and B are randomly selected out of the grid. The selected neighbors then get the chance to interact. Here the homophily principle explained above is applied and this will determine if neighbor A influences neighbor B. A random factor is used here, but the chance of interaction increases with the amount of traits the two neighbors have in common.

If the cells interact the social influence principle is applied and B receives a random trait from A out of the traits that they do not have in common yet. After this step the two cells are more similar than before.

When running the simulation we see the formation of opinion clusters indicated by color clusters. What we are dealing with here is a case of social self-organization. Although the cells are very simple and only allow a couple of different states, their interaction with each other has a state of its own.

The Implementation

I wanted to keep the implementation and the design of the user interface as simple as possible. It is all about understanding the model and its implications here. At the same time I wanted it to be possible for the user to set different parameters because this can change the path the simulation takes quite a lot. So the grid size as well as the amount of features and traits are mutable.

One challenge in the implementation was the visual representation. How can I indicate which cells have the same traits and which ones are different? I chose to implement two different modes of viewing the “world”: one that shows each cells trait with a different color for every trait. This means you can switch between color-coded visual representations of the world for every feature.

In the second way of viewing the world I wanted the user to be able to see all the information at once as far as that is possible without having to switch between the different features. So I implemented a ‘similarity’ view where the similarity of each cell to its neighbors is indicated by color. The more black a cell is displayed the less similar it is to its neighbors, the whiter it is the more traits it has in common with its neighbors. In this viewing mode the overall result of the simulation can be more easily investigated and the clustering over all the features is made visible.

Trying it out will make this more clear. You can find the live version here:

The code of the implementation lives here.


I like how this simple model can yield such a complex behavior and outcome. Although the rules of the model are very simple, it is not easy at all to predict the outcome of what happens when the cells interact with each other. The system of cells is literally more than the sum of its parts. That’s why seeing it live in action in form of a computer simulation can help us develop an intuition for these kinds of phenomena in society.

The amount of insight we get that can be applied to reality is vastly determined by the model that is chosen though. One problem with Axelrod’s model is that it represents actual developments in a very small society quite well, but that it does not reflect the development in a big society with a big opinion space. We can see this by increasing the amount of features and traits. The result after running the simulation is quite counterintuitive: there is less diversity in opinions (“cultural diversity”) than when running the simulation with a smaller opinion space. This results out of the fact that when there are more features, the likelihood of two cells agreeing on at least one feature is higher and thus the likelihood of two neighbors interacting at all is generally higher. In a world with less features there is quite a big chance that two neighbors don’t agree on a single feature and thus will never have the chance to interact. The model could be extended e.g. by introducing noise as suggested by Flache & Macy in an attempt to have an outcome closer to reality.

In summary we can for sure say that models like this can help us understand social phenomena better. But we should not make the mistake to confuse them with reality and expect exact predictions of the future. Models like this are more like a crutch trying to bring us closer to understanding what happens in reality.