Draw a random-beta distribution in netlogo

倾然丶 夕夏残阳落幕 提交于 2019-12-10 20:57:27

问题


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




回答2:


I was asked this offsite as apparently the rngs extension hasn't been updated for awhile and thought I should post here too. Here is the code to draw beta using the built-in gamma distribution generators.

to-report random-beta [ #alpha #beta ]
  let XX random-gamma #alpha 1
  let YY random-gamma #beta 1
  report XX / (XX + YY)
end


来源:https://stackoverflow.com/questions/38493122/draw-a-random-beta-distribution-in-netlogo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!