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

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Programming for Social Scientists Lecture 8 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Input from STDIN STDIN, standard input, comes from the keyboard. STDIN can also be used with file re-direction from the command line. For instance, if.
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.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
Programming for Social Scientists Lecture 5 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Programming for Social Scientists Lecture 7 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Programming for Social Scientists Lecture 6 UCLA Political Science 209-1: Programming for Social Scientists Winter 1999 Lars-Erik Cederman & Benedikt Stefansson.
Exercise 10 Review: pointers, strings and recursion.
C Slides and captured lecture (video and sound) are available at:
15213 C Primer 17 September Outline Overview comparison of C and Java Good evening Preprocessor Command line arguments Arrays and structures Pointers.
CS1061 C Programming Lecture 15: More on Characters and Strings A. O’Riordan, 2004.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Some Example C Programs. These programs show how to use the exec function.
1. Reference  2  Algorithm :- Outline the essence of a computational procedure, step by step instructions.  Program :- an.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Object Oriented Programming in C++ Dr. Hammadi Nait-Charif Media School Bournemouth University
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
Chapter 17 Pointers and Arrays. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Pointers and Arrays.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
ITEC 320 C++ Examples.
© M. Winter COSC 4P41 – Functional Programming Programming with actions Why is I/O an issue? I/O is a kind of side-effect. Example: Suppose there.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
1 Command-Line Processing In many operating systems, command-line options are allowed to input parameters to the program SomeProgram Param1 Param2 Param3.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
July Doxygen A Code Documentation System Doxygen generates documentation directly from the structure and comments in the code –Browsable HTML documentation.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Python – May 12 Recap lab Chapter 2 –operators –Strings –Lists –Control structures.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
Introduction to Objective-C Spring Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics…
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
C Primer Session – 1/25/01 Outline Hello World Command Line Arguments Bit-wise Operators Dynamic Memory / Pointers Function Parameters Structures.
1 Homework Continue with K&R Chapter 5 –Skipping sections for now –Not covering section 5.12 Continue on HW5.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Introduction to programming in java Lecture 21 Arrays – Part 1.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Week 4 – Functions Coding Functions. Purpose of Coding Functions A function is written to perform a well-defined task; rather than having all logic in.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Input from STDIN STDIN, standard input, comes from the keyboard.
C Primer.
A bit of C programming Lecture 3 Uli Raich.
Characters and Strings
Command Line Arguments
Command Line Arguments
Structure of C Programs
Computer Science 210 Computer Organization
Command-line Arguments
Computer Science 210 Computer Organization
Starting JavaProgramming
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
An Introduction to Java – Part I, language basics
Command Line Parameters
Characters and Strings
15213 C Primer 17 September 2002.
Presentation transcript:

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

POL SCI Cederman / Stefansson 2 Today's topics Running experiments Graph File input/output Code example: ExperIPD –Based on ProbeIPD from last week

POL SCI Cederman / Stefansson 3 ExperIPD: Running experiments main ModelSwarm ExperSwarm Graph ControlPanel

POL SCI Cederman / Stefansson 4 Changes to ProbeIPD... New ExperSwarm controls experiment Use command line parameter to choose between Observer and ExperSwarm Read loop parameters from file Graph created from x,y data Using OutFile to create model.setup and datafiles

POL SCI Cederman / Stefansson 5 Changes to main.m int main(int argc,const char ** argv) {... initSwarm(1,argv); if (argc == 1) { observerSwarm = [ObserverSwarm create: globalZone]; [observerSwarm buildObjects]; [observerSwarm buildActions]; [observerSwarm activateIn: nil]; [observerSwarm go]; } else { experSwarm = [ExperSwarm create: globalZone]; [experSwarm buildObjects]; [experSwarm run]; } return 0;}

POL SCI Cederman / Stefansson 6 Switching on command line args initSwarm(1,argv); if (argc == 1) {... The argc variable and argv array come from the command line We 'trick' initSwarm to think there are no arguments (so it doesn't parse argv) argc==1 means there were no arguments

POL SCI Cederman / Stefansson 7 ExperSwarm : GUISwarm { id modelSwarm; char * parameterName; double lowerBoundParameter; double upperBoundParameter; double incrementParameter; int lowerBoundSeed; int upperBoundSeed; int numGenerations; id graph; id data; } +createBegin: (id) aZone; -createEnd; -buildObjects; ExperSwarm is set up to read a parameter name to loop over and the bounds and increments for the loop It also displays results on a Graph and saves to file

POL SCI Cederman / Stefansson 8 Pseudo code for experiments for(parameter values) { for(random seeds) { SAVE setupfile FOR model CREATE model,averager,file LOAD model setupfile for(generations) RUN model UPDATE average,graph,file DROP model,averager } SHOW graph SAVE file The ExperSwarm has a exper.setup file which determines parameter to loop over and parameter values It communicates with ModelSwarm through loop.setup file which

POL SCI Cederman / Stefansson 9 Example exper.setup numGenerations20 parameterName numIter lowerBoundParameter 1 upperBoundParameter 5 incrementParameter 1 lowerBoundSeed upperBoundSeed By saving the loop parameter name as string we can choose which of instance variables in model to loop over

POL SCI Cederman / Stefansson 10 Handy classes from Simtools ObjectLoader –Loads instance variable values from file ObjectSaver –Saves instance variable values to file OutFile –Supports printing to file InFile –Reading from files Use OutFile to create an loop.setup for model that contains values of loop parameters ObjectLoader used to prime ModelSwarm from –model.setup (STATIC) –loop.setup (DYNAMIC) Also use OutFile to create data file

POL SCI Cederman / Stefansson 11 Creating the loop.setup file for(p=pl;p<pu;p+=pi) { for(s=sl;s<su;s++) {... %d\n%s outFile=[OutFile create: self withName: "loop.setup"]; [outFile putString: string]; [outFile drop];... } 1 2

POL SCI Cederman / Stefansson 12 Creating the loop.setup file (cont) The sprintf() function has same syntax as printf() except that result ends up in string (here str): i=3 sprintf(str,"Hello %d !",i) The string str now holds: Hello 3 ! OutFile prints strings or values to file: put{TYPE}: val Where {TYPE} is one of the C variable types (char,int,double...) or string,tab,newLine 1 2

POL SCI Cederman / Stefansson 13 OutFile and InFile Basic idea that InFile opens file and “gets” strings and OutFile opens file and “puts” same Both can deal with any var type (only String and Int shown) In addition methods to insert delimiter (“tab”), skip line, go to next line etc. Some methods in InFile: -(int) getWord: (char *) aWord -(int) getInt: (int *) anInt; -(int) skipLine...and OutFile: -putString: (char *) aString -putInt: (int) anInt -putTab: (char) aChar -putNewLine

POL SCI Cederman / Stefansson 14 Major GUI classes ZoomRaster –Resizeable raster Graph –Basic x,y graph Histogram –Basic histogram Colormap –Map between integer values and colors RasterGraph Histogram Widget ZoomRaster Colormap

POL SCI Cederman / Stefansson 15 Creating a simple line graph Creating graph (in -buildObjects) graph = [Graph createBegin: self]; graph = [graph createEnd]; [graph setTitle: parameterName]; [graph setWidth: 400 Height: 300]; data = [graph createElement]; [data setLabel: "average payoff"]; Adding data to graph (in -run) [data addX: parameter Y: value]; Displaying graph (in -run) [graph pack]; Basic Graph class creates a widget with title and dimensions For each dataset we create an "element" Series of x,y values then fed to "element"