andyvandy / summer_game_theory_repo

Peter Taylor research
10 stars 4 forks source link

Evolutionary Game Theory simulations

This is the repository for the students working with Dr. Taylor on evolutionary game theory this Summer (2015).

Current simulations:

-iterated prisoner's dilema simulation from the AshlockKim paper

-2d agents simulation from the Burtsev paper

Iterated prisoner's dilemma

How to use

The main file is IPD_simulation.py, all settings are stored in IPD_functions/IPD_config.py

Setting the number of simulations to 1 will result in the above html output. Any greater number of simulations will save the data to a json file which can then be used to make graphs with IPD_functions/grapher.py and then viewed in a similar format as above using IPD_functions/viewer.py .

Required packages
-networkx
-numpy
-matplotlib
-pandas
-seaborn
Model basics

The main idea of the simulation can explained nicely by this gif,

"Game Diagram AniFin" by HowieKor - Own work. Licensed under CC BY-SA 3.0 via Wikimedia Commons.

A population of agents are randomly paired and then play a 2x2 matrix game a random (exponentially distributed) number of times until moving onto the next partner. Once each agent has been paired with a designated number of partners, all agents are assessed and the highest scoring agents continue onto the next generation as well as their offspring (who undergo a slight mutation to the parent's strategy).

This is then continued for the desired number of generations and logged afterwhich then entie process is repeated again for a desired number of simulations.

Here is an example using the prisoner's dilemma payoff where each simulations data is traced faintly to show the percentage of cooperation(blue) vs defection(red):

Understanding the outputs

TODO

Iterated Trust Game

How to use

The main file is full_sim.py, and the settings are stored in trust_config.py.

Data from the simulations will be saved in the output/sim_name directory in json files. You can run grapher.py to generate plots of the data.

Required packages:
-numpy
-matplotlib
-seaborn
Model basics

Investor plays trustee, investor takes the first turn. Chooses a: [0, a_endowment]. Investor gives a to trustee, keeping (1 - a)A for themselves. Trustee receives Ba, and returns f(a) : [0, Ba] to investor, keeping Ba - f(a) for themselves. Investor then receives Cf(a), leaving them with a total of (1 - a)A + C*f(a).

This game is iterated over a random number of turns. Players may or may not switch positions between each turn. Each round has players matched up randomly, and it is currently guaranteed that players will play an equal number of games in each role.