Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market...

69
Sustainability Research Institute FACULTY OF ENVIRONMENT Agent-based Modelling (ABM) of socio-ecological-technical systems: A practical introduction SOEE 5582M Tools and Techniques in Ecological Economics Jonathan Busch, Christof Knoeri School of Earth and Environment [email protected] 1

Transcript of Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market...

Page 1: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

School of somethingFACULTY OF OTHER

Material Criticality

Sustainability Research InstituteFACULTY OF ENVIRONMENT

Agent-based Modelling (ABM) of socio-ecological-technical systems:

A practical introduction

SOEE 5582MTools and Techniques in Ecological Economics

Jonathan Busch, Christof KnoeriSchoolofEarthandEnvironment

[email protected]

1

Page 2: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

GoalandObjectives

Goal:

Understandingthebasicconceptsofagent-basedmodellingofsocio-ecologicalsystems,andhavesomeexperienceinapplyingit.

Practice:

IntroductionNetlogo,firstABMmodel,andmodeltesting,experiments,analysis

2

Page 3: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Content

1st March2016i. IntroductiontoSimulationModellingii. IntroductiontoABMiii. PaperdiscussionMacal &North(2010)iv. IntroductiontoNetLogoandtutorialsv. NetLogo conceptsandelements

8th March2016i. DescribingandformulatingABMs;TheODDProtocolii. ImplementingafirstABM(ThePVdiffusionmodel)iii. PaperdiscussionGrimm,etal.(2005)iv. Fromanimationtoscience(Extendingthemodel)v. Assignmentvi. Wrap-up

3

Page 4: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

SimulationModels

Page 5: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Analyticalmodelsvs.dynamicsimulationmodels

Analyticalmodels(EIOA,MFA)

• Purpose:Analyseanddescribethesystemindifferentsituations

• Attributes:systemstatechangestimeindependent(static)andfixedstructure(systemelementsandrelations)

Simulationmodels(SD,ABM,EIOA+econometrics)

• Purpose:Understand theunderlying(structural)dynamicsofasystemicchange

• Attributes:systemstatechangesasafunctionoftime(dynamic)andfixedstructure(SD)orflexiblestructure(ABM)

5

Page 6: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Simulationisthe

experimentaluseofmodels

6

WhatisSimulation?

“Weviewartificialsocietiesaslaboratories,whereweattemptto‘grow’certainsocialstructuresinthecomputer– orinsilico – theaimbeingtodiscoverfundamental localormicromechanismsthatare

sufficienttogeneratethemacroscopicsocialstructuresandcollectivebehaviours ofinterest.”

(EPSTEIN1996)

Page 7: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

UtilityofsimulationWhendoweneedsimulations?

Whenexperimentsintherealsystem

• arenotethical,

• tooexpensive,

• tootimeintensive

orimpossiblebecause

• therealsystemisnotaccessible,

• therealsystemcannotbesteered,

• therealsystemdoesnotexistyet,

• Somethingistheoreticallyinterestingbutcannotbeanalysedinrealityyet.

7

Page 8: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Utilityofsimulationsinresearchprocess

• Systemunderstanding(understandingrelationshipbetweenindividualdecisionmakingandglobal/socialchange)

• Developandexploretheoriesconcernedwithsocialchange

• Hypothesisbuildinginthebeginningofaresearchproject

• Exanteanalysisofstrategiesandmeasures

• Diagnosis:determineparameterswhichleadtoproblematicchangeswithinthesocialsystem

• Training

8

Page 9: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Themodellingcycle:

Problementity

Computermodel

Simulationresults

Conceptualmodel

Interpretation

Implementation

Modeldesign

Simulation runs

Source:Sargent,1982;Page,19919

Page 10: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

TheModelingCycle:ValidationandVerification

Problementity

Computermodel

Simulationresults

Conceptualmodel

Interpretation

Implementation

Modeldesign

Simulation runs

Source:Sargent,1982;Page,1991 10

Page 11: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Historyofsimulationsinsocialsciences

Source:Simulation fortheSocialScientistGilbert&Troitzsch,2005 11

Page 12: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Comparisonofsocialsciencesimulationtechniques

Source:Gilbert&Troitzsch,2005

12

Modellinglanguage

Deductive Computational

Analyticalfocus

