Mutation — Break Free from Stagnation

Dr. Samiran Bera (PhD)
Analytics Vidhya
Published in
3 min readJun 20, 2020

Learn how to implement Mutation Operator in Python

Mutation Operator is a popular technique used in the Genetic Algorithm. However, it has found its way to other Heuristic and Meta-Heuristic techniques through hybridization. It is primarily due to its ability to escape local optima and explore a wider solution space.

This article briefly discusses some of the popular mutation operators used today for optimization along with python codes.

The Operators:

Random Mutation: Genes from a Chromosome is modified at one or more position based on random numbers. Here ‘x’ represents a chromosome of a single dimension and ‘a’ is the number to be replaced at random positions.

Flip Mutation: Genes from a Chromosome is modified at all position based on the maximum values of all genes. For a binary chromosome, the maximum value is set to 1.

Bit-String Mutation: It is a variant of Flip Mutation, where gene modification is determined based on the random numbers for one or more positions.

Boundary Mutation: Genes from a Chromosome is modified if their value either drops below the lower bound (LB)or exceed the upper bound (UB) specified.

Swap Mutation: Two Genes from a Chromosome exchange their position, i.e. swap values of genes. Here ‘a’ and ‘b’ represents two positions at which genes are exchanged.

Inverse Mutation: It is a variant of Swap Mutation. Genes positioned at an equal distance across the center of a Chromosome are swapped, thereby reversing the chromosome.

Insert Mutation: A Gene of a chromosome is cropped from one position and inserted at another position. However, more than one gene can also be cropped at multiple positions and inserted at another position. Here ‘a’ represents the position where the gene is cropped from and ‘b’ represents the position where it is inserted.

Shift Mutation: One or more than one Gene of a chromosome is modified by shifting the genes either to the left or right by ‘n’ times.

Increment or Decrement Mutation: Genes of a Chromosome are modified either by increasing or decreasing the values using ratio. The ratio (r) is generated randomly and lies within the range [0,1].

The Concluding Note

The Mutation operator adds diversity to the population. Thus it is essential, as it allows search algorithms like the Genetic Algorithm to escape from local optima by promoting exploration. This article provides many mutation operators, however, the list above is not exhaustive. More mutation operators are developed each day and can be found on Google Scholar.

This article would be incomplete without answering these frequently asked questions on social networks.

Q1: Which mutation operator should I use?

Well, that depends on the problem. However, random mutation, flip mutation, and increment/decrement operators is a good place to start.

Q2: Should I use only one mutation operator?

Well, there is no such rule. One or more than one mutation operator can be used together in combination.

Q3: How frequently should mutation be done?

The mutation rate depends on the problem. But, it is usually quite low around 30% or less. It is because a search algorithm with a high mutation rate behaves like a random search and thus isn’t much reliable.

I hope you liked this article.

Image source: https://www.nature.com/articles/d41586-019-03536-x

--

--

Dr. Samiran Bera (PhD)
Analytics Vidhya

Senior Data Scientist | PhD | Machine Learning & Optimisation