MachineX: Genetic Algorithm

Reading Time: 2 minutes

Genetic algorithm is based on the Charles Darwin famous principle of survival of the fittest, where the fittest of the individuals are given higher importance and are chosen for reproduction in order to produce children for the new generation.

The process starts by selecting the fittest individuals from a population, who then produce offspring which inherit the characteristics of the parents. Since the parents already have better fitness among the population, their children will have a higher chance of surviving in their population.

Genetic Algorithm has five phases

  1. Intialization
  2. Fitness function
  3. Selection
  4. Crossover
  5. Mutation

Initialisation

The process starts with the set of individuals known as Population where each individual is a solution to the problem you want to solve. An individual is characterized by a set of parameters (variables) known as Genes. Genes are joined into a string to form a Chromosome (solution)

This image has an empty alt attribute; its file name is 1_virsxg12dsltpdwoo561ya.png

Fitness Function

The fitness function is used to predict a fitness score for each individual which shows how fit is that individual among the population. Individuals with a higher fitness score are given more probability for reproduction

Selection

In this phase, once the fitness function is applied and fitness score is calculated for each individual the selection of the fittest individuals starts which are then allowed to pass their genes to the next generation.

Crossover

Crossover is considered to be the most important step in the process. In this phase, a crossover point is chosen at random from within the genes. Offsprings are then generated by exchanging the genes up to the point crossover isn’t reached. Then the new offsprings are added to the population.

This image has an empty alt attribute; its file name is 2.png
This image has an empty alt attribute; its file name is 3.png

Mutation

In mutation, a random gene is inserted in offspring to maintaining the diversity in population to avoid the premature convergence

Termination

The algorithm terminates if the population has converged (does not produce offspring which are significantly different from the previous generation). Then it is said that the genetic algorithm has provided a set of solutions to our problem.

Hope you liked the post, let me know your thoughts in the comments.

Written by 

Rahul Khanna is a software consultant having 1+ years of experience. In past, Rahul has worked on Python where his main focus of work was to handle and analyze data using various libraries such as pandas, numpy etc. Rahul is currently working on reactive technologies like Scala, Akka and Spark along with Machine learning algorithms.