Programming for Social Scientists Lecture 6 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.

Slides:



Advertisements
Similar presentations
The Swarm Simulation System Je planmäßiger die Menschen vorgehen, desto wirksamer vermag sie der Zufall treffen. Katja Luther, Holger Meyer.
Advertisements

Process Management.
Operating Systems Lecture 7.
Programming for Social Scientists Lecture 8 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
T-3 Histograms. Histogram Basics A histogram is a special type of bar graph that measures the frequency of data Horizontal axis: represents values in.
Sampling Distributions (§ )
T T02-03 Histogram (Equal Classes) Purpose Allows the analyst to analyze quantitative data by summarizing it in sorted format, scattergram by.
Programming for Social Scientists Lecture 4 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Programming for Social Scientists Lecture 3 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Programming for Social Scientists Lecture 9 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Histograms & Summary Data.  Summarizing large of amounts of data in two ways: Histograms: graphs give a pictorial representation of the data Numerical.
Programming for Social Scientists Lecture 5 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Tina design review Main design decisions. Top level modules. Responsibilities. Phases A & B. Test plan. Time table.
Programming for Social Scientists Lecture 7 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
T T02-04 Histogram (User Selected Classes) Purpose Allows the analyst to analyze quantitative data by summarizing it in sorted format, scattergram.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Lesson 5 – Looking at the Output MATSim Tutorial, 2011, Shanghai 1.
Thinking Mathematically
Fundamental Graphics in R Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University.
Input for the Bayesian Phylogenetic Workflow All Input values could be loaded as text file or typing directly. Only for the multifasta file is advised.
STAT02 - Descriptive statistics (cont.) 1 Descriptive statistics (cont.) Lecturer: Smilen Dimitrov Applied statistics for testing and evaluation – MED4.
 Review homework Problems: Chapter 5 - 2, 8, 18, 19 and control chart handout  Process capability  Other variable control charts  Week 11 Assignment.
Statistics Chapter 9. Statistics Statistics, the collection, tabulation, analysis, interpretation, and presentation of numerical data, provide a viable.
Topics: Statistics & Experimental Design The Human Visual System Color Science Light Sources: Radiometry/Photometry Geometric Optics Tone-transfer Function.
Top-Down and Bottom-Up Scheduling in Swarm A comparison of implementations Paul E. Johnson University of Kansas.
The introduction to SPSS Ⅱ.Tables and Graphs for one variable ---Descriptive Statistics & Graphs.
CS1100: Computer Science and Its Applications Creating Graphs and Charts in Excel Martin Schedlbauer, Ph.D.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
1.1 EXPLORING STATISTICAL QUESTIONS Unit 1 Data Displays and Number Systems.
 Review homework Problems: Chapter 5 - 2, 8, 18, 19 and control chart handout  Process capability  Other variable control charts  Week 11 Assignment.
Entities and Objects The major components in a model are entities, entity types are implemented as Java classes The active entities have a life of their.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Chapter 5 The Binomial Probability Distribution and Related Topics.
CSC 205 Programming II Lecture 22 Carwash Simulation.
A Process Control Screen for Multiple Stream Processes An Operator Friendly Approach Richard E. Clark Process & Product Analysis.
Fundamentals of Data Analysis Lecture 3 Basics of statistics.
Goodness-of-Fit Chi-Square Test: 1- Select intervals, k=number of intervals 2- Count number of observations in each interval O i 3- Guess the fitted distribution.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
The Imaging Chain 1. What energy is used to create the image? 2. How does the energy interact with matter? 3. How is the energy collected after the interaction?
1 Topic 5 - Joint distributions and the CLT Joint distributions –Calculation of probabilities, mean and variance –Expectations of functions based on joint.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
2.1 Frequency distribution Histogram, Frequency Polygon.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
MDH Chapter 1EGR 252 Fall 2015 Slide 1 Probability and Statistics for Engineers  Descriptive Statistics  Measures of Central Tendency  Measures of Variability.
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,
1 of 7 Exercise 1 Populations, Histograms, Range & Simulations 45 minutes Presenter: Sebastian Tindall DQO Training Course Day 2.
Tables and Graphs. Graphs: Visual Display of Data X Axis: Independent Variable Y Axis: Dependent Variable.
Introduction to Computational Modeling of Social Systems Nils Weidmann Center for Comparative and International Studies (CIS) Seilergraben 49, Room E.3,
EOVSA Data and Database System J. McTiernan EOVSA Technical DesignMeeting 7-Nov-2011.
1 Integrating Repast Library and Running RePast Examples using JBuilder X 07/19/2004 by Deddy Koesrindartoto Department of Economics Iowa State University.
Graphs Class A Class B. Pictograph Types of Graphs Line Graphs Plots Circle Graph Histogram Single Double Stem & Leaf Line Single Double Box - and - Whisker.
Fundamentals of Data Analysis Lecture 3 Basics of statistics.
MTA ETA. Product Description A real-time simulation system that estimates the expected time that it will take a certain bus to arrive at an end- user’s.
Statistical Methods Michael J. Watts
Probability and Statistics
MT262A Review.
Swarm Idioms: Little Things Worth Knowing
Statistical Methods Michael J. Watts
Objective - To graph ordered pairs on the coordinate plane.
CHAPTER- 3.1 ERROR ANALYSIS.
Range, Width, min-max Values and Graphs
Probability and Statistics for Engineers
Sampling Distributions (§ )
Introduction to RePast and Tutorial I
Range, Width, min-max Values and Graphs
Simulate Multiple Dice
Presentation transcript:

