Genetic Algorithm in python
Python is an object oriented programming language which is highly interpreted and is highly interactive.
Python was created by Guido van Rossum in the year 1985 – 1990 .The source code of python is available in GNU General Public License (GPL).
It also has English like keywords which are often easy to understand. Python is considered as beginner level language because it is very easy to understand and also that easy to execute.
It is mainly used to build applications and also to build projects. It supports garbage collection automatically.
It is portable and also very easy to learn, read and maintain. Python just contains the soft code rather compared to hard code whereas C language consists of hard code.
Genetic algorithm is an algorithm in which we can solve the problems which are constrained and unconstrained problems on the basis of natural selection. It is mainly used to optimize the complex problems
In the process of genetic algorithm we should create an initial population and then we have to scale the population next we have to retain the elite and then we should select the parents and then should produce crossover children and the mutated children.
They are heuristic search algorithms. It is used to modify the population of individual solutions. Genetic algorithm has been inspired from Darwin’s theory of evolution in Nature.
Genetic Algorithm in Python:
Genetic algorithm is an evolutionary algorithm to optimize the given problems using biological theory of evolution using the means of natural selection with operators based on genetic combination and mutations and with binary representation.
Steps involved in Genetic Algorithm:
- Creating the initial population.
- After initializing the population then we should select the parents by evaluating the fitness.
- After selecting the parents then the next step is to produce the children’s in order to produce the children we should cross over the parents.
- After producing the children the next step is to mutating the children or off springs.
- After mutating the children then we should evaluate the children or off springs.
- After completion of mutation and evaluation of the children or off springs then we should merge the children or off springs with the main population and then we should sort them out with the main population.
The above shown steps are the steps that should be followed in genetic algorithm process. PyGad is an example for genetic algorithm in python. It is a library used to optimize the genetic algorithms in machine learning.
PyGad is an open source library that is used to build and optimize the genetic algorithms. It works mainly using keras and PyTorch. PyGad is used to support genetic algorithm methods such as initializing the population , crossover , mutating the children , evaluating the children and then selecting the parents.
It allows different types of problems by using the genetic algorithmby using the fitness functions. It is used to build and train the artificial neural networks and also to classify the problems.
For example, if there are different types of genes such as binary type , decimal type , integer type , they are treated in different manner.
We are going to use different mutation methods for different representations such as bit flip , swap , inverse , uniform , non uniform , Gaussian , shrink and other mutation types and also there are many other different cross over types. The different cross over types for different representations are blend , one point , two points , uniform and other cross over types.
Inorder to install PyGad library we need to install it using the pip command that is pip install PyGad.
It is mainly depended on numpy to manipulate arrays and it is also depended on Matplotlib. There are many modules that are involved in PyGad. The modules are shown below.
Modules in PyGad :
PyGad consists of several modules as shown below:
- PyGad first consists of the main module an the name of the main module is as same as the name of the library that is PyGad which is used to bulid and support the genetic algorithm.
- The another module of PyGad is PyGad.nn module which is used to build the artificial neural networks by using the genetic algorithm.
- The next module of PyGad is PyGad.gann module which is used to optimize the neural networks which are used for classification and regression by using the genetic algorithm.
- The next module of PyGad is PyGad .cnn module which is used to build the convolutional neural networks.
- The next module of PyGad is PyGad .gacnn module which is used to build the convolutional neural networks by using the genetic algorithm.
- The next module of PyGad is PyGad .Kerasga module which is used to build and train and support the Keras models by using the genetic algorithm.
- The another module of PyGad is PyGad . torchga module which is used to build and tarin and support the PyTorch models by using the genetic algorithm.
The above shown modules are the modules that are involved in PyGad library. In genetic algorithm we also use the fitness function.