prof. dr. lars-erik cederman eth - center for comparative and international studies (cis)...
DESCRIPTION
3 What is RePast? Recursive Porous Agent Simulation Toolkit Repast is an open-source software framework for creating agent-based simulations using Java Initially developed by the Social Science Research Computing at the University of Chicago Will be further developed by the RePast Organization for Architecture and Development (ROAD) and Argonne National LaboratoryTRANSCRIPT
![Page 1: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/1.jpg)
Prof. Dr. Lars-Erik CedermanETH - Center for Comparative and International Studies (CIS)
Seilergraben 49, Room G.2, [email protected] Weidmann, CIS Room E.3 [email protected]
http://www.icr.ethz.ch/teaching/compmodels
Lecture, December 7, 2004
Introduction to Computational Modeling of Social Systems
RePast Tutorial I
![Page 2: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/2.jpg)
2Today’s agenda
• The RePast toolkits and its features• The Iterated Prisoner‘s Dilemma• How to build a model (1)• SimpleIPD
![Page 3: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/3.jpg)
3What is RePast?
• Recursive Porous Agent Simulation Toolkithttp://repast.sourceforge.net
• Repast is an open-source software framework for creating agent-based simulations using Java
• Initially developed by the Social Science Research Computing at the University of Chicago
• Will be further developed by the RePast Organization for Architecture and Development (ROAD) and Argonne National Laboratory
![Page 4: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/4.jpg)
4Why RePast?
• Alternatives: Swarm, Ascape, NetLogo...• “RePast is at the moment the most suitable
simulation framework for the applied modeling of social interventions based on theories and data” (2004):http://jasss.soc.surrey.ac.uk/7/1/6.html
• Modeled on Swarm but easier to use and better documented
• Important criteria:– abstraction, ease of use and user-friendliness– flexibility and extensibility– performance and scalability– support for modeling, simulation & experimentation– Interoperability (GIS, statistical packages, …)
![Page 5: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/5.jpg)
5
What does RePast offer?
• Skeletons of agents and their environment
• Graphical user interface• Scheduling of simulations• Parameters management• Behavior display• Charting• Data collection• Batch and parallel runs• Utilities and sample models
![Page 6: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/6.jpg)
6Tutorial Sequence
December 7 SimpleIPD: strategy space
December 14 EvolIPD: RWRDecember 21 GraphIPD: charts
and GUIGridIPD: 2DK
January 11 ExperIPD: batch runs and parameter sweeps
![Page 7: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/7.jpg)
7
Iterated Prisoner’s Dilemma
• Cohen, Riolo, and Axelrod. 1999. “The Emergence of Social Organization in the Prisoner's Dilemma” (SFI Working Paper 99-01-002)http://www.santafe.edu/research/publications/wpabstract/199901002
• In The Evolution of Cooperation, Robert Axelrod (1984) created a computer tournament of IPD– cooperation sometimes emerges– Tit For Tat a particularly effective strategy
![Page 8: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/8.jpg)
8
Prisoner’s Dilemma Game
Column: C D
C 3,3 0,5Row:
D 5,0 1,1
![Page 9: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/9.jpg)
9
One-Step Memory Strategies
C
DC
D
p
q
Memory:C
D
Strategy = (i, p, q) i = prob. of cooperating at t = 0
p = prob. of cooperating if opponent cooperated
q = prob. of cooperating if opponent defected
t-1 t
![Page 10: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/10.jpg)
10The Four Strategies
Name i p q
ALLC 1 1 1
TFT 1 1 0
ATFT 0 0 1
ALJD 0 0 0
![Page 11: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/11.jpg)
11TFT meets ALLD
t0 1 2 3 4
Row(TFT)
Column(ALLD)
i=1
i=0
p=1; q=0
0
5
1 1
1 1 1
1
= 8
= 3+ + +
+ + +
D
C
D
C
D
D
D
D
D
D
p=0; q=0
CumulatedPayoff
![Page 12: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/12.jpg)
12
Payoffs for 4x4 strategies
Own strategy
Other‘s strategyALLC TFT ATFT ALLD
pay/move
sum
pay/move
sum
pay/move
sum
pay/move
sum
ALLC 333312
333312
00000
00000
TFT 333312
333312
01539
01113
ATFT 555520
51039
13138
10001
ALLD 555520
51118
155516
11114
![Page 13: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/13.jpg)
13
How to build a model (1)
• Extending the SimpleModel class with our own model class:
import uchicago.src.sim.engine.SimpleModel;
public class MyModel extends SimpleModel {...
}
![Page 14: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/14.jpg)
14
Setting up the simulation
import uchicago.src.sim.engine.SimpleModel;
public class MyModel extends SimpleModel {public static final int TFT = 1;public static final int ALLD = 3;
private int a1Strategy = TFT;private int a2Strategy = ALLD;
...
public void setup() {super.setup();a1Strategy = TFT;a2Strategy = ALLD;
}
public void buildModel() {super.buildModel();Agent a1 = new Agent(a1Strategy);Agent a2 = new Agent(a2Strategy);agentList.add(a1);agentList.add(a2);
}}
Called when the
simulation is first started and when
setup button pressed
Executed every time the simulation is
run
SimInit.loadModel()
![Page 15: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/15.jpg)
15Running the simulation
import uchicago.src.sim.engine.SimpleModel;
public class MyModel extends SimpleModel {...
public void setup() {...}
public void buildModel() {...}
public void preStep() {...}
public void step() {super.step();
for (Iterator it = agentList.iterator(); it.hasNext();) {
Agent agent = (Agent) iterator.next(); agent.play(); }
}
public void postStep() {...}}
Executed at every time
step
![Page 16: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/16.jpg)
16Model parameters
import uchicago.src.sim.engine.SimpleModel;
public class MyModel extends SimpleModel {public static final int TFT = 1;public static final int ALLD = 3;
private int a1Strategy = TFT;private int a2Strategy = ALLD;
public MyModel() {params = new String[] {“A1Strategy”};name = “Example Model”;}
...
public void setA1Strategy(int strategy) {this.a1Strategy = strategy;}
public int getA1Strategy() {return a1Strategy;}}
Introspection
![Page 17: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/17.jpg)
17SimpleModel methods
• setStoppingTime(long time)set the time at which the current simulation run will stop
• setRngSeed(long seed)set the seed for the random number generator (default: 1)
• getNextIntFromTo(int from, int to)returns the next random double between from and to (exclusive)
• getNextDoubleFromTo(double from,double to)returns the next random double between from and to (exclusive)
• atPause() will be executed whenever your simulation is paused
• atEnd() will be executed whenever your simulation ends
![Page 18: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,](https://reader036.vdocuments.site/reader036/viewer/2022083119/5a4d1b0d7f8b9ab05998cc19/html5/thumbnails/18.jpg)
18SimpleModel fields
• boolean isGui true if the simulation is running in GUI mode, false if running in batch mode
• long startAtthe time step at which to start executing the preStep(), step(), postStep() actions (default: 1)
• Schedule schedulecan be used to add your own actions to the schedule...
• For the full list, consult the RePast API:http://repast.sourceforge.net/docs/api/