Created
March 6, 2012 20:25
-
-
Save cmd-ntrf/1988770 to your computer and use it in GitHub Desktop.
varOr + numpy multinomial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def varOr(toolbox, population, lambda_, cxpb, mutpb): | |
assert (cxpb + mutpb) <= 1.0, ("The sum of the crossover and mutation " | |
"probabilities must be smaller or equal to 1.0.") | |
ncx, nmut, nrep = numpy.random.multinomial(lambda_, (cxpb, mutpb, 1-cxpb-mutpb)) | |
offcx = map(toolbox.clone, tools.selRandom(population, 2*ncx)) | |
offmut = map(toolbox.clone, tools.selRandom(population, nmut)) | |
offrep = map(toolbox.clone, tools.selRandom(population, nrep)) | |
for ind1, ind2 in offcx: | |
toolbox.mate(ind1, ind2) | |
del ind1.fitness.values, ind2.fitness.values | |
offcx = offcx[::2] | |
for ind in offmut: | |
toolbox.mutate(ind) | |
del ind.fitness.values | |
return random.shuffle(offcx + offmut + offrep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment