如何使用轮盘选择法选择最多海龟数量 [英] How to select up to a maximum number of turtles using roulette wheel selection

查看:63
本文介绍了如何使用轮盘选择法选择最多海龟数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的模型中,海龟有两种性别,而雄性有两种潜在策略.雌性对设定半径内的雄性数进行计数.

In my model the turtles have two sexes where the males have two potential tactics. The females count the number of males in a set radius.

我希望雌性根据两种雄性战术的相对频率,权衡其从雄性中选择的可能性(不进行替代).

I want the females to weight their probability of selecting from the group of males (without replacement) depending on the relative frequency of the two male tactics.

我已经有了用于从雄性中进行选择的可能性的代码(matingPoolProbAnadmatingPoolProbRes),但是我不知道如何实现它,尽管rnd扩展名似乎很可行,特别是rnd:weighted-n-of size agentset [ reporter ].

I already have the code for the probability of selecting from the males (matingPoolProbAnad and matingPoolProbRes) but I don't know how to implement it, though the rnd extension seems the way to go, specifically rnd:weighted-n-of size agentset [ reporter ].

有三件事使事情变得复杂:(1)雄性可以与一个以上的雌性交配,但(2)与给定的雌性只能交配一次,(3)雌性最多只能与五个雄性交配.

It's complicated by three things (1) the males can mate with more than one female but (2) only once with a given female and (3) females can only mate with a maximum of five males.

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

推荐答案

此示例可能会满足您的要求,但显然需要从此玩具版本中改编.这种设置会萌生75%的采用策略A的雄性,其余的采用策略B的雄性,并为所有海龟提供一个空的伴侣集以开始:

This example may approach what you're getting at, but obviously would need to be adapted from this toy version. This setup sprouts 75% of males with strategy A and the rest with strategy B, and gives all turtles an empty agentset of mates to start off:

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循环让每个女性迭代评估可供其使用的男性的策略比例,然后将其添加到她的队友"列表中.注释中有更多详细信息:

Use a while loop to have each female iteratively assess the strategy proportions of the males available to her, then add them to her 'mates' list. More detail in comments:

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 that 'B' males are being chosen disproportionately to their availability:

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包来清理循环.

I'm not 100% sure that that's what you're after- maybe you can use the rnd package to clean up the loop.

根据评论进行编辑

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

If you modify the end of the `choose-mates like so:

    ...
    ...
    ; 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

您可以根据需要多次运行setupgo,并且永远不会看到打印输出可用的男性少于伴侣":

You can run setup and go as many times as you like and you should never see the printout "Fewer available males than mates":

to repeat-1000
  repeat 1000 [ 
    setup
    go
  ]
end

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

I ran that a few times and never had count availa-males be less than the count of mates. However, if you add in movement without allowing the females to reset their mates agentset, you do start to see it- for example, try running this a few times:

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

现在,由于海龟在四处移动,因此在某些情况下,females会从上一个函数调用中保留在其伴侣上,然后移动到availa-males较少的空间中.快速简便的解决方法是让雌性每次都清除自己的配偶.您在哪里做取决于您的模范目标(女性选择伴侣的频率有多高?他们是否只忘记了以前的伴侣?等等),但这是一个非常简单的方法:

Now, because the turtles are moving around, you have some cases where females held on to their mates from the previous function call and then moved into a space where there were fewer availa-males. The quick and easy fix is to have females clear their mates each time. Where you do that depends on your model goals (how often do females choose mates? Do they only forget some of their previous ones? etc), but here's a very simple way:

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

现在,您可以随意运行多次,而不会看到可用的雄性比雄性少"的打印输出.

Now you can run that as many times as you like and shouldn't see the "Fewer available males than mates" printout.

这篇关于如何使用轮盘选择法选择最多海龟数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