netlogo

NetLogo monitor widget display changes when nothing is happening


I have a NetLogo model, simplified to this:

to setup
  clear-all
  create-turtles 1000 [ 
    fd 100
  ]
end

When I add a monitor widget to the UI, with a reporter like mean [xcor] of turtles and then run setup, the values in the monitor change a slight bit constantly. It might show 0.2305090322262271 one moment then 0.2305090322262268 the next, and then another similar number on and on.

What is making my monitor widget flicker or flash like this? How can I prevent it?


Solution

  • This is caused by a combination of a few things:

    1. NetLogo's use of floating point numbers, which can produce small accuracy issues. See Floating point accuracy in the NetLogo programming guide: https://ccl.northwestern.edu/netlogo/docs/programming.html#math
    2. Agentsets such as turtles are always returned in a random order.
    3. Monitors re-run their reporter calculation constantly, even when you are not running any model code with a forever button or through the command center.

    So the monitor constantly re-runs its mean [xcor] of turtles reporter, but the turtles agentset gives the turtles in a random order, and so the floating-point inaccuracies for mean will accumulate in a slightly different way each time due to the order differences. The end result is you see very slightly different numbers flashing through the monitor widget while nothing is happening.

    You would see the same problem doing sum [xcor] of turtles or variance [xcor] of turtles - anytime you're reducing a bunch of floating point numbers from an agentset into a single value. You can also see the problem running your reporter code directly in the command center repeatedly, without a monitor widget at all.

    The fixes are fortunately pretty easy: