Skip to content

Conversation

@areyoush
Copy link

Closes #300

This pull request adds a new example implementing the Deffuant–Weisbuch bounded confidence opinion dynamics model to the mesa-examples repository.

Model Description

The Deffuant–Weisbuch model studies how individual opinions evolve through repeated pairwise interactions in a population where agents are only willing to adjust their views toward others whose opinions are sufficiently close to their own. Over time, these bounded interactions can lead to emergent phenomena such as consensus, polarization, or fragmentation into stable opinion clusters, depending on the confidence threshold and convergence rate.

Motivation

This example serves as a clear and accessible reference for understanding population-level opinion dynamics under bounded confidence assumptions. It is intended to help new Mesa users learn how conditional pairwise interactions, continuous agent attributes, and data collection can be implemented within the Mesa framework.

Implementation

The model simulates a well-mixed population of agents with continuous opinion values evolving through repeated pairwise interactions.

Model Structure

DeffuantWeisbuchModel (examples/deffuant_weisbuch/model.py)

  • Initializes a population of agents with opinions sampled from a continuous range.
  • At each step, randomly selects pairs of agents for potential interaction.
  • Applies bounded confidence logic: agents only interact if their opinion difference is below a confidence threshold.
  • Updates opinions symmetrically using a convergence rate parameter.
  • Collects model-level metrics including opinion variance, interaction acceptance rate, and cluster count.

OpinionAgent (examples/deffuant_weisbuch/agents.py)

  • Stores a continuous opinion value.
  • Updates its opinion toward another agent’s opinion during interaction based on the convergence rate.

Visualization (examples/deffuant_weisbuch/app.py)

  • Displays opinion trajectories of all agents over time.
  • Visualizes summary metrics including variance, acceptance rate, and number of opinion clusters.
  • Provides interactive sliders for adjusting model parameters such as population size, confidence threshold, and convergence rate.

Opinion GIF

Usage

To run the example:

solara run app.py

What this PR includes

  • An agent-based implementation of the Deffuant–Weisbuch model
  • Interactive Solara visualization with opinion trajectories
  • Summary metrics including opinion variance, acceptance rate, and cluster count
  • Documentation describing the model, parameters, and usage

This model is drawn from the bounded confidence opinion dynamics framework introduced by Deffuant et al. (2000).

Happy to contribute! and open to any feedback or suggestions.

@EwoutH EwoutH requested a review from tpike3 January 14, 2026 19:28
Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this! Interesting theory, good use of Mesa features, shows some nice dynamics. Well structures example, nice readme, great description including animation. Runs in CI without warnings.

No notes at all, this is excellent work.

I will leave this open for a bit to give others a bit of time to review, otherwise merging this weekend.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Deffuant–Weisbuch opinion dynamics model example

2 participants