海龟分布

发布于 2025-01-09 14:41:28 字数 32 浏览 0 评论 0原文

如何创建一组位置从环境边缘到中间呈上升分布的海龟?

How to create a set of turtles with the rising distribution of their location from the edge of the environment to the middle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄傲 2025-01-16 14:41:28

您可以在设置中使用类似的东西,

let center-x (max-pxcor + min-pxcor) / 2
let center-y (max-pycor + min-pycor) / 2
let std-dev 5  ; change this to vary how clumped the turtles are

crt 100
[
  set xcor random-normal center-x std-dev
  set ycor random-normal center-y std-dev
]

如果您启用了世界环绕,那么它将起作用。如果世界环绕关闭,则必须添加一些代码来检查随机法线的 xcor 和 ycor 值是否在世界范围内(例如,乌龟的新 xcor 位于 min-pxcor 和 max-pxcor 之间)--否则,代码有时会尝试将新乌龟放在空间之外,这是一个错误。

您还可以使用三角形分布来线性改变海龟的密度,从空间中心的峰值到边缘的零。

let center-x (max-pxcor + min-pxcor) / 2
let center-y (max-pycor + min-pycor) / 2

crt 100
[
  set xcor random-triangular min-pxcor center-x max-pxcor
  set ycor random-triangular min-pycor center-y max-pycor
]

NetLogo 没有内置这种三角分布,因此您需要将此过程添加到您的代码中:

to-report random-triangular [a-min a-mode a-max]
  ; Return a random value from a triangular distribution
  ; Method from https://en.wikipedia.org/wiki/Triangular_distribution#Generating_Triangular-distributed_random_variates
  ; Obtained 2015-11-27

  if (a-min > a-mode) or (a-mode > a-max) or (a-min >= a-max)
   [ error (word "Random-triangular received illegal parameters (min, mode, max): " a-min " " a-mode " " a-max) ]

  let a-rand random-float 1.0
  let F (a-mode - a-min) / (a-max - a-min)

  ifelse a-rand < F
  [ report a-min + sqrt (a-rand * (a-max - a-min) * (a-mode - a-min)) ]
  [ report a-max - sqrt ((1 - a-rand) * (a-max - a-min) * (a-max - a-mode)) ]

end

You can use something like this in setup

let center-x (max-pxcor + min-pxcor) / 2
let center-y (max-pycor + min-pycor) / 2
let std-dev 5  ; change this to vary how clumped the turtles are

crt 100
[
  set xcor random-normal center-x std-dev
  set ycor random-normal center-y std-dev
]

That will work if you have world-wrapping on. If world-wrapping is off, you would have to add some code to check that the values of xcor and ycor from random-normal are within the world (e.g., the turtle's new xcor is between min-pxcor and max-pxcor) -- otherwise, the code will sometimes try to put the new turtle outside the space, which is an error.

You could also use a triangular distribution that varies the density of turtles linearly from a peak at the center of the space to zero at the edge.

let center-x (max-pxcor + min-pxcor) / 2
let center-y (max-pycor + min-pycor) / 2

crt 100
[
  set xcor random-triangular min-pxcor center-x max-pxcor
  set ycor random-triangular min-pycor center-y max-pycor
]

NetLogo does not have this triangular distribution built-in, so you need to add this procedure to your code:

to-report random-triangular [a-min a-mode a-max]
  ; Return a random value from a triangular distribution
  ; Method from https://en.wikipedia.org/wiki/Triangular_distribution#Generating_Triangular-distributed_random_variates
  ; Obtained 2015-11-27

  if (a-min > a-mode) or (a-mode > a-max) or (a-min >= a-max)
   [ error (word "Random-triangular received illegal parameters (min, mode, max): " a-min " " a-mode " " a-max) ]

  let a-rand random-float 1.0
  let F (a-mode - a-min) / (a-max - a-min)

  ifelse a-rand < F
  [ report a-min + sqrt (a-rand * (a-max - a-min) * (a-mode - a-min)) ]
  [ report a-max - sqrt ((1 - a-rand) * (a-max - a-min) * (a-max - a-mode)) ]

end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文