通过适应度函数从群体中选择个体

发布于 2024-10-21 09:30:46 字数 432 浏览 8 评论 0原文

我一直在研究一种算法,我需要从大小为 k 的群体中选择 n 个个体,其中 k 比 n 大得多。所有个体都有适应度值,因此选择时应优先考虑较高的适应度值。然而,我不想简单地选择最好的n个人,最差的人也应该有机会。 (自然选择)

所以,我决定找到种群内的最小和最大适应度值。因此,任何个体都有

p = (current - min) / (max - min)

的概率被选择,但我不能只是迭代所有这些,掷骰子并选择一个如果概率成立的话,因为那样我就结束了超过n个人。我可以打乱列表并从前面迭代,直到获得最多 n 个个体,但这可能会错过列表末尾的重要个体。

我还可以执行多次传递,直到剩余的种群数量达到 n。但这可能会更倾向于更好的选择,并收敛到我提到的朴素选择方法。

对这样的选择过程有何建议或参考?如果您可以参考的话,我可以阅读一些相关的统计方法。

谢谢。

I've been working on an algorithm, where I need to choose n individuals from a population of size k, where k is much bigger than n. All individuals have a fitness value, therefore the selection should favor higher fitness values. However, I don't want to simply choose best n individuals, the worse ones should have a chance also. (Natural selection)

So, I decided to find the min and max fitness values within population. So, any individual would have

p = (current - min) / (max - min)

probability to be chosen, but I can not just iterate over all of them, roll the dice and choose one if the probability holds, because then I end up with more than n individuals. I could shuffle the list and iterate from front, till I obtain up to n individuals, but that might miss great ones to the end of list.

I also could perform more than one passes, until the remaining population size reaches to n. But this might favor better ones a lot, and converge to the naive selection method I mentioned.

Any suggestion, or references to such a selection process? I could do some reading on relevant statistical methods if you can refer any.

Thanks.

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

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

发布评论

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

评论(1

池予 2024-10-28 09:30:46

使用轮盘赌选择。基本思想是,您分配相对于概率大小的轮盘赌轮区域:

Roulette Wheel

然后您只需旋转它n次来选择你想要的人。

ruby 中的示例实现:

def roulette(population, n)
  probs = population.map { |gene| gene.probability } # TODO: Implement this
  selected = []

  n.times do 
    r, inc = rand * probs.max, 0 # pick a random number and select the  individual 
                     # corresponding to that roulette-wheel area
    population.each_index do |i| 
      if r < (inc += probs[i])
        selected << population[i]
        # make selection not pick sample twice
        population.delete_at i
        probs.delete_at i
        break
      end
    end
  end
  return selected
end

注意:如果您是 Ruby 黑客,您会发现使用更多 Rubyism 代码可能会更短,但我希望算法尽可能清晰。

Use Roulette-wheel selection. The basic idea is that you assign an area of the roulette-wheel relative to the probability size:

Roulette wheel

Then you simply spin it n times to select the individuals you want.

Sample implementation in ruby:

def roulette(population, n)
  probs = population.map { |gene| gene.probability } # TODO: Implement this
  selected = []

  n.times do 
    r, inc = rand * probs.max, 0 # pick a random number and select the  individual 
                     # corresponding to that roulette-wheel area
    population.each_index do |i| 
      if r < (inc += probs[i])
        selected << population[i]
        # make selection not pick sample twice
        population.delete_at i
        probs.delete_at i
        break
      end
    end
  end
  return selected
end

Note: if you are a Ruby hacker, you see that the code could be much shorter with more Rubyisms, however I wanted the algorithm to be as clear as possible.

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