prof. dr. lars-erik cederman eth - center for comparative and international studies (cis)...

18
Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2, [email protected] Nils Weidmann, CIS Room E.3 [email protected] http:// www.icr.ethz.ch/teaching/compmodels Lecture, December 7, 2004 Introduction to Computational Modeling of Social S RePast Tutorial I

Upload: emery-tucker

Post on 17-Jan-2018

212 views

Category:

Documents


0 download

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 Laboratory

TRANSCRIPT

Page 1: Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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/