random-normal formula

181 views
Skip to first unread message

Pablo Anaya

unread,
Oct 24, 2021, 11:05:35 PM10/24/21
to netlogo-users
Hi.  I'm trying to use the random-normal formula but using the number of each turtle as an input, instead of the random-float 1 I assume the formula is using.  Do you know what's the formula used by Netlogo for random-normal?

Dale Frakes

unread,
Oct 25, 2021, 12:05:09 AM10/25/21
to netlog...@googlegroups.com
Hi Pablo,

I think you need a couple things.  First for random-normal, you can read and see examples here:
https://ccl.northwestern.edu/netlogo/bind/primitive/random-normal.html

Note that it takes 2 parameters (a mean and standard deviation) where random-float only takes 1 parameter (the maximum bound).


Next, by "number of each turtle", maybe you mean the "who" ID?  That's described here: http://ccl.northwestern.edu/netlogo/docs/dict/who.html
With "who", the first turtle created is 0, the second is 1, etc.

Assuming that's what you mean, then you need to specify what you mean by "using the number of each turtle as an input".  We could use who for either the mean, or the standard deviation, or even both:

This uses who for the mean with a fixed standard deviation:
ask turtles [ show random-normal who 1 ]

This uses who for the standard deviation with a fixed mean:
ask turtles [ show random-normal 1 who ]


This uses who for both:
ask turtles [ show random-normal who who ]

Though maybe you intend to use a population-level value from a number from the turtles, so something like this uses the mean of the IDs as the "mean" parameter (fixed SD = 1):

show random-normal mean [who] of turtles 1

And of course where we've used who, you can use any other variable the turtles own (xcor, or some other variable defined in a "turtles-own" section.

I hope that helps!

Dale




On 10/24/21 8:05 PM, Pablo Anaya wrote:
Hi.  I'm trying to use the random-normal formula but using the number of each turtle as an input, instead of the random-float 1 I assume the formula is using.  Do you know what's the formula used by Netlogo for random-normal?
--
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/f256d24f-70d9-4694-8c58-790bae2446ebn%40googlegroups.com.

-- 
Dale Frakes
Adjunct Instructor, PhD Candidate
PSU Systems Science
dfr...@pdx.edu - http://web.pdx.edu/~dfrakes/

Pablo Anaya

unread,
Oct 25, 2021, 10:13:01 AM10/25/21
to Dale Frakes, netlog...@googlegroups.com
Thank you so much Dale.
Let me explain in more detail.
I see that random-normal calculates the inverse normal distribution but I cannot find the formula for that.
I managed to do it with the random-exponential.  For this primitive the NetLogo manual provides the formula used for the calculation: 
  • random-exponential reports an exponentially distributed random floating point number. It is equivalent to (- mean) * ln random-float 1.0.
So what I did to remove the random results was to use the [who] value and divide it by the total turtles (getting a value in the range of 0 - 1) and use that value as input for the formula instead of (random-float 1.0):

to-report distribution-exponential [mean]
  report ((- mean) * ln(who / count turtles))
end

I'm trying  to do the same for the random-normal distribution.  I assume it must also use the random-float 1.0 formula in it so I'm trying to find the formula used by NetLogo for the random-normal distribution.

I hope this is better explained.

Thanks again!

Pablo.





Pradeesh Kumar K V

unread,
Oct 26, 2021, 11:33:58 AM10/26/21
to Pablo Anaya, Dale Frakes, netlogo-users
Hello Pablo,

I came across Box-Muller Transform for sampling from normal distribution. Details at this link: https://bjlkeng.github.io/posts/sampling-from-a-normal-distribution/

Hope this helps.

Best,

Pradeesh

Reply all
Reply to author
Forward
0 new messages