寻找一种在不同 GA 迭代中重用 50% 的先前种群最佳个体的方法。
例如,在进程内的当前迭代结束时,执行“population = ga.getPopulation()”。下一次迭代初始化该 pop 的 50%。
有谁知道如何处理人口结果?
寻找一种在不同 GA 迭代中重用 50% 的先前种群最佳个体的方法。
例如,在进程内的当前迭代结束时,执行“population = ga.getPopulation()”。下一次迭代初始化该 pop 的 50%。
有谁知道如何处理人口结果?
您可以使用该方法setElitismReplacement
(参见此处)来定义精英主义将使用的个人数量。
Just for the record. setElitismReplacement would be a good solution in case to specify number of individuals to elitism in 1 GA complete run. In every generation just that number of individuals will be selected for next generation.
What i've meant was in diferent running store best population achieved of all generations and reuse 50% of previous best results to initialize next run.
Anyway an example has been posted.
应用于此问题的代码片段。
所需功能:
def createOwnGen(self , ga_engine):
gen = ga_engine.getCurrentGeneration()
if gen == 0 and self.previous_population != []:
population = ga_engine.getPopulation()
popSize = len(population)
for i in xrange(popSize/2):
population[popSize/2+i] = self.previous_population[i]
population.sort()
return False
stepCallback (来自 pyevolve 的本机函数)在每一代中都被调用。
....
ga.stepCallback.set(self.createOwnGen)
....
bestIndividue = ga.bestIndividual()
population = ga.getPopulation()
self.previous_population = population.internalPop
....