Genetic Algorithm
Lương Thái Lê
Outline
1. Introduction
2. GA – main steps
3. GA algorythm
4. GA operatorss
5. Example
Introduction
• Base on (imitating) the natural evolutionary process in biology
• Apply stochastic search method to find the optimal solution (eg: an
objective function, a classification model, ...)
• Genetic Algorithm (GA) is capable of finding good solutions even with
very complex non-continuous search spaces (solutions).
• Each possible solution is represented by a binary string (e.g.
100101101) – called a chromosome
• This representation depends on each specific problem
• GA is also considered a machine learning problem based on
optimization
GA – main steps
• Build (initialize) the initial population
• Create some initial hypotheses (possible solutions)
• Each hypothesis is different from the others (e.g. different for the values of certain
parameters of the problem)
• Population assessment
• Evaluate (score) each hypothesis (e.g. by checking the accuracy of the system on a test data
set)
• In the field of biology, this evaluation score of each hypothesis is called the fitness of that
hypothesis
• Rank the hypotheses according to their suitability, and keep only the best hypotheses (called
survival of the fittest)
• Create the next generation
• Randomly change assumptions to produce the next generation (called offspring)
• Repeat the above process until the best hypothesis that has a higher fitness
than the desired (predetermined) fitness value be found
Genetic operators
• Reproduction
• A hypothesis is retained (unchanged)
• Crossover
• Merge two parent instances to create a new instance
• The crossover point is chosen randomly (on the length of the chromosome)
• The first part of chromosome hi is paired with the second part of
chromosome hj, and vice versa, to produce 2 new chromosomes.
• Mutation
• Randomly choose a bit of the chromosome, and change the value (0→1 /
1→0)
• Make only a small and random change to 1 parent individual
GA – illustration
Solving optimization problem with GA
1. Let the object to be searched for in the problem as an individual.
Describe the object class to find according to a data structure
2. Develop a method to initialize the initial population
3. Define the fitness function, determine the fitness of individuals in a
population
4. Identify operators of genetic algorithms such as crossover,
mutation, and reproduction
5. Determine the necessary parameters: population size, hybrid
probability, mutation probability, number of evolutionary
generations
Example (1)
Find the solution of the equation: x2 = 64
S1: Use a sequence of 4 binary bits to encode the result of the
problem. In the initialization, we will choose 4 in all possible results.
Index Binary Decimal
1 0100 4
2 0101 21
3 1010 10
4 1000 24
Example (2)
S2: Choose the fitness function f(x) = 1000 – (x2 – 64). Then count fitness value for each
solution. Which answer has the fitness coefficient closest to 1000 is the answer
Index Binary Decimal x2 - 64 Fitness value
1 0100 4 -48 952
2 0101 21 377 623
3 1010 10 36 964
4 1000 24 512 488
S3: 4 and 10 have higher fitness coefficients, so they are chosen for crossover and mutaion.
21 and 24 have low fitness coefficients and will be eliminated.
Example (3)
After make crossover and mutation, we have:
Index Binary Decimal Crossover Mutation Decimal
1 0100 4 1110 0110 6
2 1010 10 0000 1000 8
S4: Count fitness value for new population:
Index Binary Decimal x2 - 64 Fitness value
1 0100 4 -48 952
2 0101 10 36 964
3 1010 8 0 1000
4 1000 6 28 968
=> We find x=8 is the best answer
Q&A