ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

95
Introduction to Computing for Complex Systems (Lab Session 3) Daniel Martin Katz Michigan State University College of Law

description

 

Transcript of ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Page 1: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Introduction to Computing for Complex Systems

(Lab Session 3)

Daniel Martin KatzMichigan State University

College of Law

Page 2: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

A Few Books Worth Considering

Page 3: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Goals for Today

Finish Exploration of the Forest Fire Model

Begin exploration of theSchelling Segregation Model

Page 4: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Every item in our Model is:

Important Principles fromOur Last Session

(1) Defined within the Model

(2) Is a Primitive that is defined in the Netlogo Dictionary

OR

(remember we can think of primitives as the raw materials of models)

(such as in Globals, Breeds or in a subroutine)

Page 5: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Exploring the Forest Fire Model

http://ccl.northwestern.edu/netlogo/models/Fire

(CONDT.)

Page 6: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The Forest Fire Model

Page 7: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The Forest Fire Model

Page 8: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

3-D Forest Fire Model

Page 9: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

(1) Modify the Color of the Forest to Blue

(2) Make the Fire Move North to South Instead of West to East

How Did We Do?

Page 10: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Modify the Color of the Forest to Blue

Page 11: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

What Elements of the Code Do We Modify?

Page 12: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The Forest Fire Model

Procedures

Page 13: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The Forest Fire Model

Procedures

Page 14: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Make the Fire Move North to South Instead of West to East

Page 15: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Make the Fire Move North to South Instead of West to East

Page 16: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

What Elements of the Code Do We Modify?

Page 17: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The Forest Fire Model

Procedures

Page 18: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The Forest Fire Model

Procedures

Try this Instead:

Page 19: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 20: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

In what sense is this model random?

In what sense is this model deterministic?

Thinking conceptually about the model procedures

all of these models involve a mixture of determinism and randomness

Page 21: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

In what sense is this model random?

Thinking conceptually about the model procedures

Placement of the patches

subject to the selected density level

Page 22: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Watch the Model in 3D

Page 23: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Watch the Model in 3D

Page 24: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Watch the Model in 3D

Page 25: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Watch the Model in 3D

Page 26: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

In what sense is this model deterministic?

Thinking conceptually about the model procedures

The fire is really for G.U.I. purposes

result is basically already determined before the fire spreads

Page 27: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Back to the Forest Fire

Model Procedures

Page 28: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

relies upon:if not any? stopask fires ask neighbors4fade-embersignitetick

The ‘To Go’ Procedure

Page 29: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

if is a condition and you can think of it as:

if x condition is met than do action y

(otherwise move on to the next line)

The ‘To Go’ Procedure

Page 30: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

This is going to kill the model if

condition is achieved

vs.

Forever Button

Once-only Button

The ‘To Go’ Procedure

Page 31: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Why is this Arguably the KEY piece of code?

What does it mean in plain english?

The ‘To Go’ Procedure

Page 32: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

What is neighbors4?

Remember our basic rule:

The ‘To Go’ Procedure

It is defined within the program

or it is one of the netlogo primitives

Page 33: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The ‘To Go’ Procedure

Page 34: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Neighbors and Neighbors4

turtle turtle

neighbors4 neighbors(think of

this as the 8 neighbors)

turtle

Page 35: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

(a) we are asking “fires”

The ‘To Go’ Procedure

(b) to ask their 4 neighbors

(c) the 4 neighbors that are green

(d) to run the “ignite” protocol

(e) and then set their breed to embers

(f) now run the “fade-embers” protocol

Page 36: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The ‘To Go’ Procedure

Page 37: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The ‘To Go’ Procedure

Page 38: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The ‘To Go’ Procedure

When is this finally going to halt?

It is a forever button which can be halted using “STOP”

“STOP” is triggered when the “if” condition is satisfied

Page 39: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Lets Discuss Some Extensions of The Forest Fire Model

Page 40: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Extensions of The Forest Fire Model

What are the actual dynamics that generate and sustain forest fires?

What else could we incorporate into this model?

Page 41: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

A Non-Exhaustive List

Differential Levels of Moisture

Variable Terrain (Rivers, etc.)

Prior Interventions (Firewalls, etc)

Wind and other Weather Patterns

Page 42: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Some of the Existing Extensions

Page 43: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 44: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

different forms of implementation may impact the results

Implementation Matters

different forms of implementation may be more qualitatively appropriate

sophistication regarding implementation allows you to be a more critical consumer of scholarship