Programming for Social Scientists Lecture 6 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson

POL SCI Cederman / Stefansson 2 Today's topics Graphical User Interfaces (GUIs) –graphs –control panels Example 1: GraphIPD Program that endows EvolIPD with a dynamic graph and a control panel. Example 2: Elevator

POL SCI Cederman / Stefansson 3 The Graphical User Interface Objects provided to create and manage –Line graphs –Histograms –Raster images –Digraphs Data collection, calculation and updating is provided through support objects to the GUI widgets

POL SCI Cederman / Stefansson 4 GraphIPD: Adding GUI main EZGraph ModelSwarm popList Tournament newList winner ControlPanel Observer Swarm

POL SCI Cederman / Stefansson 5 Creating a graph EZGraph class sets up line graph for either –Single agent or object –Collection of agents In both cases need –Name of sequence –Type of sequence {Count, Total, Average, Min, Max} –Target (object or collection) –Name of method to get data Agent Averager Collection

POL SCI Cederman / Stefansson 6 Graph IPD: File Structure main.m Model- Swarm.m Tourna- ment.m Tourna- ment.h Model- Swarm.h Observer- Swarm.m Observer- Swarm.h Player.m Player.h

POL SCI Cederman / Stefansson 7 GraphIPD: main.m #import #import "ObserverSwarm.h" int main(int argc,const char ** argv) { ObserverSwarm * observerSwarm; initSwarm(argc, argv); observerSwarm = [ObserverSwarm create: globalZone]; [observerSwarm buildObjects]; [observerSwarm buildActions]; [observerSwarm activateIn: nil]; [observerSwarm go]; return 0; }

POL SCI Cederman / Stefansson 8 GraphIPD: ObserverSwarm : GUISwarm { int displayFrequency; id displayActions; id displaySchedule; id modelSwarm; id numGraph; } +createBegin: (id) aZone; -createEnd; -buildObjects; -buildActions; -activateIn: (id)

POL SCI Cederman / Stefansson 9 Creating an ObserverSwarm createBegin,createEnd –Initialize memory and parameters buildObjects –Build ModelSwarem –Build graphs, rasters and probes buildActions –Define order and timing of GUI events activate

POL SCI Cederman / Stefansson 10 Step I: Initializing + createBegin: aZone { ObserverSwarm *obj; obj = [super createBegin: aZone]; obj->displayFrequency = 1; return obj; }

POL SCI Cederman / Stefansson 11 Step II: Creating objects -buildObjects { [super buildObjects]; modelSwarm = [ModelSwarm createBegin: self]; modelSwarm = [modelSwarm createEnd]; [modelSwarm buildObjects]; // cont'd

POL SCI Cederman / Stefansson 12 Step II: Creating objects (cont'd) numGraph = [EZGraph createBegin: self]; [numGraph setTitle: "Number of all-C"]; [numGraph setAxisLabelsX: "Time" Y: "Number"]; numGraph = [numGraph createEnd]; [numGraph createSequence: "all-C" withFeedFrom: modelSwarm andSelector: M(getNum0)]; [numGraph createSequence: "TFT" withFeedFrom: modelSwarm andSelector: M(getNum1)]; [numGraph createSequence: "aTFT" withFeedFrom: modelSwarm andSelector: M(getNum2)]; [numGraph createSequence: "all-D" withFeedFrom: modelSwarm andSelector: M(getNum3)]; [controlPanel setStateStopped]; return self; }

POL SCI Cederman / Stefansson 13 -buildActions { [super buildActions]; displayActions = [ActionGroup create: self]; [displayActions createActionTo: modelSwarm message: M(step)]; [displayActions createActionTo: numGraph message: M(step)]; [displayActions createActionTo: actionCache message: M(doTkEvents)]; displaySchedule = [Schedule createBegin: self]; [displaySchedule setRepeatInterval: 1]; displaySchedule = [displaySchedule createEnd]; [displaySchedule at: 0 createAction: displayActions]; return self; } Step III: Building actions

POL SCI Cederman / Stefansson 14 Step IV: Activating -activateIn: (id) swarmContext { [super activateIn: swarmContext]; // If modelSwarm also has activity schedule: // [modelSwarm activateIn: self]; [displaySchedule activateIn: self]; return [self getSwarmActivity]; }

POL SCI Cederman / Stefansson 15 Major Analysis classes EZGraph –Combines several objects to gather and display data on line graph EZBin –Does same for histogram Averager, Entropy and EZDistribution –Collect statistics from collection of objects Averager EZGraph EZBin Objectbase Entropy EZ Distribution Probe

POL SCI Cederman / Stefansson 16 Using EZGraph EZGraph is a wrapper around several objects Allows creation and setup to be achieved in one fell swoop After setting title and labels must add one or more sequences Necessary steps: 1) create an instance 2) setTitle: titleString 3) setAxisLabelsX: str Y: str 4) Add sequence(s) –With feed from object –Or feed from collection: AverageSequence TotalSequence MinSequence MaxSequence

