Ham*_*mal 1 probability agent netlogo probability-distribution
考虑 netlogo 中可能发生的以下 5 个事件,
[abcdef] 每个事件都有特定的发生概率。说[0 0 0.3 0.5 0.1 0.1],即p(a) = 0, p(b) = 0, p(d) = 0.5
必须发生一个(且只有一个事件)。如何在 Netlogo 中对其进行建模。
我做了什么:
ask turtles
[
if random-float 1 < 0
[EventA]
if random-float 1 < 0.5
[EventD] ; and so on
]
Run Code Online (Sandbox Code Playgroud)
但采用这种方法,有时不会发生任何事件,有时会发生超过 1 个事件。
简短回答:这是“轮盘赌”选择的经典用例。
您可以使用 NetLogo RND 扩展来执行此操作,或者按照模型库中的 Lottery 示例自行推出。
更多的:
该方法将概率抽象为权重,因此可以使用列表或代理集中的任何值集;选择的概率是单个值与集合或列表中所有值之和的比率。
它不需要对集合或列表进行排序,并且可以扩展到任意数量的项目。
您可以编写它来生成所选值的列表索引或相关值(例如代理或另一个列表中的值)。
它可用于从集合中进行有替换和无替换选择。
可以通过从选择列表/集合中删除个体或在选择个体后将个体的选择权重/值设置为 0 来完成无替换(如果重复选择,则使用实际值的副本。)
简单的自行示例:
;; List weight has values to consider
;; Returns the index of the selected item
To RW-Select [ weight ]
Let last-index length weight
Let total sum weight
Let index 0
Let cumulative 0
Let rnd random-float total
While [cumulative <= rnd and index < last-index]
[
Set cumulative cumulative + item index weight
Set index index + 1
]
Report (index - 1)
End
Run Code Online (Sandbox Code Playgroud)