This code was made by Maickel Hartlief, Arend Geerlofs, Dominique Weltevreden, Kaat Brinksma, and Mirjam Koedijk
Requirements:
math
sys
os
importlib
random
matplotlib
numpy
scipy
lib
.mesa
networkx
seaborn
panda
SALib
itertools
scikit_posthocs
.warnings
How to use:
To run the model, run run.py
.
Hyperparameters can be changed by changing them in normal.py
in the configs
folder, or by copying normal.py
into [name].py
and calling run.py
with input argument [name]
.
To do sensitivity analisys, run ofat.py
(local) or sobol.py
(global). These use the first element in the network
parameter in the normal.py
config file, so make sure to change that to the network you want to run the sensitivity analisys on.
To do statistical analysis on the results of the model, run statistics.py
. This uses the results saved when running run.py
, so make sure to do that beforehand.
Files:
run.py
: Runs the model with the hyperparameters set innormal.py
, unless another file is specified as input argument, and saves plots and graphs into theresults
folder.ofat.py
: Run local sensitivity analisys (one factor a time) for'prob_stimulus'
,'prob_interaction'
,'prob_move'
, and'prob_link'
, using the parameters innormal.py
and the first element of networks as the network structure. Also saves plots and results.sobol.py
: Runs global sensitivity analisys for'prob_stimulus'
,'prob_interaction'
,'prob_move'
, and'prob_link'
, using the parameters innormal.py
and the first element of networks as the network structure. Also saves plots and results.statistics.py
: Runs the statistical tests that checks whether there is a significant difference between different network implementations in the model.party.py
: Specifies theParty_model
class which is a subclass of amesa.Model
. This represents the environment of the model and handles all global functionality like environment variables, data collection, initializing agents, and calling the agents' step functions each step.agents.py
: Speficies theMember
class which is a subclass of amesa.Agent
. This represents the agents of the model and handles characteristics, interacting, and has the dependent variable political participation.utils.py
: Some useful functions that are used elsewhere in the program.normal.py
: A configuration file with hyperparameters. Alternatives can easily be made by copying this code to another file in theconfig
folder and callingrun.py
with the name of that file as an input variable.
parameters:
n_runs (int)
: Number of independent runs to run each network type for.n_agents (int)
: Number of agents in the model.n_iterations (int)
: Number of steps to run the model for.n_distinct_samples
: how many sample values to take for each parameter during sensitivity analysis.char_distr (str)
: Distribution used to initialize the characteristics of the agents.until_eligible (int)
: Steps until newly moved agents are allowed to vote.characteristics_affected (dict{str['active', 'overt', 'continuous', 'expressive', 'outtaking'] : float[0-1]})
: Whether characteristics are affected by events (pressence in the dictionary) and how they are affected (<.5 tends down, >.5 tends up).edges_per_step (int)
: Not currently used, parameter needed when making the networks dynamic (future research)prob_stimulus (float[0-1])
: Probability that a stimulus happens to all agents at any step.prob_interaction (float[0-1])
: Probability that any agent tries to find another agent to interact with at any step.prob_move (float[0-1])
: Probability that any agent gets reset (simulates moving community and getting replaced by another agent).prob_link (float[0-1])
: Parameter of Holme-Kim algorithm Triad formation probability after each preferential attachment mechanism.m_barabasi (float)
: Parameter of Holme-Kim algorithm specifiying the number of nodes to which a new node connects at each iteration.fermi_alpha (float)
: Parameter of the Fermi-Dirac distribution. it determines the speed of convergence.fermi_b (float)
: Parameter of the Fermi-Dirac distribution. the distance at with P_ij = 1.networks (list{str['not_connected', 'holme_kim', 'homophily', 'fully_connected']})
: Which type of network structure(s) to run the model with.'not_connected'
has no links,'holme_kim'
has a common social network structure,'homophily'
has a social network structure based on similarities in the agents' characteristics, and'fully_connected'
has a link between every 2 agents.