Optimisation¶
Define the genetic algorithm¶
When discussing how cBots could be optimised, we have mentioned that cBots can be refined using the genetic algorithm method. In this guide, we explain exactly what it is and how it works.
The genetic algorithm method is based on the natural selection theory. This theory states that only the fittest individuals survive for subsequent reproduction.
In cBot optimisation, each optimisation pass is considered an individual. To evaluate individual passes, the genetic algorithm calculates a certain fitness score for each pass and compares this score against all other passes.
For it to work, the genetic algorithm needs an initial population. To generate it, the optimiser will run several different passes with randomised parameters. After creating its initial population, the algorithm will start the process of finding the fittest optimisation pass. This process continues until the fitness scores of child passes start stagnating and converging. At this point, the algorithm is stopped.
Genetic algorithm stages¶
Any genetic algorithm has the following stages.
graph TB
B([Selection]) ==> C([Crossover]);
C ==> D([Mutation]);
D ==> B;
The stages are explained as follows.
Selection¶
During this stage, the algorithm finds the two fittest optimisation passes using their respective fitness scores.
Crossover¶
After finding the two fittest optimisation passes, the algorithm uses them to create new child (or offspring) passes by using combinations of the parameter values of both of the parent passes.
Example
If your cBot has four different parameters for optimisation, the algorithm will get the values of the first and second parameters of offspring passes from one parent and the third and fourth parameters from the second parent.
Mutation¶
At this stage, the algorithm mutates the offspring passes by randomly modifying one or more parameter values.
After the mutation stage, the optimiser will run a new offspring optimisation pass. Subsequently, it will repeat all stages but only if the fitness score of an offspring pass was higher than the last fittest optimisation pass. Such an outcome would mean that there is room for improvement, indicating that optimisation should continue.
Otherwise, the algorithm will increase its stagnation counter. If the stagnation counter reaches the value of the algorithm stagnation period parameter, the optimisation process will be automatically stopped.
Genetic algorithm parameters¶
The genetic algorithm has several parameters that it uses during its lifetime. These parameters cannot be changed.
Parameter | Definition |
---|---|
Population size | The maximum size of a population or the maximum number of passes made during each optimisation iteration. |
Max iteration count | The maximum number of optimisation iterations performed by the algorithm. |
Stagnation period | The maximum value of the stagnation counter. If this value is reached, the algorithm is stopped. |
Elite percentage | This value is used to select an X% of individuals with the highest fitness scores from the current algorithm iteration. These passes will survive to the next iteration. |
Tournament size percentage | This value is used to select an X% of individuals from an iteration for finding parent passes. |
Migrans percentage | This value is used to add an X% of randomly created passes during each new iteration or population generation. |
Mutation percentage | The percentage of the parameters of offspring passes to be mutated. |
Mutation probability percentage | The percentage of offspring passes to be mutated. The passes not included in this percentage will not go through the mutation stage. |