mis 585 special topics in ims agent-based modeling chapter 4: creating agent-based models

108
MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Upload: bertha-poole

Post on 29-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

MIS 585

Special Topics in IMS

Agent-Based ModelingChapter 4:

Creating

Agent-Based Models

Page 2: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Outline

IntorductionDesigning s ModelBuilding a ModelExamining a ModelPredator-Prey Models: Additional

ContextConclusion

Page 3: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Introduction

• This chapter is based on• IABM-WR: Chapter 4• Creating Agent-Based Models

Page 4: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Introduction

• This chpapter:• Devising a question or area to

explore• designing and building a model• refineing question• revising the model to analize

results to answering the question

Page 5: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Introduction• iterative exploration and refinment of

the model and motivating question• Three sections:• 1 – Designing a model:

– what elements to include

• 2 – Building a model– from conceptual to a computational object

• 3- Examining a model– running, creating and analizing results to

provcide a useful answer to the motivating question

Page 6: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Introduction• In this chapter• desining, building and examining• Wolf Sheep Simple Model• The basic quesiton addressed:

– How do population levels of two habitat-shering animal species change over time?

• Generalized:– companies competing for customers– electral parites competing for wotes– viruses evolving in a computer system

• Basic components of most ABMs

Page 7: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Outline

IntorductionDesigning a ModelBuilding a ModelExamining a ModelPredator-Prey Models: Additional

ContextConclusion

Page 8: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Designing a Model• Choosing Questions• Choosing Agents• Choosing Agent Properties• Choosing Environmental Characteristics

and Stationary Agents• Choosing Agent Behavior• Designing a Time Step• Choosing Parameters of the Model• Choosing Measures• Summary of the Wolf Sheep Simple

Model Desing

Page 9: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Designing a Model

• Two major categories of modeling– phenomena-based modeling– exploratory modeling

Page 10: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Phenomena-Based Modeling

• begin with a target phenomena• characterisitc pattern – reference

pattern• E.g.:

– common housing segregation patterns in cities

– spral shaped galaxies in space– oscilating population patterns of

interraction speices• goal: to somehow capture the

reference pattern

Page 11: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Phenomena-Based Modeling

• In ABM:• finding agents and rules of behavior and

interrection so as to generate the observed patterns

• once generated: candidate explanatory mechanism for that pattern

• vary parameters to see• other patterns can be emereged• find in data or by conducting

experiments• In EBM: writting equations that wiill give

rise to the reference pattern

Page 12: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Exploratory Modeling• less common in EBM then in ABM

– greate agents,– define their behavior

• explore the emerging patterns• may be

– abstract forms; Game of Life– similaritiies

• behavior of the model and • phenomena in the world

• refine the model in the direction of perceived similarities to explanatory modeling of the phenomena

Page 13: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Degree of Questions

• Specific research question(s)• E.g.:

– How does a colony of ants forage for food?

– -shHow does a flock of geese fly in a V-shaped

• other extream without a clear question– modeling ants or birds– gradually refine question – a specific one answered by a model

Page 14: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Combining conceptual model and coding

• top-down design• conceptual model then coding

– designing agents, behavor and environment– before any line of coding

• butom-up design• conceptual model and coding coevolve• start with a phenomena – with or

without a formal queswtion• E.g.: how a market evolves • start with sellers and buyers then add

brokers

Page 15: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

In practice

• modelers use rearly use one style• switch between forms and styles• collaborating with a programmer

– top-down design approach

Page 16: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Top-Down Design Approach

• phenomena specific RQ• design agents properties, rules,• conceptual model• revise and refine until at a fine

level

Page 17: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

ABM Design Principle

• ABM Design Principle:– start simple and build towards the

question you want to answer

• Two components

Page 18: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

First Aspect

• begin with simplest agents and rules to explore the system– A. Einstein (1933)– “Every thing should be made as

simple a spossible but not simpler”

Page 19: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Second Aspect• keep your quesiton in mind

