Genetic Algorithm — Artificial Intelligence

Sanjiv Gautam
2 min readApr 28, 2020

--

A genetic algorithm must have:

  1. Heredity: Children receive properties from their parents. Data must pass from parent to children
  2. Variation: There must be variety of traits among children.
  3. Selection: One must be selected out of many possible children. Survival of the FITTEST.

Okay, seems too vague till date. But don’t worry, we might get going.

Let us evolve phrase ‘unicorn’. What should we do?

A. Create a random population of n elements.

B. Calculate fitness for n elements. (Happens over and over again. Evolution. ).

One of the key element in Genetic algorithm is fitness function. What could be the fitness function in our case? The number of character that match up to the target phrase. In our case unicorn.

C. Reproduction (Happens n times)

So the ultimate outcome of this process if the new set of population and then we go to B again. So fitness score has to go higher.

The process of Reproduction has following process:

a) Pick 2 parents. How are they picked? Different ways. Convert fitness score to assign them probability. So, higher the fitness, more likely it is to be selected. Why are not we always selecting the parents with top 2 score? Because one with the low score may contain the target phrase which our top scoring parents may not have. You will understand this, once we do the project. Don’t worry.

b) Make new element. It has further two things:

i. CROSSOVER

ii. MUTATION.

CROSSOVER:

Suppose we have two parents. ‘Unijorn’, ‘Popcorn’. So where is the crossing over point? Meaning, from which point we should add the character of parent 1 to parent 2 to create child.

Mutation: After child is made from crossover, we assign it a mutation percentage. So, if mutation is done, then we might change the child trait to child that we have just received from crossover.

Predicting a given word is available now on github.

https://github.com/SanjivG10/GeneticAlgorithm

Upgrade

In order to create a new type of data or evolved something new, we have to change something inside DNA(you will know what it is now! )

  1. Fitness Function: Write your own fitness function. Particular problem have different fitness function!
  2. How do we evolve DNA ?

We have genotype and phenotype in DNA. What does genotype do? It is the actual data. What is phenotype? It is the expression of the data, i.e. animation or stuffs like that. In Population, we express the data as different forms, which is done by phenotype of it.

Phenotype is when you take data(genotype) and express or map it into other forms! As in your design.

Optimizing Fitness function: The better fitness function you can provide, the better is the result.

--

--

Sanjiv Gautam
Sanjiv Gautam

Written by Sanjiv Gautam

Just an average boy who wishes mediocrity over luxury.

No responses yet