repast tutorial ii
play

RePast Tutorial II Prof. Lars-Erik Cederman ETH - Center for - PowerPoint PPT Presentation

Introduction to Computational Modeling of Social Systems RePast Tutorial II Prof. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2, lcederman@ethz.ch Christa Deiwiks, CIS Room E.3,


  1. Introduction to Computational Modeling of Social Systems RePast Tutorial II Prof. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2, lcederman@ethz.ch Christa Deiwiks, CIS Room E.3, deiwiks@icr.gess.ethz.ch http://www.icr.ethz.ch/teaching/compmodels Week 6

  2. Today’s agenda 2 • IPD: Experimental dimensions • EvolIPD model • Random numbers • How to build a model (2) • Scheduling

  3. Three crucial questions: 3 1. Variation : What are the actors’ characteristics? 2. Interaction : Who interacts with whom, when and where? 3. Selection : Which agents or strategies are retained, and which are destroyed? (see Axelrod and Cohen. 1999. Harnessing Complexity )

  4. Experimental dimensions 4 • 2 strategy spaces: B, C • 6 interaction processes: RWR, 2DK, FRN, FRNE, 2DS, Tag • 3 adaptive processes: Imit, BMGA, 1FGA

  5. “Soup-like” topology: RWR 5 In each time period, ATFT ALLC a player interacts ALLD ALLD with four other random players. TFT TFT ALLC

  6. 2D-Grid Topology: 2DK 6 ALLD ALLD ALLD The players are arranged on a fixed torus and interact TFT TFT ALLC with four neighbors in the von-Neumann neighborhood. TFT ALLC ATFT

  7. Fixed Random Network: FRN 7 The players have four random neighbors ATFT TFT ALLC in a fixed random ATFT network. The relations do not have to be symmetric. ALLD ALLD TFT ALLC TFT

  8. Adaptation through imitation 8 Imitation ATFT ALLC ALLD ALLD TFT TFT? ALLC Neighbors at t

  9. Adaptation with BMGA Comparison error (prob. 0.1) 9 Genetic adaptation 6.0 Fixed spatial neighborhood 2.8 2.2 9.0 0.8

  10. BMGA continued Copy error (prob. 0.04 per “bit”) 10 Genetic adaptation 6.0 Fixed spatial p =0; q =0 => p =1 ; q =0 neighborhood 2.8 6.0 9.0 0.8

  11. Tutorial Sequence 11 November 21 SimpleIPD: strategy space Today EvolIPD: RWR December 05 GraphIPD: charts and GUI GridIPD: 2DK December 12 ExperIPD : batch runs and parameter sweeps

  12. EvolIPD: flowchart 12 setup() buildModel() resetPlayers() interactions() adaptation() play() play() reportResults() remember() remember() step() addPayoff() addPayoff()

  13. Markovian vs. asynchronous adaptation 13 Markovian t-1 t asynchronous

  14. Going sequential 14 private void stepMarkovian() { // We carry out four sub-activities: // Reset the agents' statistics // Loop through the entire agent list for ( int i = 0; i < numPlayers; i++) { // Pick the agent final Player aPlayer = (Player) agentList.get(i); private void stepAsynchronous() { resetPlayer(aPlayer); // We carry out four sub-activities: } for ( int i = 0; i < numPlayers; i++) { // Pick an agent at random // Let them interact with their neighbors final Player aPlayer = (Player) agentList.get( for ( int i = 0; i < numPlayers; i++) { this .getNextIntFromTo(0, numPlayers - 1)); final Player aPlayer = (Player) agentList.get(i); interactions(aPlayer); // Reset the agent's statistics } resetPlayer(aPlayer); // FIRST STAGE OF DOUBLE BUFFERING! // Let it interact with its neighbors // Let all agents calculate their adapted type first interactions(aPlayer); for ( int i = 0; i < numPlayers; i++) { // Let it adapt final Player aPlayer = (Player) agentList.get(i); adaptation(aPlayer); adaptation(aPlayer); } // Let it update its new type updating(aPlayer); // SECOND STAGE OF DOUBLE BUFFERING! } // Second, once they know their new strategy, // let them update to the new type reportResults(); // Report some statistics for ( int i = 0; i < numPlayers; i++) { } final Player aPlayer = (Player) agentList.get(i); updating(aPlayer); } reportResults(); // Report some statistics }

  15. How to work with random numbers 15 • RePast full-fledged random number generator: uchicago.src.sim.util.Random • Encapsulates the Colt library random number distributions: http://dsd.lbl.gov/~hoschek/colt/ • Each distribution uses the same random number stream, to ease the repeatability of a simulation • Every distribution uses the MersenneTwister pseudo-random number generator

  16. Pseudo-random numbers 16 • Computers normally cannot generate real random numbers • “Random number generators should not be chosen at random” - Knuth (1986) • A simple example (Cliff RNG): x 1 = 0.25850929940455103 x 2 = 0.28236111950289455 X 0 = 0.1 x 3 = 0.4568461655760814 x 4 = 0.3408562751932891 X n+1 = |100 ln(X n ) mod 1| x 5 = 0.6294370918024157 x 6 = 0.29293640856857195 140 x 7 = 0.7799729122847907 120 x 8 = 0.849608774153694 100 Frequency 80 x 9 = 0.29793011540822434 60 x 10 = 0.08963320319223556 40 20 x 11 = 0.2029456303939412 0 ... 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

  17. Simple random numbers distribution 17 • Initialization: Automatically standard Random.setSeed(seed); executed by deviation SimpleModel Random.createUniform(); Random.createNormal(0.0, 1.0); • Usage: mean standard deviation int i = Random.uniform.nextIntFromTo(0, 10); double v1 = Random.normal.nextDouble(); double v2 = Random.normal.nextDouble(0.5, 0.3); mean standard deviation

  18. Available distributions 18 • Beta • Normal (or Gaussian) • Binomial • Pareto • Chi-square • Poisson • Empirical (user- • Uniform defined probability • … Normal distribution function) • Gamma • Hyperbolic Beta • Logarithmic

  19. Custom random number generation 19 • May be required if two independent random number streams are desirable • Bypass RePast’s Random and use the Colt library directly: import cern.jet.random.*; import cern.jet.random.engine.MersenneTwister; public class TwoStreamsModel extends SimModel { Normal normal; Uniform uniform; seeds public void buildModel() { super .buildModel(); MersenneTwister generator1 = new MersenneTwister(123); MersenneTwister generator2 = new MersenneTwister(321); uniform = new Uniform(generator1); normal = new Normal(0.0, 1.0, generator2); } public void step() { int i = uniform.nextIntFromTo(0, 10); double value = normal.nextDouble(); } }

  20. How to build a model (2) 20 • If more flexibility is desired, one can extend SimModelImpl instead of SimpleModel • Differences to SimpleModel – No buildModel() , step() , ... methods – No agentList , schedule , params , ... fields – Most importantly: no default scheduling • Required methods: public void setup() public String[] getInitParam() public void begin() public Schedule getSchedule() public String getName()

  21. SimModelImpl 21 import uchicago.src.sim.engine.Schedule; import uchicago.src.sim.engine.SimInit; import uchicago.src.sim.engine.SimModelImpl; public class MyModelImpl extends SimModelImpl { public static final int TFT = 1; public static final int ALLD = 3; private int a1Strategy = TFT; private int a2Strategy = ALLD; private Schedule schedule; private ArrayList agentList; public void setup() { a1Strategy = TFT; a2Strategy = ALLD; schedule = new Schedule(); agentList = new ArrayList(); } public String[] getInitParam() { return new String[]{"A1Strategy"}; }

  22. SimModelImpl (cont.) 22 public String getName() { return "Example Model"; } public void begin() { Agent a1 = new Agent(a1Strategy); introspection Agent a2 = new Agent(a2Strategy); agentList.add(a1); agentList.add(a2); schedule.scheduleActionBeginning(1, this , "step"); } public void step() { for (Iterator iterator = agentList.iterator(); iterator.hasNext();) { Agent agent = (Agent) iterator.next(); agent.play(); } }

  23. SimModelImpl (cont.) 23 public String[] getInitParam() { return new String[]{"A1Strategy"}; } public int getA1Strategy() { return a1Strategy; } public void setA1Strategy( int strategy) { this .a1Strategy = strategy; } public static void main(String[] args) { SimInit init = new SimInit(); SimModelImpl model = new MyModelImpl(); init.loadModel(model, null , false ); }

  24. How to use a schedule 24 • Schedule object is responsible for all the state changes within a Repast simulation schedule.scheduleActionBeginning(1, new DoIt()); schedule.scheduleActionBeginning(1, new DoSomething()); schedule.scheduleActionAtInterval(3, new ReDo()); tick 1: DoIt, DoSomething tick 2: DoSomething, DoIt tick 3: ReDo, DoSomething, DoIt tick 4: DoSomething, DoIt tick 5: DoIt, DoSomething tick 6: DoSomething, ReDo, DoIt

  25. Different types of actions 25 • Inner class class MyAction extends BasicAction { public void execute() { doSomething(); } } schedule.scheduleActionAt(100, new MyAction()); • Anonymous inner class schedule.scheduleActionAt(100, new BasicAction(){ public void execute() { doSomething(); } ); • Introspection schedule.scheduleActionAt(100, this , "doSomething");

  26. Schedule in SimpleModel 26 public void buildSchedule() { if (autoStep) schedule.scheduleActionBeginning(startAt, this ,"runAutoStep"); else schedule.scheduleActionBeginning(startAt, this , "run"); schedule.scheduleActionAtEnd( this , "atEnd"); schedule.scheduleActionAtPause( this , "atPause"); schedule.scheduleActionAt(stoppingTime, this , "stop", Schedule.LAST); } public void runAutoStep() { public void run() { preStep(); preStep(); autoStep(); step(); postStep(); postStep(); } } private void autoStep() { if (shuffle) SimUtilities.shuffle(agentList); int size = agentList.size(); for ( int i = 0; i < size; i++) { Stepable agent = (Stepable)agentList.get(i); agent.step(); } }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend