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

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Java Programming Abstract classes and Interfaces.
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
Chapter 2 Programming by Example. A Holistic Perspective Three sections separated by blank lines. Program comment File: FileName.java
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
Graphic representations in statistics (part II). Statistics graph Data recorded in surveys are displayed by a statistical graph. There are some specific.
Lecture 28: Abstract Classes & Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Read: –Chapter 9 Cahoon & Davidson.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
CIS 101: Computer Programming and Problem Solving Lecture10 Usman Roshan Department of Computer Science NJIT.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Programming for Social Scientists Lecture 7 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
1 Flash and Animation Presented by : Behzad Sajed Khosrowshahi.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
1 Features of Java CS 3331 Fall Outline  Abstract class  Interface  Application --- animation applets.
Things and Relations - Examples Things Relationships Structural Behavioral Grouping Annotational Dependency Association Generalization Realization Class,
Tutorial 2 Drawing Text, Adding Shapes, and Creating Symbols.
Writing Widgets & Custom Script API for BOY Xihui Chen
Week 3 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
The CarryDrop Model (Steps 19-24) : A RePast Tutorial by John Murphy by Junjie Sun 8/16/2004 Department of Economics Iowa State University.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Chapter 2 Graphs, Charts, and Tables - Describing Your Data ©
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
_______________________________________________________________CMAQ Libraries and Utilities ___________________________________________________Community.
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
1 Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120 – Fall 2005 Lecture Unit 2 - Using Objects.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
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,
Intelligent Database Systems Lab N.Y.U.S.T. I. M. Externally growing self-organizing maps and its application to database visualization and exploration.
Prof. Lars-Erik Cederman ETH - Center for Comparative and International Studies (CIS) Seilergraben 49, Room G.2, Nils.
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Thomas Kuehne.
Features of Java CS 3331 Sections and 5.5.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Continuation of John Murphy’s RePast Tutorial Steps Charlie Gieseler
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
Histograms, Frequency Polygons, and Ogives. What is a histogram?  A graphic representation of the frequency distribution of a continuous variable. Rectangles.
Histograms, Frequency Polygons, and Ogives
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 Inheritance and Subclasses. 2 Inheritance Often we create very similar classes –Different types of triangles: equilateral, isosceles, etc. –Different.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Introduction to Computational Modeling of Social Systems Nils Weidmann Center for Comparative and International Studies (CIS) Seilergraben 49, Room E.3,
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Creating a RePast Model Introduction, (Sim)Model Object, CarryDrop.
Go4 Workshop J.Adamczewski-Musch, S.Linev Go4 advanced features.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Why Is It There? Chapter 6. Review: Dueker’s (1979) Definition “a geographic information system is a special case of information systems where the database.
Modern Programming Tools And Techniques-I
Add More Zing to your Dashboards – Creating Zing Plot Gadgets
Inheritance ITI1121 Nour El Kadri.
2D Graphics: Part 2.
12 Data abstraction Packages and encapsulation
Introduction to RePast and Tutorial I
Introduction to Computer Science and Object-Oriented Programming
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 21, 2004 RePast Tutorial III

2 Today’s agenda GUI versus batch mode How to create charts GraphIPD How to use spaces How to create displays GridIPD

3 Two modes of modeling Organizations of agents Animate agents Data Artificial world Observer Inanimate agents If then else If then else

4 GUI features Graphical user interfaces offer: Customized parameter panel Dynamic graphs Graphical displays Probes GraphIPD GridIPD

5 Separating GUI and batch modes Model extends SimpleModel ModelGUI extends Model ModelBatch extends Model ExperIPDGraphIPD,GridIPD

6 Subclassing a GUI model class Model extends SimpleModel { model variables setup() buildModel() step() main() } class ModelGUI extends Model{ GUI variables (graph) setup() { super.setup(); params =... delete old graphs } buildModel() { super.buildModel(); create graph } step() { super.step(); update graph }... main() }