– do not add anything in your model that does not help you in answering your question

• G. Box (1979)• “All models are wrong but some models are

useful”

– all models are incomplete – simplify some aspects of the world,

– some are useful because they are designed to answer particular questions and the simplifications in the model do not interfere with the answer

Page 20: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

ABM Design Principle Useful

• 1- examine every possible agent and rules– eliminate if progress can be made

without it– Starting simple and adding elements

slowly – those irrelevant components never appear

Page 21: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

• More understanable and easier to varify

• Verification: a computational model correctly implements its conceptual model

• just in time results– at every point in model development– the model give same answer about

the

Page 22: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models
Page 23: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Questions

• first research question• may be too general• may change as new versions of the

model are developed• for SWSM

– How do population levels of two habitat-shering animal species change over time?

• is is appropriate for ABM or refine it for ABM

Page 24: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Questions

• ABM: interacting, autonomous, heterogoenus entites

• Some questions are more amenable to ABM some not– so try other modeling approaches

• E.g.: examine population dynamics of two species, well mixed (no spatial dependence), homogenous, change depends on only levels of each– system dynamics more appropriate

Page 25: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Questions

• ABM more relevant• how animals use resources – food at

specific locations to get energy• Aggregates depends on agents

interractions with themselfs and their environments– start simple only prey with a simple

environment – add resources, predator-prey

interractions

• Time dependen processes

Page 26: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Refined Question

• suitable for ABM• can we find model parameters for

two species that will sustain with positive population levels in a limited area when one is a predator the other – prey – consuming resources from the environment.

Page 27: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Example• some times reference pattern is observed

or• from the rules examine generated

patterns • One reference pattern: wolf-moose

species, Isle Royale, Michigan• Figure 4.2, 1959 – 2009

– no population going extinct, but oscilating– a phenomena-based modeling

• RQ refined: can we find oscilating patterns of two species without going to extinct in a limited area

Page 28: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Agents

• after research question• what are the agents?• compoents of the model:

automomous, heterogenous, having states, properties and behavior and bearing on the quesiton

• Avoid agent overload – any component could be an agent

• more relevant to RQ

Page 29: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Agents• Granularity of agents: every entity

is composed of smaller levels of entities

• what is the rigth level of entiy to choose

• proto-agents: in future versions of the model candidates to be agents – not individual characteristics but global

• E.g.: a humman hunter – affects the two species.

• E.g.: WSSM-wolf ,sheep, grass• added: hunter or soil

Page 30: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Agent Properties

• properties distinguish agents from others

• E.g.: in WSSM– wolves and sheep: location, heading

and energy• notion of vitality, abstracting messy

details of methabolism, caloric storage or starvation

• condencing all to a single measure• other properties may be added but not

related to the RQ

Page 31: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Environmental Characteristics and Stationary Agents

• Environment: mobile agent live and interact with

• E.g.: in WSSM– grass sheep consume– not every blade of grass – patches – grass amount– granularity shold be choosen properly

• Not the deal with boundary conditions– the world will wrap verrically and

horizontally – torus

Page 32: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Agent Behavior

• behaviors of agents determine how they interact with each other and environment

• E.g.: in WSSM, wolves and sheep – common behavior - turn, move

forward, reproduce die– differs – sheep consume grass, wolves

consume sheep– may have many other common or

differing behaviors – but not relevant to the RQ

Page 33: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing a Time Step

• designing the time step• all behavior of agents• in what order in a time step• in ABM time discrete• each step is divided into

serialized, ordered phases• determining the order may be

tricky

Page 34: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing a Time Step• In WSSM wolves and sheep have the

behavior:move, die,eat, reproduce• grass growhs• order for animals arbitary – any

order– movement – truning and stepping forward

• costs energy– death – if no energy– eating – to store energy, if something in

their local envirnoment to eat– reproduce – if hes enough energy, which

consumes energy• The grass agents may grow• before next time step

