Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetLogo monitor widget display changes when nothing is happening

Tags:

netlogo

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?

like image 926
Jasper Avatar asked Mar 04 '23 05:03

Jasper


1 Answers

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:

  • Sort your numbers before you calculate: mean sort [xcor] of turtles, sum sort [xcor] of turtles, variance sort [xcor] of turtles. If the numbers are in the same order you'll still have small floating-point inaccuracies, but they'll be the the same every time so you won't see the values change. This is probably the best solution, but it can be slow if you have a really large agentset.
  • Change the Decimal places setting of your monitors to a number where you don't notice the changing values. Since the differences in results should be small, this is usually possible.
like image 128
Jasper Avatar answered May 16 '23 09:05

Jasper