Skip to content

A project on how third-party enforcement systems that sustain cooperation can emerge evolutionarily

License

Notifications You must be signed in to change notification settings

alex-rigos/Community-Enforcement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emergence of Specialised Third-Party Enforcement

Overview

This software is meant to support the research paper "Emergence of Specialised Third-Party Enforcement" by Erik Mohlin, Alexandros Rigos, and Simon Weidenholzer. It contains the tools that were used to produce the simulations and figures for the paper, as well as a demo script. All function definitions are found in ComEn-Definitions.jl.

  1. System requirements
  2. Installagtion guide
  3. Demo
  4. Instructions for use
  5. Replication code for the paper's figures

1. System requirements

Hardware requirements

The software only requires a standard computer.

Software requirements

The code is written in the Julia language (v1.7). Moreover, LaTeX should be installed on the system for the generation of some figures.

OS Requirements

The software should be able to run on all major operating systems. It has been tested on the following systems:

  • macOS: Catalina (10.15.7)
  • Windows 10 (OS version 19044.1288)

Julia dependencies

  • CSV (v0.10.4)
  • ColorSchemes (v3.17.1)
  • LaTeXStrings (v1.3.0)
  • Measures (v0.3.1)
  • PGFPlotsX (v1.4.1)
  • Plots (v1.27.4)
  • StatsBase (v0.33.16)
  • Tables (v1.7.0)
  • Distributed
  • Random

2. Installation guide:

2.1. Instructions

  1. Download and install the Julia language from https://julialang.org/
  2. Download the software from github and move to the installation directory.
  • If you use git and have access to a terminal, you can use the following commands to do that.
    $ git clone https://github.com/alex-rigos/Community-Enforcement
    $ cd Community-Enforcement
  • If you do not have access to a terminal
    1. Navigate to https://github.com/alex-rigos/Community-Enforcement
    2. Click on the green Code button, and select Download ZIP to download the ZIP file.
    3. Unzip the file. This will create a folder called Community-Enforcement-master, where the files are found.
    4. Open the Julia REPL and navigate it to the Community-Enforcement-master folder:
      julia> cd("My\\Path\\Community-Enforcement-master")   (On Windows)
      julia> cd("My/Path/Community-Enforcement-master")   (On Mac/Linux)
      for example.
  1. Install Julia dependencies:
    1. From the terminal
    $ julia install.jl
    1. or from the Julia REPL
    julia> include("install.jl")

2.2. Typical installation time

After installing Julia, the installation of the required dependencies takes about 80 seconds.

3. Demo

3.1. Instructions

3.1.1. Set model and simulation parameters

Select the parameters to be used in the simulation by editing the file demo-params.jl (and saving it). A short description of each parameter is included in this file. For more details, please see the paper.

The version of the demo-params.jl file provided includes the parameter values for the baseline model and for a population of 50 agents with initial state $(n_{CP},n_{CE},n_{DP},n_{DE})=(20,20,5,5)$. The default number of periods for which simulations are run is 1,000. This can be changed by setting the value of the generations variable. Increasing this number will considerably affect execution times.

3.1.2. Generate simulation data and plots

After setting the parameter values, you can run a simulation:

  1. From the terminal
$ julia demo-sims.jl
  1. or from the Julia REPL
julia> include("demo-sims.jl")

3.2. Output

The script generates three output files, which are placed under the demo/ folder:

  • demo-data.csv: simulation data
  • demo-time-series.pdf: population evolution period by period
  • demo-time-avg.pdf: strategy averages across all periods

3.3. Expected run time

The demo script takes approximately 65 seconds to execute the first time, as Julia needs to compile the source. After that, the script takes approximately 14 seconds to execute. These numbers are for 10,000 period-long simulations. Increasing the number of periods will significantly increase execution time.

4. Instructions for use

