1 / 54

MIS 643 Agent-Based Modeling amd Simulation 2017/2018 Fall Creating Simple Agent-Based Models

MIS 643 Agent-Based Modeling amd Simulation 2017/2018 Fall Creating Simple Agent-Based Models. Outline. Intorduction Life Heroes and Cowards Simple Economy. Introduction. Intorduction to Agent-Based Modeling by U. Wilensky and W. Rand Chapter 2. Introduction.

vtibbetts
Télécharger la présentation

MIS 643 Agent-Based Modeling amd Simulation 2017/2018 Fall Creating Simple Agent-Based Models

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MIS 643 Agent-Based Modeling amd Simulation 2017/2018 Fall Creating Simple Agent-Based Models

  2. Outline Intorduction Life Heroes and Cowards Simple Economy

  3. Introduction • Intorduction to Agent-Based Modeling • by U. Wilensky and W. Rand • Chapter 2

  4. Introduction • learn to construct simple ABMs • “toy models” – not mean models of real phenomena • thought experiments • objects to think with • simple to construct but • exebits interesting, suprising emergent behavior

  5. Outline Intorduction Life Heroes and Cowards Simple Economy

  6. Life • In 1970 British mathematician John Horton Conway, Conway (1976) • cellular automata - the “Game of Life” • Martin Gardner, • Scientific American colomn

  7. The Game • Played on checkeboard – graph paper • N x N cells – • can be • “alive” or “dead”: state of a cell • surrounded by • eight neighbour cells • the grid is “wrap around” • clock ticks – generation

  8. Rules of the Game • Each cell checks its own state and states of its neighbors and • set itself as “alive” or ”dead” • if the cell has less than 2 alive neighbors • it dies • if it has more than 3 alive neighbors • it also dies • if it has 2 alive neighbors • it remains in its current state • if it has 3 alive neighors • if dead become alive, if alive, stay alive

  9. NetLogo • NetLogo has three tabs • Interface tab • black area – “view” • white area – interface • set user interface elements; buttoms, siliders.. • observe results: output, plots.... • Code tab • Info tab

  10. The view • composed of grid of cells – patches • how to open • click settings in toolbar or • on the visw double click and select edit • Parameters to set • Location of orgin • max-pxcor, max-pycor 25 • patch size: 13 to 8 • world wraps hirizonally, vertically, see IABM-WR pp 55 Box 2.1 Wrapping

  11. NetLogo Code • modules – procedures • begin with to • end with end • usually • setup • initializations • go • processes taking place advences clock by tick

  12. Procedures • procedures – commands • to procedure_name • commands • end • Create a button executing procedure setup • Create a button executing procedure go • forever is cheked – forever button • write setup procedure • code tab

  13. Procedures (cont.) to setup end to go end

  14. Initialization to setup ;; ask patches [ comands ] .. ;; other commnads end ask primitive asks selected agents to do actions by commands in brackets set color of all pathces to red set - primitive is assignment pcolor – variable for patches

  15. Initialization - algorithm to setup ;; clear all setings ;; set dead patches to blue ;; 10% of patches are alive ;; initilize clock end

  16. to setup clear-all ask patches [ set pcolor blue if random 100 < 10 [ set pcolor green ] ] reset-ticks end

  17. Exercise • What is the difference between asking exactly 10% of the patches being alive • How do you perform this in general for any number of patches, exactly X% being alive • the chance of a randomly seleced patch being alive is 10%

  18. Box 2.2: Agent Centreric Thinking • WR-IABM Chapter 2 • Box 2.2

  19. Asking Patches Probabilistically • each patch performs the tasks in ask with a probability • probability of a patch being green is 0.1 • in each run different number of patches turn into green

  20. Probability of a Patch being green ask patches [ if random 100 < 10 [set pcolor green] ;; end if ] ;; end ask • or ask patches with [random 100 < 10] [ set pcolor green ] ] ;; end ask

  21. Asking exactly 10% of patches to setup ask n-of 0.1*(51*51) patches [ set pcolor green ] ] ;; end ask ] ;;end setup • or more generally to setup let number-of-patches count patches ask n-of 0.1*number-of-patches patches [ set pcolor green ] ] ;; end ask ] ;;end setup

  22. go Procedure - algorithm to go ;; each patch counts its alive neighbors ;; number of green neighboring patches ;; patches with 3 green naigbors turn or stay green ;; patches with 0 or 1 green neighbors turn or stay blue ;; patches with 4 or higher neighbors turn to blue end

  23. go Implementation to go ask patches [ set live-neighbors count neighbors with [pcolor = green] ] ask patches [ if live-neighbors = 3 [set pcolor green] if live-neighbors = 1 or live-neighbors = 0 [set pcolor blue] if live-neighbors >= 4 [set pcolor blue] ]

  24. clear-all to setup clear-all ;abriviares as – ca - ask patches [ set pcolor blue if random 100 < 10 [ set pcolor green ] ] end clear-all: clear all default values

  25. variable for patches patches-own [ live-neighbors ] live-neighbors different variable for each patch initialized to 0

  26. firther modifications • adding ticks • add reset-ticks • to the end of setup • add tick to the begining or as a last statemet of go procedure

  27. to setup clear-all ask patches [ set pcolor blue if random 100 < 10 [ set pcolor green ] ] reset-ticks end

  28. to go ask patches [ set live-neighbors count neighbors with [pcolor = green] ] ask patches [ if live-neighbors = 3 [set pcolor green] if live-neighbors = 1 or live-neighbors = 0 [set pcolor blue] if live-neighbors >= 4 [set pcolor blue] ] ;; end ask tick ] ;; end go procedure

  29. Stable Patterns • 1 – Still Lifes: stable shapes unless other shapes collide with them • block, the beehive, the loaf,... • 2 – Oscillators: repeat over time • 3 – Spaceships: move across the life world • Unstable Patterns: • guns: a pattern with a main part that repeats like an oscillator and periodically emits spaceships

  30. In 1983, Stephan Wolfram – physisist and mathematical software entrepreneur • One dimensional CA with only one neighbor in each side • classified all possible rules into four behavioral regions • homogenous, periodic, chatoic and complex • Complexity in nature – due to CA like simple mechanisms

  31. Outline Intorduction Life Heroes and Cowards Simple Economy

  32. Heroes and Cowards • Each member (player) has an enemy and a friend selectd from other people playing the game

  33. Rules of the game • with people each choose a heroe and an enemy • two stages: • first every one act – cowardly • move be sure that your friend is always between you and your enemy • hiding from your enemy behind your friend cowardly • second – behave like a heroe • move between your friend and enemy • protecting your friend from your enemy – herotic manner

  34. setup pseudocode to setup ;; clear all previous settings variables ;; make patches white ;; create a set of turtles read tne number froma slider ;; set x y corrdinates randomly ;; set colors to blue for cowards and red for heroes ;; if mixed is choosen determine crowads and heroes randomly while settng their colors ;; set one other turtle as their friends and oneother turtle as their enemies ;; reset ticks end

  35. setup code turtles-own [friend enemy] to setup ca ask patches [set pcolor white] crt number [ setxy random-xcor random-ycor if personalities = "cowardly" [set color red] if personalities = “breverly" [set color blue] if personalities = "mixed" [set color one-of [blue red]] set friend one-of other turtles set enemy one-of other turtles ] reset-ticks end

  36. Interface elements • slider: • variable: number • default 68 • Chooser • variable: personalities • choices: “coward”, “heroe”, ”mixed” • Settings • wrap off

  37. go pseudocode go at each tick if the agent is heroe act brawely – in a herotic manner if the agent is cowars act cowardly advance clock by one end

  38. to go ask turtles [ if color = blue [act-bravely] if color = red [act-cowadly] ] tick end

  39. acting submodels to act-bravely ;; cıbtext turtle ;; move toward the mid of your friend and your enemy facexy ([xcor] of friend + [xcor] of enemy) / 2 ([ycor] of friend + [ycor] of enemy) / 2 fd 0.1 end to act-cowadly ;; cıbtext turtle ;; set your friend between you and your enemy facexy [xcor] of friend + ([xcor] of friend - [xcor] of enemy) / 2 [ycor] of friend + ([ycor] of friend - [ycor] of enemy) / 2 fd 0.1 end

  40. Random number generation • sequance of random numbers • initial value is taken from the clock of computer • if you want to strart from the same seed random-seed 137 show random 100 show random 100 show random 100 • always generate the same sequance of random numbers 79 89 61

  41. Outline Intorduction Life Heroes and Cowards Simple Economy

  42. Simple Economy • Economies – heterogenous actors • buyers and sellers • in 1996, J. Epstein, R. Axtell, • SugerScape

  43. Fixed number of people: 500 • each starting out with inital amount of money: 100 • At each tick, • each person gives one of her 1 dollar‘s to any other person at random • What will happen to the distribution of money? • constraint – total amount of money fixed • no one can have negative money • if income is zore, connot give any away

  44. is there a limiting distribution of money? • Intiution: • flat – • initially every body has the saime money • randomly seleced one to give • normal -

  45. Version 1 to setup ;; clear everything ;; create 500 turtles with an initial wealth of 100 each ;; reset tick end

  46. setup turtles-own [wealth] to setup ca crt 500 [ set wealth 100 ] reset-ticks end

  47. Version 1 to go ;;ask turles to transact if they have positive wealth ;; advence clock end to transact ;; contecst turtle ;; decrement wealth of current turtle by one ;; for one of the other turtles, increment its wealth by one end

  48. go and transact to go ask turtles with [wealth > 0] [transact] tick end to transact set wealth wealth - 1 ask one-of other turtles [set wealth wealth + 1] end

  49. Histogram • Select a plot • title: Wealth Distribution • min x cor: 1 nax x cor 500 • min y cor 1 max y cor 80 • pen update command: • histogram [wealth] of turtles • pen – select bar

  50. Exercises • can you move the wealth chacking condition to transact? • can you use with instead of if?

More Related