Genetic Algorithm from scratch via Python
I am currently reading “Genetic Algorithms and Investment Strategies” by Richard Bauer Jr. In the second chapter of the book, Richard walks through a basic example of a GA to solve X² = 64 using a 5 bit binary string. The search space ends up being between 00000 — 11111 with an optimal solution equaling 01000. Some creative adjustments were added.
Step 1: Import and setup the basic Binary / Int conversion methods.
Step 2: Setup the Crossover method.
Step 3: Setup the Mutation method.
- If the random percentage is below our threshold, flip the bits, otherwise leave them alone.
Step 4: Method to calculate / rank the Fitness of all individuals in our Population.
Step 5: Setup a random starting population.
Step 6: Converge on a potential solution