Human Science NetLogo utilities

In the file human.jar, we make available a Human-Science-based extension for NetLogo simulations. The current version is 1.2.3.

This extension may require NetLogo with Java 7 (but should work with NetLogo with bundled Java 6 – if there are problems, use NetLogo with no bundled Java VM instead). All software is copyright © Anthony H. Dekker, 2013, but the current version may be freely used (under the GNU GPL) as long as it is properly attributed. The extension currently provides the following functions:

Simple path planner

A simple grid-based path planner (encapsulated in a GridPlanner object), which will find the shortest path around an arbitrary number of obstacles. The picture below shows the result of several agents travelling to a shared goal patch, avoiding three rectangular obstacles. NetLogo usage is:
human:init-grid-planner world-width world-height min-pxcor min-pycor — create (and return) a GridPlanner object, based on the world dimensions
human:grid-planner-add-obstacle grid-planner x y width height — add a rectangular obstacle, specified by lower left coordinate, plus width and height in patches (command)
human:grid-planner-next-heading grid-planner pxcor pycor goal-x goal-y — given the coordinates of the current patch and the goal patch, compute a path. The heading (from 0 to 360) to the next patch is returned. An appropriate action is to set this heading, move forward one patch, and then recompute (repeating these steps until the goal patch is reached). The major calculations will be done only once, and retained in the GridPlanner object. Negative headings are returned if no path exists, or if the goal has already been reached.

Two-process sleep model

An implementation of the two-process sleep model from here (provided for demonstration purposes only, rather than as a truly accurate sleep model), using SleepState extension objects. NetLogo usage is:
human:init-sleep asleep? ticks-per-day — create a SleepState object, starting at midnight
human:tick-sleep sleep-state — do one tick, allowing the person to fall asleep if need be (command)
human:force-wake-tick sleep-state — do one tick, forcing the person to stay awake (command)
human:is-asleep? sleep-state — is the person now asleep?
human:changed-sleep? sleep-state — did the person just wake up, or just fall asleep?
human:nice-time t ticks-per-day — utility function to convert a tick count t to a displayable time

Age and sex probabilities

Age and sex structure for Australia, based on ABS tables for 2011 (summarised in the diagram below), for setting up realistic population structures. NetLogo usage is:
human:aust-mf-prob male? — probability that a member of the population is male (0.4944) or female (0.5056)
human:aust-random-age (random-float 1) — given a random number between 0 and 1, a random person’s age (an offset of 1,000 is added for females)
human:aust-male-birth — probablity that a new baby is male (0.513)

Death probabilities

Probabilities of dying in a given year in Australia, based on aged and sex, from ABS life tables for 2008–2010, for use in population simulations. NetLogo usage is:
human:aust-death-prob age male? — using a boolean to specify whether the person is male
human:aust-death-prob-male age
human:aust-death-prob-female age

US military ranks

Decoding of US military ranks, such as “SCPO,” “COL,” or “E-8.” NetLogo usage is:
human:rank-std rank — conversion into standard form, e.g. “E-8” or “O-6”
human:rank-kind rank — conversion into type, i.e. “E,” “W,” or “O”
human:rank-level rank — conversion into level within type (1–10)
human:rank-int rank — conversion into level with offsets: 1–9 for “E,” 11–15 for “W,” and 21–30 for “O”
human:rank-desc rank — conversion into description, e.g. “Senior Chief Petty Officer”

Statistics for various properties

Means and standard deviations for several human properties are made available, with the following NetLogo syntax to use them in simulations:
human:property-names — return a list of property names
human:property-mean name — mean for the property
human:property-sd name — standard deviation for the property
human:property-unit name — unit for the property (e.g. “cm”)
human:property-info name — description of the property

The following named properties are currently defined, but it is intended to include more:

US-height-male175.5147.112cmHeights for US adult males, 18–74 years, for 1976–1980. See here
US-height-female161.7986.604cmHeights for US adult females, 18–74 years, for 1976–1980. See here
Swedish-gestation281.013.0daysDurations of human singleton pregnancies, from this Swedish study
Walking-speed1.340.37m/sWalking speed, from this Dutch study
IQ100.015.0Intelligence quotient, by definition
Extraversion4.3951.087Personality trait scores from this study
Agreeableness5.4030.888Personality trait scores from this study
Conscientiousness5.1521.005Personality trait scores from this study
Emotional-stability5.1951.047Personality trait scores from this study
Openness-to-experience4.2371.052Personality trait scores from this study

General routines

human:about — reports software version number
human:biased-random-choice (random-float 1) power value-list — implements biased random choice. The numbers in value-list are raised to power, and then the random number (assumed to be in the range 0 to 1) is used to chose an element, with probabilities proportional to the modified values. A list index (starting from 0) is returned.

NetLogo Example Code

Place the jar file in a folder called “human” in your NetLogo extensions folder, and put extensions [human] at the top of your NetLogo code. The following NetLogo code computes, for an agent with age and male? attributes, whether it should die in the course of a one-year timestep:

to do-age
  let death-prob human:aust-death-prob age male?
  if-else (random-float 1 < death-prob)
    [ die ]
    [ set age 1 + age ]
The following NetLogo code allows the generation of normally distributed random numbers from the specified distributions:
to-report n-random-properties [n name]
  report n-values n [ random-normal (human:property-mean name) (human:property-sd name) ]

to-report random-property [name]
  report random-normal (human:property-mean name) (human:property-sd name)

to-report n-random-heights [n male?]
  if-else (male?) 
    [ report n-random-properties n "US-height-male" ]
    [ report n-random-properties n "US-height-female" ]

to-report random-height [male?]
  if-else (male?) 
    [ report random-property "US-height-male" ]
    [ report random-property "US-height-female" ]

to print-properties
  print "Properties:"
  foreach human:property-names [
    type "\""
    type ?
    type "\" : mean = "
    type human:property-mean ?
    type " "
    type human:property-unit ?
    type ", sd = "
    type human:property-sd ?
    type " "
    type human:property-unit ?
    type " ("
    type human:property-info ?
    print ")"

This page maintained by Anthony Dekker: last updated 17 Dec 2013.