/users/rlr/Courses/ICPSR-03/Handouts/intro-run-ipdm0.txt -------------------------------------------------------- In this computer lab exercise, we will explore the effects of the temptation payoff and the update method on the fraction of cooperators in the lattice PD model described in the papers: Nowak, Martin and May, R.M. (1992) "Evolutionary games and spatial chaos." Nature, 359, pp826-929. Nowak, Martin, Bonhoeffer, S. and May, R.M. (1994) "Spatial games and the maintenace of cooperation." PNAS (USA), v91, pp4877-4881. Agents are Cooperators (C) or Defectors (D). You can set the fraction of C at start from 0 to 1. The strategies are distributed randomly in a 2D world. To specify the Nowak-May model, set the number of agents equal to the number of cells in the world (worldSize * worldSize). Note the population size is fixed: All that changes is the strategy used by the agents in the cells, i.e., some use Defect (red/green), some use Cooperate (blue). In this case the relevant parameters are: - worldSize size of each side of the square world - numBugs initial number of agents - fractionC starting fraction of cooperators - b the temptation payoff - sync Synchronous updating 1 (1, the default) or off (0). sync=1 The original Nowak/May mechanism. First each agent gets one chance to play all its neighbors and accumulate scoreseach generation. Then each agent is allowed to update its strategy based on those scores. sync=0 Asynchronous play and updating, as described in Huberman, Bernardo A. and Glance, Natalie S. (1993) "Evolutionary Games and Computer Simulations." Proc. Natl. Acad. Sciences (USA), 90, 7716-18. Each generation numBugs agents are selected to play and be updated; they are selected with replacement, which means in any given generation some agents might be picked 0, 1, 2 or more times, but the expectation is to be selected once per generation. When an agent is picked, it plays its neighbors, then immediately decides based on accumulated scores whether or not it wants to update its strategy. - ColorScheme control color of agent display (see notes below) Note that the only relevant graph is the C_f (fraction Cooperators) vs. T (time), since these agents don't accumulate wealth over time, and the total population is fixed equal to the number of cells. **Reminder: when you change a parameter using the GUI, you must: - STOP (pause) the model while you change it - Press the Enter (Return) key to send the change to the model (The box around the value flashes red.) To run the model, enter ipdm0 or if that doesn't work, try /users/rlr/SwarmStuff/CSCS-Demos/IPDm0/m0 First run the model with the default parameters, i.e., b = 1.9 sync = 1 fractionC = 0.99 worldSize = 50 numBugs = 2500 You might want to start with a world that is a bit smaller than the default of 50x50, just to make it run faster, e.g. enter ipdm0 -DworldSize=40 -DnumBugs=1600 & Note the C_f will vary around approximately 0.35 or so. (The exact value is in the paper.) Now try some different b values...this controls the amount of "temptation" payoff for defectors playing cooperators. What effect does higher/lower b values have on C_f? NB: The easiest way to try multiple b values is to set it on the run command, run, quit, then bring back the command (with the arrow keys), change the b value, and restart. ipdm0 -DworldSize=100 -DnumBugs=10000 -Db=1.7 -DfractionC=0.5 & ipdm0 -DworldSize=100 -DnumBugs=10000 -Db=1.7 -DfractionC=0.6 & ... Note that some versions of this program crash if you set the b value via the gui before taking the first step!! Note that if you end up with all one type (e.g., all defectors), you can use the left mouse button to flip some to the other type... just click on the cells in the world display when the model is in STOP (pause) state. Next, go back to b=1.9 and run the model for a 100 or so cycles to get to the "equilibrium" condition. Now change the updating from sync=1 to sync=0. This changes to the asynchronous updating described in the Huberman and Glance (H&G) article. Note what happens to C_f. This is what led H&G to critique the claims made by Nowak and May. However, Nowak etal. responded to H&G. Try setting the b value lower, e.g., b=1.5 or 1.3, but with sync=0 still. That is updating is still asynchronous, but the temptation to defect is lower. If need be, use the left-mouse clicks to introduce some cooperators into the world, e.g. a small cluster of or 20 or so in the middle. How big does the cluster have to be to estblish cooperation? What about different "shapes" for the initial cooperator clusters? In short: whether cooperation can flourish or not depends on a number of factors, not just whether the updating is synchronous or asynchronous. But it is certaintly true that the update method is an important factor. There are other updating schedules than the ones considered here. Scott Page will talk more about update schedules in one of his lectures. ---------------------------------------------------------------------- In this exercise we will focus on some experiments with the Epstein model implemented in the directory /users/rlr/SwarmStuff/CSCS-Demos/IPDm0 which implements, more or less, the model described in: Zones of Cooperation in Demographic Prisoner's Dilemma. Joshua M. Epstein Santa Fe Institute Working Paper SFI-97-12-094 (1997). A later version appeared in: Complexity, Vol 4, No. 2, pp36-48. Agents are Cooperators (C) or Defectors (D). You can set the fraction of C at start from 0 to 1. The strategies are distributed randomly in a 2D world. To specify the Epstein model, just start with the number of Agents < the number of cells in the world (ie < worldSize * worldSize). Agents play one round when they meet. Thus its not an ``iterated'' prisoner's dilemma, except across generations. Payoffs are C-C 1,1 C-D 0,b D-C b,0 D-D 0,0 b is the parameterized tempatation payoff. It can be changed ``on the fly'' via the GUI. Note that the above payoff scheme is not exactly what Epstein used, but by changing b, and manipulating the metabolic rate and the metabEachStep parameters, one can get payoff regimes that capture the essential relationships Epstein specifies through the more flexible full T,R,P and S payoff table. Each ``generation'' each agent plays some or all of its neighbor agents, and both the agent and its neighbors accumulate scores from those plays. Agents then either give birth and die in the Epstein, based on how well they have been doing, which is summarized in their wealth attributes. Agents are displayed on a 2D raster. There are two color schemes, controlled by changing the value of the ColorScheme parameter: ColorScheme ----------- 0 two colors, C = Blue, D = Red 1 A 4-color scheme: Strategy(t) Strategy(t=1) Blue C C Red D D Yellow C D Green D C Mouse clicks on agents in the raster display produce these effects: MB1 (left): toggle type MB3 (right): probe that agent, so you can watch its instance variables (internal state) change from step to step. These parameters can be set only at the start of a run, before agents are created: Parameter Relevant Model --------- -------------- worldSize both numBugs both fractionC both minVision, maxVision Epstein These can be set at any time: ColorScheme both b both birthTh Epstein offspringShare Epstein mRate Epstein metabEachStep Epstein maxAge Epstein mutRate Epstein sync both The function of all these parameters are explained below. In this model, each ``generation'' each agent does the following: 1. it looks within its vision range (a square region around it) for any open sites, and of those found, it moves to a random one. 2. it looks for agents in its 8 (Moore-)neighborhood, and from any there, it picks *one* at random to play one PD game. Both agents add their payoffs from that game to their cummulative wealth. if metabEachStep == 0, and the agent plays at least one game, then each (ie the agent and the one its plays) decrements its wealth by mRate. if metabEachStep == 1, then the agent being moved/updated decrements its wealth whether it played another agent or not. (it may not play another because its 8 neighboring cells may all be empty.) 3. the agent then checks to see if its wealth > birthTh (birth threshold), and if it is, and if there is an open site in its vision range, it creates an offspring. The parent wealth is split giving wealth * offspringShare to the offspring, the parent keeping the rest. The offspring is a clone if muRate is 0, otherwise its strategy is changed with probability == mutRate. 4. if the agent's wealth < 0, or if the agent's age > maxAge, the agent is marked to die, and is killed off *at the end of the generation*. 5. the agent's age is incremented by one. There is a metabolic rate, mRate, which is an amount that is decremented from an agent's wealth each time it interacts with another agent (if metabEachStep=0), or each time they are active (if metabEachStep=1). Other relevant parameters: - maxVision, minVision initial agents are created with vision uniformly distributed in this range. Here is a typical way to start it: ipdm0 -DX=30 -DN=90 -DfractionC=0.2 -DmRate=0.3 -Db=2.0 -DmaxAge=200 but usually the agents all die off fairly fast! One exercise, then, is to find some parameter settings in which we get a stable, or at least meta-stable or moderately cycling, mixed population of cooperators and defectors. So try some various parameter settings, see what happens, then try to reason about what might work better, and try that! You might want to try some smaller worlds, so the runs go faster. After you find some parameters that seem to work, then you can try them on larger worlds to see if it matters. (But don't try it on worlds that are too small, otherwise there won't be room for accidental swings in population sizes without having extinctions!) Here are a few I did: These fills up with a mix, but then the cooperators slowly die, after which the defectors die: ipdm0 -DX=20 -DN=300 -DfractionC=0.9 -Db=1.9 -DmRate=0.5 -DbirthTh=50 ipdm0 -DX=20 -DN=300 -DfractionC=0.9 -Db=1.7 -DmRate=0.5 -DbirthTh=50 ----------------------------------------------------------------------- ----------------------------------------------------------------------- How to make your own copy of this model (on CSCS machines) To get a copy of the source codes for this model into your own directory space on the CSCS computers, do something like this: Make a directory IPDm0 in your home dir: cd mkdir IPDm0 cd IPDm0 Copy the program source files into that new directory. NB the dot (.) at the end of the cp commands: cp /users/rlr/SwarmStuff/CSCS-Demos/IPDm0/Makefile . cp /users/rlr/SwarmStuff/CSCS-Demos/IPDm0/*.h . cp /users/rlr/SwarmStuff/CSCS-Demos/IPDm0/*.m . Use the linux make command to compile and link the program: make You should see a lot of compiler commands go by, but it should start and end like this: badger-IPDm0$ make gcc -c -g -O2 -march=i386 -mcpu=i686 -Wall -Wno-import -Wno-protocol ... path -Wl,/usr/lib/swarm -Wl,--rpath -Wl,/usr/lib/swarm -Wl,--rpath -Wl,/usr/lib -Wl,--rpath -Wl,/usr/X11R6/lib badger-IPDm0$ That is, there should be no lines that have ERROR messages. (There will be one "warning" message...that is ok.) Now if you list files ll you should see all the *.h *.m files along with *.o files and the executable program, m0 . You can thus run that version by typing (in that IPDm0 directory): ./m0 & ------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- ***** Don't peek below here ***** ------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- If you want to find your own, without contamination from some things I tried, don't read below here until you have tried your own sets of experiments! This seems to work, i.e., give a mixed population that lasts for a long time: ipdm0 -DX=25 -DN=300 -DfractionC=0.9 -Db=1.3 -DmRate=0.3 -DbirthTh=20 It does seem to die off eventually, alas. But maybe try a few of these--sometimes it goes to allC, sometimes to other things: ipdm0 -DX=20 -DN=300 -DfractionC=0.9 -Db=1.3 -DmRate=0.3 -DbirthTh=20