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

Pygad: An Intuitive Genetic Algorithm Python Library: June 2021

Uploaded by

Berto Erto
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Pygad: An Intuitive Genetic Algorithm Python Library: June 2021

Uploaded by

Berto Erto
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/352373466

PyGAD: An Intuitive Genetic Algorithm Python Library

Preprint · June 2021

CITATIONS READS
0 1,248

1 author:

Ahmed Fawzy Gad


University of Ottawa
63 PUBLICATIONS   73 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

PyGAD: A Python Library for Building the Genetic Algorithm and Training Machine Learning Algorithms View project

Building Android Apps in Python Using Kivy with Android Studio View project

All content following this page was uploaded by Ahmed Fawzy Gad on 19 June 2021.

The user has requested enhancement of the downloaded file.


PyGAD: An Intuitive Genetic Algorithm Python
Library
Ahmed Fawzy Gad
School of Electrical Engineering and Computer Science
University of Ottawa
Ottawa, ON, Canada
[email protected]
arXiv:2106.06158v1 [cs.NE] 11 Jun 2021

Abstract—This paper introduces PyGAD, an open-source easy-


to-use Python library for building the genetic algorithm. PyGAD
supports a wide range of parameters to give the user control over
everything in its life cycle. This includes, but is not limited to,
population, gene value range, gene data type, parent selection,
crossover, and mutation. PyGAD is designed as a general-
purpose optimization library that allows the user to customize
the fitness function. Its usage consists of 3 main steps: build
the fitness function, create an instance of the pygad.GA class,
and calling the pygad.GA.run() method. The library supports
training deep learning models created either with PyGAD itself
or with frameworks like Keras and PyTorch. Given its stable
state, PyGAD is also in active development to respond to the
user’s requested features and enhancement received on GitHub
github.com/ahmedfgad/GeneticAlgorithmPython. PyGAD comes
with documentation pygad.readthedocs.io for further details and
examples.
Keywords— genetic algorithm, evolutionary algorithm, optimiza-
tion, deep learning, Python, NumPy, Keras, PyTorch

I. I NTRODUCTION
Nature has inspired computer scientists to create algorithms for
solving computational problems. These naturally-inspired algorithms
are called evolutionary algorithms (EAs) [1] where the initial solution
(or individual) to a given problem is evolved across multiple iterations
aiming to increase its quality. The EAs can be categorized by different
factors like the number of solutions used. Some EAs evolve a single
initial solution (e.g. hill-climbing) and others evolve a population of
solutions (e.g. particle swarm or genetic algorithm).
The genetic algorithm (GA) a biologically-inspired EA that solves Fig. 1. Flowchart of the genetic algorithm.
optimization problems inspired by Darwin’s theory “survival of the
fittest” [1], [2]. Originally, the GA was not designed for being a
computational algorithm rather understanding how natural selection children. Each child shares genes from its 2 parents using the
happens. Later, it becomes one of the most popular computational crossover operation.
EAs. To go beyond the parents’ capabilities, the mutation is introduced
The core concepts of the GA are derived from the natural solution. to make some changes to the children. Due to the randomness in these
There are several organisms called population. The members of changes, some children may be fitter or worse than their parents. By
the population may have the ability to mate and reproduce new mating the best parents and producing more children, a better solution
organisms. Because the good organisms can produce better offspring, is likely found after each generation. Either the offspring only or
then the good members of the population are selected for mating and combined with the parents form the next generation’s population.
others die. When 2 good organisms mate, their offspring will likely The process is repeated for a limited number of generations or until
be better specially when some new, hopefully, better, changes are a satisfactory solution is found where no further optimization is
introduced. These concepts form the core of the GA in computer necessary.
science. There are many parameters to tune in to make the GA fits the
The GA steps are explained in Figure 1 [2]. The first step creates problem. For experimentation, it is essential to use an easy tool for
an initial population of solutions for the problems. These solutions building the genetic algorithm.
are not the best for the problem and thus evolved. The evolution starts This paper introduces PyGAD, an open-source intuitive Python
by selecting the fittest solutions as parents based on a maximization library for optimization using the genetic algorithm. PyGAD was
fitness function. Each pair of parents mate to produce one or more released in April 2020 and has over 185K installations at the time of