Systemicvariables

Analyticalmodels(macroeconomics)

Macro-simulations(system dynamics)

Micromechanism

Rationalchoice(decision&gametheory) Agent-basedmodelling

Page 13: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

SystemDynamics(SD)• systemofdifferenceanddifferentialequations• basedonstocks,flowsandfeedbackloops• restrictedtothemacrolevel(top-down)• targetthephenomena(invisiblewhole)

13

Literature:World dynamics (Forester 1969,1971,1980; Meadows etal, 1974, 1992)Business dynamics (Sterman, 2000)

Page 14: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Microsimulations“microanalyticalsimulations”

• Basedonindividuals(bottom-up)

• Complexbutfixedindividualcharacteristics

• Examples:Microeffectsofpopulationdynamics,taxesandtransferpolicies

• Literature:Harding(1996),Mitton,etal.(2000)

14

Page 15: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Cellularautomata(CA)

“CAarediscretedynamicalsystemsthatmodelcomplexbehaviourbasedonsimple,localrulesanimatedonalattice”(JohnvonNeumann&StanislawUlam)

15

GameofLife:FirstpracticalCA(late1960)byJohnConway(Gardner,M.1971)

Page 16: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

CellularAutomata(CA)

„Incellularautomatamodelaworldinwhichspaceisrepresentedasauniformgrid,time advancesbysteps,andthe‘laws’oftheworldarerepresentedbyauniformsetofruleswhichcomputeeach cell’sstatefromitsownpreviousstateandthoseofitscloseneighbours.”Examples:• Conway’sGameofLife(Berlekamp etal.1982)(acellcanonly survive

ifthereareeithertwoorthreeotherlivingcellsinitsimmediateneighbourhood)

• Segregation/Migration(Schelling,1971)(Schellingsupposed thatpeoplehada‘threshold oftolerance’ofotherethnicgroups)

• Literature:Hegselmann R.(1996)WolframS.(1986,2002)https://www.youtube.com/watch?v=CgOcEZinQ2I

16

Page 17: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

References(neitherexclusivenorcomprehensive)

Berlekamp, E.R.,Conway,J.H.,&Guy,R.K.(2004/1982).Winningwaysforyourmathematicalplays.4:Peters.Costanza,R.,Wainger, L.,Folke,C.,&Maler,K.G.(1993).Modeling complexecologicaleconomic-systems- towardsanevolutionary,dynamicunderstandingofpeopleandnature.Bioscience,43(8),545-555.Epstein,J.M.,&Axtell,R.(1996).Growingartificialsocieties:socialsciencefromthebottomup.Washington,D.C:BrookingsInstitutionPress.Forrester, J.W.(1999/69).UrbanDynamics:PegasusCommunications.Forrester, J.W.(1971).Worlddynamics:Wright-AllenPress.Forrester, J.W.(1990/68).Principlesofsystems:ProductivityPress.Gilbert,N.,&Troitzsch,K.G.(2005).Simulationforthesocialscientist. (2ed.).Berkshire,England:OpenUniversityPress,McGraw-Hill.Grimm,V.,&Railsback,S.F.(2005).Individual-basedModeling andEcology:PrincetonUniversityPress.Grimm,V.,&Railsback,S.F.(2011).Agent-BasedandIndividual-BasedModeling:APracticalIntroduction:PrincetonUniversityPress.Harding,A. (1996).Microsimulation&PublicPolicy:Elsevier.Hegselmann,R.,Mueller,U.,&Troitzsch,K.G.(1996).ModellingandSimulationintheSocialSciencesfromthePhilosophyofSciencePointofView:Springer.Holling,C.S.(1964).AnalysisofComplexPopulationProcesses.CanadianEntomologist,96(1-2).Janssen,M.A.(2002).Complexityandecosystemmanagement:thetheoryandpracticeofmulti-agentsystems.Cheltenham:Elgar.Knoeri,C.,Binder,C.R.,&Althaus,H.J.(2011).Anagentoperationalizationapproachforcontextspecificagent-basedmodeling.JASSSTheJournalofArtificialSocietiesandSocialSimulation,14(2).Levins,R.(1966).StrategyofModelBuildinginPopulationBiology.AmericanScientist,54(4).Meadows,D.H.,Meadows,D.L.,&Randers,J.(1992).Beyondthelimits:confrontingglobalcollapse,envisioningasustainablefuture:ChelseaGreenPub.Meadows,D.L.(1974).Dynamicsofgrowthinafiniteworld:Wright-AllenPress.Mitton,L.,Sutherland,H.,&Weeks,M.(2000).Microsimulation ModellingforPolicyAnalysis:ChallengesandInnovations:CambridgeUniversityPress.Minsky,M.(1968).THEORYOFCOMPUTATION.AmericanMathematicalMonthly,75(4).Sargent,R.G.(1982).VerificationandValidationofSimulationModels.InF.E.Cellier (Ed.),ProgressinModellingandSimulation (pp.159-169).London:AcademicPress.Schelling,T.(1978).Micromotives andMacrobehavior.NewYork:WW Norton&CoLtd.Stachowiak,H.(1973).AllgemeineModelltheorie [GeneralModellingTheory].Berlin:Springer.Sterman, J.D.(2000).Businessdynamics:systemsthinkingandmodeling foracomplexworld.Boston:IrwinMcGraw-Hill.Tesfatsion,L.,&Judd,K.L.(2006).Handbookofcomputationaleconomics:agent-basedcomputationaleconomics (Vol.2).Amsterdam:Elsevier.vanDam,K.H.,Nikolic,I.,&Lukszo,Z.(2013).Agent-BasedModellingofSocio-TechnicalSystems (Vol.9):Springer,Netherlands.Wolfram,S.(1986).TheoryandApplicationsofCellularAutomata:(includesSelectedPapers1983- 1986):WorldScientificPub.Wolfram,S.(2002).Anewkindofscience:WolframMedia.

