Most ABM tools require some degree of programming
Programming in NetLogo has been simplified
Similar to other programming languages, but with shortcuts
Other popular packages (e.g. Repast Simphony or MASON) require Java knowledge
If you are inspired to learn more...
Try: Code Academy
And: code.org.
What are they?
Pieces of software to help people build models
Wide range of tools
Computer code ('libraries')
Entire graphical environment
Somewhere in the middle
Researchers write software to perform useful functions:
Draw graphs
Visualise the model
Manage the schedule
Great for programmers
Less time spend worrying about admin, more time on modelling
Examples:
Loads of others listed here
Entirely visual - no programming needed
Most useful for non-programmers
Examples
Some code writing, some visual development
More powerful than purely visual tools, but easier to use.
Save time having to learn to do simple tasks and concentrate on model behaviour
e.g. NetLogo
Base on Star Logo.
Popular teaching tool
Designed to be used by children
But also powerful
Developed by The Center for Connected Learning (CCL) and Computer-Based Modeling at Northwestern University
Free!
Uses Java in the background
Multi platform
Can be converted into applets (and embedded in websites)
Great for quickly putting a model together and thinking through ideas
Easy to build
Easy to interact with models
East to extract data and create plots
Excellent documentation: http://ccl.northwestern.edu/netlogo/docs/
Birks et al. (2012)
Randomly generated abstract environments
Theoretical 'switches'
Rational choice perspective
Routine activity theory
Geometric theory of crime
Compare results to expected outcomes:
Spatial crime concentration
Repeat victimisation
Journey to crime curve
Theory | Enabled | Disabled |
---|---|---|
Routine activities | Agents assigned a 'home' and routine paths | Random movements |
Rational choice | Victim attractiveness (based on risk, reward, effort) | Homogeneous target attractiveness |
Awareness space | Dynamic awareness - alters offender decision-making | Uniform environment awareness |
Results:
All hypotheses are supported
Rational choice has lower influence
NetLogo is "somewhere in the middle"
Graphical part (Interface) with sliders, graphs, buttons and a map
Scripting part (Procedures) which contains instructions (code)
Switch | Slider | ||
Button | Monitor | ||
Graph |
There are two types of objects in NetLogo: turtles and patches.
Both are agents
They have rules that determine their behaviour
They can interact with other agents
Main differences:
Patches cannot move
You can create different types of 'turtle' (e.g. person, dog, cat, car, etc.)
Why turtles?
'Logo' language originally used to control robot turtles. It seems that the name 'turtle' has stuck..
Also important: the observer
The 'god' of a model
Oversea everything that happens, give orders to turtles or patches, control other things like data input/output, virtual time, etc.
In programming, variables are a way of storing information. E.g.
my-name = "Nick"
seconds-per-minute = 60
pi = 3.142
infected = True
Variables can belong to different objects in the model.
Examples:
Turtle variables: e.g. name
, age
,
occupation
, wealth
, energy
Patch variables: e.g. height-above-sea
,
amount-of-grain
, building-security
,
deprivation
Observer variables:total-wealth
, weather
,
time-of-day
pi
Different objects can have different variable values
Commands are the way of telling NetLogo what we want it to do
Some examples
(don't worry, these will be explained properly in the first practical):
show "Hello World" | Prints something to the screen |
set my-age 13 | Sets the value of a variable |
ask turtles [ ... ] | Ask the turtles to do something |
ask turtles [ set color blue ] |
Asks the turtles to turn blue |
Commands are very well documented
NetLogo uses both square [ ]
and round ( )
brackets.
Round brackets are used to set the order of operations. E.g.:
2 + 3 × 4 = 14
(2 + 3) × 4 = 20
Square brackets are used to split up commands. E.g.:
ask turtles [ ... ]
the ask
command
expects to find some more commands inside the brackets.
Contexts are NetLogo's way of controlling where commands are sent.
There are three contexts:
Don't Panic: Lots of opportunity to understand these during the practicals..
Programs are recipes
And computers are really, really stupid cooks.
Programmers need to tell the computer exactly what to do, and in what order
Geek joke:
Q: How do you keep a programmer in the shower forever?
A: Give him a bottle of shampoo that says "lather, rinse, repeat".
Usually, NetLogo will run through your code, one line after the other.
But! Sometimes there are two or more possibilities for what to do next.
if
statements are one example:
... start here ...
if ( age < 18 )
 [ .. do something .. ]
if ( age > 18 )
 [ .. do something else .. ]
... now continue ...
Computers don't care what code looks like
But there are some good conventions that we can use to make our code easier to understand by humans
Indentation
New blocks of code should be indented (moved to the right)
E.g. the if
statements on previous slide
White space
Different sections of code can be separated by lots of white space
Comments
Comments are special parts of code that NetLogo will ignore.
Anything after a ;
is ignored.
Use comments to explain what your computer code does.
Good
if age = 15 [
if count friends > 0 [
set happiness ( happiness + 1 )
]
if count friends > 5 [
set happiness ( happiness + 5 )
]
]
Bad
if age = 15 [
if count friends > 0 [
set happiness ( happiness + 1 )
]
if count friends > 5 [
set happiness ( happiness + 5 )
]
]
Good
if age = 15 [
if count friends > 0 [
set happiness ( happiness + 1 )
]
if count friends > 5 [
set happiness ( happiness + 5 )
]
]
Bad (well, not too bad, but ..)
if age = 15 [
if count friends > 0 [
set happiness ( happiness + 1 )
]
if count friends > 5 [
set happiness ( happiness + 5 )
]
]
Good
if age = 15 [
; This happens if the agent is 15 years old
if count friends > 0 [
; If at least 1 friend, then they're happy
set happiness ( happiness + 1 )
]
if count friends > 5 [
; If they have 5, then even more happy
set happiness ( happiness + 5 )
]
]
Bad
if age = 15 [
if count friends > 0 [
set happiness ( happiness + 1 )
]
if count friends > 5 [
set happiness ( happiness + 5 )
]
]