0% found this document useful (0 votes)
78 views

Genetic Algorithms: Aroob Amjad Ahmed

Genetic algorithms are a search and optimization technique inspired by biological evolution. They utilize concepts like natural selection, crossover, and mutation to evolve solutions to problems. The document discusses genetic algorithms and their implementation in Python using the Pyevolve framework. It provides examples of using genetic algorithms to solve problems like finding a list of zeros, the Rastrigin function, and the travelling salesperson problem. The laboratory sessions involve hands-on work with genetic algorithms, including analyzing results visually through different types of plots.

Uploaded by

Aroob amjad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Genetic Algorithms: Aroob Amjad Ahmed

Genetic algorithms are a search and optimization technique inspired by biological evolution. They utilize concepts like natural selection, crossover, and mutation to evolve solutions to problems. The document discusses genetic algorithms and their implementation in Python using the Pyevolve framework. It provides examples of using genetic algorithms to solve problems like finding a list of zeros, the Rastrigin function, and the travelling salesperson problem. The laboratory sessions involve hands-on work with genetic algorithms, including analyzing results visually through different types of plots.

Uploaded by

Aroob amjad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Genetic Algorithms

Aroob Amjad Ahmed


Intelligent Systems, Higher School of
Technology and Experimental Sciences,
Jaume I University
Castellón, Spain
Abstract— Genetic algorithms (GAs) are a search and optimization The fitness function decides how fit an individual
technique using natural evolution. These have been successfully
used in a wide variety of real-world problems with similar is, which means the capacity of an individual to
complexity or smaller ones, such as the crawling gait imitated by a compete with others. As a result, a fitness score is
robot or a travelling salesperson problem. The results of these given to each individual and it also determines the
algorithms are shown through various different plots clearly
marking the each score of individuals. probability of this to be selected for reproduction.
The next phase is the selection. Its aim is to get
I. INTRODUCTION the fittest individuals, the ones that have the
A genetic algorithm (GA) is the abstract form of highest fitness scores, and allow them to pass their
biological evolution based on Charles Darwin's genes to the next generation.
theory of natural selection, where the fittest In the crossover phase, which is the main stage,
individuals are selected for the reproduction of the randomly a crossover point is selected from within
next generation. This concept was introduced by the genes of the mated parents. As a result, an
John Holland in the 1970s. By the time, these offspring is created when the genes of these
genetic algorithms have been broadly used as parents are exchanged up until this point is
search and optimization tools in different aspects reached.
of science, including commerce and engineering. Mutation is an adjustment of the value of a
The essential purposes behind their prosperity are string position. Its motivation is to guarantee that
their wide appropriateness and convenience. [1] significant data contained inside strings may not be
1) The fundamental qualities of a genetic lost prematurely.
algorithm are as per the following: Finally, the algorithm finishes if the population
2) The genetic algorithm works with a coding has converged. At that point it is said that the
of the parameter set, not the parameters calculation has given a set of solutions to our
themselves. problem. [2]
3) The search of this algorithm starts from a There are numerous benefits of genetic
population of points, not a single one. algorithms compared to the traditional ones, such
4) The genetic algorithm utilizes result data, as their easily understandable concepts, supportive
not derivatives. to multi-objective optimization or the capacity of
5) The genetic algorithm utilizes probabilistic managing complex problems and parallelism.
progress rules, not deterministic ones. [1] However, genetic algorithms also have
There are five phases that are considered in a disadvantages. An important aspect in this process
genetic algorithm: initial population, fitness is carefully selecting the population size, the
function, selection, crossover and mutation. formulation of fitness function and other
Initial population marks the starting point of the parameters because an incorrect choice of this can
process and it is a set of individuals which is called make it difficult for the algorithm to converge.
a Population. An individual is described by a set of Genetic algorithms should be used when the
parameters, which are variables, known as Genes. other solutions are too slow or complicated, when
These genes are joined into a string to shape a there is a need of hybridizing with an existing
Chromosome, which is a solution. solution or to explore new approaches. [1]
The remaining sections of the paper are as Algorithm Engine, using GSimpleGA.GSimpleGA
follows: Section 2 explains the work done in the and also with default parameters, such as the
laboratory sessions about basic genetic algorithms number of generations, mutation rate or the
and an example of Robot crawling problem using selector method. Lastly, to evolve the algorithm,
this type of algorithms. Section 3 discusses the we use the evolve() function and show different
experimental results obtained with the types of plots, which is deeply discussed in the next
implementation of GA. Section 4 is a conclusion to section, graphical analysis.
the topic and the experiment. The graphical representation uses Graphical
Plotting Tool, based on the Matplotlib plotting
library and an adapter and a database file, where
II. WORK WITH GENETIC ALGORITHMS IN LABORATORY SESSIONS
the scores are stored.
The laboratory sessions are divided into two After creating the GD List, the evaluation function
blocks: the first block is an introduction to genetic and setting the parameters, the database adapter
algorithms and the second one is a robot crawling is defined with a specific identifier. As a result, all
problem using this type of algorithm. the statistics are saved in this database file. Lastly,
we evolve the algorithm and do the plotting. The
A. Introduction to genetic algorithms different types of graphs shown in this exercise
The genetic algorithms are implemented using are: Error bars (raw scores), where we can see the
the Pyevolve algorithm framework. At first, it was generations on the x-axis and the raw scores on
created to be a complete genetic algorithm the y-axis; error bars (fitness scores);
framework written in pure python, but, with time, max/min/avg/std. dev. graph (fitness scores);
it also started including Genetic Programming. [3] min/max difference graph, raw and fitness scores
This session consists of three examples (a basic and heat map of population raw score distribution.
introduction, graphical analysis and Rastrigin “ The Rastrigin function is a non-convex function
function) and a last problem named as Travelling used as a performance test problem for
Salesperson Problem. optimization algorithms. It is a typical example of
The first example is a slightly modified version of non-linear multimodal function.” [5] In our case,
the tutorial that appears on the Pyevolve website. we will use a 20-dimensional space. To achieve the
To make it easier, some default parameters are function, we will define a rastrigin function, which
used (defined in the Const module), such as does a total calculation of the genome passed as a
implementing the 1D List, without specifying the parameter. Then, the 1D List is created, with
Crossover, Initializator or the Mutator. Instead, the different maximum and minimum ranges and
default ones are used: Swap Mutator, One Point initializator, mutator and evaluators are set.
Crossover and the Integer Initializator. Finally, the different rates are set and we evolve
In this exercise, the aim is to find a simple 1D list the genome.
of integers of n-size with zero in all positions. To Travelling Salesperson problem, which is the last
solve this problem, first we import the framework section of this session, consists of finding the
from pyevolve. The next step is to define the shortest possible route that visits each city exactly
evaluation function [4], which gives a high score to once and returns to the origin city. The task is to
the zero’ed chromosomes, passed as a parameter solve the problem with a set of 48 cities ( ATT 48
to the function. In the following steps, one sample dataset) and store the results in a database file. For
genome is created with the list n-size of 20. The this problem, 5 different functions are
API also allows us to change the maximum and implemented: cartesian_matrix, tour_length,
minimum range values of the genome. The next write_tour_to_img, G1DListTSPInitializator and
step is the main one, which does the evolution or evolve_callback. It follows the basic structure of a
control statistics. It is the creation of Genetic genetic algorithm.
B. Robot Crawling with genetic algorithms the following ones: the plot of population which
scores each individual (Fig. 1) and the display of
Robot crawling problem imitates the human
the best individual and its score (Fig. 2). Last, we
crawling gait by using genetic algorithms. In this
will plot the histogram of the best individual after
case, a humanoid robot called NAO robot is
each generation step (Fig. 3).
used to perform the actions. [6]
To get the perfect human-like movements,
these have to be inherently periodic and should
keep repeating the same steps. This is defined
with a periodic function.