Page 18: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

AgentBasedModelling

Page 19: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Aclassicexample:schoolingandflockingbehavior

https://www.youtube.com/watch?v=ctMty7av0jc

19

Page 20: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Aclassicexample:schoolingandflockingbehavior

Tomake“Boids”looklikeaflockandavoidcollisions,theymust:• Swim/flytowardstheirneighbour

• Aligntheirdirectionwithneighbour

• Maintainaseparationdistance

(Reynolds,1987)

20

Page 21: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Acornucopiaoffancymodels,papers,grants...

Page 22: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Reynolds1998

“Boids”inspiredmanymodelsforresearchand“practical”applications...

Page 23: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Recentresults

Ballerinietal.2009:• Starlingflockmovement,responsetopredatorsisreproducedbestifmodel

assumeseachindividualinteractswith6-7nearestneighbors

Hildenbrandt,Carere,&Hemelrijk (2010):• Simulatedstarlingflockscanbeevenmorerealisticiftheyincludesimplified

aerodynamics,attractiontoroostingsites

What have ecological modelers learned?*

*Other than: follow your neighbor and stay together

Page 24: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Developingabodyoftheory

“Looks like a fish school” (Aoki 1982)

Collision avoidance (Reynolds 1987)

Realistic nearest-neighbor distance, polarization (Huth and Wissel 1992)

Flock shapes, response to predators, etc. (Ballerini et al. 2009; Hildenbrand et al. 2010)

Page 25: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

WhatmakesanABM?

• Autonomy (nocentralcontrol)

• Activeagents:• pro-activeorgoal-directed

• reactive/perceptive

• boundedrational

• interactive/communicative

• mobile

• adaptation/learning

• Heterogeneity

25

Page 26: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

OtherABMapplications

Ecology:• Landuseandlandusechange (Lambin etal.,2003;Parkeretal.,2003;Veldkamp &Verburg,2004;Berger etal.,

2006;Matthews et.al., 2007)

• Ecosystemmanagement (Jansen,2001;Parkeretal.,2003;Bousquet &LePage,2004)

Economics:• Stockmarket simulation(Arthuretal.,1997;LeBaron etal.,1999;LeBaron,2001)

• Computationaleconomics (Tesfatsion &Judd,2006)

Socialscience: (Gilbert&Troitzsch,1999/2005)• Competitionandcooperation(Axelrod,1997)• Groupbuilding(Dittrich etal.,2000)

• Socialnetworks(Liljeros etal.,2001;Dugundji &Gulyas,2004)• Developmentofsocieties (Holme etal.,2003;Newman, 2003)

