Class | Ai4r::GeneticAlgorithm::GeneticSearch |
In: |
lib/ai4r/genetic_algorithm/genetic_algorithm.rb
|
Parent: | Object |
This class is used to automatically:
1. Choose initial population 2. Evaluate the fitness of each individual in the population 3. Repeat 1. Select best-ranking individuals to reproduce 2. Breed new generation through crossover and mutation (genetic operations) and give birth to offspring 3. Evaluate the individual fitnesses of the offspring 4. Replace worst ranked part of population with offspring 4. Until termination
If you want to customize the algorithm, you must modify any of the following classes:
- Chromosome - Population
population | [RW] |
We combine each pair of selected chromosome using the method Chromosome.reproduce
The reproduction will also call the Chromosome.mutate method with each member of the population. You should implement Chromosome.mutate to only change (mutate) randomly. E.g. You could effectivly change the chromosome only if
rand < ((1 - chromosome.normalized_fitness) * 0.4)
1. Select best-ranking individuals to reproduce 2. Breed new generation through crossover and mutation (genetic operations) and give birth to offspring 3. Evaluate the individual fitnesses of the offspring 4. Replace worst ranked part of population with offspring
Select best-ranking individuals to reproduce
Selection is the stage of a genetic algorithm in which individual genomes are chosen from a population for later breeding. There are several generic selection algorithms, such as tournament selection and roulette wheel selection. We implemented the latest.
Steps: