This package and analysis can be reproduced using a conda environment with the
required dependencies installed. Dependencies are listed in
placed on the code folder.
Assuming you have the Anaconda Python distribution installed
(see page), an environment
can be recreated automatically by running the following command:
conda create -n schelling --file env_spec.txt
Once that is completed, activate the environment by running:
source activate schelling
When you are done with the session, deactivate the environment with:
There are three main scripts used to for the simulations in the paper, and all are included in the code folder:
schelling.pycontains the core methods to set up and run a Schelling-type agent-based model. See some instructions on how to use it below.
sim_enginge_scoop.pyis the script used to run the simulations on a super-computer. It relies on the library
scoopfor the parallel computations. The results can be found in the code folder and are named
results.pycontains the methods required to generate the figures in the paper and those included additionally in this page. An example on how to use them can be found in the visualizations section of this website.
import time print "Ran last ", time.strftime("%d/%m/%Y")
Ran last 23/09/2015
This document offers a short tutorial of the basic usage of the
schelling module, employed in the simulations of the paper "How diverse can spatial measures of cultural diversity be? -- Results from Monte Carlo simulations on an agent-based model", by Dani Arribas-Bel, Peter Nijkamp and Jacques Poot.
The library flexibly allows to generate different topologies on which to run the "bounded neighborhood" of the Schelling model. This includes generating standard grids or using arbitrary topologies specified in a shapefile.
For this tutorial, we will be using a world of 70 by 70 cells, which can be vacant or occupied by agents.
world_dims = 70, 70
This example uses a grid of 10 by 10 neighborhoods (hence 7x7 locations per neighborhood. With this information, we can build the world topology:
nr, nc = neighs = (7, 7) w, ns, xys = schelling.bounded_world(world_dims, world_dims, nr, nc)
Similarly, we allow for 25% of the spots to be vacant at any time, thus setting population size to 75% of all the 4,900 (70x70) potential spots.
pop_size = int((world_dims * world_dims) * 0.75)
At this point, we are ready to specify the groups in the population and their preferences for diversity.
We will use a case with two groups only and equal distribution (50%-50%). Note that you only specify population shares for n-1 groups, the remaining being assumed:
prop_groups = [0.5]
Preferences are controlled globally by the parameter $\tau$, which represents the number of agents alike every individual needs in the inmediate neighborhood to be happy. We will start with flat preferences:
pct_similar_wanted = 0.
At this point, we are ready to initialize the world:
world = schelling.World(pop_size, pct_similar_wanted, prop_groups, w, ns)
And ready to run the simulation!
CPU times: user 0 ns, sys: 0 ns, total: 0 ns Wall time: 217 µs
Once the world converges to a situation in which every individual is content, it stops. We can then examine the output by querying the object
The most obvious way to explore the output is by visualizing it. Note we need to pass coordinates for the locations and, in this case, a specification of the grid-like neighborhoods (both specififed above):
For the sake of the example, we can try now with a situation in which everyone requires at least three quarters of its neighbors to be similar. Note the clearly longer time of computation until convergence but also the radically different pattern that emerges).
pct_similar_wanted = 0.5 world = schelling.World(pop_size, pct_similar_wanted, prop_groups, w, ns)
CPU times: user 5.52 s, sys: 40 ms, total: 5.56 s Wall time: 5.5 s