Draw a random-beta distribution in netlogo

2019-07-21 01:57发布

问题:

I'm attempting to generate a breed-owned variable which draws it's values from a random beta distribution in Netlogo.

I've found the "bc" code example online but am struggling to adapt it to what I need. Right now, for convenience, I've generate my distribution from a random-normal distribution using

create-breed 500
 [
  set target_factor random-normal 0.9 0.05
  if target_factor > 1 [set target_factor 0.9999999999]
  if target_Factor < 0.5 [set target_factor 0.5000000001]
 ]

So basically I'd like to get a reporter that can replace the "random-normal 0.9 0.05" part with a random beta distribution

I got so far as:

to-report random_beta
  set asocial_alpha 2
  set asocial_beta 2
  set asocial_min_eps 0
  set asocial_max_eps 0.25
  let x random-gamma asocial_alpha 1
  let asocial_eps (x / (x + random-gamma asocial_beta 1))
  set asocial_eps asocial_min_eps + (asocial_eps * (asocial_max_eps -   asocial_min_eps)) 
 foreach ( n-values 99 [ (? + 1) / 100 * (asocial_max_eps -     asocial_min_eps) + asocial_min_eps] ) 
  [report ? ( ((? - asocial_min_eps) ^ (asocial_alpha - 1) * (asocial_max_eps - ?) ^ (asocial_beta - 1)) / ( asocial_max_eps - asocial_min_eps ) ^ (asocial_alpha + asocial_beta - 1) )]
end

all of the 'set' variables here are global factors

I'm honestly out of my depth with this one mathematically. If anyone can help me fix this reporter (or if a procedure would work that's fine too). so my final code for breed creation is:

create-breed 500
 [
  set target_factor random-beta
  if target_factor > 1 [set target_factor 0.9999999999]
  if target_Factor < 0.5 [set target_factor 0.5000000001]
 ]

I would be eternally grateful!!

回答1:

The rngs extension provides a random beta distribution (among many others). You can find it here: https://github.com/NetLogo/NetLogo/wiki/Extensions.

Charles