• Epidemics&pandemics(Carley etal.2006,Epsteinetal.2007)

Politicalscience:• Policyandconflict research (L.-E.Cedermann,2003,2004;L.-E.Cedermann &Girardin,2005)

26

Page 27: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

ABMinEcologicalEconomics

27

Page 28: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

ModelstoInformPolicy?

“Itisdeeplydestructivetopursueausterityinadepression"

- PaulKrugman(NobelPrizewinner)

28

“Overthelongterm,debtreductioncanraiseoutputbybringingdownrealinterestratesandallowingtaxestobereduced"

- IMF,WorldEconomicOutlook2010

Page 29: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

29

RethinkingEconomicModelling

• Manyeconomistshavecriticised economicmodelsinthewakeofthe2008financialcrisis.

• Models,inanattempttobemathematicallyrigorous,aretoodivorcedfromreality.

• Mainstreameconomicsmustengagewithheterodoxeconomicsandothersocialsciences.

Page 30: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

30

OECD WEEK2 0 1 5

Meeting of the OECD Councilat Ministerial Level

Paris, 3-4 June 2015

www.oecd.org

OECD Paris2, rue André-Pascal, 75775 Paris Cedex 16

Tel.: +33 (0) 1 45 24 82 00

FINAL NAEC SYNTHESISNew Approaches to Economic Challenges

RethinkingEconomicModelling

Keyrecommendations:1. “…analysing theglobaleconomyasacomplexadaptivesystem.

Thiswillhelptotakeintoaccountuncertainty,spill-overs,systemicrisksandnetworkeffects.“

2. “… toreviewandimproveitsmodellingapproaches,takingamoreintegratedapproachwhilediversifyingthetypesofmodelsituses”

Page 31: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

31

EcologicalEconomicsModelling

Page 32: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

ABMConclusionsWhatisABM?• Abottomupsimulationmethod;wheretheinteractionofmany

componentsgeneratespatternsonahighersystemlevel.WhatisthepotentialofABM?• ABMmightfillthegapbetweenformal butrestrictivemodels

andwide-rangingbutimprecisequalitativeframeworks.• Allowstodevelop&testtheories(ofindividualbehaviours)

leadingtoemergentphenomena(systembehaviour)LimitationsofABM?• Empiricalfoundation(beyondproof-of-concept)• Rightlevelofdescription(purpose)• Computationalintensityforrobustresults

32

Page 33: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

GeneralreadingonABM

• Axelrod,R.(1997).Thecomplexityofcooperation:Agent-basedmodelsofcompetitionandcollaboration.Princeton:PrincetonUniversityPress.

• Cedermann,L.-E.(1997).EmergentActorsinWorldPolitics:HowStatesandNationsDevelopandDissolve.Princeton:PrincetonUniversityPress.

• Epstein,J.M.,&Axtell,R.(1996).Growingartificialsocieties:socialsciencefromthebottomup.Washington,D.C:BrookingsInstitutionPress.

• Heppenstall,A.J.,Crooks,A.T.,&See,L.M.(2012).Agent-BasedModelsofGeographicalSystems:SpringerDordrecht.

• Holland,J.H.(1995).HiddenOrder:HowAdaptationBuildsComplexity.ReadingMA:Addison-Wesley.

• Janssen,M.A.(2002).Complexityandecosystemmanagement:thetheoryandpracticeofmulti-agentsystems.Cheltenham:Elgar.

• Tesfatsion,L.,&Judd,K.L.(2006).Handbookofcomputationaleconomics:agent-basedcomputationaleconomics (Vol.2).Amsterdam:Elsevier.

• Grimm,V.,&Railsback,S.F.(2005).Individual-basedModeling andEcology:PrincetonUniversityPress.

• vanDam,K.H.,Nikolic,I.,&Lukszo,Z.(2013).Agent-BasedModellingofSocio-TechnicalSystems (Vol.9):Springer,Netherlands.

• Miller,J.H.,&Page,S.E.(2007).ComplexAdaptiveSystems:AnIntroductiontoComputationalModelsofSocialLife.PrincetonandOxford:PrincetonUniversityPress.

33

Page 34: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Paperdiscussion

IntroductiontoABM:

Macal,C.M.,&North,M.J.(2010).Tutorialonagent-basedmodellingandsimulation.JournalofSimulation,4(3),151-162.

• WhatarethecharacteristicsofthetreetypicalABMelements?

• HowdoeconomicABMapplicationscontrastwithtraditionaleconomicmodels?

• WhentouseABM?

34

Page 35: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

• When the problem has a natural representation as being comprised of agents• When there are decisions and behaviours that can be well-defined• When it is important that agents have behaviours that reflect how individuals actually

behave (if known) • When it is important that agents adapt and change their behaviours • When it is important that agents learn and engage in dynamic strategic interactions • When it is important that agents have a dynamic relationship with other agents, and

agent relationships form, change, and decay • When it is important to model the processes by which agents form organizations,

and adaptation and learning are important at the organization level • When it is important that agents have a spatial component to their behaviours and

interactions • When the past is no predictor of the future because the processes of growth and

change are dynamic • When scaling-up to arbitrary levels is important in terms of the number of agents,

agent interactions and agent states • When process structural change needs to be an endogenous result of the model,

rather than an input to the model 35

When to use ABM? (Axtell, 2000, Macal & North, 2008)

Page 36: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

IntroducingNetLogo

Page 37: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

ImplementingaConceptualModel

37Sargent,2008

Page 38: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

§ All-purposeprogramminglanguages(C++,MatLab,Delphi,Java,etc.)§ Youcandoanythingyouwant(flexibility)§ Youhavetoimplementanythingyouwantyourself.Almostnothing

thatsupportsABMsisprovidedready-to-use§ Noobserverfacilities§ Platformsoftenproprietary

§ SoftwarelibrariesdesignedforABMs(Swarm,Repast,Mason)§ Youcandoanythingyouwant(flexibility)§ ManyABM-specificthingsprovided,includingobservertools§ Free(basedonObjectiveCorJava)§ Usercommunities§ Easiertosharecodewithothers(samedesignconcepts)§ Steeplearningcurve(unsuitableforbeginnerscourse)

HowtoimplementAgent-basedmodels?

38

Page 39: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Integratedsoftwareplatforms(NetLogo)§ Easytouseforbeginners(goodforcourses)§ ProvidesmanyABMthings§ Powerfulconcepts(patches,turtles,ask)§ Youcanprobablydo(almost)anythingyouwant,butthatmight

sometimesrequirework-arounds§ Veryeasytosharecode§ Verygooddocumentation§ Usercommunity§ Maintainedbyactivegroup(NorthwesternUniversity)§ Teachingsoftware§ ModellibrarygivesanincompleteideaofNetLogo§ Increasinglyusedfor„seriousscience“

NetLogo

39

Page 40: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Netlogo(Version5.0)

Downloadfrom:

http://ccl.northwestern.edu/netlogo/download.shtml

40

NetLogo:firststeps

Page 41: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

• Threetabs:Interface,Information,Code• StartwithTutorials• ModelLibrary• CodeExamples• UserManualandDictionary• FourdifferenttypesofagentsinNetLogo

• Turtles,patches,links,observer(context)• Warning:usually,onlyturtleswouldbereferredtoasagents

• Primitives (commandsandreporters)

NetLogo (showinthesoftware)

41

Page 42: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Work through the NetLogo tutorials 2 and 3:

http://ccl.northwestern.edu/netlogo/5.0/docs/

42

Introduction to NetLogoTutorials

Page 43: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

NetLogo Basics– Review*

1) Understandingcodestructure

2) ElementaryNetLogo Commands

43

Adaptedfrom:SteveRailsback andMarinBozic

*LookedatUserManual45timeswhilewritingthis

Page 44: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

globals []turtles-own []breed[wolveswolf]

tosetupaskpatches[do-something]askturtles[do-something]

endtogo

askpatches[do-something]askturtles[do-something]tick

endtodo-something-special

endtodo-something-boringend

1. Declarationofvariablesandcollectives

2. ModelInitialization

3. Scheduledactions(tick)

4. Submodels

(scienceandcosmetics)

Input:FundamentalCodeParts

Page 45: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

2.ModelInitialization(setup)

IncludeonlythingsDONEONCEtoinitializethemodel

tosetup

clear-all

setuppatchesvariables

paintpatches

createturtles

setupturtlevariables