Page 35: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Parameters of the Model

• agent behavior with specified rules• parameters control the model• In the WSSM

– initial number of sheep and wolves– how much energy it costs an egent to move– energy gained from eating

• from grass or sheep

– how much energy is needed to reproduce– grass regrowth rate

• not included in WSSM

Page 36: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Choosing Measures• What measures to be collected

from the model• what measures – RQ• most relevant to the RQ• In WSSM – most relevant measures:

– population levels of sheep and wolves– relevant to RQ: what parameters sets

enable two populationns oscilating together– other may not be so relevant – energy

• Some may be added for debuging the model

Page 37: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Summary of the Wolf Sheep Simple Model Design

• Driving Question: Under what conditions the two species sustain oscilating positive levels in a limited geographical area when one is a predator of the other and the other consumes limited but regenerating resource from the environment

• Agent Types: sheep, wolves, grass• Agent Properties: location,

heading, energy (sheep,wolves), grass amount (grass)

Page 38: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Summary of the Wolf Sheep Simple Model Design

• Agent Behavior: Move, die, reproduce (sheep and wolves), eat sheep (wolves), eat grass (sheep), regrow (grass)

• Parameters: number of sheep, number of wolve, move cost, energy gain from grass, energy gain from sheep, grass regrowth rate

• Time Step: 1-sheep and wolves move 2-sheep and wolves die 3-sheep and wolve eat 4-sheep and wolve reproduce 5-grass regrows • Measures: sheep and wolve population over

time

Page 39: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Top-Down Design Approach• Take notes and dates of versions• Answer the following quesitons:• What part of the phenomena would you like to

build a model of?• What are the principle types of agents involed

in the phenomenon?• In what kind of environment do these agents

operwate? Are there environmental agents?• What properties do these agents have?

(describe by agent type)• What actrions or behavior can these agents

take? (describe by agent type)• How do these agents interact with the

environemt and with each other?• What do you hope to observe from the model?

Page 40: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

A more buttom-up Approach to Modeling

• Start with an ecological problem• add sheep – spread around• then they move, eat, reproduce,

die• they eat grass• grass should regrow• something should eat sheep –

wolves• come to the research question

Page 41: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Outline

IntorductionDesigning a ModelBuilding a ModelConclusion

Page 42: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Building a Model

• First Version• Second Version• Third Version• Forth Version• Fift Version

Page 43: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Building a Model

• Fife iterations• Many times in ABM, the end result

is not what modeler expects– error in coding– core propertiy of compled systems –

emergent behavior

• Building models gradually– observe unusual behavior– determine its causes

Page 44: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

First Version• Simplest model – behavor• one species• ignore the environment• Some sheep wondering around on

a lanscapebreed [sheep a-sheep]• a breed: class of turtles • plural form: sheep• singular form: a-sheep• all mobile agents are turtles

Page 45: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

creating sheep

to setup clear-all create-sheep 100 [ ;;initialize sheep ;; randomly spread around the world ;; set their color to white ;; give shape “sheep” ] reset-ticksend

Page 46: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

setupbreed [sheep a-sheep]

to setup clear-all ask patches [ set pcolor green ]

create-sheep 100 [ setxy random-xcor random-ycor set color white set shape "sheep" ] reset-ticksend

Page 47: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

iterations

• sheep behavior – moving around• break into two

– turning and moving forward

Page 48: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

iterations: go, wiggle and move

at each iterationeach sheep first turn a little bit in each direction then step forward

wiggle: sheep procedure, the sheep changes its heading

turn right then left, so the average is straight ahead

move: sheep proceduretake a step forward

Page 49: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

go, wiggle and moveto go ask sheep [ wiggle move ] tickend

to wiggle rt random 90 lt random 90end

to move fd 1 ;; take a step forwardend

Page 50: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Second Version• movements costly – consumes energy• Properties of sheep:

– location, heading – build in turtles’– energy – specific to sheep

