One Pager Cheat Sheet
A Genetic Algorithm (GA) is a **nature-inspired** algorithm used to solve **optimization problems**, belonging to the branch of **approximation algorithms**, which will be learned in this lesson in terms of its source of inspiration, general structure, working, and implementation.Optimization is the process of finding the best solution to a problem by formulating it mathematically and then using an optimization algorithm such as GA to minimize/maximize the output of a function to reach the optimal solution.- We can use an
optimization algorithmsuch asGAto find the optimal solution of the function . - The process of natural selection is used as an inspiration for
Genetic Algorithm(GA), which generates a population of candidate solutions randomly and selects the fittest individuals to produce similar solutions and ensure the survival of better solutions' traits over time. - GA is a population-based
algorithm, where aset of candidate solutions(chromosomes) are evaluated against anobjective function(fitness function) to find the optimal solution. Genetic Algorithmmimics theprocess of natural selectionwith the use ofgenetic operators, such ascrossover,mutation, andselectionto generate apopulation of random solutionswhich undergofitness evaluationto arrive at the best solution.- A solution is typically encoded as a binary string, integer-valued array, floating-point array, or a
permutationof a fixed set ofelements, depending upon the nature of the problem. - The population is
randomly generatedwithcontinuous variablesin the range of[-5, 5]in order to begin any Genetic Algorithm (GA) or other Evolutionary Algorithm. - The fitness of each of the randomly generated
chromosomesin the population iscalculatedanddepictedin the figure. - The
crossoveroperatoris used to produce new solutions from existing ones in the Genetic Algorithm, and a suitable selection method is necessary to determine theparentsfor the crossover, with two popular methods discussed in the literature. - Selecting the
k bestsolutions from thematting poolis the simplest method for progressing to the next phase of crossover. Fitness Proportionate Selectionis a method of selecting a solution to crossover such that each solution is assigned a probability of selection based on its fitness.- The accumulated probability distribution for this population is calculated by summing the fitness of each solution into the sum of fitness of all previous solutions.
- The crossover operator mimics the sexual reproduction of natural selection and
exchanges genetic informationbetween twoparentsto create newoffspring, with various methods discussed in the literature. - One-point crossover randomly chooses one crossover point and creates two children using the first half of one parent and the second half of the other parent.
Multipoint crossovercreates offspring by selecting alternative portions from both parents at multiple crossover points.- In uniform crossover, each gene for an offspring is chosen with
equal probabilityfrom both Parents,resulting in the exchanged gene positionsin the resulting offspring. - Mutation is a
biological operatorthat introduces new traits in genetic information and helps maintain diversity to prevent populations from converging prematurely. Flip mutationis a type of mutation used with binary crossover, in which a randomly selected bit of the chromosome is flipped.Swap mutationis a kind of mutation where two randomly selected genes have their alleles swapped.- Random initialization is used to re-initialize the discrete values/integers of a gene with a random value from a given range.
- Selection methods are used to decide which solutions will continue into the next generation, such as
random selectionandproportionate selectionwhich gives better solutions a higher chance of surviving, ormerging parents and new offspring, which gives the new generation a mix of both. - The algorithm terminates when
a predefined number of iterations,fitness value, orlack of improvementhas been achieved. - Using the mathematical function , Genetic Algorithm (GA) was
implementedin Python tooptimizethe function. - The population can be randomly initialized using
numpy's function for creating random vectors/arrays. - An example of the
random populationis printed below whererowsshow thechromosomesandcolumnsshow thegenes. - The overall fitness of the
populationis determined by summing up the individualfitness scores. - Making a
matting poolof the best solutions according to the mattingPoolSize variable is essential for successful crossover. Crossoveris used to generate a predefined number of offspring from selected parents, implementing a single-point method to assign each parent's genes to the corresponding offspring.- Mutation, with
random initialization, is used to randomly initialize each offspring's allele to anycontinuous value. - Natural selection occurs through environmental selection, in which
weak chromosomesare replaced with newoffspringfrom the previous generation. - The algorithm of the fitness calculations and environmental selection will be repeated in a loop a total of
generationsiterations. - By understanding the source of inspiration behind and the operations used in Genetic Algorithms, readers should be able to implement and solve optimization problems with GA in Python.


