Genetic Algorithms — ELI5
Imagine you want to design the fastest paper airplane, but you have no idea what shape works best. You could try every possible design one by one — but there are millions of combinations of wing size, nose shape, weight, and fold angle.
Instead, try evolution:
- Start with a bunch of random airplanes. Some fly terribly. A few fly okay.
- Keep the best ones. Throw away the worst.
- Make babies. Take two good airplanes and mix their features — maybe the wings from one and the nose from another.
- Add mutations. Randomly change a small detail here and there — maybe one airplane gets slightly wider wings.
- Repeat. Test the new generation, keep the best, breed again.
After many generations, you end up with surprisingly good airplanes — even though nobody designed them. Evolution found the answer by trial and error, keeping what works and discarding what does not.
That is a genetic algorithm. Computers use this same trick to solve hard problems:
- Scheduling — finding the best arrangement of classes, shifts, or deliveries
- Game AI — evolving strategies that beat human players
- Engineering — designing antenna shapes, bridge structures, or circuit layouts
- Route planning — finding efficient paths when there are too many options to check them all
In Python, you define what “fitness” means (how good a solution is), and the algorithm breeds, mutates, and selects until it finds something great.
One thing to remember: A genetic algorithm copies nature’s strategy — create variety, test everything, keep what works, and repeat until you get something amazing.
See Also
- Python Bayesian Inference How updating your beliefs with new evidence works — and why it helps computers make smarter guesses.
- Python Convolution Operations The sliding-window trick that lets computers sharpen photos, recognize faces, and hear words in noisy audio.
- Python Fourier Transforms How breaking any sound, image, or signal into simple waves reveals hidden patterns invisible to the naked eye.
- Python Linear Algebra Numpy Why solving puzzles with rows and columns of numbers is the secret engine behind search engines, video games, and AI.
- Python Markov Chains Why the next thing that happens often depends only on what is happening right now — and how that one rule generates text, predicts weather, and powers board games.