Elite selection chooses the highest-performing individuals as parents for reproduction. A simple genetic algorithm can select the two fittest individuals to parent the entire next generation. section 2.5.5
The mechanism is deliberately direct: sort the population’s fitness values, take the top two indexes, and use those indexes to retrieve parents before crossover produces offspring. section 2.5.5
Selecting the two fittest parents
The implementation returns the highest fitness indexes in descending order: elite_selection(fitness) returns fitness.argsort()[-2:][::-1]. Those indexes can retrieve parents with pop[parents[idx]]. section 2.5.5
Listing 2.16 EDL_2_5_Genetic_Algorithms.ipynb: Selecting the fittest
def elite_selection(fitness): return fitness.argsort()[-2:][::-1] #1 parents = elite_selection(fitness) print(pop[parents[0]])
Inspect the compact listing that sorts fitness values, returns two parent indexes, and prints a selected individual. section 2.5.5
Use elite selection when:
- Fast improvement matters and the population is not yet vulnerable to premature specialization. section 3.4
- Replace it with more diverse selection when the population gets stuck at a local maximum or minimum. section 2.5.5 section 3.4
