ped*_*ete 5 algorithm artificial-intelligence genetic-algorithm
我正在使用一系列教程在javascript中构建我的第一个遗传算法.
我正在为这个调度教程http://www.codeproject.com/KB/recipes/GaClassSchedule.aspx#Chromosome8构建一个稍微简单的结构,但是我遇到了育种问题.
我得到了60个人口,现在我正在挑选前两个人来繁殖,然后选择一些随机的其他个体与前两个人一起繁殖,我不会最终得到相当少的父母相当快?
我想如果我在接下来的20个赛季中分别获得前两个成绩,我将不会在解决方案方面取得很大进展.
那是对的吗?有一个普遍接受的方法吗?
我这里有一个 Javascript 遗传算法的示例。
你的方法的一个问题是,你总是通过与前两个个体交配来破坏种群的多样性。这永远不会很好,因为它太贪婪了,而且你实际上首先就违背了遗传算法的目的。
这就是我实现精英主义交配的方式(这意味着我保留一定比例的未改变的最适合个体并随机交配所有其余个体),我将让代码来说话:
// save best guys as elite population and shove into temp array for the new generation
for(var e = 0; e < ELITE; e++) {
tempGenerationHolder.push(fitnessScores[e].chromosome);
}
// randomly select a mate (including elite) for all of the remaining ones
// using double-point crossover should suffice for this silly problem
// note: this should create INITIAL_POP_SIZE - ELITE new individualz
for(var s = 0; s < INITIAL_POP_SIZE - ELITE; s++) {
// generate random number between 0 and INITIAL_POP_SIZE - ELITE - 1
var randInd = Math.floor(Math.random()*(INITIAL_POP_SIZE - ELITE));
// mate the individual at index s with indivudal at random index
var child = mate(fitnessScores[s].chromosome, fitnessScores[randInd].chromosome);
// push the result in the new generation holder
tempGenerationHolder.push(child);
}
Run Code Online (Sandbox Code Playgroud)
它的评论相当不错,但如果您需要任何进一步的指导,请询问(这里是 github 存储库,或者您可以在上面的 url 上查看源代码)。我多次使用这种方法(精英主义),对于基本场景,它通常效果很好。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
2848 次 |
| 最近记录: |