banner-nll

5. Coding and Documentation

Once the model is flow-charted, you can begin the actual coding. The goal here is to turn the hypotheses you developed into lines of code.

This is the process you have been working towards, and it will be much easier if you have fully thought through the first four steps.  We believe that as you code, it is critical that you begin to document or comment each procedure you write. Not only will this make it easier for you to understand the logic of the model, but it will make it much easier for others to understand your code when they look at the model. 

This is the part of model-building which is fun, but it is also challenging. You cannot anticipate every issue that you will encounter beforehand, nor can you always write code exactly the way your flow-chart says you will.

It is also a lot easier to take into account a future addition to the code from the beginning, than it is to completely redesign a model that is almost finished.  You can build a change into the model from the beginning, but not actually implement it much easier than you can implement a major change further into the development process.

PLAN AHEAD and SAVE TIME LATER!!!

6. Validate Your Model

Once the model is running, you enter one of the most difficult stages of model-building; that of validating the model, to be sure that the model is actually doing what you think it is doing. 

There is no one way to validate a model, although if you use the process we outlined above, the odds are your model will be much more sound than one that is just put together “off the cuff.”

Part of validating involves making sure that your model’s code is actually accurate. For example, in models with nested IF and IFELSE statements, it is very easy to put a closing bracket (“]”) in the wrong-place, and not have the model give you a compiling error, even though the bracket’s placement is causing the model to act incorrectly. 
This becomes much easier the more comfortable you become with Netlogo.

Another part of validation deals with such questions as:

  • Testing to see how the model changes with different settings, and determining if those differences are meaningful.
  • Determining what impact randomness has on the model’s results.
  • Deciding how many times you need to run the model to be sure of the results, and how long the model has to run so you can capture all of the model’s behavior.

Once you are satisfied that the model does what you want it to do, and you have answered these questions, you have reached the final step:

7. Testing and Publication

You are now ready to test your model, perhaps use some of the data exporting tools built into Netlogo such as Behavior-Space or explot plots.   Once you test your model, you can write up your results and publish the model.

The goal of the model will determine how much effort you put here. Obviously a model used in a peer-reviewed research article will probably require more analysis than a simple model you are creating to explore an idea for a class.

 

You have completed this Study Guide,
but might consider completing Lab 6 to supplement it.


With Support from:

The NetLogo Learning Lab is part of modelingcomplexity.org, the home of the Mesa State College Center for Agent-Based Modeling.

This website is copyright by Mesa State College, 2004. All rights are reserved.

Some materials are adapted from the NetLogo User manual, and are copyright Wilensky, U. (1999). NetLogo.  Center for Connected Learning and Computer-Based Modeling. Northwestern University, Evanston, IL.