为什么我的遗传算法看起来表现得很随机?
我正在尝试使用以下方法制定迭代囚徒困境的最佳策略基本遗传算法(随机通用采样,1 -点交叉,Canonical GA)。我已经在 Haskell 中实现了这个算法,并且最近添加了图表输出。不幸的是,生成的图表不符合此问题的预期模式,因此看来我有一个错误。
我见过的关于这个问题的所有健身图看起来都是这样的:
可以看到其他示例在 关于迭代囚徒困境的稳健策略,PJ Darwen 和 X. Yao (1993) p6-7
但是我的输出如下所示:
如果我将突变率设置为 1,我会得到:
也许表明我的选择函数并不像我想象的那么随机,因为该图暗示了同质群体。
如果您想检查的话,我的代码位于 此 git 存储库 中。
现在的问题是:你们中的任何人都可以建议我在 GA 实现中可能做错了什么,以使图表看起来像这样吗?
例如,我假设它不太可能是适应度函数,因为我使用相同的适应度函数来最大化它的输出,因此即使适应度函数在某种程度上是错误的,它仍然会最大化该错误的函数(尽管我是当然我在这里可能是错的,我对遗传算法相当陌生)
我只是想了解要查看哪些函数的建议,我正在努力解决这个问题。
编辑:在我的组合函数中添加了一些调试代码后,它似乎总是被传递给相同的个体(即使突变设置为 1),所以可能选择在某个地方出错了。
编辑:选择出了问题,但这并没有造成所有问题,只是人口的同质性。
I'm attempting to evolve optimal strategies for the Iterated Prisoner's Dilemma using a basic genetic algorithm (Stochastic Universal Sampling, 1-point crossover, Canonical GA). I've implemented this algorithm in Haskell and recently added chart output. Unfortunately the graphs produced don't fit the expected pattern for this problem so it appears I have a bug.
All graphs of fitnesses I have seen for this problem look something like this:
Other examples can be seen in On Evolving Robust Strategies for Iterated Prisoner's Dilemma, P.J. Darwen and X. Yao (1993) p6-7
However my output looks like this:
If I set mutation rate to 1 I get:
Perhaps suggesting that my selection function is not being quite so random as I had thought as the graph implies a homogeneous population.
My code is in this git repository should you wish to inspect it.
Now for the question: Could any of you suggest what I might be doing wrong in my GA implementation to make the graph look like this?
e.g. I would assume it is unlikely to be the fitness function as I am using the same fitness function for output that it is maximising so even if the fitness function is wrong in some way it will still be maximising that wrong function (though I'm sure I could be wrong here, I'm rather new to genetic algorithms)
I would just like suggestions for which functions to look at, I'm tearing my hair out trying to fix this.
EDIT: Having added some debug code to my combine function it seems that it is always being passed the same individuals (even with mutation set to 1) so presumably selection is going wrong somewhere.
EDIT: Selection was going wrong, but that wasn't causing all the problems, just homogeneity in the population.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有一个函数
maybeFlip
,它将以给定的概率将等位基因更改为相反的等位基因。因此,当突变率为 1 时,您将继续在两个相反的之间来回翻转所有等位基因。这解释了图表中看到的之字形图案。此外,
交换
位于Data.Tuple
:)You have a function
maybeFlip
, which will change an allele to its opposite with a given probability. Hence, when the mutation rate is 1, you will just keep flipping all the alleles back and forth between two opposites. This explains the zig-zag pattern seen in your graph.Also,
swap
is inData.Tuple
:)