Page 45: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

the neighbors4 example

Page 46: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Neighbors and Neighbors4

turtle turtle

neighbors4 neighbors(think of

this as the 8 neighbors)

turtle

Page 47: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Neighbors and Neighbors4

neighbors(think of

this as the 8 neighbors)

what did the implementer of the model decide?

neighbors4

decided that the fire could not move diagonally

this is probably not qualitatively reasonable

Page 48: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Step 1: map the dependancies

Step 2: learn the syntax and functionality for all unknown primitives

Protocol to Decode 3rd Party Implementation

Step 3: read each line of code and determine what it doing

Page 49: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 50: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Mapping of the Code

Page 51: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

just some examples of primitives from the dictionary that we have already learned

Protocol to Decode 3rd Party Implementation

Page 52: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Next We Went Line by Line Through the Code

Page 53: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Step 4: sketch a procedures map that follows the chronology of your program

There is one additional step that often proves useful

Protocol to Decode 3rd Party Implementation

Particularly when you are writing a model from scratch

Page 54: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Very Rough Sketch of the Fire Procedures Map

(1)

(2) (1)(a)(i)

(1)(a)

(1)(a)(ii)

(1)(b)

the point is just to aid in your understanding

(2)(a)

(2)(a)(i)

(2)(a)(i)(I)

(2)(b)

(2)(b)(i) (3) - End

Loop Until “if”

Condition is met

Page 55: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

The Value for Global Must Get “Set” Somewhere in the Model Procedures

Globals -- one other note

Page 56: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 57: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Mapping of the Code

Page 58: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 59: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Introduction to theSchelling

Segregation Model

Page 60: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

What Does this Title Mean?

What is the micro to macro disconnect?

relationship to the ecological inference

fallacy?

Page 61: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 62: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 63: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 64: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 65: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 66: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 67: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

versus

note: stopped model before % unhappy = 0

Page 68: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Test these Parameters and report

Results

Page 69: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 70: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 71: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 72: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

versus

Page 73: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 74: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Schelling Social Segregation Model

Page 75: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

the full model

Page 76: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 77: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Print This and Draw the Connections for a Full Map

of the Schelling Code

Page 78: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Mapping of the Schelling Code(%-similar-wanted is a slider)

Page 79: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Learn the Syntax and Functionality for all unknown Primitives

(starting with “to setup”)

Page 80: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Again this is the conditional “if” statement

It is relying upon “number”

Is number a netlogo primitive?

Page 81: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

It is the name of the slider

How could I rename this “totalagents”?

Take 5 minutes and Try to Figure it out

Page 82: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

(1) Right Click (ctrl + Click on Mac)

on the “number” slider

(2) change the global variable name from “number” to “totalagents”

Modifying the name (or values) of a Slider

Page 83: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Modifying the name (or values) of a Slider

Notice the error Message

Must Change all instances from “number”

to “totalagents”

Then double check by hitting

the “check” Button

Page 84: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

We have learned a small exception to our rule

Revised Rule --> everything in the model:

(1) defined somewhere in the code (2) is a primitive (3) it is something like a slider

Page 85: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

What is this doing in plain english?

clear everything

if the end user selects a slider value that exceeds the number of patches

tell that end user to modify and try again

Page 86: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz
Page 87: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

(1) Close Netlogo

(2) Discard the Changes

(3) Restart the Segregation model

Quick Reset

Page 88: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Open the SchellingSegregation Model

Delete all procedures except those shown to left

What is has this done to the model?

<Only Red Turtles>

<“Go” button is red>

Page 89: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

What is this doing in plain english?

asks all of the patches

to randomly “sprout” 1 turtle per patch

and make that turtle color = red

Page 90: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

What is this doing in plain english?

now take half of those turtles

and set turtle color = green

Page 91: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

We Need to see What “update-varables” is Actually Doing

Page 92: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Here we are going to “set” some of our “turtles-own” variables

Page 93: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

“Set” the Turtles-own Variable “similar-nearby”

to the count of “turtles-on” neighbors (8 of them)

but only those with color = my color

Page 94: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

“Set” the Turtles-own Variable “similar-nearby”

to the count of “turtles-on” neighbors (8 of them)

but only those with color = not my color

Page 95: ICPSR - Complex Systems Models in the Social Sciences - Lab Session 3 - Professor Daniel Martin Katz

Take a look at what is happening here

The “happy?” condition is going to be important

involves an agent by agent comparison of the spread between “similarity-wanted” & “similar-nearby”