Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

The Random Class.
Lecture 4 More on Java® Data Types, Control Structures.
Chapter 6 Queues and Deques.
CS18000: Problem Solving and Object-Oriented Programming.
Generating Random Numbers
Efficiency of Algorithms
—————————— CACI Products Company ————————————————————————————— SimScript II.5 —————————————— 3-1 Day 2 Section 3 - Introduction to Process Simulation –Modeling.
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
Sampling: Final and Initial Sample Size Determination
A Java API Package java.security  The Java Security Package contains classes and interfaces that are required by many Java programs.  This package is.
Random Number Generators. Why do we need random variables? random components in simulation → need for a method which generates numbers that are random.
Simulation Where real stuff starts. ToC 1.What, transience, stationarity 2.How, discrete event, recurrence 3.Accuracy of output 4.Monte Carlo 5.Random.
Chapter 7 – Arrays.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
1 Software Testing and Quality Assurance Lecture 24 – Testing Interactions (Chapter 6)
C Lecture Notes Functions (Cont...). C Lecture Notes 5.8Calling Functions: Call by Value and Call by Reference Used when invoking functions Call by value.
UNIT II Decision Making And Branching Decision Making And Looping
Java Unit 9: Arrays Declaring and Processing Arrays.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Sampling. Concerns 1)Representativeness of the Sample: Does the sample accurately portray the population from which it is drawn 2)Time and Change: Was.
Standard Statistical Distributions Most elementary statistical books provide a survey of commonly used statistical distributions. The reason we study these.
Chapter 6 Iteration.  Executes a block of code repeatedly  A condition controls how often the loop is executed while (condition) statement  Most commonly,
More Object Concepts Chapter 4.  Our class is made up of several students and each student has a name and test grades  How do we assign the variables.
The CarryDrop Model (Steps 19-24) : A RePast Tutorial by John Murphy by Junjie Sun 8/16/2004 Department of Economics Iowa State University.
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Chapter 6: Iteration Part 1. To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To understand.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
Problem of the Day  Why are manhole covers round?
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Lecture 2 Forestry 3218 Lecture 2 Statistical Methods Avery and Burkhart, Chapter 2 Forest Mensuration II Avery and Burkhart, Chapter 2.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
2Object-Oriented Program Development Using C++ 3 Basic Loop Structures Loops repeat execution of an instruction set Three repetition structures: while,
Controlling Program Flow. Data Types and Variable Declarations Controlling Program Flow.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 7. Control Charts for Attributes
1 On (computational) simplicity We are trying to teach not just Java, but how to think about problem solving. Computer science has its field called computational.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Prof. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2, Nils.
KIC/Computer Programming & Problem Solving 1.  Header Files  Storage Classes  Scope Rules  Recursion Outline KIC/Computer Programming & Problem Solving.
Grouping objects Iterators. Iterator type Third variation to iterate over a collection Uses a while loop and Iterator object But NO integer index variable.
Lesson 6 – Libraries & APIs Libraries & APIs. Objective: We will explore how to take advantage of the huge number of pre-made classes provided with Java.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Prof. Dr. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2,
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
int [] scores = new int [10];
Introduction to Computational Modeling of Social Systems Nils Weidmann Center for Comparative and International Studies (CIS) Seilergraben 49, Room E.3,
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
1 Integrating Repast Library and Running RePast Examples using JBuilder X 07/19/2004 by Deddy Koesrindartoto Department of Economics Iowa State University.
Creating a RePast Model Introduction, (Sim)Model Object, CarryDrop.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
CIS199 Test Review 2 REACH.
Software Development Java Classes and Methods
Lecture 5: Some more Java!
Counted Loops.
A Framework for Automatic Resource and Accuracy Management in A Cloud Environment Smita Vijayakumar.
Chapter 5 - Functions Outline 5.1 Introduction
Smita Vijayakumar Qian Zhu Gagan Agrawal
int [] scores = new int [10];
Introduction to RePast and Tutorial I
Loops CGS3416 Spring 2019 Lecture 7.
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2, Nils Weidmann, CIS Room E.3, Lecture, December 14, 2004 RePast Tutorial II

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

3 Three crucial questions: 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 Harnessing Complexity)

4 Experimental dimensions 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 ALLC TFT ALLD ATFT TFT ALLD In each time period, a player interacts with four other random players.

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

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

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

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

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

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

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

13 Markovian vs. asynchronous adaptation tt-1 Markovian asynchronous

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

15 How to work with random numbers RePast full-fledged random number generator: uchicago.src.sim.util.Random Encapsulates the Colt library random number distributions: 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 Computers normally cannot generate real random numbers “Random number generators should not be chosen at random” - Knuth (1986) A simple example (Cliff RNG): X 0 = 0.1 X n+1 = |100 ln(X n ) mod 1| x 1 = x 2 = x 3 = x 4 = x 5 = x 6 = x 7 = x 8 = x 9 = x 10 = x 11 =

17 “True” random numbers New service offered by the University of Geneva and the company id Quantique No (yet) integrated into RePast

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

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

20 Custom random number generation 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; 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(); } } seeds

21 How to build a model (2) 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()

22 SimModelImpl 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"}; }

23 SimModelImpl (cont.) public String getName() { return "Example Model"; } public void begin() { Agent a1 = new Agent(a1Strategy); 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(); } introspection

24 SimModelImpl (cont.) 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); }

25 How to use a schedule 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

26 Different types of actions 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");

27 Schedule in SimpleModel 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(); }

28 Scheduling actions on lists An action can be scheduled to be executed on every element of a list: public class Agent { public void step() { } } schedule.scheduleActionBeginning(1, agentList, "step"); is equivalent to: public void step() { for(Iterator it = agentList.iterator(); it.hasNext();) { Agent agent = (Agent) it.next(); agent.step(); } } schedule.scheduleActionBeginning(1, model, "step"); step() in SimpleModel step() in Agent

29 Different types of scheduling scheduleActionAt(double at, …) executes at the specified clock tick scheduleActionBeginning(double begin, …) executes starting at the specified clock tick and every tick thereafter scheduleActionAtInterval(double in, …) executes at the specified interval scheduleActionAtEnd(…) executes the end of the simulation run scheduleActionAtPause(…) executes when a pause in the simulation occurs

30 Homework C Modify the EvolIPD program by introducing a selection mechanism that eliminates inefficient players. The current adaptation() method should thus be modified such that the user can switch between the old adaptation routine, which relies on strategic learning, and the new “Darwinian” selection mechanism. The selection mechanism should remove the 10% least successful players from the agentList after each round of interaction. To keep the population size constant, the same number of players should be “born” with strategies drawn randomly from the 90% remaining players. Note that because it generates a population-level process, the actual selection mechanism belongs inside the Model class rather than in Player. Does this change make any difference in terms of the output?