Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← abm 2 5 doc random

Get Embed Code
3 Languages

Showing Revision 4 created 05/11/2017 by mrmrjones.

  1. Now that we have our model and it's
    pretty much doing what we want it to
  2. I want to use the model to talk about a
    couple of key concepts in ABM.
  3. First of all, we did a pretty good job of
    going through
  4. and documenting our code as we were
    doing it.
  5. But one other thing you probably want to
    do is document in the info tab as well.
  6. So I'm going to go over to the info tab
    and hit edit.
  7. And then under 'What is it?', for
    instance, we can say:
  8. 'This is a model of the Heroes and Cowards
    game from the Fratelli group'
  9. And you can go ahead and fill in a lot of
    these other sections.
  10. Now one thing I find very valuable as a
    model coder is to write out early on...
  11. what's called a pseudocode description
    of the way the model works.
  12. I usually do this under the 'How it
    Works?' section,
  13. because it will eventually morph into
  14. You might also want to save this off in a
    separate, more technical, document,
  15. if you didn't want to include it in the
    info tab directly.
  16. But I always talk about how's there going
    to be an initialise procedure,
  17. and there's going to be an iterative, or
    a tick, procedure.
  18. So the initialise is the 'setup' and the
    iterative or tick section is the 'go'.
  19. And so what do we want the model to do?
  20. And sometimes I'll do this before I even
    create the model -
  21. in this case I knew the model pretty well
    so I just started writing it -
  22. we wanted to create a group of turtles,
    and maybe in future work...
  23. we want the number of turtles to be from
    an input slider on the interface.
  24. I didn't do that on this model, but maybe
    this is something I'm going to do in the future.
  25. We could have each turtle move to a random
    location on the screen, obviously.
  26. We could have the conditional based upon
    the personalities,
  27. so, there is a chooser called
    PERSONALITIES that specifies the behaviour
  28. A lot of times in NetLogo code, if we're
    talking about a variable
  29. in the pseudocode description, we'll put
  30. So we might want to put SETUP, GO,
    PERSONALITIES in caps,
  31. and NUMBER, our number of turtles,
  32. to distinguish it from the rest of what
    we're writing.
  33. Then we can say:
  34. If PERSONALITIES = 'Brave' the turtle
    turns blue
  35. and then we can do the same thing for
  36. if PERSONALITIES = 'Cowardly' the turtle
    turns red
  37. and we could do the same for 'mixed':
  38. if PERSONALITIES = 'Mixed' the turtle
    turns red or blue randomly.
  39. We also have to say that each turtle picks
    a FRIEND and an ENEMY,
  40. and we reset the ticks.
  41. So this is just like a natural language
  42. we can go in and finish this off by
    writing the 'GO' description:
  43. Each turtle which is blue -
  44. actually - I just realised I backed this
    up didn't I -
  45. so this is why documentation is always
    important to do!
  46. So, if you notice, when I was writing it,
    I said the turtle turns blue if it's brave
  47. but in the code I said that it's the
    cowards that turn blue
  48. so let's change that around, while
    we're doing this,
  49. which is why it's important to check
    your code.
  50. So each turtle which is blue moves away
    from the ENEMY past the FRIEND
  51. and those are variables so I can
    capitalise them.
  52. and then we can also do the same,
  53. Each turtle which is red moves toward the
    ENEMY in the way of the FRIEND.
  54. And that's it! That's the natural language
    description of the model itself,
  55. and it's a pseudocode description that I
    can now hand to someone else
  56. and ask them what they thought of this
  57. So it's important to do documentation.
  58. Make sure you're documenting the
    model both in terms of a separate document
  59. as well as within the code, because it
    makes it easier to tell
  60. whether your conceptual model and your
    implemented model are matching each other.
  61. So one thing that I find very interesting
    about this model
  62. is that when you hit 'mixed' you never
    quite get the same results,
  63. it always looks a little different.
  64. And that's because NetLogo is randomly
    placing the turtles in the world
  65. But what's interesting is because the
    computer doesn't have a true random notion
  66. what it's actually doing instead is it's
    using a random number generator
  67. to create what we call pseudo random
  68. Now these numbers are generated using a
    deterministic process
  69. but specified by a random seed.
  70. And what NetLogo does is generate a bunch
    of random seeds every time it runs
  71. and then uses those seeds to decide what
    the values are to pull.
  72. But you can set the seed.
  73. So one thing I could do is say the random
    seed is 188: 'random-seed 188'
  74. and then I can say 'show random 100', and
    I can do that a couple of times,
  75. and what this is doing is generating three
    random numbers
  76. and if I set the random seed back to that
    same value, 188,
  77. I will then get the same three random
    numbers in a row.
  78. So this means that if I see a pattern of
    behaviour, and I've set the random seed,
  79. I can re-create that pattern, even though
    it's technically a 'random' outcome.
  80. In fact this is often done when you're
    running a bunch of agent based models -
  81. that you've set the seed before you run,
  82. so that if something interesting happens
    in the model
  83. you can then go back and look at the
    results at a later time.
  84. In fact, if you pull up the 'Heroes and
    Cowards' model
  85. that is in the NetLogo 'Models Library',
  86. it's under the 'IABM Textbook' section,
    chapter 2
  87. What we've done is we've got some preset
  88. and so what are those preset
    configurations doing?
  89. Well, if you look you'll see that they're
    actually running this command 'preset'...
  90. which has this long string after it.
  91. If you look in the code, what 'preset'
    does is take a random number seed
  92. and set the random number seed to that
  93. and in fact it also has to set the number
    of agents to a specific value
  94. because if the number of agents is
  95. then you'll get a different number of
  96. So what does this allow us to do?
  97. Well, it means that when we hit one of
    these preset configuration buttons
  98. we will always get the same pattern.
  99. So here we're going to hit the 'dot'
  100. and if we let it run,
  101. you'll see that eventually we get down to
    a spinning dot.
  102. That's a common pattern that we see.
  103. If we hit the 'frozen' button, and then
    let it run
  104. you'll see we get to this stage which is
  105. where a bunch of the turtles are just
    frozen in the middle of the world.
  106. Then, one of my favourites is the 'slinky'
  107. which causes this 'slinky' which just
    bounces from edge to edge.
  108. The 'spiral' pattern...
  109. which creates this 'spiral' effect in the
  110. And you can get other 'slinky's and
  111. and the 'wandering flock' pattern as we
    call it
  112. and the 'generally cool one that
    eventually stops' -
  113. we didn't have a short name for that one!
  114. So this illustrates a powerful both
    problem and benefit of the NetLogo world
  115. which is that you're going to be able to
    control somewhat the randomness
  116. of what goes on
  117. but it's something you need to think about
    when you're generating your model results
  118. as to what that randomness really is.
  119. That's it for this week, except for the
    'wrap up' which will be next.
  120. The test will be live shortly.
  121. So, thanks! Next week, we'll be starting
    on unit 3
  122. where we'll be talking about how to extend
    models that other people have built.