如何创建数字随时间服从泊松分布的海龟

how to create turtles with the numbers following a poisson distribution over time

我想为每一刻生产海龟。

但条件是,它们的个数要服从泊松分布

因此,如果 x 轴是具有一定限制的 tick 数,y 轴表示在该 tick 中创建的新海龟,则该图应该类似于泊松分布。

到目前为止我所做的是

to setup
ca
reset-ticks
end

to go
produce
tick
end

to produce
create-events random-poisson n [ 
set color red
set random-xcor random-ycor
]
end

但我认为这是不对的。

您需要的是泊松分布的质量函数。它可以针对任何 n 和 lambda 进行计算(其中 lambda 是分布的“均值”

e^−λ * λ^n / n!

incompleteGammaComplement(n+1, λ) - incompleteGammaComplement(n, λ)

后者需要使用 stats 扩展,但处理更大的 n 值。 (第一个公式中的 n! 对于较大的 n 会很快爆炸。)

这是一个可以满足您的需求的模型。它总共创建了 100 个事件,在 tick 20 处创建的新事件数量最多。poisson 使用第一个公式; poisson1 使用第二个。您可以在 let to-be-created ... 行中交替使用它们。

extensions [stats]  ;; you need this only for poisson1
globals [total-events lambda]
breed [events event]

to setup
  ca
  set total-events 100
  set lambda 20
  reset-ticks
end

to go
  produce
  show count events
  tick
end

to produce
  let to-be-created round (total-events * poisson ticks lambda)
  show to-be-created
  create-events to-be-created [
    set color red
    setxy random-xcor random-ycor
  ]
end

to-report poisson [n lamda]
  let n-factorial ifelse-value (n = 0) [1] [reduce * n-values n [i -> i + 1]]
  report e ^ (- lamda) * lamda ^ n / n-factorial
end

to-report poisson1 [n lamda]
  ifelse (n = 0) [
    report stats:incompleteGammaComplement (n + 1) lamda
  ]
  [
    report stats:incompleteGammaComplement (n + 1) lamda 
    - stats:incompleteGammaComplement n lamda
  ]
end