NetLogo : How to make sure a variable stays in a defined range?

前端 未结 3 698
盖世英雄少女心
盖世英雄少女心 2020-12-06 03:29

I have a few variables which can be inherited to child agents by a variation of + 0.1 and -0.1 or without any changes, or random again, What I have done is like this: (The

3条回答
  •  情深已故
    2020-12-06 03:45

    Answering very late to add another option for future seekers...

    Another option if you're looking for a distribution that is bell-shaped like a normal distribution, but bounded, the Beta distribution can be a good choice. If you use parameters like 3,3 or 4,4, it looks a lot like a Normal distribution, but won't have any out-of-bounds values (it scales from 0 to 1, so it may have to be moved/scaled like you would a normal).

    Netlogo doesn't have a built-in Beta, but you can get it from drawing from the built-in gamma twice, like this:

    to-report random-beta [ #shape1 #shape2 ]
    
      let Xa random-gamma #shape1 1
      let Xb random-gamma #shape2 1
      report Xa / (Xa + Xb)
    
    end
    

    For more mathematical detail, see: https://math.stackexchange.com/questions/190670/how-exactly-are-the-beta-and-gamma-distributions-related

提交回复
热议问题