340 likes | 807 Views
Agent-Based Modeling Overview . Basic ABM Components Background for guest talks Background for using NetLogo ABM Creation Conceptual Model design ABM implementation - a computer program General Programming Tips NetLogo basics – building blocks for ABMs Start Group Project Design.
E N D
Agent-Based Modeling Overview • Basic ABM Components • Background for guest talks • Background for using NetLogo • ABM Creation • Conceptual Model design • ABM implementation - a computer program • General Programming Tips • NetLogo basics – building blocks for ABMs • Start Group Project Design
ABM - Represents (part of) the world < Look at El Farol , Wolf-Sheep-Grass > • Population of agents; often multiple types of agents • Each Agent: state (data); actions; choice mechanisms (goals); • Adaptive processes (individual; population) • Environment (non-agent): often spatial; has its own dynamics; • Dynamics: who does what, when; activity schedule; time • Interaction topology: Who interacts with whom/what • Initial state of ABM (agent/environment state; parameters ) • Measures: aggregate values we are interested in! • GUI (Graphical User Interface) -- Controls and Displays
Agent Types – What kinds of agents are there? Agent Type = Set of Variables and procedures • Defines a set of variables (fields) that all agents of this type have • Defines a set of procedures all agents of this type can carry out. • Variables represent agent characteristics, memory, relationships • Example types and variables: • Cell -- infected, activationLevel • Person -- sex, age, education, income, infected priceOfCigarettesAtLocalStore, seenFriendSmoke, parents, siblings, friends • School – size, budget, teachers, students
Agents (continued) Agent Instances • One instance for each “real world agent” being modeled • An instance’s variables contain values (the agent’s “state”) representing one real world agent’s characteristics, memory, relationships, etc. < look at running model with agent monitors showing their state > Population of Agent Instances • An explicit representation of distributions agent characteristics, etc.
Agent Procedures – Represent what agents can do • All agents of a given type can execute the same procedures • What each agent actually does can differ and vary over time: Each agent has its own state / place in environment. Procedures defined to carry out various agent activity: • Sense their (local) environment: countSimilarNeighbors() • Communicate with other agents: askNeighborsType() • Make choices (calculations; heuristics): pickBestSite( candidates ) • Move / change environment moveForward( distance ) • Exchanges with other agents: trade, buy, predation grazeOnPlant( loc ) • Learn: change state; change relations; change rules addFriend( person ) • Reproduce, die haveOffspring()
Agent Procedures in Action A particular agent executes a procedure when “asked” (told!) • Agent already has access to its own state • Agent may be sent “arguments” with procedure: moveForward ( d ) • Agent carries out procedure’s specified operations: • Built from language primitives and calls to other procedures • Conditional on state of agent, its neighbors and environment • Agent own state may change, or it may do nothing! • Agent actions may try to change state of environment (or other agents!)
Designing / Programming agents: Think like an agent! • Who is asking me to do what? • What do I know? • Who can I ask for information? • What actions-options do I have? • How do I choose? • How do I learn ? (Do I have offspring?) Example: Program (conceptual) a sheep or wolf agent
The Environment (Non-agent) • Often spatial – 2D grid of locations (easy to see what’s happening!) • Sites (“patches”) can have variables to store environment state • Ex: occupied, grassLevel, toxinConcentration • Dynamics independent of agents: “the biophysics” of the world • growGrass() , diffuse(toxin), • Agents interact with environment • Ask for information: isSiteOccupied(), getListOfNeighbors() • Change state of world: eatGrass(), moveTo(x,y), addToxin(x,y) • Spatial biases can be represented by constraining agent actions • Only sense local information • Only affect / move to local sites • Non-spatial environment: “globally available” information • Ex: barAttendanceLastStep, govSpendingOnEducation
Adaptive Behavior Agent behavior is a function of its “behavioral rules” (procedures) and its current state, neighbors’ state, environment state Agent’s can adapt (change behavior) when/if : • Conditional behavior changes because: • Agent’s own state changes (if unhappy then move) • Neighbor agents change • Environment state changes • Learning – individual agents change behavioral rules based on experience • Evolution – population changes: new agents with new rules, etc.
ABM Dynamics -- Generated “Bottom Up” • Define micro-level mechanisms: agents, environment • Set model parameters: control initialization ; set mechanism parameters • Initialize environment, agents -- System State at t=0 • Run the model: System State(t+1) = F( State(t) ) • F(.) is very complicated – use computer! • Stochastic -- multiple runs generate distribution of histories • Measure/observe macro-level behavior of system generated by agents • Aggregate measures • Patterns in space • Correlations in agents’ states • Static snapshots and over time.
Agent Dynamics -- Time • Which agents do which actions (procedures) in what order? • When is the environment state updated? • How is model time related to “real world” time? • How are “rates” of different model components related to each other? • Can be complicated: model and modeling-goal dependent. Typical approaches (hybrids also common): • Discrete Time – agents activated each discrete step (random order) • Synchronous update: All change state “instantaneously” based on same information about previous state. Like playing Rock-Paper-Scissors! Or GameOfLife & EqnBasedModels • Asynchronous update: One agent acts and changes state, Then next acts based on updated state, then next, etc. • Discrete event: time advances as “events” (agent actions) happen. Order is dynamically determined (stochastically)
Interaction Topologies Who interacts with whom ? “Traditional” assumptions: • Complete mixing: everyone interacts with all others • Random mixing: interact with uniform random sample Complex systems approaches often include: • Spatial bias: higher probability interact with spatial neighbors • Social network bias: higher probability interact with family, friends, … Often include combinations of spatial / social interactions
ABM Projects – This week and later Most of these comments applicable to all modeling approaches. Some especially relevant to ABM. Keep in mind the modeling choices going from: • The World – what parts do you want to explain/understand What questions are being addressed? • A Conceptual Model • What agents, what actions, etc. (sketches, not details) • Hard questions (for any modeling enterprise…): • What to include? What to leave out? • Implementation of a conceptual model – a computer program Many choices -> many implementations of same conceptual model. (Unless you do it “by hand” as Schelling did!)
Designing a Conceptual (Agent Based) Model Start with simple, conceptual sketches, fill in as needed as you proceed • What types of agents? What do they do? How do they decide? • What data do agents need to have? • What is the environment, its state and dynamics (if any)? • How do agents interact with each other and the environment? Remember the KISS Principle (Keep It Simple, Stupid) • Model as political cartoon – focus on some aspects of the world, Other parts admittedly overly simple or ignored. • ABM – great temptation to add zillions of mechanisms! (Its looks cool!) • Sketch a series of conceptual models: • V0: has few components— probably it is too simple Include only the one or two key components/mechanisms • V1, V2: Add/complicate components/mechanisms only as needed
Designing a Conceptual (Agent Based) Model (cont) Keep asking: • What questions is the model being designed to answer? • What is model intended to explain or help us understand better? • What kind of model is desired / required / possible? • Simple, abstract, “stylized facts” – Exploratory Models Ex: Schelling; An’s “Toy” models (Wedn); Eisenberg etal (Wedn) • More “realism” – data for parameters / for model evaluation Still simple: Bruch’s models of segregation (Tues) Complicated: An’s models; Galea/Kaplan model (Thur) • Model specific situations – lots of data for initial state, etc. Ex: An’s models; models of traffic in specific cities; EpiSim (Portland)
Implementing an ABM as a computer program. • Choose language / platform (Friday) • Start from available program if you can! (See NetLogo Models Libraries) • Implement program stepwise, as a series of versions • Get each version doing something, no matter how simple • Add one mechanism/feature at a time. Test… (Makes testing and debugging later…) • See examples of sequences of versions this week (Tues,Thur)
On Programming Style Really important to make programs understandable & debuggable! • Use indentation, horz spacing, to emphasize program “structure” Take advantage of our eyes pattern recognition capabilities • Name variables, procedures in some standard way Case matters! Easier to read, understand and guess names Ex: avgAgemaxIncomefindNeigbhors() • Be consistent! Be Consistent!! • Procedure definitions should be short – see it all on one screen Complicated procedures should call sub-procedures.
Document Your Models, Programs and Experiments • Document, Document, Document • For others (sharing programs, especially with publication) • For yourself! In 2 months you’ll wonder “why did I do it that way?”! • Comments in programs • General comments about overall program structure • At start of each procedure • Write it before writing procedure! (Guide your coding; save mis-starts) • Describe anything “tricky” – again, you will forget! • Notebook files / wiki / etc • Model design / implementation decisions • Model Testing • Model Experiments (“How did I generate that figure…?”)