|
|
||
|---|---|---|
| .. | ||
| Diophantine.ipynb | ||
| Genetic.ipynb | ||
| README.md | ||
README.md
Genetic Algorithms
Pre-lecture quiz
Genetic Algorithms (GA) are based on an evolutionary approach to AI, where methods inspired by the evolution of a population are used to find an optimal solution to a given problem. They were introduced in 1975 by John Henry Holland.
Genetic Algorithms are built on the following principles:
- Valid solutions to the problem can be represented as genes.
- Crossover allows combining two solutions to create a new valid solution.
- Selection is used to choose more optimal solutions based on a fitness function.
- Mutations are introduced to disrupt optimization and help escape local minima.
To implement a Genetic Algorithm, you need the following:
- A method to encode problem solutions as genes g∈Γ.
- A fitness function fit: Γ→R defined on the set of genes Γ. Smaller values of the function correspond to better solutions.
- A crossover mechanism to combine two genes into a new valid solution: crossover: Γ2→Γ.
- A mutation mechanism: mutate: Γ→Γ.
In many cases, crossover and mutation are relatively simple algorithms that manipulate genes as numeric sequences or bit vectors.
The specific implementation of a genetic algorithm can vary, but the general structure is as follows:
- Select an initial population G⊂Γ.
- Randomly choose one of the operations to perform at this step: crossover or mutation.
- Crossover:
- Randomly select two genes g1, g2 ∈ G.
- Compute crossover g=crossover(g1,g2).
- If fit(g)<fit(g1) or fit(g)<fit(g2), replace the corresponding gene in the population with g.
- Mutation: Select a random gene g∈G and replace it with mutate(g).
- Repeat from step 2 until a sufficiently small value of fit is achieved, or until the step limit is reached.
Typical Tasks
Genetic Algorithms are commonly used to solve tasks such as:
- Schedule optimization
- Optimal packing
- Optimal cutting
- Accelerating exhaustive search
✍️ Exercises: Genetic Algorithms
Continue your learning in the following notebooks:
Visit this notebook to explore two examples of using Genetic Algorithms:
- Fair division of treasure
- 8 Queens Problem
Conclusion
Genetic Algorithms are applied to solve a variety of problems, including logistics and search challenges. This field is inspired by research that combines ideas from Psychology and Computer Science.
🚀 Challenge
"Genetic algorithms are simple to implement, but their behavior is difficult to understand." source Research an implementation of a genetic algorithm, such as solving a Sudoku puzzle, and explain how it works using a sketch or flowchart.
Post-lecture quiz
Review & Self Study
Watch this excellent video that explains how a computer can learn to play Super Mario using neural networks trained by genetic algorithms. We will explore more about computers learning to play games like this in the next section.
Assignment: Diophantine Equation
Your task is to solve a Diophantine equation—an equation with integer solutions. For example, consider the equation a+2b+3c+4d=30. You need to find the integer solutions that satisfy this equation.
This assignment is inspired by this post.
Hints:
- You can assume the roots are in the interval [0;30].
- Use a list of root values as a gene.
Start with Diophantine.ipynb.