reset-ticks

end45

Page 46: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

3.Scheduledactions(GO)

“go”isrepeatedoverandover toexecutemodelIncludeONLY stufftobeexecutedEACHTIMESTEPKeepthe“go”proceduresimpleandneat(forcomplicatedstuffcallsubmodels)Includeterminationpoint

togo

tick

ifticks>500[stop]

askpatches[update]

askturtles[dosomething]

do-plots

end

46

Page 47: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Tickvs.ticks

tick– incrementstimebyoneperiod

ticks– measuresthetimelapsedsincethestart

Moretechnicalexplanation:• NetLogo hasainternalvariable- tickcounter

• “tick”isaprimitivethatsimplyincrementsthevalueoftickcounter

• “ticks”isareporterthatprovidesthecurrentvalueoftickcounter

47

Page 48: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

ElementaryNetLogo commands

A. SearchingNetLogo Dictionary

B. Workingwithagentsets

C. Workingwithvariables

D. Codebranching(conditionalstatements)

E. Workingwithstochasticity

F. Workingwithgraphics

G. Howtomakeyourcodelegibletoothers(documentation,commentsandtabbing)

48

Page 49: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

A.SearchingNetLogo Dictionary

NetLogo Dictionaryisawebpage

Use“Findonthispage”inyourwebbrowser

49

Page 50: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

B.Workingwithagentsets (ASK)

“ask”tellsallmembersofanagentset*todothecodeinthefollowingbrackets

Allmembersoftheagentset dothecode,oneatatime

Becarefulnottoputanythinginthebracketsthatshouldnotberepeatedforeachmemberoftheagentset!

*Oroneagent

50

Page 51: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

ASK:Howarethesedifferent?

askturtles[

buy

sellupdate-bank-account

]

askturtles[buy]askturtles[sell]

askturtles

[update-bank-account

]

51

Page 52: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

B.Workingwithagentsets (WITH)

“with”isoneofmanyprimitivesthatsubsetanagentset:

askturtleswith[color=blue][move]

Usethedictionarytogetsyntaxcorrect!!

52

Page 53: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

B.Workingwithagentsets (OF)

Whenappliedtoagentsets “of”providesalist ofvaluesofa-ownvariable:

sethappinessmin[happiness]ofneighbors

Moregenerally,“of”isaprimitiveforgettingavaluefromanotheragent:

sethappiness[happiness]ofa-neighbor-turtle

Usethedictionarytogetsyntaxcorrect!!

53

Page 54: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

C.Workingwithvariables(=,SET)

Twofundamentalsetsofoperations• Updatingvalueofavariable

à “Assignment”operations

• Checkingifavaluesatisfiessomecondition

à “Conditional”operations

54

Page 55: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

(equals ornoequals?)

“Assignment”statements

Wrong:happiness=([happiness]ofa-neighbor-turtle)

Right:sethappiness([happiness]ofa-neighbor-turtle)

55

“Conditional”statements(boolean;yes-or-no)

ifhappiness=3[stop]

ifhappiness<=3[stop]

ifhappiness!=5orticks>17[stop]

Page 56: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

C.Workingwithvariables(SETvs.LET)

Global variables– knowntoallprocedures

Local variables– knownonlytooneprocedure

Uselet tocreate andset thevalueofanewlocalvariable:

letmean-neighbor-sizemean[size]ofturtles-onneighbors

Use“set”tochange thevalueofanexistingvariable

• global,turtle,patch...orlocalvariables

setmean-neighbor-sizemean-neighbor-size ^0.5

56

Page 57: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

C.Workingwithvariables:Givingavaluetoanotheragent

Howdoesonepatch(turtle)giveitsvalueofavariabletootherpatches?

Therearetwowaystodothis:

1. askneighbors[setpcolor [pcolor]ofmyself]

2. letmy-colorpcoloraskneighbors[setpcolormy-color]

57

Page 58: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

D.Codebranching(conditionalstatements)

Ifelse (boolean condition)

[

;Dothisifconditionistrue

]

[ ;else

;Dothisifconditionisfalse

]

58

Page 59: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

E.Workingwithstochasticity

UniformdistributionU(a,b)

random(b-a)+a

NormaldistributionN(mean,variance)

random-normalmeanstd

