| Path: | data/SELECTION |
| Last Update: | Sat Feb 09 00:32:47 +0100 2008 |
A selection operator generates the new generation from the old.
The selection strategy should be defined as a next_generation method in the metaclass of your genotype class.
class Example < Genotype
...
class << self
def next_generation(population)
# select parents and yield(parent1,parent2) them to the crossover and mutation operator.
# Create an array from several of these calls to get the next generation.
end
end
use RouletteSelection # or include some builtin operator
end
The builtin selection operators are implemented as modules which should be included in the metaclass. Using the Genotype.use keyword does this automatically.
These strategies work with genotype classes which define a fitness function. The fitness function should return a number, higher fitness means better and more likely to be selected. All except RouletteSelection can handle negative fitness values.
The documentation for selection.rb contains explanations for most of these.
Generates a module which applies elitism to some selection strategy. This:
This ensures the maximum fitness can never decrease.
Applies crossover OR mutation instead of both for generating children. Common in genetic programming. Only works for selection methods which use yield to generate children (currently all of the built-in selection methods do this).
Because there is no way to determine who is the actual best individual, using Population#benchmark for comparing strategies for convergence speed, etc. is not possible. Defining a fitness function as some statistic you want to track or using track_stats to override the default and then using benchmark should be possible, but is untested.