©2021 Ahmed Fawzy Gad. Published at arXiv on June, 10 2021. Donation is open at PayPal (paypal.me/ahmedfgad or e-mail [email protected]),
OpenCollective (opencollective.com/pygad), and Interac e-Transfer ([email protected]).
writing this paper. The library supports single-objective optimization The library leaves much stuff to be built by the end-user which
with a wide range of parameters to customize the GA for different makes the user feel lost between the modules, classes, and functions
types of problems in an easy-to-use way with less effort. PyGAD needed to customize the library to solve a problem. For example,
has a lifecycle to trace how everything is working from population building a population of mixed data types requires the user to:
creation until finding the best solution. The lifecycle can also be 1) Register a data type for each gene.
customized to help researchers alter its sequence, enable or disable 2) Register an individual that combines those gene data types.
some operations, make modifications, or introduce new operators. 3) Register a population that uses that individual.
PyGAD works with both decimal and binary representations. The 4) Build the population
genes can be of int, float, or any supported NumPy numeric
data types (int/uint/float). Given the advantages of the GA over There is no way to restrict the gene values to a set of sparse
the gradient-based optimizers, PyGAD supports training Keras and discrete values. This is necessary for some problems where the gene
PyTorch models. value may not fall within a regular range. To select which genes to
The paper is organized so that section II covers the related mutate, DEAP only supports the mutation probability. There is no
work, section III extensively introduces PyGAD and briefly com- way to specify the exact number of genes to be mutated.
pares PyGAD with DEAP and LEAP, and finally, section IV draws DEAP only supports the traditional mutation operators where all
conclusions. Appendix A lists some resources to know more about solutions, regardless of their fitness value, are given equal mutation
PyGAD and Appendix B lists the GitHub links of some projects built probability. This would distort the high-quality solutions.
with PyGAD. Another major drawback of DEAP is the lack of means of
visualizing the results after the evolution completes [4]. The users
II. R ELATED W ORK have to manually create their plots to summarize the results.
There are already existing Python libraries for building the genetic
B. Pyevolve
algorithm. Some examples include:
A DEAP (Distributed Evolutionary Algorithms in Python) II-A Pyevolve is another pure Python library for building the genetic
B Pyevolve II-B algorithm [5]. Even that it is published in 2009, it is less popular than
C EasyGA II-C DEAP and this is based on the total number of installations (50K for
D LEAP (Library for Evolutionary Algorithms in Python) II-D all the time), GitHub stars (301), and citations. It also has a limited
community compared to DEAP.
This section gives an overview of these libraries by explaining
Its scripts start by creating the fitness function, preparing the
their objectives and limitations.
chromosome, setting some parameters like which operators to use,
A. DEAP create an instance of the GSimpleGA class and then call the
evolve() method to start the evolution.
DEAP (Distributed Evolutionary Algorithms in Python) [3] is Like DEAP, this library has boilerplate code for configurations that
considered one of the most common Python libraries for optimization makes its scripts unnecessarily longer even for simple problems. The
using the genetic algorithm based on the number of installations, supported mutation operators apply mutation equally to all solutions
GitHub issues, and stars (4.2K). One of the reasons is being one independent of their fitness value.
of the first libraries about EAs which was published in 2012. DEAP Even that Pyevolve is easier than DEAP, but it is limited in its
supports other algorithms than GA like non-dominated sorting genetic features. It supports some predefined data types for the genes like in-
algorithm II (NSGA-II), particle swarm optimization (PSO), and teger and real. To create new data types, then more details about some
evolution strategy (ES). Its latest release at Python Package Index classes in the library are needed like GenomeBase.GenomeBase
(PyPI) is 1.3.1 released on Jan 2020. which may be problematic for some users.
DEAP uses 2 main structures which are creator and toolbox. A comparison between DEAP and Pyevolve shows that the number
The creator module is used for creating data types like fitness, of code lines needed to solve the OneMax problem is 59 for DEAP
individual, and population. These data types are empty and filled and 378 for Pyevolve [3]. Given the simplicity of the problem,
using the toolbox module. Given the special structure of DEAP, Pyevolve needed too many lines.
the user would take some time until understanding getting familiar. This library is no longer maintained as the latest version was
It needs more than a beginner’s level in Python. released at the end of 2014 and the most recent commit on its GitHub
One problem about DEAP is being not user-friendly as the user project was at the end of 2015.
has to do some efforts for each optimization problem. For example,
the user has to write extra code for creating the population and filling
C. EasyGA
it with appropriate values. The motivation for that is to enable the
user to create custom data types that are not supported. But this The EasyGA library allows only defining a continuous range for
boilerplate code unnecessarily increases the length of the Python the gene values. If the range has some exclusions or if the gene values
script and makes it uncomfortable for users to write and understand do not follow a range at all, then there is no way to define the gene
more syntax about DEAP. Sometimes, the scripts are hard to read. values. Moreover, the user has to build the solutions manually without
Moreover, the users have to create a main function in which given a simple interface. Commonly, users would like to focus more
everything is grouped in an evolutionary loop. The loop in this user- on the algorithm itself and save time building additional modules
defined function should is where the user needs to follow the GA specially if they are not involved in Python.
pipeline by 1) calculating the fitness function, 2) selecting the parents, This library has a limited number of operators for crossover,
3) applying crossover and mutation, 4) and repeating that for several mutation, and parent selection. Given the
generations. This is not the best interface for users who try to focus The EasyGA library supports a random mutation operation that
on the experiments and save time on the other stuff. Writing the applies mutation over any solution in the population, including
evolutionary loop makes the library non-friendly. parents, and is not restricted to the new offspring. It randomly selects
Even if the library supports some ready-to-use algorithms that the solutions to mutate. This is against the nature of the GA as only
save time building the main function, each algorithm does a specific random changes could be introduced to the offspring, not the parents.
task and is limited in its features. With the few parameters each The users have to know about decorators, at some stage, to
algorithm accepts, there is little customization possible. Examples of build their operators. While writing the paper, the GitHub project
these algorithms are eaSimple, eaMuPlusLambda, and varOr. of EasyGA has only 22 stars.
D. LEAP The 7 modules included in PyGAD are:
LEAP (Library for Evolutionary Algorithms in Python) is another 1) pygad.pygad: It is the main module which builds everything
recent Python library published in 2020 for EAs that supports the in the genetic algorithm. This module is implicitly imported
genetic algorithm [6]. This library has 3 core classes which are when the library itself is imported.
Individual, Decoder, and Problem. The decoder is respon- 2) pygad.nn: Builds fully-connected neural networks (FCNNs)
sible for converting the genes from one form to another to calculate from scratch using only NumPy.
the fitness value for each individual given the current problem. 3) pygad.gann: Uses the pygad module to train networks build
According to the examples posted by the developers, the decoder using the nn module.
is usually set to IdentityDecoder() which means the gene is 4) pygad.cnn: Similar to the nn module but builds convolu-
translated to itself. This is a design issue in the library. Maybe this tional neural networks (CNNs).
feature is helpful in some specific problems but the library uses it 5) pygad.gacnn: Similar to the gann module but trains CNNs.
as something essential for all types of problems. It is better to work 6) pygad.kerasga: Trains Keras models using the pygad
directly on the genes without having to decode them to another form module.
or leave that decoding part to the fitness function. 7) pygad.torchga: Trains PyTorch models using the pygad
Even it is published in July 2020, the library has many missing module.
features as mentioned in its documentation. One of these missing Given that the pygad.pygad is the most critical module in the
features is the mixed data representation in the individual. There is no library, it is given the most attention.
lifecycle in LEAP to help trace what is happening in each generation. PyGAD has detailed documentation that covers all of its features
Even if one of the objectives of LEAP is to make it simpler than with examples. Moreover, the source code of various projects built
the other libraries, the user still has to write the evolution loop. This using PyGAD is explained in tutorials. A list of some of these
results in more lines to solve a problem. Moreover, the user has to tutorials is available in Appendix A.
take care of calling a function that increases the generations counter PyGAD gained popularity in the last months and some of its
by calling the util.inc_generation() function. Avoiding to English articles and tutorials are translated to different languages
call it causes an infinite evolution loop. This would be a problem for like Korean, Turkish, Hungarian, Chinese, and Russian. A list of
users with less experience. such translated articles and tutorials is found in the PyGAD in Other
Creating and managing the evolution loop is against another Languages section of the documentation.
objective of LEAP to make it suitable for all types of software users The documentation of PyGAD has a section called Release History
(users who solve problems with existing tools). to summarize the changes and additions in each release.
This library is not popular as it has a total of 3.4K installations Appendix A has extra reading resources about PyGAD. Appendix
since publication in addition to just 39 starts in the GitHub project. B lists some projects built with PyGAD.
III. P ROPOSED P Y GAD L IBRARY
B. PyGAD Usage
PyGAD is an open-source Python library for optimization us-
ing the genetic algorithm. It is published in April 2020 at PyPI There are 3 core steps to use PyGAD:
(pypi.org/project/pygad). Its GitHub project has over 525 stars 1) Build the fitness function.
(github.com/ahmedfgad/GeneticAlgorithmPython). With over 185K 2) Instantiate the pygad.GA class with the appropriate configu-
installations over 1 year, PyGAD is the most rising library compared ration parameters.
to the other libraries. 3) Call the run() method to start the evolution.
The name PyGAD has 3 parts: For the following equation with 3 inputs, we can use PyGAD to
1) Py which means it is a Python library. This is a common naming find the values of w1 , w2 , and w3 that satisfy equation:
convention for Python libraries.
2) GA stands for genetic algorithm. Y = w1 X1 + w3 X3 + w3 X3
3) D for decimal because the library was originally supporting only W here Y = 44, X1 = 4, X2 = −2, and X3 = 3.5
decimal genetic algorithm. Now, it supports both decimal and
binary genetic algorithm. A basic PyGAD example that solves this problem is given in
This section gives an overview of PyGAD III-A, discusses the Listing 1. Line 1 imports the library. This import statement implicitly
steps of its usage III-B, its lifecycle III-C, and main features in imports the pygad module. The NumPy library is also imported in
PyGAD III-D. Line 2 because it is used in the fitness function.
Line 4 creates a Python list to hold the 3 inputs and line 5 holds
A. PyGAD Overview the output.
PyGAD is an intuitive library for optimization using the genetic The fitness function in PyGAD is a regular Python function that
algorithm. It is designed with 2 main objectives: accepts 2 parameters:
1) Making everything as simple as possible for the users with the 1) The solution evolved by the genetic algorithm as a 1D vector.
least knowledge. The function should return a single numeric value representing
2) Giving the user control over everything possible. the fitness of this solution.
The simplicity comes from using descriptive names for the classes, 2) The index of the solution within the population.
methods, attributes, and parameters. This is in addition to making The length of the solution in this example is 3, one value for each
things straightforward to build the genetic algorithm and specify a weight in the equation. The fitness function must be a maximization
wide range of easy-to-understand configuration parameters. There function (the higher the fitness value the better the solution).
are fewer classes, methods, or functions to call to solve a problem The fitness function is defined from line 7 to line 10 in Listing 1.
compared to the other libraries. The function calculates the sum of products between each value in
The users do not have to build the evolution loop in any situation the solution and its corresponding input. The absolute difference is
as PyGAD supports an elastic lifecycle that can be altered. This calculated between the sum and the output.
includes, but is not limited to, enabling or disabling the mutation Returning the absolute difference makes it a minimization function.
or crossover operators and overriding them to build new operators This is why the result is returned as 1.0/abs. A tiny value of
for research purposes. 0.000001 is added to the denominator to avoid diving by zero.
A new instance of the pygad.GA class is created in line 12.
All configuration parameters are grouped in the pygad.GA class’s
constructor. With the available IDE’s, the user can easily check the
names of all available parameters. This way the user does not have
to memorize the names of functions or classes compared to the other
libraries.
There are 5 required parameters that must be specified for each
problem:
1) num_generations: The number of generations/iterations.
2) sol_per_pop: The number of solutions/chromosomes/indi-
viduals in the population (i.e. population size).
3) num_parents_mating: The number of solutions to be se-
lected from the population as parents for mating and producing
the offspring.
4) num_genes: The number of genes in each solution.
5) fitness_func: The fitness function.
These are the minimum parameters to use PyGAD. Note that the
names of the parameters are self-describing. The documentation has
information about the classes, parameters, attributes, methods, and Fig. 2. Evolution of the fitness value for 100 generations.
functions in all PyGAD modules.