Selectingrandompatches

askpatcheswith[random1<density]

Selectingrandomlyoneagentfromanagentset

askone-ofpatches[setpcolor green]59

Page 60: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

F.Workingwithgraphics

ProgrammingGuideà Colors60

Page 61: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

F.Workingwithgraphics

topaint-patch

ifelse own-stress-level>=100

[

setpcolor scale-colorredown-stress-level300100

]

[

ifown-stress-level>10

[

setpcolor scale-colorgreenown-stress-level0100

]

]

end61

Page 62: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

G.Makingyourcodelegible(tootherpeople)

1) Comment,comment,comment• Variabledeclaration– purposeandrange

• Procedure– purposeanddescription

• Submodel equations– cite,explain

2) Indentthecodesothatitshowsclearcodeblocks(i.e.previousslide)

3) Oncedone,taketimetoprovidedetaileddocumentation(ODD)

62

Page 63: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Finally,whenindoubt,Usethis!!

63

Page 64: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Work through the Mushroom Hunt and Butterfly HilltoppingExercises – both are on the VLE.

64

NetLogo Practice

Page 65: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

To do: Readings: Grimm, V., Revilla, E., Berger, U., Jeltsch, F., Mooij, W. M., Railsback, S. F., et al. (2005). Pattern-oriented modeling of agent-based complex systems: Lessons from ecology. Science, 310(5750), 987-991.Practice: Finish Netlogo Tutorials & Exercises, read through the PV diffusion ODD

65

Next week:

Page 66: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

ReadtheODDofthePVdiffusionmodelbelow.

Purpose: Thepurposeofthemodelistosimulatethephotovoltaic(PV)solarpaneldiffusioninaregionwithdifferentsubsidyschemes.InspiredbytheslowuptakeofPVdespitetheshortpaybacktime.

Entities,statevariables:Themodelincludesthreetypesofagents;

(i) theobserverrepresentingthepoliticalandeconomicmarketenvironment, issettingpolicyspecificparameter(i.e.PVsubsidies),marketspecificparameters(i.e.PVlifetime,panel-cost,efficiency,andgridelectricitycosts),butaswellagentspecificparameter(i.e.sensingradius,neighbourthreshold, andinterestrate).

(ii) houseowners(turtles)livinginaparticularhousedecidingabouttheinstallationofaPVpanelontheirhouse,basedontheirsocialenvironment,andacost-benefitanalysis.

(iii) patcheshavedifferentsolarpowergenerationpotentialbasedontheirinsolation(afunctionofthelocationonthelandscape)andpatchquality(shadowfromotherbuildingsandrooforientation,randomfactorbetween30-100%) influencingtheoptimalyield.Ifthereisahouseonthepatch,thevaluesforpanelsize(roofsizeavailableforPVinstallation,randomvaluebetween10and40m2)andPVattributesareset.

Scales:Weuseanartificiallandscapeof100x100patches,thetimeresolutionisoneyears(onetickrepresentsoneyear)andwerunthemodelfor50years.

66

FirstNetlogomodel:ThePVdiffusionmodel (ODD)

Page 67: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Processoverviewandscheduling:

Agents(ownersofthehouses)developtheideaofinstallingPVifenoughoftheirneighbours(inacertainsensingradius)havePVinstalled,orinasmallpercentagetheywillcomeupwiththe ideaontheirown.OncetheydevelopedtheIdeaofinstallingaPV,agentscalculatethePVinvestmentanddecide.Thecalculationismadebasedontheagentscostestimationof“his”PVinstallation,consideringsubsidies,investmentcosts, interestrates,feed-intariffs,andtheexpectedelectricitypriceincrease.PVisinstalledifthegenerationcostsperkWhofelectricity(dependingonPVoutput,costs,subsidiesperm2,andinterestrate)arelowerthantheavoidedcosts(gridcostsexpectedtoincrease)plusthefeed-intariff(subsidiesperkWhexpected).

Initialization:

Landscape:Asimpleartificialtopographyofthelandscape(theelevationofeachpatch)isinitializedwhenthemodelstarts.Weassumemaximalonehouseoneachpatch.Patch-qualityisrandomlyassignedbetweenit’sextremevalues.Insolationvariesbetween300-1300W/m2dependingontheelevation(reducedby30%throughfogbelow50m)andtheorientationoftheslope(southmaximalifnofogandnorthminimal).

