Now that we have our model and it's pretty much doing what we want it to
I want to use the model to talk about a couple of key concepts in ABM.
First of all, we did a pretty good job of going through
and documenting our code as we were doing it.
But one other thing you probably want to do is document in the info tab as well.
So I'm going to go over to the info tab and hit edit.
And then under 'What is it?', for instance, we can say:
'This is a model of the Heroes and Cowards game from the Fratelli group'
And you can go ahead and fill in a lot of these other sections.
Now one thing I find very valuable as a model coder is to write out early on...
what's called a pseudocode description of the way the model works.
I usually do this under the 'How it Works?' section,
because it will eventually morph into that.
You might also want to save this off in a separate, more technical, document,
if you didn't want to include it in the info tab directly.
But I always talk about how's there going to be an initialise procedure,
and there's going to be an iterative, or a tick, procedure.
So the initialise is the 'setup' and the iterative or tick section is the 'go'.
And so what do we want the model to do?
And sometimes I'll do this before I even create the model -
in this case I knew the model pretty well so I just started writing it -
we wanted to create a group of turtles, and maybe in future work...
we want the number of turtles to be from an input slider on the interface.
I didn't do that on this model, but maybe this is something I'm going to do in the future.
We could have each turtle move to a random location on the screen, obviously.
We could have the conditional based upon the personalities,
so, there is a chooser called PERSONALITIES that specifies the behaviour
A lot of times in NetLogo code, if we're talking about a variable
in the pseudocode description, we'll put it in CAPITAL LETTERS.
So we might want to put SETUP, GO, PERSONALITIES in caps,
and NUMBER, our number of turtles,
to distinguish it from the rest of what we're writing.
Then we can say:
If PERSONALITIES = 'Brave' the turtle turns blue
and then we can do the same thing for cowardly:
if PERSONALITIES = 'Cowardly' the turtle turns red
and we could do the same for 'mixed':
if PERSONALITIES = 'Mixed' the turtle turns red or blue randomly.
We also have to say that each turtle picks a FRIEND and an ENEMY,
and we reset the ticks.
So this is just like a natural language description
we can go in and finish this off by writing the 'GO' description:
Each turtle which is blue -
actually - I just realised I backed this up didn't I -
so this is why documentation is always important to do!
So, if you notice, when I was writing it, I said the turtle turns blue if it's brave
but in the code I said that it's the cowards that turn blue
so let's change that around, while we're doing this,
which is why it's important to check your code.
So each turtle which is blue moves away from the ENEMY past the FRIEND
and those are variables so I can capitalise them.
and then we can also do the same,
Each turtle which is red moves toward the ENEMY in the way of the FRIEND.
And that's it! That's the natural language description of the model itself,
and it's a pseudocode description that I can now hand to someone else
and ask them what they thought of this model.
So it's important to do documentation.
Make sure you're documenting the model both in terms of a separate document
as well as within the code, because it makes it easier to tell
whether your conceptual model and your implemented model are matching each other.
So one thing that I find very interesting about this model
is that when you hit 'mixed' you never quite get the same results,
it always looks a little different.
And that's because NetLogo is randomly placing the turtles in the world
But what's interesting is because the computer doesn't have a true random notion
what it's actually doing instead is it's using a random number generator
to create what we call pseudo random numbers.
Now these numbers are generated using a deterministic process
but specified by a random seed.
And what NetLogo does is generate a bunch of random seeds every time it runs
and then uses those seeds to decide what the values are to pull.
But you can set the seed.
So one thing I could do is say the random seed is 188: 'random-seed 188'
and then I can say 'show random 100', and I can do that a couple of times,
and what this is doing is generating three random numbers
and if I set the random seed back to that same value, 188,
I will then get the same three random numbers in a row.
So this means that if I see a pattern of behaviour, and I've set the random seed,
I can re-create that pattern, even though it's technically a 'random' outcome.
In fact this is often done when you're running a bunch of agent based models -
that you've set the seed before you run,
so that if something interesting happens in the model
you can then go back and look at the results at a later time.
In fact, if you pull up the 'Heroes and Cowards' model
that is in the NetLogo 'Models Library',
it's under the 'IABM Textbook' section, chapter 2
What we've done is we've got some preset configurations,
and so what are those preset configurations doing?
Well, if you look you'll see that they're actually running this command 'preset'...
which has this long string after it.
If you look in the code, what 'preset' does is take a random number seed
and set the random number seed to that value,
and in fact it also has to set the number of agents to a specific value
because if the number of agents is different
then you'll get a different number of calls.
So what does this allow us to do?
Well, it means that when we hit one of these preset configuration buttons
we will always get the same pattern.
So here we're going to hit the 'dot' pattern,
and if we let it run,
you'll see that eventually we get down to a spinning dot.
That's a common pattern that we see.
If we hit the 'frozen' button, and then let it run
you'll see we get to this stage which is interesting
where a bunch of the turtles are just frozen in the middle of the world.
Then, one of my favourites is the 'slinky' pattern...
which causes this 'slinky' which just bounces from edge to edge.
The 'spiral' pattern...
which creates this 'spiral' effect in the middle.
And you can get other 'slinky's and 'yo-yo's,
and the 'wandering flock' pattern as we call it
and the 'generally cool one that eventually stops' -
we didn't have a short name for that one!
So this illustrates a powerful both problem and benefit of the NetLogo world
which is that you're going to be able to control somewhat the randomness
of what goes on
but it's something you need to think about when you're generating your model results
as to what that randomness really is.
That's it for this week, except for the 'wrap up' which will be next.
The test will be live shortly.
So, thanks! Next week, we'll be starting on unit 3
where we'll be talking about how to extend models that other people have built.