PyDynamica is a freely available agent-based economy simulation

Overview

PyDynamica

PyDynamica is a pure python implementation of Sociodynamica, a virtual environment to simulate a simple economy with minimal dependencies.

PyDynamica is loosely based on ideas presented by Axtell and Epstein in Growing Artificial Societies (https://wtf.tw/ref/epstein_axtell.pdf) and Klaus Jaffe's work in developing Agent based models to visualize ideas in classical economics. (https://arxiv.org/abs/1509.04264)

Installation

pip3 install -r requirements.txt

python3 visualizer.py or python3 run_cli.py After the installation is complete and the server is running, open a web browser and navigate to http://localhost:8050 to see the visualizer.

Visualizer

How good of a model is this?

Not very. But even so, we can still learn a lot from this simple model, testing different economic hypotheses. A full economic analysis is coming soon.

It's easy to think of each agent as a "person" but really, it's more accurate to think of them as corporations. Here's why...

How does it work?

Sociodynamica is a freely available agent-based simulation model.

Resources

The grid world is filled with resources of three kinds: food, minerals, and empty. Each grid also keeps track of resource abundance.

Resources are generated by first creating three individual grids representing the abundance of each resource using perlin noise. At each grid, we choose the resource with highest abundance since each cell can only have one resource.

Minerals are a limited resource and therefore cannot regenerate. However, food regenerates at a constant rate.

Agent

There are four types of agents: omnipotent, trader, farmer, and miner. A miner can only mine minerals and trade with the trader. A farmer can only gather food and trade with the trader. A trader can trade with anybody. An omnipotent agent can, as the name implies, perform every action.

At the start of each turn, the agents move according to brownian motion except when they encounter an edge. After they move, they are given a chance to look for someone to trade with under the max trade per step contraint. An agent may choose who to trade with randomly as long as they are within the "contact horizon." Contact horizon represents how integrated an economy is.

The agents then collect resources if they are standing on a tile with resources they can collect. They then consume resources at a constant rate and adjust the internal value of each commodity.

The internal value represents how much an agent is willing to sell/buy a product for. The average sum of the internal value of all agents represents the "true market value" of products.

If the agent run out of food the agent dies. There is also a random chance that an agent may die (to simulate natural disasters, accidents, disease, etc). An agent can decrease the chance of this random death by accumulating minerals. Sudden death is determined through mineral_wealth < random[0,1] * danger.

Bartering / Trading mechanism

Each agent has a risk property which determines how much of their stockpile they want to sell off at each timestep. The amount to purchase is determined by the minimum of either the maximum amount the trading partner wants to sell or the amount of money the agent currently has.

If the agent values a resource more than its tradnig partner, a purchase will be made accordingly.

After each trading period comes a value adjustment period. If the resources sold in the previous trading round is less than the minerals the agent wanted to sell, the agent will decrease it's internal perceived value of that resource by a certain percentage. Otherwise, it will increase its internal perceived value.

Environment

An environment is defined by its terrestrial dimensions as well as the number of agents. Unlike other simulators which imbue agents with genetics and heredity, PyDynamica chooses to randomly generate agents at each step to replace dead agents.

This is more like how corporations work in free market capitalism. New companies don't inherit properties of the fallen ones (for the most part). In fact, people don't even try to replicate behaviors of successful companies (for the most part).

Statistics

The provided visualizer can show a couple interesting statistics about the economy:

  • GDP per capita: the sum of wealth of all agents divided by the number of agents.
  • Avg internal values: Price of food and price of minerals
  • Resources: the wealth of the richest agent and the wealth of the poorest agent and the wealth disparity

Todo

  • Mineral efficiency increase (innovation in capitalism)
  • More statistics about wealth disparities and the top 10% (See if bernie is right)
  • Implement "innovation" (increase extraction efficienties and extraction difficulties)
  • Implement replenishing resources
  • How do we get the price to determine the innovation level?
  • Make visualizer pretty
  • Implement Stalin
  • Implement income tax & wealth tax at different rates

Bugs & Qs

Feel free to report bugs and issues on github. Also feel free to email me at [email protected]

You might also like...
Transformers4Rec is a flexible and efficient library for sequential and session-based recommendation, available for both PyTorch and Tensorflow.
Transformers4Rec is a flexible and efficient library for sequential and session-based recommendation, available for both PyTorch and Tensorflow.

Transformers4Rec is a flexible and efficient library for sequential and session-based recommendation, available for both PyTorch and Tensorflow.

Transformers4Rec is a flexible and efficient library for sequential and session-based recommendation, available for both PyTorch and Tensorflow.
Transformers4Rec is a flexible and efficient library for sequential and session-based recommendation, available for both PyTorch and Tensorflow.

Transformers4Rec is a flexible and efficient library for sequential and session-based recommendation, available for both PyTorch and Tensorflow.

This is a python based command line Network Scanner utility, which input as an argument for the exact IP address or the relative IP Address range you wish to do the Network Scan for and returns all the available IP addresses with their MAC addresses on your current Network.

This is a python based command line Network Scanner utility, which input as an argument for the exact IP address or the relative IP Address range you wish to do the Network Scan for and returns all the available IP addresses with their MAC addresses on your current Network.

A customisable 3D platform for agent-based AI research
A customisable 3D platform for agent-based AI research

DeepMind Lab is a 3D learning environment based on id Software's Quake III Arena via ioquake3 and other open source software. DeepMind Lab provides a

Deep Reinforcement Learning based Trading Agent for Bitcoin
Deep Reinforcement Learning based Trading Agent for Bitcoin

Deep Trading Agent Deep Reinforcement Learning based Trading Agent for Bitcoin using DeepSense Network for Q function approximation. For complete deta

A parallel framework for population-based multi-agent reinforcement learning.
A parallel framework for population-based multi-agent reinforcement learning.

MALib: A parallel framework for population-based multi-agent reinforcement learning MALib is a parallel framework of population-based learning nested

Urban mobility simulations with Python3, RLlib (Deep Reinforcement Learning) and Mesa (Agent-based modeling)
Urban mobility simulations with Python3, RLlib (Deep Reinforcement Learning) and Mesa (Agent-based modeling)

Deep Reinforcement Learning for Smart Cities Documentation RLlib: https://docs.ray.io/en/master/rllib.html Mesa: https://mesa.readthedocs.io/en/stable

A simple agent-based model used to teach the basics of OOP in my lectures
A simple agent-based model used to teach the basics of OOP in my lectures

Pydemic A simple agent-based model of a pandemic. This is used to teach basic principles of object-oriented programming to master students. It is not

Pytorch modules for paralel models with same architecture. Ideal for multi agent-based systems
Pytorch modules for paralel models with same architecture. Ideal for multi agent-based systems

WideLinears Pytorch parallel Neural Networks A package of pytorch modules for fast paralellization of separate deep neural networks. Ideal for agent-b

An evolutionary multi-agent platform based on mesa and NEAT
An evolutionary multi-agent platform based on mesa and NEAT

An evolutionary multi-agent platform based on mesa and NEAT

A platform for intelligent agent learning based on a 3D open-world FPS game developed by Inspir.AI.

Wilderness Scavenger: 3D Open-World FPS Game AI Challenge This is a platform for intelligent agent learning based on a 3D open-world FPS game develope

Simulation-Based Inference Benchmark

This repository contains a simulation-based inference benchmark framework, sbibm, which we describe in the associated manuscript "Benchmarking Simulation-based Inference".

NeuralWOZ: Learning to Collect Task-Oriented Dialogue via Model-based Simulation (ACL-IJCNLP 2021)
NeuralWOZ: Learning to Collect Task-Oriented Dialogue via Model-based Simulation (ACL-IJCNLP 2021)

NeuralWOZ This code is official implementation of "NeuralWOZ: Learning to Collect Task-Oriented Dialogue via Model-based Simulation". Sungdong Kim, Mi

Event-based hardware simulation framework

An event-based multi-device simulation framework providing configuration and orchestration of complex multi-device simulations.

 pulse2percept: A Python-based simulation framework for bionic vision
pulse2percept: A Python-based simulation framework for bionic vision

pulse2percept: A Python-based simulation framework for bionic vision Retinal degenerative diseases such as retinitis pigmentosa and macular degenerati

A cool little repl-based simulation written in Python
A cool little repl-based simulation written in Python

A cool little repl-based simulation written in Python planned to integrate machine-learning into itself to have AI battle to the death before your eye

A framework for training and evaluating AI models on a variety of openly available dialogue datasets.
A framework for training and evaluating AI models on a variety of openly available dialogue datasets.

ParlAI (pronounced “par-lay”) is a python framework for sharing, training and testing dialogue models, from open-domain chitchat, to task-oriented dia

HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And Android(Termux)
HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And Android(Termux)

HPomb v2020.02 Coming Soon Created By Secanonm HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And An

Comments
  • 90% tax doing better than free market

    90% tax doing better than free market

    Results show that a society that's taxed 90% does 5x better than a free market. This doesn't make logical or economic sense to me.

    Potential cause: The rate of resource unlock is determined by the global average extraction efficiency, meaning that if everyone gets a bunch of money due to redistribution, they will go out and purchase minerals to upgrade their own efficiency, which would, in turn, lead to massive resource unlocks.

    This is problematic partly because it's unrealistic to assume that everyone who receives redistributed cash will use it as efficiently as those from whom we took it.

    One way to fix this is to tie the extraction efficiency to each agent rather than taking an average and using that. This will hopefully allow individuals who invest to be awarded rather than the society as a whole.

    opened by ianmkim 0
  • Inflation

    Inflation

    With the creation of each new agent, money is injected into the economy since no money is lost (all money is either saved or traded). In societies with high death rates and high taxation, this will cause an issue because the GDP will increase beyond what it should be.

    One way to solve the issue would be to implement a central bank, but that's overly complex. A more simplistic method might be to make "minerals" the official currency, causing the money supply to be regulated through market prices

    opened by ianmkim 0
Owner
null
This repo is to be freely used by ML devs to check the GAN performances without coding from scratch.

GANs for Fun Created because I can! GOAL The goal of this repo is to be freely used by ML devs to check the GAN performances without coding from scrat

Sagnik Roy 13 Jan 26, 2022
A community based economy bot with python works only with python 3.7.8 as web3 requires cytoolz

A community based economy bot with python works only with python 3.7.8 as web3 requires cytoolz has some issues building with python 3.10

null 4 Jan 1, 2022
A library for interacting with Path of Exile game and economy data, and a unique loot filter generation framework.

wraeblast A library for interfacing with Path of Exile game and economy data, and a set of item filters geared towards trade league players. Filter Ge

David Gidwani 29 Aug 28, 2022
A simple tool which automate commands of discord economy bots

A simple tool which automate commands of discord economy bots. Fully configurable using an intuitive configuration made in YAML

SkydenFly 5 Sep 18, 2022
A simple economy bot for discord!

Enter all the correct values in the given configuration.json file. Make sure that BOT_TOKEN is a string value, and that OWNER_ID and GUILD_ID are integer values.

WonkyPigs 0 Aug 22, 2022
A fun discord bot for music, mini games, admin controls, economy, ai chatbot and levelling system

A fun discord bot for music, mini games, admin controls, economy, ai chatbot and levelling system. This bot was specially made for Dspark discord server.

null 2 Aug 30, 2022
This project uses reinforcement learning on stock market and agent tries to learn trading. The goal is to check if the agent can learn to read tape. The project is dedicated to hero in life great Jesse Livermore.

Reinforcement-trading This project uses Reinforcement learning on stock market and agent tries to learn trading. The goal is to check if the agent can

Deepender Singla 1.4k Dec 22, 2022
This is an incredible led matrix simulation using the ultimate mosaik co-simulation framework.

This project uses the mosaik co-simulation framework, developed by the brilliant developers at the high-ranked Offis institue for computer science, Oldenburg, Germany, to simulate multidimensional LED matrices.

Felix 1 Jan 28, 2022
A lightweight Python-based 3D network multi-agent simulator. Uses a cell-based congestion model. Calculates risk, loudness and battery capacities of the agents. Suitable for 3D network optimization tasks.

AMAZ3DSim AMAZ3DSim is a lightweight python-based 3D network multi-agent simulator. It uses a cell-based congestion model. It calculates risk, battery

Daniel Hirsch 13 Nov 4, 2022