Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Readme.md

Boltzmann Wealth Model (Tutorial)

Summary

A simple model of agents exchanging wealth. All agents start with the same amount of money. Every step, each agent with one unit of money or more gives one unit of wealth to another random agent. Mesa's Getting Started section walks through the Boltzmann Wealth Model in a series of short introductory tutorials, starting withCreating your First Model.

As the model runs, the distribution of wealth among agents goes from being perfectly uniform (all agents have the same starting wealth), to highly skewed -- a small number have high wealth, more have none at all.

How to Run

Install Mesa with recommended dependencies:

pip install "mesa[rec]"

Then run the example:

solara run app.py

Open the displayed local URL in your browser.

Files

  • model.py: Final version of the model.
  • agents.py: Final version of the agent.
  • app.py: Code for the interactive visualization.

How the Model Is Structured

This example follows Mesa's standard separation of concerns:

  • agents.py: Defines individual agent behavior (WealthAgent with its step method for giving money to other agents)
  • model.py: Manages the simulation environment, instantiates agents, handles the grid/space, and collects data
  • app.py: Sets up the visualization components to display the model in a web interface
  • st_app.py: (Optional) Alternative Streamlit-based visualization

The visualization displays the state of the model but does not influence how agents behave or how the system evolves over time.

Understanding the Output

The Gini coefficient shown in the visualization measures wealth inequality, ranging from 0 (perfect equality) to 1 (perfect inequality). It is computed in model.py using Mesa's DataCollector at each simulation step.

Optional

An optional visualization is also provided using Streamlit, which is another popular Python library for creating interactive web applications.

To run the Streamlit app, you will need to install the streamlit and altair libraries:

    $ pip install streamlit altair

Then, you can run the Streamlit app using the following command:

    $ streamlit run st_app.py

Further Reading

This model is drawn from econophysics and presents a statistical mechanics approach to wealth distribution. Some examples of further reading on the topic can be found at:

Milakovic, M. A Statistical Equilibrium Model of Wealth Distribution. February, 2001.

Dragulescu, A and Yakovenko, V. Statistical Mechanics of Money, Income, and Wealth: A Short Survey. November, 2002