sheep-own [energy]• initialize and change when sheep move• number-of-sheep: from a silider

– min value: 1– max value: 1000– increment: 1– default:

Page 51: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

• cost-of-movment• from a slider

– variable: cost-of-movment– max value: 2.0– min value: 0.0– increment: 0.1– default: 1.0

Page 52: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

ploter

• Header: population change• x axis: time, min:0, max:10• y axis: population,min:0,max:10• update scale is on• a pen colors for

– sheep

Page 53: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Initialization

• get number of sheep from a slider– default value:100

• initilize energy of each sheep to 100

Page 54: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

initializatgion

sheep own energyin the setupafter setting patches create number-of-sheep sheep and

set their initial properties ... set enery of each sheep to 100

Page 55: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

setup

sheep-own [ energy ]

to setup... create-sheep number-of-sheep [ ... set energy 100 ] ...end

Page 56: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Iterations

if there is no alive sheep then stop foreach sheep first turn a little bit then step forward with a procedure check-if-dead: checks to see if sheep should die increment tick with a procedure my-update-plots: plot the population counts

Page 57: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

go

to go if not any? sheep [stop] ask sheep [ wiggle the sheep moves consuming its energy check-if-dead ] tick my-update-plotsend

Page 58: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

moving by consuming energy

the sheep moves which costs it energy

after each move, reduce the energy by the cost of movement

Page 59: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

move

to move forward 1 set energy energy - movement-costend

Page 60: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

check-if-dead, my-update-plots

;; sheep procedure, if my energy is low, I die

to check-if-dead if energy < 0 [ die ]end

;; update the plots in the interface tabto my-update-plots plot count sheepend

Page 61: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Third Version

• Version 2 after 100 ticks, every sheep dies by moving

• no way of gaining energy• Extension• sheep eat grass to gain energy• patches – grass-amount

Page 62: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

initialization

patches have grass

for each patche give grass to the patches

uniformly distributed between 0.0 and 10.0

variable: grass-amount color it shades of green...

Page 63: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

setuppatches-own [ grass ]...to setup clear-all ask patches [ set grass random-float 10.0 set pcolor scale-color green grass 0

20 ] ...end

Page 64: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

iterations

• let sheep eat grass• alow grass to regrow

Page 65: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

iterations

each sheep wiggles and move ;; first turn a little bit checks to see if agent should die sheep eat grass procedure: eat the grass grows backprocedure: regrow-grassincrement tickplot the population counts

Page 66: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

goto go...ask sheep [ wiggle move check-if-dead eat ] regrow-grass tick my-update-plots ;; plot the population

countsend

Page 67: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Interface elements• slider

– variable: grass-regrow-rate– min value: 0.0– max value: 2.0– increment: 0.1– default: 1.1

• Slider– variable: energy-gain-from-grass– min value: 0.0– max value: 2.0– increment: 0.1– default: 0.4

Page 68: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

regrow-grass

to regrow-grass ask patches [ set grass grass + grass-regrowth-

rate if grass > 10.0 [ set grass 10.0 ] recolor-grass ]end

Page 69: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

how grass regrows