7 Types of plots and charts Time series user defined variable(s) over time Histogram bar chart showing a variable’s distribution Scatter plot snapshot of two variables

8 Showing time series Main class: OpenSequenceGraph uchicago.src.sim.analysis.OpenSequenceGraph Extension: NetSequenceGraph Specialized for network statistics (path length, cluster coefficient, density,...). Note: agentList should implement the Node interface! Declaration: public class ModelGUI extends Model { private OpenSequenceGraph graph;... }

9 Showing time series (cont.) Initialization: public void setup() { super.setup(); if (graph != null) graph.dispose(); } Instantiation: public void buildModel() { super.buildModel(); graph = new OpenSequenceGraph(“Graph", this); graph.setXRange(...); graph.addAxisTitles(...); graph.display(); }

10 Showing time series (cont.) Updating: public void step() { super.step(); graph.step(); } Adding variables: graph.createSequence(“X", this,“getXValue"); Name of the method returning the value to be displayed

11 OpenSequenceGraph API addSequence(String name, Sequence seq, Color color, int markStyle) Adds a sequence with a specific name to be drawn in a user-defined color and points in a pre-defined style record() Records the data for this graph without updating the display setYAutoExpand(boolean autoExpand) Sets whether the y-axis scale will expand to include new points or not setYRange(double min, double max) Sets the initial range of the y-axis. writeToFile() Writes this graph to a file.

12 Example: Scatter plot Plot aPlot = new Plot("Test Plot"); aPlot.addLegend(0, "Sin", Color.blue, Plot.FILLED_DIAMOND); aPlot.addLegend(1, "Manual", Color.red); aPlot.setConnected(true); aPlot.display(); for (double i = 0; i < 100; i++) { aPlot.plotPoint(i, Math.sin(i), 0); } aPlot.plotPoint(3.0, 4.0, 1); aPlot.plotPoint(5.0, 1.4, 1); aPlot.updateGraph(); aPlot.fillPlot(); uchicago.src.sim.analysis.Plot

13 Beyond RePast charts For tailor-made graphics, bypass RePast and develop your own custom classes Example can be found as part of the GraphIPD model ( CustomModelGUI ). It is also possible to integrate third-party libraries: –Java3D: –JFreeChart: –JMSL:

14 GridIPD: How to use spaces Two purposes: –Collection of agents –Spatial relationship of agents Discrete Package: uchicago.src.sim.space Declaration: public class Model extends SimpleModel { protected Object2DGrid world; private int worldSize;... }

15 How to use spaces (cont.) Initialization: public void setup() { super.setup(); worldSize = 16; } Instantiation: public void buildModel() { super.buildModel(); world = new Object2DGrid(worldSize, worldSize); for (int x = 0; x < worldSize; x++) for (int y = 0; y < worldSize; y++) { Player aPlayer = new Player(x,y,...); world.putObjectAt(x, y, aPlayer); agentList.add(aPlayer); } } }

16 Types of spaces Boundaries –Grid –Torus Cell’s shape –Rectangular –Hexagonal Cell’s content –One object –Collection of agents V1V1 0,0 0,1 0,2 0,3 0,4 1,0 1,11,3 1,4 1,2

17 Classes Object2DGrid A discrete two-dimensional grid whose cells may contain an object. Object2DTorus A discrete two-dimensional torus whose cells may contain an object. Multi2DGrid A two-dimensional grid whose cells can contain more than one Object. The order of the Objects in each cell is undefined. OrderedMulti2DGrid A two-dimensional grid whose cell can contain more than one Object. The order of the Objects in each cell is first in, first out. Diffuse2DGrid A discrete approximation of two-dimensional diffusion. The space itself is a toroidal (donut-shaped) grid whose cells contain doubles.

18 Usage Random arrangement: Object2DGrid space = new Object2DGrid(spaceWidth, spaceHeight); for (int i = 0; i < numAgents; i++) { int x, y; do { x = Random.uniform.nextIntFromTo(0, space.getSizeX() - 1); y = Random.uniform.nextIntFromTo(0, space.getSizeY() - 1); } while (space.getObjectAt(x, y) != null); MyAgent agent = new MyAgent(x, y, space); space.putObjectAt(x, y, agent); agentList.add(agent); } Moving agent space.putObjectAt(x, y, null); space.putObjectAt(newX, newY, agent); Random arrangement One occupant per cell

19 Neighborhood Moore getMooreNeighbors(int x, int y, int xExtent, int yExtent, boolean nulls) Von Neumann getVonNeumannNeighbors(int x, int y, int xExtent, int yExtent, boolean nulls)

20 How to create displays Displays: graphical presentations of agents and their environments Package: uchicago.src.sim.gui Declaration: public class ModelGUI extends Model { private DisplaySurface dsurf;... } Extends JComponent

21 How to create displays (cont.) Initialization: public void setup() { super.setup(); if (dsurf != null) dsurf.dispose(); DisplayConstants.CELL_WIDTH = 30; DisplayConstants.CELL_HEIGHT = 30; dsurf = new DisplaySurface(this, “2D Display"); registerDisplaySurface("Main", dsurf); } Delegation to buildDisplay method: public void buildModel() { super.buildModel(); buildDisplay(); } Size of a cell in pixels Good practice!

22 How to create displays (cont.) Instantiation: public void buildDisplay() { Object2DDisplay display = new Object2DDisplay(world); display.setObjectList(agentList); dsurf.addDisplayable(display, "Display"); addSimEventListener(dsurf); dsurf.display(); } Updating: public void step() { super.step(); dsurf.display(); }

23 How to create displays (cont.) Cell drawing: public class Player implements Drawable { int x, y; public Player(int x, int y) { this.x = x; this.y = y; } public void draw(SimGraphics g) { g.setDrawingParameters(DisplayConstants.CELL_WIDTH * 2/3, DisplayConstants.CELL_HEIGHT * 2/3, DisplayConstants.CELL_DEPTH * 2/3); g.drawFastRoundRect(COLOR[type]); } public int getX() { return x; } public int getY() { return y; } }

24 SimGraphics API drawCircle(Color c) Draws a true circle with the specified color. drawFastRoundRect(Color c) Draws a rounded rectangle of the specified color. drawHollowOval(Color c) Draws a hollow oval in the specified color. drawStringInRoundRect(Color rectColor, Color stringColor, String text) Draws the specified string inside a rounded rectangle.... setDrawingParameters(int width, int height, int depth) Sets the parameters for the next drawing operation. Usually faster than drawRoundRect No fill

25 Drawable, space and display Space DisplayInterface Object2DGridObject2DDisplayDrawable Object2DTorusObject2DDisplayDrawable Diffuse2DValue2DDisplay N/A. Map to values to a ColorMap instead.ColorMap Multi2DGridMultiObject2DDisplayDrawable Multi2DTorusMultiObject2DDisplayDrawable OrderedMulti2DGridMultiObject2DDisplayDrawable OrderedMulti2DTorusMultiObject2DDisplayDrawable Object2DHexagonalGridObject2DHexaDisplayDrawable Object2DHexagonalTorusObject2DHexaDisplayDrawable DiffuseHexagonal2DValue2DHexaDisplay N/A. Map to values to a ColorMap instead.ColorMap RasterSpaceObject2DDisplayDrawable

26 Snapshots and movies Snapshots: dsurf.setSnapshotFileName("snapshot"); schedule.scheduleActionAtInterval(100, dsurf, "takeSnapshot"); Movies dsurf.setMovieName("movie.mov", DisplaySurface.QUICK_TIME); schedule.scheduleActionAtInterval(10, dsurf, "addMovieFrame"); schedule.scheduleActionAtEnd(dsurf, "closeMovie"); snapshot- 100.gif

27 Advanced graphics Use network displays (see RePast How To document) Use custom Java drawing (see CustomGraphGUI of GraphIPD for an example)