【问题标题】:How to select up to a maximum number of turtles using roulette wheel selection如何使用轮盘赌选择最多选择海龟
【发布时间】:2018-06-05 12:00:57
【问题描述】:

在我的模型中,海龟有两种性别,而雄性有两种潜在的策略。女性计算设定半径内的男性数量。

我希望女性根据两种男性策略的相对频率来衡量从男性组中选择的概率(无需替换)。

我已经有了从男性中选择概率的代码(matingPoolProbAnad 和 matingPoolProbRes),但我不知道如何实现它,尽管 rnd 扩展似乎是要走的路,特别是 @ 987654324@。

这由三件事复杂化:(1) 雄性可以与不止一名雌性交配,但 (2) 只能与给定的雌性交配一次,(3) 雌性最多只能与五名雄性交配。

to count-mates ; ask the females to count the number of males in a 10 patch radius & then 
                ; determine the frequency of the resident males in their patch

  ask turtles with [sex = "female"]
  [
    if any? turtles with [sex = "male"] in-radius 10
    [ set potentialMates turtles with [sex = "male"] in-radius 10
       ifelse any? potentialMates with [anadromousM = 1]
    [ set FA count potentialMates with [anadromousM = 1] / count potentialMates ]
    [ set FA 0]
      ifelse any? potentialMates with [anadromousM = 0]
    [ set FR count potentialMates with [anadromousM = 0] / count potentialMates ]
    [ set FR 0]
    ]
    ]
end

to mating-pool-prob ; negative frequency dependency which is based on the number of male 
                    ; resident turtles 

  ask turtles with [sex = "female"]
  [
  ifelse (FA = 1) and (FR = 0)[
      set matingPoolProbAnad 1
      set matingPoolProbRes 0
  ]
  [ifelse (FA > 0) and (FR < 1)
    [
        set matingPoolProbRes exp(a - b * (FR - c ))/(1 + exp(a - b * (FR - c)))
        set matingPoolProbAnad 1 - matingPoolProbRes 

    ]
    [
        set matingPoolProbAnad 0
        set matingPoolProbRes  1
        ]
  ]
  ]
end

【问题讨论】:

  • 交配池概率块返回 2 个值(加到 1)。我认为每只雌性乌龟都是根据自己的交配池中的值计算这些值的想法是否正确?在那种情况下,我认为您不需要加权随机选择 - 加权随机选择是根据某些属性的值在海龟之间进行选择(例如,更富有的人有更多的机会)。我想你只想说“给我 20% 的机会选择 A 类型之一”
  • 另外,你的约束是否会改变选择 A 或 R 的概率,或者你想计算离开所有海龟的概率,然后在选择时应用约束?
  • 感谢您的 cmets。你是对的,女性在 10 块半径内查看并计算每种男性策略类型的频率。我用它来计算 mate-pool-prob 中的值。所以你会建议一个随机浮动或类似的让女性选择男性?关于第二点,你的意思是一旦女性开始选择,概率应该改变吗?那将是理想的。

标签: netlogo


【解决方案1】:

这个例子可能接近你所得到的,但显然需要从这个玩具版本改编。这种设置让 75% 的雄性使用策略 A,其余的使用策略 B,并为所有海龟提供一个空的配偶代理集:

breed [ males male ]
breed [ females female ]
turtles-own [ mates ]
males-own [ strategy ]
females-own [ max-mate-count mate-count ]

to setup
  ca
  ask n-of 200 patches [
    sprout-males 1 [
      ifelse random-float 1 < 0.75 [
        set strategy "A"
        set color orange
      ] [
        set strategy "B"
        set color violet
      ]
    ]
  ]
  ask n-of 50 patches with [ not any? turtles-here ] [
    sprout-females 1 [
      set color green
    ]
  ]
  ask turtles [
    set mates ( turtle-set )
  ]
  reset-ticks
end

使用 while 循环让每个女性反复评估可供她使用的男性的策略比例,然后将它们添加到她的“伙伴”列表中。 cmets 中的更多详细信息:

