Methods to stagger start times for agent behaviors

75 views
Skip to first unread message

Sunny Boyd

unread,
Jul 18, 2021, 1:49:00 PM7/18/21
to netlogo-users
Hello experienced modelers!

I am trying to model frogs in a swamp that -- over time -- start to call.  Thus, every frog should not start calling at tick one.  Can anyone provide advice on how to realistically stagger start times?

I have done this rather inelegantly by:

to choose-to-call
  ifelse (random 1000 = 0) [
    set calling? true
    set wandering? false
    set color sky
    set calling-bouts calling-bouts + 1
  ] [
    set wandering? true
    set color lime + 1
  ]
end

This does work to slow the addition of new callers to the simulation but I picked "1000" out of thin air and this does not seem like a well-reasoned and justified technique.  I would appreciate advice on other approaches, especially with reference to plusses and minuses of those approaches, if available.  I am especially interested in non-normal distributions, such as beta distributions for example, as the behavior of the frogs in the field is skewed and not normal.

Many thanks in advance.  Sunny

Wade Schuette

unread,
Jul 18, 2021, 4:01:08 PM7/18/21
to Sunny Boyd, netlogo-users
The Netlogo document also describes these primitives one of which might help.  ( see below ) According to Wolfram on
beta(a,b) = gamma(a)*gamma(b) / gamma( a + b)  which ( if true ! ) might be helpful.  Google shows a number of computational approximations for beta and inverse beta. Wolfram has 71 other forumulas for beta:

random-exponential mean

 random-gamma alpha lambda 

random-normal mean standard-deviation

 random-poisson mean

Meanwhile  random(1000) = 0 is not bad for a uniform distribution, or  number mod other number.
A sum of ten uniform distributions that sum to approximately the beta shape you need might be sufficient for frog modeling.

Wade


--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/103c46e5-42d1-4766-a952-6e2b5d22ce2en%40googlegroups.com.

Steve Railsback

unread,
Jul 18, 2021, 4:14:13 PM7/18/21
to netlogo-users
You could also look at the Time extension's Discrete Event scheduling primitives. They let you program the model so each frog decides the exact time at which it will next call, which could be drawn from a random number distribution but also could be made adaptive: the time until calling next could depend on what the other frogs do (e.g., a frog calls 2.3 seconds after it hears another frog within some radius call), the temperature, etc. (This extension is built into NetLogo now.)

These Discrete Event primitives have the additional advantage of using real times (down to 1 millisecond) instead of being restricted to discrete ticks. Therefore, you do not need to use very short ticks to let individual frogs call at different times.

Steve R.

Wade Schuette

unread,
Jul 18, 2021, 4:28:33 PM7/18/21
to Steve Railsback, netlogo-users
or, you could model a Frog's thinking in such a way that the result is a beta distribution. I forget what real world situations generate one but there are surely some.
wade


Dale Frakes

unread,
Jul 18, 2021, 4:32:52 PM7/18/21
to netlog...@googlegroups.com
Sunny,

you've already gotten some great advice... and since I already did a bit of work with a different approach, I wanted to share it here too.

This has a "create-new-turtle" block that you use whenever creating turtles that sets the delay in ticks before they start calling.  I also included example code that will draw from a beta distribution using the built-in gamma distribution because I had figured that out once before.  Though I multiply by 100 and round it so you get discrete ticks.  Steve suggests an alternative to discrete ticks that might work better for you.

Cheers!

Dale


turtles-own [
  call-start    ;; tick at which this turtle starts calling
  calling?      ;; is this turtle actively calling?
]

to setup
  clear-all
  reset-ticks

  create-turtles 100 [ create-new-turtle ]

  tick
end


to create-new-turtle  ;; turtle procedure
  set calling? false
  set color green
  setxy random-pxcor random-pycor
 
  ;; for fun, let's use a beta distribution to calculate delay
  let #start-delay floor ( 100 * random-beta 1 4 ) ;; discrete # ticks until calling
  set call-start ticks + #start-delay
 
end

to check-if-calling  ;; turtle procedure
  if call-start <= ticks [
    set calling? true
    set color yellow
  ]

end

to go
  ask turtles [
    check-if-calling
    if calling? [ show (word who " is calling!") ]
  ]

  ;; create 1 new turtle each tick
  create-turtles 1 [ create-new-turtle ]
 
  tick
 
end