Fig. 1 periodic function decomposed into a sum of simple oscillators

The simulation of the setup is done by running the


script called launch_map.bat, which runs a 3D Fig. 1 Plot of population scoring each individual
environment. Nextly, we also run another script
which positions us the robot in this environment.
In the following steps, the nao robot is connected
using the Nao() function and we set the
parameters for it to start crawling. But, it also
includes some restrictions such as using a 1D list
with 10 chromosomes, a Roulette method for
selection and a uniform method for crossover. The
mutation rate uses a probability of 0.5 and a
crossover rate of 0.8. An important aspect of this
problem is the correct selection of the fitness
function and the maximum and minimum range Fig. 2 Plot of population of the best individual with its score

values for the 1D list. With these values, the scaling


is done through the calculation of the following
expression: robot_parameter = genome_value *
(max - min) + min. The range values are shown for
each joint of the robot.
The aim for this exercise is to test it with 10
individuals, reaching 20 or more than 50
generations.
III. EXPERIMENTAL RESULTS

The main purpose of the first example of genetic Fig. 3 Histogram of population of the best individual
algorithm is to find a simple 1D list of integers of n- The graphical representation of genetic
size with zero in all positions.
algorithms consists of different plots representing
The evaluation function we have defined, returns different colors and lines in the axis, all shown for
a raw score of 3.0 if the list passed as a parameter 20 generations.
contains the values 1, 2, 3, 8, 0, 2, 0, 4, 1 and 0. The error bars (raw scores) graph has green
The plots shown after evolving the algorithm are vertical lines (showing maximum and the minimum
raw scores of the current population at generation
indicated in the x-axis) and blue lines (representing
average raw score of the population) (e.g. Fig. 4).