1 i m p o r t pygad 1 solution , solution fitness , solution idx =


2 i m p o r t numpy ga instance . best solution ()
3 2 fig = ga instance . plot result ()
4 e q u a t i o n i n p u t s = [ 4 , −2 , 3 . 5 ]
5 Y = 44 Listing 2. Evolution results.
6
7 def f i t n e s s f u n c ( solution , s o l u t i o n i d x ) : For the OneMax optimization problem, it is solved with PyGAD
8 o u t = numpy . sum ( s o l u t i o n * e q u a t i o n i n p u t s ) in just 15 lines of code compared to 45 for DEAP and 34 for LEAP.
9 f i t n e s s = 1 . 0 / ( numpy . a b s ( o u t − Y) + 0 . 0 0 0 0 0 1 ) For 3 different runs with 100 generations each, the average time
10 return fitness for PyGAD is 0.14 seconds compared to 0.65 for DEAP and 0.052
11
for LEAP. The trouble with LEAP is that the optimal solution was
12 g a i n s t a n c e = pygad .GA( n u m g e n e r a t i o n s =100 , not found even after 1,000 generations. The maximum number of
13 s o l p e r p o p =10 ,
14 n u m p a r e n t s m a t i n g =5 ,
ones did not even reach 90/100 after tens of trials with the code
15 num genes =3 , published by the developer at GitHub.
16 fitness func=fitness func )
17 C. PyGAD Lifecycle
18 g a i n s t a n c e . run ( ) PyGAD has a lifecycle that helps to user to keep track and control
all different stages of the evolution process. Figure 3 shows the
Listing 1. PyGAD example.
PyGAD lifecycle. Note that the side blocks refer to operations done
In Listing 1, a population of size 10 is evolved through 100 between one state and another.
generations. Out of the population, 5 solutions are selected for mating. The passed parameters to the pygad.GA class’s constructor are
Each solution has 3 genes where the fitness value is calculated using validated. Then, instance attributes are initialized according to the
the Python function named fitness_func. passed parameters. Some of these attributes include population
The instances of the pygad.GA class has a method called which is a NumPy array holding all solutions in the population.
run() which runs the genetic algorithm to start evolving the initial Once an instance of the pygad.GA class is created successfully,
population according to the selected parameters. This is the minimal then it is time to start the lifecycle of PyGAD by calling the run()
code for optimizing this problem using PyGAD. method. For the 7 states in PyGAD lifecycle, the following 7 callback
Once the run() method completes, additional methods can be functions exist:
called to find information about the solution found by PyGAD. Two 1) on_start(): Called once after the run() method is called.
of these methods are: 2) on_fitness(): Called after calculating the population fitness
in each generation.
1) best_solution(): Returns the following information about
3) on_parents(): Called in each generation after the parents
the best solution found by PyGAD:
are selected.
a) The parameters of the best solution (e.g. the 3 weights for 4) on_crossover(): For each generation, it is called after
the problem solved in Listing 1. applying the crossover operation.
b) The fitness value of the best solution. 5) on_mutation(): For each generation, it is called after ap-
c) The index of this solution in its population. plying the mutation operation.
2) plot_result(): Creates a plot showing how the fitness 6) on_generation(): Called at the end of each generation.
value evolves by each generation. This method returns the figure 7) on_stop(): Called once after the run() method stops.
in case the user would like to save it. The user can assign a Python function, with the appropriate
These 2 methods are called in Listing 2. Figure 2 shows that the parameters, to any of these callback functions. By doing this, the
best solution is found after 31 generations only with a fitness value user can track and control everything from the start to the end of the
of 182.698. The best solution’s parameters can be plugged into the evolution. This includes, but is not limited to, getting information
equation to return the predicted value. about the population, fitness, selected parents, crossover or mutation
results, and the best solution yet found. The user can also do some
PyGAD that make it distinctive compared to the other libraries. For
more details, check its documentation pygad.readthedocs.io.