Agents:Theturtlesrepresentsthehouseownerandareinitializedbycreating5.000ofthemandsettingthemonarandomemptypatch.Roof-sizeandinterestratearerandomlyassignedbetweentheirextremevalues.PVinstallationsarerandomlyassignedto0.1%earlyadoptersandtheageoftheplantissettoarandomvaluebetween 0andPV-lifetime.

67

FirstNetlogomodel:ThePVdiffusionmodel (ODD)

Page 68: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Submodels:

DeterminetheideatoinstallPVpanels:OnlyhouseownerswithoutanexistingPVinstallationenterthissubmodel.Theysensetheirlocalneighbourhood inacertainsensingradiusandifenoughoftheirneighboursalreadyhaveaPVinstalledtheythinkabout installingoneaswell.Theownerssensingradius(defaultof4patches)andtherequired%ofPVinstalledintheneighbourhood tothinkaboutone(defaultof10%),arebothmodelledasglobalparameters.Inadditioneachyear0.1%ofallownerswithout PVthinkabout installingoneindependent oftheirneighbours.

CalculatePVinvestmentbalanceanddecide:PVisinstalledifthegenerationcostsperkWhofelectricity(dependingonPVoutput, costs,subsidiesperm2,andinterestrate)arelowerthantheavoidedcosts(gridcostsexpectedtoincrease)plusthefeed-intariff(subsidiesperkWhexpected).ThegenerationcostsareafunctionofthetotalcostsforthePVinstallationdividedbytheelectricityoutput ofthepanelsovertheirlifetime.Totalcostsdependonthe installationsize,PVcostsperm2,subsidiesperm2,scaledbyadiscountingfactorwhichis(1+interestrate)̂ PVlifetime.Thisincreasesthetotalcostwith increasinginterestrate,which issetasaglobalparameter.Theelectricityoutputoftheinstallationperyearisasimplemultiplicationofinsolation,patch-quality,PV-efficiency,roof-size,wherePV-efficiencyisdefinedasaglobalparameter.TheavoidedcostsperkWhequaltotheelectricitycostsfromthegrid,butsinceagentsexpectanincreaseinelectricityprice(annualgrowthrate),wecalculatesimplifiedmeangridcostsbytakingtheaverageofastartandanendvalue.

68

Section3.5Implementing afirstagent-basedmodelFirstNetlogomodel:ThePVdiffusionmodel (ODD)

Page 69: Agent-based Modelling (ABM) · Introduction Netlogo, first ABM model ... • Stock market simulation (Arthur et al., 1997; ... of the 2008 financial crisis.

Now, letusforthefirsttimewriteaNetLogo programbytranslatingtheODDformulation,forthePV-diffusionmodel.Thewaywearegoingtodothis ishierarchicalandstep-by-step,withmanyinterimtests.Westronglyrecommendyoualwaysdevelopprogramsinthisway:

1. Programtheoverallstructureofamodelfirst,beforestartinganyofthedetails.Thiskeepsyoufromgettinglostinthedetailsearly.Oncetheoverallstructureisinplace,addthedetailsoneatatime.

2. Beforeaddingeachnewelement(aprocedure,avariable,analgorithmrequiringcomplexcode),conductsomebasictestsoftheexistingcodeandsavethefile.Thisway,youalwaysproceedfrom‘firmground’: ifaproblemsuddenlyarises,itverylikely(althoughnotalways)wascausedbythe lastlittlechangeyoumade.

• First,letuscreateanewNetLogo program,saveit,andincludetheODDdescriptionofthemodelontheInformationtab.

• StartNetLogo anduseFile/NewtocreateanewNetLogo program.UseFile/Savetosavetheprogramunderthename“PV-diffusion-1.nlogo” inanappropriatefolder.

• CopytheODDdescriptionofthePVdiffusionmodel.GototheInformationtabinNetLogo,clicktheEditbutton, andpaste inthemodeldescriptionatthetop.ClicktheEditbutton again.

YounowseetheODDdescriptionoftheButterflymodelatthebeginningofthedocumentation.

69

Implementing afirstagent-basedmodelFirstNetlogomodel:ThePVdiffusionmodel