POL SCI Cederman / Stefansson 17 Creating an EZGraph A sequence with feed from collection is created with -createASequence: aString withFeedFrom: collection andSelector: M(method) where A is one of Average, Total, Min, Max or Count aString The title, made with: -setTitle: aString The axis labels, set with -setAxisLabelsX: str Y: str

POL SCI Cederman / Stefansson 18 Using EZBin EZBin, is also a wrapper around several objects This type of graph needs to be told the number of bins for histogram and interval in which values lie Necessary steps: 1) create an instance 2) setTitle: titleString 3) setCollection: collection 4) setProbedSelector:M(method) 5) setBinNum: n 6) setUpperBound: and setLowerBound:

POL SCI Cederman / Stefansson 19 Creating an EZBin Data is fed into Histogram by -setCollection: collection and -setProbedSelector:M(method) The title, made with: -setTitle: aString The axis labels, set with -setAxisLabelsX: str Y: str The number of bins is determined with -setNumBins: num and the range of values by -setUpperBound: -setLowerBound:

POL SCI Cederman / Stefansson 20 Other utility objects in Analysis Averager –Gets feed from collection and calculates: Average Total Min Max Count Entropy –Gets feed from collection and calculates entropy assuming data is probabilities EZDistribution –Subclass of EZBin, gives acces to underlying distribution of data

POL SCI Cederman / Stefansson 21 Homework Week 6 1. Modify GraphIPD sample program: a. Add a second graph plotting the average payoff of the players over time b. Replace frequency graph with histogram showing the frequency of the four strategies dynamically 2. Extend Elevator sample program to n- tenant case

POL SCI Cederman / Stefansson 22 Homework Week 6: Exercise Apartment building with elevator: What is the average waiting time?... n Two types of elevators: Type 0: "standard" Car remains where it is after use Type 1: "modified" Car returns to zero after use

POL SCI Cederman / Stefansson 23 Assignment: a. Derive theoretical waiting times for n=2. b. Generalize the program Elevator from two-tenant case to any n. c. Simulate the estimated waiting time for both elevator types. d. Plot the waiting times as a function of n. e. Which elevator type minimizes waiting? *f. Derive theoretical waiting times for n.

POL SCI Cederman / Stefansson 24 Theoretical average waiting times for elevator types 0 and 1 n = number of stories

POL SCI Cederman / Stefansson 25 Elevator: main.m int main(int argc, const char ** argv) {... for (eType = 0; eType < 2; eType++) { [tenant1 init: 1]; [tenant2 init: 2]; [elevator init: 2 type: eType]; for (repl = 0; repl < n; repl++) { if ([uniformIntRand getIntegerWithMin: 0 withMax: 1]) [tenant1 move: elevator]; else [tenant2 move: elevator]; } printf("Type: %d Time: %10.6f \n", eType, (double) ([tenant1 getTime]+[tenant2 getTime])/(double) n); } return 0; }

POL SCI Cederman / Stefansson 26 Elevator: Tenant: SwarmObject { int floor, homeFloor; int waitingTime, trips; } -init: (int) n; -setFloor: (int) f; -(BOOL)isAtHome; -(int)getTime; -move: (id)

POL SCI Cederman / Stefansson 27 Elevator: Tenant.m... -init: (int) n { homeFloor = n; if ([uniformIntRand getIntegerWithMin: 0 withMax: 1]) floor = homeFloor; else floor = 0; waitingTime = 0; trips = 0; return self; }... -move: (id) e { waitingTime = waitingTime + [e callAtFloor: floor]; if ([self isAtHome]) [e take: self toFloor: 0]; else [e take: self toFloor: homeFloor]; trips++; return self; }

POL SCI Cederman / Stefansson 28 Elevator: Elevator: SwarmObject { int floor; int type; } -init: (int) nFloors type: (int) eType; -(int)getFloor; -(int)callAtFloor: (int) f;// returns waiting time! -take: (id) t toFloor: (int)

POL SCI Cederman / Stefansson 29 Elevator: Elevator.m Elevator -init: (int) nFloors type: (int) eType { type = eType; if (type) floor = 0; else { if ([uniformIntRand getIntegerWithMin: 0 withMax: 1]) floor = 0; else floor = [uniformIntRand getIntegerWithMin: 1 withMax: nFloors]; } return self; }...

POL SCI Cederman / Stefansson 30 Elevator: Elevator.m (2)... -(int)callAtFloor: (int) f { int wait; wait = abs(floor-f); floor = f; return wait; } -take: (id) t toFloor: (int) f { [t setFloor: f]; if (type==1) floor = 0; else floor = f; return self;