Preview of genetic algorithm

Skip straight to the tutorial? Hello world! Genetic Algorithm – GitHub.

Many years ago, when I was about fourteen, I was introduced to a computer science graduate student in Sri Lanka. I got to know him at a photoshoot for a magazine that we were publishing at the time. I was there to figure out what photos we needed, and he took the photos. It was his hobby. After we were done, I saw him sitting on the floor, with his laptop on a step, waiting for some code to finish running. Obviously, I was curious and asked him about it.

Genetic algorithms use random exploration of the problem space combined with evolutionary processes like mutations and crossovers (exchange of genetic information) to improve guesses. But also, because they have no experience in the problem domain, they could try things a human would never think to try.

The idea of using basic principles of Darwinian evolution to write code that can solve problems through evolutions blew me away. It fascinates me to this day.

As young and naive as I was at the time, his explanation of using the biological principles of crossovers and mutations to write algorithms that can "evolve" a dataset (aka population) into a solution, instantly resonated with me. At the time, I had a rudimentary understanding of evolution, mostly based off exercises on cross-pollinating pea plants to breed different kinds of peas. Six years later, some residual effect of that moment lead me to study Bioinformatics; a field at the intersection of genetics and computer science.

It’s been almost a year since I've done any serious work in the field. I hope this is the start of changing that. My love for this space was rekindled when I came across a rudimentary project that implemented the "Hello world" equivalent of a genetic algorithm. It simply used a random population of strings and "evolved" them until it got to the word "Hello world". What a cool fu*king way to illustrate how genetic algorithms work. That project is almost 10 years old, I'm going to revamp it. Hopefully the result will be a small, versatile framework that I or anyone else can extend on.

My favourite thing about this example is that it is seemingly very simply at the surface, making it very easy to understand. However, as you learn more about genetic algorithms you can easily incorporate things like complex mutations and more variables.

If I could instil a sliver of curiosity in just one person reading this post, this would've been entirely worth its while.  For the rest of this post, which is a tutorial, I'm going to assume little prior knowledge in genetics and programming. Feel free to ask as many questions as you want, but do so by creating an issue on GitHub (you'll need a free account) or tweet me @fakeUdara.

The rest of this tutorial is hosted on GitHub, along with source code and notes: https://github.com/UdaraJay/simple-ga/blob/master/Genetic%20Algorithm.ipynb.