Fig. 6 Max/min/avg/std. dev. graph (fitness scores)

The last two graphs that are represented in this


section are the Min/max difference graph (e.g. Fig.
7) using fitness and raw score and a heat map of
Fig. 4 Error bars graph (raw scores) population using raw score distribution (Fig. 8).
The error bars fitness score graph is different The first one, marks the difference between the
from the previous one because it uses the fitness best individual raw score and the worst individual
score instead. raw score and the second one, difference between
In the Max/min/avg/std. dev. graph using raw the best individual fitness score and the worst
scores, the green line represents the maximum raw individual fitness score.
score at the generation in the x-axis,the red line
represents the minimum raw score, and the blue
line shows the average raw scores. The green
shaded area represents the difference between
max. and min. raw scores. Finally, the black line
shows the standard deviation of the average raw
scores (Fig. 5.).

Fig. 7 Min/max difference graph, raw and fitness scores

Fig. 5. Max/min/avg/std. dev. graph (raw scores)

In the Max/min/avg/std. dev. graph (raw scores),


the red line shows the minimum fitness score and
the blue line shows the average fitness score from
the population. The green shaded region between
the green and red line shows the difference
between the best and worst individuals of the Fig. 8. Max/min/avg/std. dev. graph (raw scores)
population. (Fig. 6.)
In the heat map, a Gaussian interpolation method In conclusion, GAs are a heuristic searching
is used. The obtained result shows the dark blue technique based on natural evolution. They are a
color as the individual with the worst score. hearty and adaptable methodology that can be
applied to a wide scope of learning and
The Rastrigin function uses 20 parameters. The
optimization problems. They are especially fit to
final results are shown for generations from 0 to
examples where traditional optimisation
150, each generation scored separately with its
techniques separate, either because of the
maximum, minimum and average fitness raw
unpredictable construction of search space or
score. The solution for the genome base is a score
because the search becomes computationally
of 0.039575 and a fitness score of 9.072782. The
recalcitrant. [7]
evaluation process finishes at the 173rd
generation, 34.60%, and the following scores: REFERENCES
Max/Min/Avg Fitness(Raw) [1] Genetic Algorithm - an overview | ScienceDirect Topics
https://www.sciencedirect.com/topics/engineering/genetic-algorithm
[12.88(24.55)/9.07(0.04)/10.74(10.74)] [2] Introduction to Genetic Algorithms — Including Example Code

Finally, the travelling salesperson problem (TLP) https://towardsdatascience.com/introduction-to-genetic-algorithms-


including-example-code-e396e98d8bf3
has similar results to the previous example. [3] Welcome to Pyevolve documentation ! — Pyevolve v0.6rc1
However, it has extra graphs showing the route documentation
images and with much bigger values (2000 http://pyevolve.sourceforge.net/0_6rc1/
generations). As a result, the final best individual [4] Introduction — Pyevolve v0.6rc1 documentation

image is shown (Fig. 9.). http://pyevolve.sourceforge.net/0_6rc1/intro.html#term-evaluation-


function
[5] Rastrigin function - Wikipedia
https://en.wikipedia.org/wiki/Rastrigin_function#:~:text=In
%20mathematical%20optimization%2C%20the%20Rastrigin,has
%20been%20generalized%20by%20Rudolph.
[6] SoftBank Robotics - Nao Robot
https://www.softbankrobotics.com/emea/en/cool-robots/nao
[7] Genetic algorithms for modelling and optimisation -
https://www.sciencedirect.com/science/article/pii/S03770427050007
74

Fig. 9. Final best individual of TLP with 900 generations

Lastly, the results shown for the robot crawling


example, using genetic algorithms, uses more than
20 or 50 generations. Plot evolution with raw and
fitness scores, maximum and minimum raw and
fitness score plots and the one with difference raw
score are represented to demonstrate the evolved
algorithm.
IV. CONCLUSIONS

You might also like