Genetic algorithms (GA) are adaptive heuristic search algorithms based on genetics and natural selection that falls under optimization algorithms. That was a lot. But simply, genetic algorithms are algorithms that are designed to find an optimal solution in a sometimes large problem set.
Understand that the algorithm is based off of evolution.
Here are the steps the algorithm takes:
The example I am going to use is designing rockets to reach space. There are thousands if not millions of different rocket designs and in order to find the best one, we follow a genetic algorithm. (This is not how actual rockets are designed, but I'm just using it as an example.)
A sacrificial lamb is brought in and members chant the names of the seven gods of Tehgkejw. (Just kidding)
Initiation is when a population is randomly generated. It is expected that the members of the population will perform poorly; they are randomly generated after all. For example, in this step, we would randomly create thirty rockets that would probably be so bad they wouldn’t reach the heights of modern skyscrapers.
Now we score the population. In the rocket design scenario, this would be measuring the attitude they reach.
Here we select some of the fittest in the population to “breed”. We might select the ten highest altitude reaching rockets or select the highest altitude rocket out of a small randomly-picked sample and do this ten times, each time with a different sample. Different methods would result in different results.
Crossover (also called Recombination)
Here we will generate a second (hopefully better) population. We take the best rockets selected in step three and “breed” them together (Cover your eyes kids!) to create “children” that would make up the second population. Two rockets would be “bred” by combining random features of both, for example, taking the fins of one “parent” and the engine of the second ”parent”. The result is not necessarily better than either of the parents, but generally would be. Now that we create the second population what happens to the first? The first is scrapped and the second takes their place. It’s a brutal world.
There is still a problem with this algorithm. What if one rocket type just completely overwhelms the population? This is bad as the population lacks diversity and would not be able to improve itself, so we would introduce little changes, mutations, to every rocket. Not always a better population, but it is certainly possible that one or more rockets receive improvements.
Repeat steps 2 to 5.
Why does it work? Because evolution works. Notice the similarities. The step of selection is the selection of the fittest. Only the strongest will be able to breed and pass on their traits. The step of crossover is the step of procreation, parents creating offspring. The step of mutation is literally when mutation occurs within our bodies.
Great. Any downsides? Plenty.
Evaluation has to measure the individuals in a population on a continuous scale. So a success or fail when evaluating an individual wouldn’t work.
It is also quite possible that the population is stuck in a local minimum. The individuals in it might seem to be the best possible, but there might be a completely different design that would be much better.