To generate new data and figures like those in the paper, please follow the procedures laid out below. The scripts below use parallel processing to reduce execution time. To set the default parameter values for any of the data generation scripts below, edit the file ComEn-ParametersBaseline.jl accordingly (and Save). All data-generation scripts below take considerable amounts of time to execute for the default parameter values (up to 30 minutes).

4.1. Time series and time averages plots

4.1.1. Data generation

Run the script time-series-data-generation-multiple-IC.jl. This creates a directory tree with root time-series-and-averages/time-series-data/ where the data are stored in files under the appropriate folders. The subfolder structure is as follows (in parent -> child order)

  • Parameter list: Parameters and values that differ from the Baseline
  • Reputation system (karma): karma 1 uses the CE reputation system; karma 2 uses the PE reputation system; karma 3 uses the following set of enforcer strategies: ${CE,PE,DE}$.
  • Number of strategies: 4 strategies includes {CP,DP,CE,DE} under karma 1 and ${CP,DP,PE,DE}$ under karma 2. 18 strategies includes ${CP,DP}$ as well as all the four-binary-digit combinations of enforcer strategies for each of karma 1 and karma 2. 5 strategies is only used under karma 3 and includes the strategies ${CP,DP,CE,PE,DE}$.

The files containing the data are named run-(number).csv, where number is used to differentiate between the 7 independent simulations that the code runs.

4.1.2. Generation of time-series plots (e.g. fig. 3c,f)

Run the script time-series-plots-multiple-IC.jl. This will create the folder time-series-and-averages/time-series-plots/, where the figures are stored under appropriately-named directories (see 4.1.1 above).

4.1.3. Generation of time-averages plots (e.g. fig. 3a,b,d,e and fig. 5a-f)

Run the script time-averages-plots-multiple-IC.jl. This will create the folder time-series-and-averages/time-averages-plots/, where the figures are stored under appropriately-named directories (see 4.1.1 above).

4.2. Comparative statics plots

4.2.1. Data generation

To generate the data, run the script comp-stat-data-generation.jl. This will create data files in subfolders under the directory comp-stat/comp-stat-data/. The subfolders are named with the variables for which the comparative statics computation is being conducted.

Parameter values are read from the ComEn-ParametersBaseline.jl file. The parameters and parameter values for which the simulations are carried out can be edited in the comp-stat-data-generation.jl file.

4.2.2. Generation of comparative statics plots (e.g. fig. 4 and Supplement fig. 2)

Run the script comp-stat-plots.jl. This will create the folder comp-stat/comp-stat-plots/, where the figures are stored for the data found in the comp-stat/comp-stat-data/ folder.

4.3. Phase diagrams (aka fishtank plots; not included in the current version of the paper)

4.3.1. Data generation

To generate the data, run the script fishtank-data-generation.jl. This will create data files in the directory fishtanks/fishtank-data/.

Parameter values are read from the ComEn-ParametersBaseline.jl file. The population states for which the calculations are run can be edited in the fishtank-data-generation.jl file.

4.3.2. Generation of phase diagram plots

Run the script fishtank-plots.jl. This will create the folder fishtanks/fishtank-plots/, where the figures are stored for the data found in the fishtanks/fishtank-data/ folder.

5. Replication code for the paper's figures

Replicate the paper's figures:

  1. From the terminal
$ julia paper-figures-replication.jl
  1. or from the Julia REPL
julia> include("paper-figures-replication.jl")

The scipt runs code that generates plots for the data that are found in subfolders under the paper-figures/ folder (and were used for the paper's figures). These subfolders are

  • time-series-and-averages/time-series-data/
  • comp-stat/comp-stat-data/

The script creates the following subfolders (under the paper-figures/ folder) where the generated figures are placed:

  • time-series-and-averages/time-series-plots/
  • time-series-and-averages/time-averages-plots/
  • comp-stat/comp-stat-plots/ The terms baseline and worse in the filenames refer to the baseline and the alternative parameter combinations mentioned in the paper, respectively.