1) PyGAD is very intuitive to use. Its steps are self-explanatory


and easy to follow in a user-friendly way. With just 3 simple
steps, PyGAD can optimize different types of problems.
2) All parameters are grouped in the constructor of the pygad.GA
class. This helps the user to be focused and not distracted.
3) A user-defined gene value space, either for all genes at once
or for each gene, can be created using the gene_space
parameter. This is helpful even if the gene’s values do not follow
a certain pattern. If a gene has values enclosed within a given
range, then the gene value can be randomly generated from a
user-defined range.
4) It is possible to control the gene data type, for all genes or
each gene, using the gene_type parameter. The supported
data types are Python’s int and float in addition to all
int/uint/float types in the NumPy library.
5) Using the initial_population parameter, a user-defined
initial population can be used as the start point. This helps to
continue where the evolution stopped. PyGAD builds an initial
population randomly if this parameter is not set.
6) PyGAD has a lifecycle to keep track of everything. A call to a
callback function can be triggered for each step in the lifecycle.
7) The user can stop the evolution at any time. For example, return-
ing the string “stop” from the on_generation() callback
function stops PyGAD at the current generation.
8) It is easy to access the best solutions across all generations
in addition to their fitness using the best_solutions and
best_solutions_fitness attributes, respectively.
9) The crossover and mutation operations can be disabled by
setting crossover_type or mutation_type to None and
then plug a user-defined operation in the lifecycle.
10) There are different ways to specify the number of genes to
mutate. According to the user’s preference, this can be speci-
fied as probability (mutation_probability), percentage
(mutation_percent_genes), or an explicit number of
genes (mutation_num_genes).
11) PyGAD supports adaptive mutation so that the user controls
how mutation is applied based on the solution’s fitness. For
the high-quality solutions, low mutation probability/percent-
age/number is expected compared to low-quality solutions. This
helps to maintain the quality of the good solutions in addition
to increasing the quality of the bad solutions.
12) The mutation_by_replacement bool parameter selects
whether the mutation adds to or replaces the gene value.
13) A bool parameter called allow_duplicate_genes helps
to accept or reject duplicate values in the same chromosome.
For this to work, there must be enough value space to guarantee
unique genes’ values.
Fig. 3. PyGAD lifecycle.
14) Ability to control the number of parents to keep in the next
generation using the keep_parents parameter. This helps to
save 0 or more parents to keep the fitness curve increasing.
15) The instance attributes in the pygad.GA class starting with
pre-processing or post-processing tasks in the on_start() and last_generation_ help to keep track of the outcomes of
on_stop() functions, respectively. each generation.
For research purposes and supporting an operator that is not 16) PyGAD supports training Keras and PyTorch models using the
supported by PyGAD, the user can define custom crossover and pygad.kerasga and torchga modules, respectively.
mutation operators in the callback functions. 17) PyGAD also has its own modules to build and train neu-
The on_generation() callback function can be used to add ral networks (pygad.nn, pygad.gann, pygad.cnn, and
some conditions and alter the execution. For example, returning the pygad.gacnn).
string ”stop” immediately stops the run() method earlier before 18) The interface to use any PyGAD feature is very simple and
completing all generations. does not require much knowledge about Python compared to
the other libraries. The minimum level is to know how to create
D. PyGAD Features variables, how to define a Python function that accepts param-
The previous sections should have covered some features of eters and returns something, little about classes like creating
PyGAD. This section highlights the main features supported by instances in addition to accessing class/instance attributes.
19) PyGAD has built-in support to visualize the results. For exam- • How To Train Keras Models Using the Genetic Algorithm with
ple, the best_solution() method shows how the fitness PyGAD, December 2020, Ahmed Gad
changes by generation. • Genetic Algorithm V Gradient Boosting, January 2021, Mark
20) There are many resources to help you get started with PyGAD. Littlewood
This includes documentation, blog posts, examples, projects, • Clustering Using the Genetic Algorithm with PyGAD, March
and a community over GitHub, reddit, StackOverflow, Face- 2021, Ahmed Gad
book, and Twitter. • Train PyTorch Models Using Genetic Algorithm with PyGAD,
March 2021, Ahmed Gad
IV. C ONCLUSION • How Genetic Algorithms Can Compete with Gradient Descent
This paper proposed a new Python library called PyGAD for and Backprop, March 2021, László Fazekas
single-objective optimization using the genetic algorithm. PyGAD • Adaptive Mutation in Genetic Algorithm with PyGAD Exam-
is an intuitive library that makes it easy to optimize problems in just ples, April 2021, Ahmed Gad
3 steps: fitness function creation, instantiating the pygad.GA class, • PyGAD v GBM, June 2021, Mark Littlewood
and calling run() method. There is a wide range of parameters and A PPENDIX B
attributes to have a high degree of customizing the genetic algorithm.
This includes defining a space of values for each gene, customizing P ROJECTS WITH P Y GAD
each gene’s data type, training Keras and PyTorch models, rejecting This is a list of some projects built using PyGAD with their source
duplicates, and more. PyGAD has a lifecycle to keep track of the code:
evolution process from the beginning to the end. PyGAD supports • github.com/ahmedfgad/CoinTex/tree/master/PlayerGA: Play a
a simpler interface for users with less experience with Python to game called CoinTex.
solve problems with few lines of code and even faster than the other • github.com/ahmedfgad/FlappyBirdPyGAD: Play the flappy bird
libraries. game.
• github.com/ahmedfgad/8QueensGenetic: Solve the 8-queen puz-
ACKNOWLEDGMENT zle.
• github.com/ahmedfgad/GARI: Reproduce gray and RGB im-
I would like to thank everyone who used or showed interest in
PyGAD. Some of those people who reported issues or suggested ages.
useful features are Tamer Farrag (Assistant Professor, Misr Higher
Institute for Engineering and Technology, Egypt), Hamada Kassem
(RA/TA, Faculty of Engineering, Alexandria University, Egypt),
Curt McDowell, Andrei Rozanski (PhD Bioinformatics Specialist,
Max Planck Institute for Biophysical Chemistry, Germany), Marios
Giouvanakis (PhD candidate in Electrical & Computer Engineer,
Aristotle University of Thessaloniki, Greece), László Fazekas (CTO
Senior Software Developer at Pressenger Ltd, Hungary), and special
thanks to Rainer Engel (Imaging Artist and Pipeline Developer,
Germany) for his generous suggestions and time offered in inspecting
PyGAD.