with the procedure:regrow-grass for each patch[ grass increses by grass-regrowth-rate maximum possible grass is 10.0 rescale color of grasswith procedure: recolor-grass

Page 70: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

eating grass a sheep procedure.How sheep eat grassto eat check to make sure there is grass here if amount of grass is greater then

energy-gain-from-grass then increment the sheep's energy by

energy-gain-from-grass

decrement the grass by the same amountrescale grass color

Page 71: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

eat

to eat if ( grass >= energy-gain-from-grass ) [ set energy energy + energy-gain-from-

grass set grass grass - energy-gain-from-grass recolor-grass ]end

Page 72: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

recolor-grass

;; recolor the grass to indicate how much has been eaten

to recolor-grass set pcolor scale-color green grass 0

20 end

Page 73: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Run

• start with 700 sheep• a starvation strarts at around tick

300• at 500 ticks, population is stable

around 400 sheep• after enough sheep died out• grass steadily grows• feedn enough sheep

Page 74: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Forth Version

• add reproduction to the model• sheep population can increase• simplfying assumptions:

– signle sheep can reproduce– sheep give birth to a new lamb when

they rich a certain energy level

Page 75: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

iterations

aftrer eating grass let the sheep reproduce

with procedure:reproduce

Page 76: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

goto go if not any? sheep [ stop ] ask sheep [ wiggle ;; first turn a little bit move ;; then step forward check-if-dead eat reproduce ] regrow-grass ;; the grass grows back tick my-update-plots ;; plot the population countsend

Page 77: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

how reproduce

• ;; check to see if this sheep has enough energy to reproduce– energy is greater then 200

• reproduction transfers 100 units of energy to the lamb

Page 78: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

reproduce

to reproduce if energy > 200 [ set energy energy - 100 hatch 1 [ set energy 100 ] ]end

Page 79: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Run

• relatively low movement cost to the energy gained from grass

• initailly 700 sheep– movement-cost:1– energy-gain-from-grass:2.0– grass-regrowth-rate:1

• population increases over time and levels off at around 1300 sheep

Page 80: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Fifth Version

• introduce wolves• give energy as sheep• use turtles as common movinvg

agentsbreed [sheep a-sheep]breed [wolves wolf]

turtles-own [ energy ] ;; agents own energy

Page 81: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

initialization of wolves

create number-of-wolves wolves distribute positions evenly set thier color to brown set their shape as "wolf" increase their size to 2, so they

are a little easier to see set the initial energy to 100

Page 82: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

initialization of wolves

to setup... create-wolves number-of-wolves [ setxy random-xcor random-ycor set color brown set shape "wolf" set size 2 set energy 100 ]

Page 83: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Interface elements• slider

– variable: number-of-wolves– min value: 0– max value: 100– increment: 1– default: 10

• Slider– variable: energy-gain-from-sheep– min value: 0.0– max value: 10.0– increment: 0.1– default: 3.5

Page 84: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

iterations

if not any turtles; check for both wolves and shee to stopfor each turtles ;ask both wolves and sheep wiggle move checksee if agent should die with procedure: check-if-dead sheep eat grass, wolves eat sheep with the same procedutre: eat reproduce regrow the grassincremetn tick plot the population countswith proceddure: my-update-plots

Page 85: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

goto go if not any? turtles [ ;; now check for any turtles, that is

both wolves and sheep stop ] ask turtles [ wiggle move check-if-dead eat reproduce ] regrow-grass tick my-update-plotsend

Page 86: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

eating

• Eagting behavior of sheep is different from that of wolve

• modify eat procedure

Page 87: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

eat

to eat

ifelse breed = sheep

[eat-grass]

[eat-sheep]

end

Page 88: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

wolves eat sheep

wolf procedure, wolves eat sheepif there is any sheep on the same

pathc as the wolve is on then eat one of them

let the sheep eaten die increase the energy of the wolf

eating the sheep by the parameter setting:

energy-gain-from-sheep

Page 89: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

eat-sheepto eat-sheep if any? sheep-here [ let target one-of sheep-here ask target [ die ]

set energy energy + energy-gain-from-sheep

]end

Page 90: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

update the plots;; update the plotsto my-update-plots set-current-plot-pen "sheep" plot count sheep set-current-plot-pen "wolves" plot count wolves * 10 ;; scaling factor so plot

looks nice set-current-plot-pen "grass" plot sum [grass] of patches / 50 ;; scaling factor

so plot looks niceend

Page 91: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Interface

• different pen colors for – sheep– wolf– grass

Page 92: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Run

• run the model with the parameter set:– number-of-sheep: 500– number-of-wolves: 12– movement-cost: 0.4– grass-regrow-rate: 0.3– energy-gain-from-grass: 1.7– energy-gain-from-sheep: 3.5

Page 93: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Outline

IntorductionDesigning a ModelBuilding a ModelExamining a ModelConclusion

Page 94: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Examining a Model

• Multiple runs• Parameter Sweeping and

Collection of Results• Analysis of Data

Page 95: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Examining a Model

• build the model• set of parameters:

– wolf and sheep populations coexitst and oscilate

• the research question is partially • answered• found rules to produce target

reference pattern – generative explanation

Page 96: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Examining a Model• stochastic elements

– rerun the model• can different parameter sets

generate the same pattern– run with different parameter sets

• generate a lot of data– analyz the data generated by the

model• run the model

– multiple times wsith different parameters and summurizee the resulting data

Page 97: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Multiple Runs

• a model with stochastic components

• to run several times to be certain about characterizing the behavior correctly

• if run once, abnormal rear patterns might be observed

• Run multiple times with the same pearmeter setting to characterize the normal/average behaior

Page 98: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Multiple Runs• NetLogo – BehaviorSpace toool: to run

the model iteratively with the same or different parameter settings and collect data

• How many time steps to run the model?– usually for each run fix the time step

• How long to run• How many times to run• How to compute averages• Not easy• E.g.: run the model 10 times collet the

average of sheep, wolf and amout of grass

Page 99: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Parameter Sweeping and Collection of Results

• Run the model with different parameter sets

• Sometimes little change in one or more parameters values may result very different patterns

• critical parameters • robustness of the model to

parameter changes• how sensitive results to these

changes

Page 100: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

• Robustness and sensitvity analysis• in chapter 6• For the wolf Sheep model:• critical parameter: number of wolf

– too many – they eat sheep then find no food and die

– too few: may not survive until sheep population increases enough

• E.g.: run the model 10 times varying the number of wolves from 5 to 15 incrementing by 1

Page 101: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Analysis of Data• Summurizing data with variety of ways

– describe complex results in a compact way– compare and contrast different data sets

• E.g.: – 10 (runs replications) * – 11 (parameter values) * – 3 (variables)

• take averages and standard deviations of runs for the three variables

• plots of parameters values v.s. outputs Figure 4.10

Page 102: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Outline

IntorductionDesigning a ModelBuilding a ModelExamining a ModelPredator-Prey Models:

Additional ContextConclusion

Page 103: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Predator-Prey Models: Additional Context

• Individual-based modeling (IBM)• applications of ABM to ecology• if better undertand how these systems

operate and effect their environment• better intervine for their sustenance• Lutka (1925), Voltera (1926)

– system of equations to descirbe behavior of two species predator-prey interractions

– general results: predator and prey populations move in cycles Figure 4.11

Page 104: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Predator-Prey Models: Additional Context

• Start equal populations– first predators eat prey – prey population falls – predators can not find food – predator population falls – prey population increases– ...

• Differential equations continuous– a population can not be zero – nano-sheep problem– use IBM or ABM - extinctions

Page 105: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Advanced Modeling Applications

• modeling of food webs Yoon (2004)– both ABM and network analysis

Schmitz and Booth (1997)

• prescriptive design of engineered systems – effects of verious fish ladders near

dams on salamaon populations

• modeling evolution– natural selection and other

evolutionary mechnisms are computational algorithms

Page 106: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Outline

IntorductionDesigning a ModelBuilding a ModelExamining a ModelPredator-Prey Models: Additional

ContextConclusion

Page 107: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Conclusion

• Sheep Wolf Simple Model designed • ABM principle: start simple and

build towards the question you want to answer

• How guide in design, implementation and analysis

• ABM – thinking like an agent• not causel relations betweeen

Page 108: MIS 585 Special Topics in IMS Agent-Based Modeling Chapter 4: Creating Agent-Based Models

Conclusion

• Extensions to economics or politics– firms, consumers or budget

constraints– parties, voters

• not exactly the same model mey need to change some processes and parameters settings