THE BINARY GENETIC ALGORITHM
DR H.K. LAM
Department of Engineering
Kings College London
Office S2.14, Strand Building, Strand Campus
Email: [email protected]
https://nms.kcl.ac.uk/hk.lam
Nature-Inspired Learning Algorithms (7CCSMBIM)
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 1/87
Outline
1 Problem and Difficulties
2 Introduction
3 The Binary Genetic Algorithm
Binary Encoding and Decoding Decision Variables and Cost Function Population
Natural Selection
Selection
Mating Crossover
Mutation
Convergence
4 Performance Evaluation
5 Binary GA Example by Hand
6 Why do GAs work? Schema Theorem
7 Examples
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 2/87
Learning Aims and Objectives
Aims
To understand the process of the binary genetic algorithms.
To apply the binary genetic algorithm to optimisation problems. To know the limitations of the binary genetic algorithms.
Objectives
To study how the binary genetic algorithm works in details.
To consider a number of applications and formulate as minimisation problems.
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 3/87
Problem and Difficulties
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 4/87
Problem and Difficulties
Problem Statement:
Task: minimisation of a cost function. Gradient information is not required Function evaluation
Difficulties:
non-convexity multi-modality non-smoothness discontinuity dimensionality
DrH.K.Lam (KCL)
TheBinaryGeneticAlgorithm
NILAs2020-21 5/87
Introduction
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 6/87
Introduction
The Genetic Algorithm
Genetic algorithm (GA) is a technique to solve problems which need optimisation.
GA is a subclass of Evolutionary Computing.
GA is based on Charles Darwins theory of evolution History of GA
Evolutionary Computing evolved in the 1960s.
GA were proposed by John Hollan in the middle of 1970s.
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 7/87
Introduction
Darwins Theory of Evolution 1
An offspring has many of the characteristics of its parents, which implies that
the population is stable.
There are variations in characteristics between individuals that can be passed from one generation to the next.
Only a small percentage of the offspring produced survive to adulthood. Which of the offspring survive depends on their inherited characteristics.
1Sue Ellen Haupt, ValliappaLakshmanan, CarenMarzban, AntonelloPasini, and John K. Williams. Environmental Science Models and Artificial Intelligence. Artificial Intelligence Methods in the Environmental Sciences. Springer Science (3-14, 103-126), 2009.
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 8/87
Introduction
The Binary Genetic Algorithm
Biological Metaphor Natural Selection
Genetics and Evolution gene, chromosome, allele, genotype, phenotype, mitosis, meiosis, gamete, crossover, mutation,
Components of Binary Genetic Algorithm
Variable encoding and decoding, fitness function, population, selection, mating mutation, offspring and convergence,
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 9/87
Introduction
Advantages:
Optimise with continuous or discrete variables.
Derivative information is not required.
Able to deal with a large number of decision variables.
Optimise decision variables with extremely complex cost function. Is less likely trapped in local optimum.
Tends to search for global optimum.
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 10/87
Notation
Nvar : number of decision variables of the chromosome
Nbits : total number of bits of the chromosome
Npop : population size
Npop Nbits : total number of bits of the population
Xrate : selection rate in the step of natural selection
Nkeep = Npop Xrate : number of chromosomes that are kept for each generation Npop Nkeep : number of chromosomes to be discarded
xlo: lower bound of variable x
xhi: upper bound of variable x
Pn : probability of the nth chromosome in the mating pool of Nkeep to be chosen cn : cost of the nth chromosome
Cn : normalised cost of the nth chromosome
: mutation rate (or probability of mutation)
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 11/87
The Binary Genetic Algorithm
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 12/87
The Binary Genetic Algorithm
Initial population with random members
Rating
Selection
Reproduction
Mutation
DrH.K.Lam (KCL)
TheBinaryGeneticAlgorithm
NILAs2020-21
13/87
The Binary Genetic Algorithm
COMPONENTS OF A BINARY GENETIC ALGORITHM 29
Define cost function, cost, variables Select GA parameters
Generate initial population
Decode chromosomes
Find cost for each chromosome
Select mates
Mating
Mutation
Convergence Check
done
Figure1:Flioguwrec2h.2artFolofwachbaritnoafraybignearnyeGtAic.algorithm. DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm
Initial population with random members
Rating
Selection
Reproduction
Mutation
NILAs2020-21
14/87
Binary Encoding and Decoding
Binary number conversion:
Example: Convert 25.3125 to binary. The integer part: 25
25/2 ! 12/2 ! 6/2 ! 3/2 ! 1/2 !
Binary to Decimal:
The fractional part: 0.3125
0.3125 2 = 0.625 ! 0.625 2 = 1.25 ! 0.252=0.5 ! 0.52=1 !
25.312510 = 11001.01012
1
0
0
(124 +123 +022 +021 +120).(02 1 +12 2 +02 3 +12 4)
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 15/87
0
1
0
1
1
1
Binary Encoding and Decoding
Given a number x 2 [xlo,xhi], how many bits (m) are required to achieve precision of d decimal places?
xhi xlo 2m 1 10 d
Example: x 2 [25, 100], precision: 2 decimal places
100 25 2m 1)75012m )m=12.872913bits
10 2
0000000000000!25+0100 25 =25
213 1 0000000000001!25+1100 25 =25.0092
213 1 0000000000010!25+2100 25 =25.0183
213 1
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 16/87
Decoding: x = x + decimal(1001 001 ) xhi xlo lo 2 2m 1
Decision Variables and Cost Function
The optimisation/decision variables are represented by chromosome. chromosome = [p1,p2, ,pNvar ]
Each gene (pi, i = 1, 2, , Nvar) is coded by mi bits. Nvar
Total number of bits per chromosome: Nbits = A mi i=1
The cost is evaluated by a cost (fitness) function.
cost = f (chromosome) = f (p1 , p2 , , pNvar )
Genotype: The bit string representation of the chromosome Phenotype: The decision variables. The genotype can be mapped to phenotype through decoding or vice versa through encoding.
Allele: the value of a single bit in the chromosome
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 17/87
Decision Variables and Cost Function
Example: Consider an optimisation problem with decision variables of p1, p2, , pNvar .
Phenotype: [p1,p2, ,pNvar ]
When each gene is represented by 10 bits,
Chromosome: 241100110011011110000111100111135 | {z }| {z } | {z }
gene1(p1) gene2(p2) geneNvar (pNvar ) Genotype: 1100110011 011110000 1111001111
Allele: the allele of the first bit from the left is 1.
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 18/87
Population
The GA starts with a group of chromosomes known as the population. The population has Npop.
A population represented by a Npop Nbits matrix filled with random 0s and 1s.
Purposes: Population collects a group of potential solutions, which will be evolved to improve their quality in each generation.
DrH.K.Lam (KCL) TheBinaryGeneticAlgorithm NILAs2020-21 19/87
Population
Example: A cost function: cost = f (x, y) with 7 bits in each gene. chromosome = 241100011 001100135
xy
Chromosome 00101111000110 11100101100100 00110010001100 00101111001000 11001111111011 01000101111011 11101100000001 01001101110011
Cost