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

Post on 29-Jan-2016

217 views 0 download

Tags:

Transcript of 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

Outline

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

ContextConclusion

Introduction

• This chapter is based on• IABM-WR: 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

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

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

Outline

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

ContextConclusion

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

Designing a Model

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

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

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

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

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

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

In practice

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

– top-down design approach

Top-Down Design Approach

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

level

ABM Design Principle

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

question you want to answer

• Two components

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”

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

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

• 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

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

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

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

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.

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

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

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

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

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

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

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

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

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

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

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)

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

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?

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

Outline

IntorductionDesigning a ModelBuilding a ModelConclusion

Building a Model

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

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

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

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

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

iterations

• sheep behavior – moving around• break into two

– turning and moving forward

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

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

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:

• cost-of-movment• from a slider

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

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

Initialization

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

• initilize energy of each sheep to 100

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

setup

sheep-own [ energy ]

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

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

go

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

moving by consuming energy

the sheep moves which costs it energy

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

move

to move forward 1 set energy energy - movement-costend

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

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

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...

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

20 ] ...end

iterations

• let sheep eat grass• alow grass to regrow

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

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

countsend

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

regrow-grass

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

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

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

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

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

recolor-grass

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

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

20 end

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

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

iterations

aftrer eating grass let the sheep reproduce

with procedure:reproduce

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

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

reproduce

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

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

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

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

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 ]

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

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

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

eating

• Eagting behavior of sheep is different from that of wolve

• modify eat procedure

eat

to eat

ifelse breed = sheep

[eat-grass]

[eat-sheep]

end

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

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

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

Interface

• different pen colors for – sheep– wolf– grass

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

Outline

IntorductionDesigning a ModelBuilding a ModelExamining a ModelConclusion

Examining a Model

• Multiple runs• Parameter Sweeping and

Collection of Results• Analysis of Data

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

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

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

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

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

• 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

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

Outline

IntorductionDesigning a ModelBuilding a ModelExamining a ModelPredator-Prey Models:

Additional ContextConclusion

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

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

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

Outline

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

ContextConclusion

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

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