to choose-mates
  ask females [
    ; set a cap on possible mates for females; 5, or the number
    ; available within the radius if less than 5
    let availa-males males in-radius 10
    let n-max count availa-males
    set max-mate-count ifelse-value ( n-max < 5 ) [ n-max ] [ 5 ]

    ; Until a female has chosen up to her maximum number of mates:
    while [ mate-count < max-mate-count ] [
      ; determine which available males are not already in her 'mates' agentset
      set availa-males availa-males with [ not member? self [mates] of myself ]  

      ; assess the proportion of B strategy in remaining available males
      let prop_B ( count availa-males with [ strategy = "B" ] ) / n-max

      ; example probability choice, just meant to choose B males 
      ; with a frequency disproportionate to availability
      let proba_B ifelse-value ( prop_b * 2 < 0.6 ) [ prop_b * 2 ] [ 0.6 ]

      ; use a random float to determine which strategy type is chosen
      set mates ( turtle-set mates ifelse-value ( random-float 1 < proba_B ) 
      [ one-of availa-males with [ strategy = "B" ] ] 
        [ one-of availa-males with [ strategy = "A" ] ]  )

      ; count the current mates to break the while loop once
      ; the maximum number of mates is reached
      set mate-count count mates
    ]
    ; have the female's males add her to their own mates agentset
    ask mates [ 
      set mates ( turtle-set mates myself )
    ]
  ]
end

检查“B”男性的选择是否与其可用性不成比例:

to check-values
  let all-mates  map [ i -> [strategy] of i ] [mates] of females
  print word "Average proportion of 'B' mates chosen: " mean map b-proportion all-mates
  print word "Actual proportion of 'B' males: " ( ( count males with [ strategy = "B" ] ) / count males )
end

to-report b-proportion [ input_list ]
  let tot length input_list
  let nb length filter [ i -> i = "B" ] input_list
  report nb / tot  
end

我不能 100% 确定这就是你所追求的 - 也许你可以使用 rnd 包来清理循环。

根据评论进行编辑

如果你像这样修改`choose-mates的结尾:

    ...
    ...
    ; have the female's males add her to their own mates agentset
    ask mates [
      set mates ( turtle-set mates myself )
    ]
    if n-max < count mates [
      print "Fewer available males than mates"
    ]
  ]
end

你的go 看起来像:

to go
  choose-mates  
end

您可以随意运行setup 和go,并且您永远不会看到打印输出“可用的雄性比配偶少”:

to repeat-1000
  repeat 1000 [ 
    setup
    go
  ]
end

我运行了几次,从来没有计数 availa-males 小于 mates 的计数。但是,如果您在不允许 females 重置其 mates 代理集的情况下添加移动,您会开始看到它 - 例如,尝试运行几次:

to go
  choose-mates  
  ask turtles [ fd 1 ]
end

现在,因为海龟在四处移动,所以在某些情况下,females 会在之前的函数调用中抓住它们的伙伴,然后移动到 availa-males 较少的空间。快速简便的解决方法是让雌性每次都清除它们的配偶。你在哪里做这取决于你的模型目标(女性多久选择一次配偶?他们只会忘记以前的一些吗?等等),但这里有一个非常简单的方法:

to go
  ask turtles [ set mates ( turtle-set ) ]
  choose-mates  
  ask turtles [ fd 1 ]
end

现在您可以根据需要多次运行它,并且不会看到“可用的雄性比配偶少”打印输出。

【讨论】:

  • 感谢您的回复,我认为这就是我的目标。我不明白的一件事是,availa-males 代理集如何小于 mates 代理集,当然 mates 是availa-mates 的子集?
  • @ManassaMauler - 抱歉,不太清楚你的意思 - availa-males 只是雌性可用的雄性,而 mates 是一个从空乌龟集开始的代理集(计数 0)迭代增加,直到等于max-mate-count,即 5 或availa-males 的计数,以较小者为准。如果我误解了你的意思,请告诉我!
  • 如果我正确理解了您的代码,mates 变量会迭代地从 availa-males 中选择,因为 availa-males 是女性可用的所有男性。当我将模拟空间的大小增加到 100 x 100 块时,就会出现问题。对于某些女性,这可能会导致 availa-males 小于 mates。
  • @ManassaMauler - 我进行了一些编辑以更好地解释我的意思!希望这会有所帮助
  • 您的回答确实有助于理清模型,因此我将其标记为正确。我又来了,所以如果你不介意我做你的奴隶,也许你可以看看它! stackoverflow.com/questions/50947716/…
猜你喜欢
  • 2018-07-04
  • 2021-06-02
  • 2014-05-25
  • 1970-01-01
  • 2012-05-06
  • 1970-01-01
  • 2010-09-15
  • 2019-07-06
相关资源
最近更新 更多