repast tutorial iv
DESCRIPTION
RePast Tutorial IV. Week 8. Today’s agenda. More on the GUI mode… Probes How to create property descriptors How to create custom actions Introducing the batch mode How to use parameters and parameter files How to collect data ExperIPD. Probes. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/1.jpg)
Introduction to Computational Modeling of Social Systems
Prof. Lars-Erik CedermanETH - Center for Comparative and International Studies (CIS)
Seilergraben 49, Room G.2, [email protected] Deiwiks, CIS Room E.3, [email protected]
http://www.icr.ethz.ch/teaching/compmodels
RePast Tutorial IV
Week 8
![Page 2: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/2.jpg)
2
Today’s agenda
• More on the GUI mode…– Probes– How to create property descriptors– How to create custom actions
• Introducing the batch mode– How to use parameters and parameter
files– How to collect data
• ExperIPD
![Page 3: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/3.jpg)
3
Probes
• Probes allow the user to view and manipulate single agents
• Require the display surface to be “probeable”
• Variables become available through introspection using the get-set-methods (with set-methods necessary for changes)
![Page 4: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/4.jpg)
4
How to create property descriptors
• To adjust parameters at startup or when the simulation is paused
• Can be applied to both models and agents
• Setup through the pre-defined descriptors variable of SimpleModel
![Page 5: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/5.jpg)
5
How to create property descriptors (cont.)
• Drop-down list:public void setup() { super.setup();
Hashtable h1 = new Hashtable(); h1.put(new Integer(0), "Von Neumann"); h1.put(new Integer(1), "Moore"); ListPropertyDescriptor pd = new ListPropertyDescriptor("Type", h1); descriptors.put("Type", pd);}
public void setType(int type) { this.type = type;}
![Page 6: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/6.jpg)
6
How to create property descriptors (cont.)
• Numerical slider:
public void setup() { super.setup();
RangePropertyDescriptor d = new RangePropertyDescriptor("NumAgents", 10, 100, 20); descriptors.put("NumAgents", d);}
public void setNumAgents(int numAgents) { this.numAgents = numAgents;}
![Page 7: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/7.jpg)
7
How to create custom actions
• Modify the simulation while it is running
• Setup through modelManipulator variable of SimpleModel
• Works for buttons, check boxes, sliders, and arbitrary Java components
![Page 8: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/8.jpg)
8
How to create custom actions (cont.)
• modelManipulator.addButton("Clear Space", new ActionListener() { public void actionPerformed(ActionEvent e){ space.clear(); }});
• modelManipulator.addSlider("Slider", 0, 100, 10, new SliderListener());
• modelManipulator.addCheckBox("Show/Hide", new CheckBoxListener(), false);
• modelManipulator.addComponent(Component c);
![Page 9: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/9.jpg)
9
Failed invasion of TFT in ALLD-World
ALLD
ALLD ALLD ALLD
ALLD
TFT
ALLD ALLD
ALLD3
3
3
3 84
4
4
4+4+4+8 4
= 5.0
3+3+3+3 4
= 3.0
ALLD:
TFT:
![Page 10: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/10.jpg)
10
Successful invasion of two TFT players in ALLD-World
ALLD
ALLD ALLD ALLD
ALLD
TFT
ALLD ALLD
TFT
4+4+4+8 4
= 5.0
3+3+3+12 4
= 5.25
ALLD:
TFT:
ALLD
ALLD
ALLD3
3
3
12 123
3
3 84
4
4
![Page 11: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/11.jpg)
11
Further spread of TFT players in ALLD-World
TFT
ALLD TFT TFT
ALLD
TFT
TFT TFT
TFT
ALLD
ALLD
TFT
![Page 12: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/12.jpg)
12
Separating GUI and batch modes
Modelextends
SimpleModel
ModelGUIextendsModel
ModelBatchextendsModel
ExperIPDGraphIPD,GridIPD
![Page 13: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/13.jpg)
13
Subclassing a batch model
class Model extends SimpleModel { model variables
setup()
buildModel()
step()
main()}
class ModelBatch extends Model{ Batch variables (data recorder)
setup() { super.setup(); params = ... }
buildModel() { super.buildModel(); create data recorder }
step() { super.step(); record data }
main() { init.loadModel(m, "params.txt", true); }}
Parameter file
Batch mode
![Page 14: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/14.jpg)
14
How to use parameters
• Different purpose depending on context:– Batch mode: allow variables to be
changed through parameter files– GUI mode: show the variables in the
control panelpublic void setup() { super.setup(); params = {"NumPlayers", "PALLC", "PTFT", "PATFT", "PALLD", "PAdapt"};}
![Page 15: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/15.jpg)
15
How to use parameters (cont.)
• Requires accessor methods:
public void setup() { super.setup(); params = {"Variable", ...}}
public double getVariable() { return value;}
public void setVariable(double value) { this.value = value;}
Setters only required to
allow modification
![Page 16: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/16.jpg)
16
How to use parameter files
• Different effects depending on context:– GUI mode: set initial values– Batch mode: allow to run sweeps
• Usually defined in a file named params.txt
• Runs the simulation with values of 10, 20, and 30:
runs: 1Variable { start: 10 end: 30 incr: 10}
![Page 17: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/17.jpg)
17
How to use parameter files (cont.)
• Multiple parameters:
• Nestingruns: 10Food { start: 10 end: 30 incr: 10}
MaxAge { start: 10 end: 30 incr: 10}
runs: 1Food { start: 10 end: 30 incr: 10 { runs: 10 MaxAge { start: 0 end: 40 incr: 1 } }}
![Page 18: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/18.jpg)
18
How to use parameter files (cont.)
• Additional keywords:– set
defines a single numerical value as a constant for the entire collection of batch runs.
– set_booleandefines a boolean value (true / false).
– set_stringdefines a string value (without any white space).
– set_list,set_boolean_list, set_string_list define a space-separated list of values. A batch simulation will iterate through the list.
![Page 19: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/19.jpg)
19
How to collect data
• Recording of simulation states to:– archive simulation runs– further process the data into third-party
packages (e.g. Excel, Stata, SPSS, SAS, ...)
• Output format: Text files (comma, space or tab delimited)
![Page 20: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/20.jpg)
20
How to collect data (cont’d)
• Prepare for the measurements in buildModel()• Determine the duration of the simulations:
setStoppingTime(n);
• Create the data recorder with output to file data.txt:recorder = new DataRecorder(“./data.txt”,this);
• Add numeric streams using introspection:recorder.createNumericaDataSource(“X”,this,”computeX”);
• The output can be formatted with x number of digits before the decimal point, and y after…createNumericaDataSource(“X”,this,”computeX”,x,y);
![Page 21: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/21.jpg)
21
How to collect data (cont’d)
• Using introspection requires a method delivering the values
• It is also possible to use inner classes (see the Repast How-To Documentation)
• The data recorder has to be told to record and to write the data to file:recorder.record();
recorder.writeToFile();
• The user can change the data delimiter:recorder.setDelimiter(“ “);
![Page 22: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/22.jpg)
22
Typical output fileTimestamp: May 31, 2004 6:09:01 PM
Neighborhood: 0
NumOfTimeSteps: 200
PALLC: 0.25
PALLD: 0.25
PATFT: 0.25
PAdapt: 0.2
PTFT: 0.25
WorldSize: 16
"run" "tick" "Topology" "RngSeed" "ALLC" "TFT" "ATFT" "ALLD" "Payoff"
1 200.0 0 1 0.0 256.0 0.0 0.0 3.0000
2 200.0 0 2 0.0 256.0 0.0 0.0 3.0000
3 200.0 0 3 0.0 256.0 0.0 0.0 3.0000
4 200.0 0 4 0.0 256.0 0.0 0.0 3.0000
…
59 200.0 2 19 0.0 0.0 0.0 256.0 1.0000
60 200.0 2 20 0.0 0.0 0.0 256.0 1.0000
End Time: May 31, 2004 6:09:16 PM
![Page 23: RePast Tutorial IV](https://reader033.vdocuments.site/reader033/viewer/2022051416/568134a3550346895d9ba588/html5/thumbnails/23.jpg)
23
Replication results (N = 200)
0 6020 40
Number ofTFT-dominatedruns
Initial numberof TFT players