to-report random-beta [ #shape1 #shape2 ]

  let Xa random-gamma #shape1 1
  let Xb random-gamma #shape2 1
  report Xa / (Xa + Xb)

end
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/0fc8d80a-e7c2-4f18-9e42-0a34d3b52765n%40googlegroups.com.

-- 
Dale Frakes
Adjunct Instructor, PhD Candidate
PSU Systems Science
dfr...@pdx.edu - http://web.pdx.edu/~dfrakes/
turtle-random-start-at-tick.nlogo

Wade Schuette

unread,
Jul 18, 2021, 4:42:35 PM7/18/21
to Sunny Boyd, netlogo-users
Oh you could also just connect Netlogo to the R extension and run an actual beta distribution in R.

Leo Niehorster-Cook

unread,
Jul 18, 2021, 8:48:55 PM7/18/21
to netlogo-users
Hi Sunny. You've gotten some good advice already, but I have a quick question. Roughly, what do you want the distribution of call times to look like? Perhaps you want very few frogs to begin calling early, most frogs to call around a clustered mean, and then very few frogs to begin their calls late again - in this case, a binomial distribution might suit you well. Alternatively, if you want most of your frogs to start calling early, with a lower number of frogs deciding to call each tick than the tick previous, an exponential function might suit you better.

Best of luck,
Leo

Wade Schuette

unread,
Jul 19, 2021, 5:11:21 AM7/19/21
to Leo Niehorster-Cook, netlogo-users
Leo, Beta distributions are pretty flexible but organically occur in some real world circumstances.

This is why I was seriously inquiring about what decision process goes on in a frog's mind or brain or body or whatever which CAUSES it to decide to wait a time that ends up with such a distribution.

A special subclass of them which someone called PERT distributions, for example,  describe the expected time that   any task on a large project will take to accomplish and are fully defined by three estimatable parameters -- shortest likely time, most probable time-to-accomplish, and longest-likely-time, where all are vague but sufficiently meaningful for a human manager to ballpark.    

As expected there is a low probability of a quick delivery, a highest probability of a moderate delivery time, and a very long tail (if everything and then some goes wrong ) on delivery time.     By the way the PERT process then takes the order tasks must occur in,  and the beta-distributions for each task, and computes the "critical path" and the probabilty distribution of the entire project based on those  ( 95% confident we can deliver by X-date.)


image.png

But as you say, there are other distributions and maybe the outcome of a simulated experiment is not sensitive to the exact distribution selected, -- or then again, maybe it is.  That's what Behavior Space is about!!!

And since a beta distribution can be computed from a few gamma-distributions, and those are primitive functions delivered by Netlogo, it seems easy enough to generate one and use it.

The questions are why frogs should behave that way ( is that empirical data?) and, of course, like swarms of birds, if you simulate a pond of frogs with such a distribution and just listen to the result, does it "sound right"?

Wade


--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.

Sunny Boyd

unread,
Jul 19, 2021, 1:48:05 PM7/19/21
to netlogo-users

This was my first post to this group and I am so impressed with the careful and useful answers.  Thank you all very much.  Wow! 

 How male frogs call and where they are spatially located in the breeding aggregation influence whether they will mate, so these have important consequences for natural selection.  We are seeking to model the attraction of males to an aggregation and the influence of competitive and aggressive interactions within the aggregation on where they end up forming territories.  Importantly, once males start to call, they stop moving.  Thus, we seek good ways to slow their addition to the ranks of the callers, because that brings a speedy halt to attraction, competition, and aggression!

 Wade’s questions about the real world are spot-on but we really have no empirical evidence.  I’m interested in the beta distribution because it seems to best describe what we hear – a slow increase in the number of callers to a peak and then rapid fall in additional callers as the night goes on.

 Wade – or anybody else – you mentioned that “…beta distributions can be computed from a few gamma-distributions…”  Could you please expand on this and how we can use primitives for it?  (Recognizing that I’m a biologist and not a mathematician or computer scientist?)

 My grad student is working on implementing several of your ideas now.  I do truly appreciate your input.

Dale Frakes

unread,
Jul 19, 2021, 6:01:09 PM7/19/21
to netlog...@googlegroups.com
Hi Sunny,

I tried replying yesterday but don't see it in the threads, so I'll repeat again below, just in case.

But to answer the question about drawing from the Beta distribution based on the Gamma distribution, the following code will accomplish this:


to-report random-beta [ #shape1 #shape2 ]

  let Xa random-gamma #shape1 1
  let Xb random-gamma #shape2 1
  report Xa / (Xa + Xb)

end


Dale

----
Reply all
Reply to author
Forward
0 new messages