R EFERENCES
[1] Simon, Dan. Evolutionary optimization algorithms. John Wiley & Sons,
2013.
[2] Gad, Ahmed Fawzy. Practical computer vision applications using deep
learning with CNNs. Apress, 2018.
[3] Fortin, Félix-Antoine, et al. ”DEAP: Evolutionary algorithms made easy.”
The Journal of Machine Learning Research 13.1 (2012): 2171-2175.
[4] Kim, Jinhan, and Shin Yoo. ”Software review: Deap (distributed evolu-
tionary algorithm in python) library.” Genetic Programming and Evolv-
able Machines 20.1 (2019): 139-142.
[5] Perone, Christian S. ”Pyevolve: a Python open-source framework for
genetic algorithms.” Acm Sigevolution 4.1 (2009): 12-20.
[6] Coletti, Mark A., Eric O. Scott, and Jeffrey K. Bassett. ”Library for
evolutionary algorithms in Python (LEAP).” Proceedings of the 2020
Genetic and Evolutionary Computation Conference Companion. 2020.

A PPENDIX A
P Y GAD S UPPLEMENTAL R ESOURCES
This appendix lists some tutorials and articles to get started with
PyGAD.
• 5 Genetic Algorithm Applications Using PyGAD, June 2020,
Ahmed Gad
• Building a Game-Playing Agent for CoinTex Using PyGAD,
July 2020, Ahmed Gad
• Working with Different Genetic Algorithm Representations in
PyGAD, September 2020, Ahmed Gad
• Train Neural Networks Using a Genetic Algorithm in Python
with PyGAD, September 2020, Fatima Ezzahra Jarmouni

View publication stats

You might also like