This repository contains the code and simulations for the paper "Epistemic Communities under Active Inference" (Albarracin et al., 2022).
Paper Link: https://pubmed.ncbi.nlm.nih.gov/35455140/
This codebase implements a multi-agent simulation of opinion dynamics using the Active Inference framework. The model investigates the cognitive and social mechanisms behind confirmation bias and echo-chamber formation.
In this model:
- Agents are active inference systems that sample information to minimize free energy (uncertainty).
- Agents generate observable social claims (e.g., "tweets") supporting one of two mutually exclusive ideas.
- Agents choose which neighbors to "listen" to based on the expected epistemic value (information gain) of their observations.
- Confirmation Bias emerges as agents preferentially sample information that validates their existing model of the world, leading to self-reinforcing belief structures and the consolidation of epistemic communities.
Key features of the simulation include:
- Generative Models: Agents maintain beliefs about an abstract "Idea" and the beliefs of their neighbors.
- Active Sampling: Agents select actions (who to attend to) to resolve uncertainty.
- Network Dynamics: The structure of social attention evolves as agents change who they sample from over time.
- Install dependencies:
pip install -r requirements.txt
To run the main experiments and generate plots, run the reproduction script:
python3 reproduce_experiments.pyThe results (plots) will be saved in the results/ directory.
You can also run individual demos as modules:
-
Active Inference Demo (3 agents):
python3 -m demos.active_inference_demo
Generates plots showing belief updates and sampling probabilities for a simple 3-agent scenario. This demonstrates the basic dyadic interaction and sampling logic.
-
Inference Demo:
python3 -m demos.inference_demo
Runs inference simulations and plots belief switching rates across different parameters (e.g., Epistemic Confirmation Bias vs. Environmental Determinism).
-
Network Demo:
python3 -m demos.network_demo
Simulates a larger network of agents (e.g., N=10) and plots the evolution of beliefs over time, showing how communities of belief emerge or fracture.
model/: Core agent and generative model implementation.agent.py: TheAgentclass implementing active inference.genmodel.py: The generative model (matrices A, B, C, D, E).pymdp/: Python library for MDPs and active inference math.
demos/: Executable scripts for running simulations.analysis/: Tools for analyzing simulation results.simulation/: Helper functions for initializing and running network simulations.results/: Output directory for plots generated byreproduce_experiments.py.
If you use this code, please cite the original paper:
Albarracin, M., Demekas, D., Ramstead, M. J. D., & Heins, C. (2022). Epistemic Communities under Active Inference. Entropy, 24(4), 476. https://doi.org/10.3390/e24040476