Text Evolution

Explanation

This is an example of a genetic algorithm. Genetic algorithms are comprised of three main components: selection, crossover, and mutation. Selection (also known as evaluation) is a function that assigns a value to each entity in the population. This allows us to determine an individual’s overall fitness level. Crossover is a method in which we generate a child based on the attributes of two or more parents. Finally, we have mutation which will ensure genetic diversity in our population.

In practice there are three phases that a genetic algorithm will go through: initialization, evaluation, and breeding. During the initialization phase we must create our starting population. It's important that the creation of our population be done randomly to some extent. The randomness in our population is what gives us the genetic diversity we need to be able to evolve into our target.

This example helps us to visualize how a genetic population works in a very simple example. First, we select a phrase that we want our text population to evolve into. In my example, the phrase is chosen at random from a list when the page loads. We then randomly generate a population of phrases. These phrases are random collections of characters that is the same length as the our target phrase. The next step is to evaluate the fitness of each phrase. I did this by looking at every letter in the phrase and seeing how far it was from the correct letter. So if our target letter is a "C" then the letter "B" is ranked higher than the letter "P". I then give a much higher point for any exact match, so that phrases with more matches have a higher survival rate. Once we have evalulated each individual's fitness, we then need to breed the top performers of the population. This is done by selecting one letter from either parent randomly, and giving it to the offspring. This is also the point in which we introduce genetic mutation. We introduce a small probability that rather than getting a particular gene from the parents, we instead give it a random value. This is the part that allows us to maintain the genetic diversity we want. Once we have our new population we simply rinse and repeat until we eventually have an exact match.

Scroll To Top