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

Lecture 11 - Genetic Algorithms II (1)

Lecture 11 discusses Genetic Algorithms (GAs), a search technique inspired by biological evolution for solving optimization problems. It covers the workings of GAs, including initialization, fitness assignment, selection, reproduction (crossover and mutation), and termination, along with various selection and reproduction methods. The lecture also provides examples, such as the MAXONE problem and the Traveling Salesman Problem, to illustrate the application of GAs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Lecture 11 - Genetic Algorithms II (1)

Lecture 11 discusses Genetic Algorithms (GAs), a search technique inspired by biological evolution for solving optimization problems. It covers the workings of GAs, including initialization, fitness assignment, selection, reproduction (crossover and mutation), and termination, along with various selection and reproduction methods. The lecture also provides examples, such as the MAXONE problem and the Traveling Salesman Problem, to illustrate the application of GAs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Lecture 11: Genetic Algorithms II

Key Points from Last


Lecture
Outline of today’s lecture
Genetic Algorithms
1. What is a Genetic Algorithm (GA)?
2. Intuition Behind Genetic Algorithms
3. How Genetic Algorithms Work
4. Applications of Genetic Algorithms
What is a Genetic Algorithm (GA)
A Genetic Algorithm (GA) is a search technique used in computing to find exact
or approximate solutions to optimization and search problems.

• GAs are classified as global search heuristics, but they perform local search within
populations. Through evolution-inspired processes, they balance exploration (global
search) and exploitation (local search).
• GAs belong to a class of evolutionary algorithms, leveraging mechanisms inspired
by biological evolution, such as inheritance, mutation, selection, and crossover
(also called recombination).
Intuition Behind Genetic Algorithms
Inspired by Biological Evolution:
• Mimics the biological evolution process, where species evolve over generations to
adapt to their environments.
• In GAs, candidate solutions (individuals) evolve through processes like selection,
crossover, and mutation, imitating the way nature refines species.
• The fittest individuals — those with the best solutions to the problem — are more likely
to survive and pass advantageous traits to the next generation, gradually improving the
overall solution quality.
General Working of GA
• The evolution usually starts from a population of randomly
generated individuals and happens in generations.
• In each generation, the fitness of every individual in the population is
evaluated,
• Multiple individuals are selected from the current population (based
on their fitness),
• And modified to form a new population.
• The new population is used in the next iteration of the algorithm.
• The algorithm terminates when either a maximum number of
generations has been produced, or a satisfactory fitness level has
been reached for the population.
No convergence rule or
guarantee!
Vocabulary
• Population: Population is the subset of all possible or probable solutions,
which can solve the given problem.

• Chromosomes: A chromosome is one of the solutions in the population for


the given problem, and the collection of gene generate a chromosome.

• Gene: A chromosome is divided into a different gene, or it is an element of


the chromosome.
Vocabulary
• Fitness Function: The fitness function is used to determine the individual's fitness level in
the population. It means the ability of an individual to compete with other individuals. In
every iteration, individuals are evaluated based on their fitness function.

• Genetic Operators: In a genetic algorithm, the best individual mate to regenerate offspring
better than parents. Here genetic operators play a role in changing the genetic
composition of the next generation.

• Selection: After calculating the fitness of every existent in the population, a selection
process is used to determine which of the individualities in the population will get to
reproduce and produce the seed that will form the coming generation.
How Genetic Algorithm Works?
The genetic algorithm works on the evolutionary generational cycle to generate high-
quality solutions. These algorithms use different operations that either enhance or
replace the population to give an improved fit solution.

It basically involves five phases to solve the complex optimization problems, which are
given as below:
o Initialization
o Fitness Assignment
o Selection
o Reproduction
o Termination
1. Initialization
The process of a genetic algorithm starts by generating the set of individuals, which is called
population. Here each individual is the solution for the given problem. An individual contains
or is characterized by a set of parameters called Genes. Genes are combined into a string and
generate chromosomes, which is the solution to the problem. One of the most popular
techniques for initialization is the use of random binary strings.
2. Fitness Assignment

Fitness function is used to determine how fit an individual is?


It means the ability of an individual to compete with other
individuals. In every iteration, individuals are evaluated based on their
fitness function. The fitness function provides a fitness score to each
individual. This score further determines the probability of being
selected for reproduction. The high the fitness score, the more
chances of getting selected for reproduction.
3. Selection
The selection phase involves the selection of individuals for the reproduction of
offspring. All the selected individuals are then arranged in a pair of two to
increase reproduction. Then these individuals transfer their genes to the next
generation.

There are three types of Selection methods available, which are:


o Roulette wheel selection
o Tournament selection
o Rank-based selection
4. Reproduction

After the selection process, the creation of a child occurs in the reproduction step. In this
step, the genetic algorithm uses two variation operators that are applied to the parent
population. The two operators involved in the reproduction phase are given below:

• Crossover
• Mutation
i. Crossover
The crossover plays a most significant role in the reproduction phase of the
genetic algorithm. In this process, a crossover point is selected at random
within the genes. Then the crossover operator swaps genetic information of
two parents from the current generation to produce a new individual
representing the offspring

The genes of parents are exchanged among themselves until the crossover point is met.
These newly generated offspring are added to the population. This process is also called or
crossover. Types of crossover styles available:
oOne point crossover
oTwo-point crossover
oLivery crossover
oInheritable Algorithms crossover
ii. Mutation
The mutation operator changes random genes in the offspring (new child) to maintain the
diversity in the population. It can be done by flipping some bits in the chromosomes.

Mutation helps in solving the issue of premature convergence and enhances diversification.
The below image shows the mutation process:
Types of mutation styles available,
o Flip bit mutation
o Gaussian mutation
o Exchange/Swap mutation
5. Termination

After the reproduction phase, a stopping criterion is applied as a base for


termination. The algorithm terminates after the threshold fitness solution is
reached. It will identify the final solution as the best solution in the
population.
Work Flow
Of
Genetic
Algorithm
Example: the MAXONE problem
Suppose we want to maximize the number of ones in a string of n binary digits (e.g.,
transforming 001010 into 111111).
Is it a trivial problem?

It may seem so because we know the answer in advance.

However, Instead of just viewing it as flipping all bits to 1, we can reframe the problem:
• Imagine each bit (1 or 0) represents the correct (1) or incorrect (0) answer to a series of
yes/no difficult questions.
• The GA's task is to iteratively evolve a population of candidate solutions, selecting those
with more correct answers and improving them over generations.
Example: the MAXONE problem

• An individual is encoded (naturally) as a string of l binary digits

• The fitness f of a candidate solution to the MAXONE problem is the


number of ones in its genetic code
• We start with a population of n random strings. Suppose that l = 10
and n = 6. (each individual has 10 bits)
Example: the MAXONE problem
Step 1: Initialization
We toss a fair coin 60 times and get the following initial population:

s1 = 1111010101 f (s1) = 7
s2 = 0111000101 f (s2) = 5
s3 = 1110110101 f (s3) = 7
s4 = 0100010011 f (s4) = 4
s5 = 1110111101 f (s5) = 8
s6 = 0100110000 f (s6) = 3
Step 2: Selection
• The probability of an individual being selected is proportional to its fitness.
• Higher fitness individuals have a greater chance of being selected.

Individual i will have a f (i)


probability to be chosen  f (i)
i

▪ f(i) = Fitness of individual iii. Area is


1 2
▪ ∑f(i) = Total fitness of all individuals in the Proportional
n
population. to fitness
value
3

13
Selected set

Suppose that, after performing selection, we get


the following population:

s1` = 1111010101 (s1)


s2` = 1110110101 (s3)
s3` = 1110111101 (s5)
s4` = 0111000101 (s2)
s5` = 0100010011 (s4)
s6` = 1110111101 (s5)

14
Step 3: Crossover

• Next, we recombine the strings for crossover. For each pair we first
decide (using some pre-defined probability, for instance 0.6)
whether to actually perform the crossover or not
• If we decide to actually perform crossover, we randomly extract the
crossover points, for instance 2 and 5

15
Crossover result

Before crossover:
s1` = 1111010101 s2` = 1110110101
After crossover:
s1`` = 1110110101 s2`` = 1111010101

16
Step 4: mutations
The final step is to apply random mutations: for each bit that we are to copy to the
new population we allow a small probability of error (for instance 0.1)

Initial strings After mutating


s1`` = 1110110101 s1``` = 1110100101
s2`` = 1111010101 s2``` = 1111110100
s3`` = 1110111101 s3``` = 1110101111
s4`` = 0111000101 s4``` = 0111000101
s5`` = 0100011101 s5``` = 0100011101
s6``` = 1110110001
s6`` = 1110110011

17
And now, iterate …

In one generation, the total population fitness


changed from 34 to 37, thus improved by ~9%

At this point, we go through the same process


all over again, until a stopping criterion is met

Introduction to Genetic Algorithms 18


“Natural selection”

• The origin of species: “Preservation of favourable


variations and rejection of unfavourable variations.”
• There are more individuals born than can survive,
so there is a continuous struggle for life.
• Individuals with an advantage have a greater
chance for survive: so survival of the fittest.
Mutations

• In any copying process errors can occur, so single (point) mutations are
pretty common.
• Other types of errors, including affecting longer regions (either deletion,
inversions, substitutions etc.) can also occur
GA Operators

• Methods of representation
• Methods of selection
• Methods of Reproduction
Common representation methods
• Binary strings.
• Arrays of integers (usually bound)
• Arrays of letters
• ….
Methods of Selection

There are many different strategies to select the individuals to be


copied over into the next generation
Methods of Selection

• Roulette-wheel selection.
• Elitist selection.
• Cutt-off selection.
• Tournament Selection
• Rank based selection.
• …
Roulette wheel selection
Conceptually, this can be represented as a game of roulette - each
individual gets a slice of the wheel, but more fit ones get larger
slices than less fit ones.
Roulette wheel selection

No. String Fitness % Of Total

1 01101 169 14.4

2 11000 576 49.2

3 01000 64 5.5

4 10011 361 30.9

Total 1170 100.0


Other selection methods
• Elitist selection:
Chose only the most fit members of each
generation.
• Cutoff selection:
Select only those that are above a certain
cutoff for the target function.
Types of Selection in GA
Tournament Selection Rank-Based Selection
Tournament Selection is a selection technique Rank-Based Selection is a selection method in
in Genetic Algorithms (GA) where a subset of Genetic Algorithms (GA) where individuals are
individuals is randomly chosen from the ranked based on their fitness, and selection
population, and the best one (based on fitness) probabilities are assigned based on these ranks
is selected for reproduction. instead of raw fitness values.

How It Works (Step-by-Step)?


How It Works (Step-by-Step)?
1.Sort the population in ascending or descending order
1.Pick k individuals randomly from the population (this
based on fitness.
is called the tournament size).
2.Assign ranks (Rank 1 = lowest fitness, Rank N = highest
2.Compare their fitness values and select the best one
fitness).
(higher fitness wins).
3.Assign probabilities proportional to the rank (not the
3.Repeat the process until the required number of
fitness score).
parents is selected.
4.Select parents using these probabilities (e.g., using
4.Use these selected parents for crossover and
Roulette Wheel or Stochastic Universal Sampling).
mutation.
Methods of Reproduction
• There are primary methods:
–Crossover
–Mutation
Methods of Reproduction:
Crossover
– Two parents produce two offspring
– Two options:
1. The chromosomes of the two parents are copied to the next
generation
2. The two parents are randomly recombined (crossed-
over) to form new offsprings
Several possible crossover strategies

• Randomly select a single point for a crossover


• Multi point crossover
• Uniform crossover
Crossover
• Single point crossover

Cross point
• Two point crossover (Multi point crossover)


Two-point crossover
Two crossover points are selected, and the genes between them are
swapped between two parents to create offspring.

Key Benefits:
• Preserves more genetic diversity than single-point crossover.
• Prevents important genes at the start and end from always being split.
• Encourages better mixing of genetic material
Two-point crossover
• Choose two points e.g. 2-8
• Apply cross over, including 2, excluding 8
• The indexing here starts from 0.

Parents: 1010001110 0011010010

Offspring: 0101010010 0011001110


Uniform crossover
A crossover technique used in Genetic Algorithms (GAs) where genes from
two parent chromosomes are randomly swapped with a fixed probability

1. A binary mask (same length as chromosomes) is randomly generated, where each


position is either 0 or 1.
2. The mask determines which parent contributes each gene to the offspring.
• If the mask bit is 1, the gene is taken from Parent 1.
• If the mask bit is 0, the gene is taken from Parent 2.

MASK: BAABBAABBB (Randomly generated)


Parents: 1010001110 0011010010
Offspring: 0011001010 1010010110
Methods of Reproduction:
Mutations

– Generating new offspring from single parent


EXAMPLE
The Traveling Salesman Problem:

Find a tour of a given set of cities so that


– each city is visited only once
– the total distance traveled is minimized
Representation

Representation is an ordered list of city


numbers known as an order-based GA.

1) London 3) Dunedin 5) Beijing 7) Tokyo


2) Venice 4) Singapore 6) Phoenix 8) Victoria

CityList1 (3 5 7 2 1 6 4 8)
CityList2 (2 5 7 6 8 1 3 4)
Crossover
Crossover combines inversion and recombination:
* *
Parent1 (3 5 7 2 1 6 4 8)
Parent2 (2 5 7 6 8 1 3 4)

Child (2 5 7 2 1 6 3 4)
Mutation
Mutation involves reordering of the list:

* *
Before: (5 8 7 2 1 6 3 4)

After: (5 8 6 2 1 7 3 4)
TSP Example: 30 Cities

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x
Solution i (Distance = 941)
TSP30 (Performance = 941)

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x
Solution j(Distance = 800)
TSP30 (Performance = 800)

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x
Solution k(Distance = 652)
TSP30 (Performance = 652)

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x
Best Solution (Distance = 420)
TSP30 Solution (Performance = 420)

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x
GA Applications
Domain Application Type
Control Gas pipeline, missile evasion
Design Aircraft design, keyboard configuration,
communication networks
Game Poker, checkers
playing
Security Encryption and Decryption

Robotics Trajectory planning


Benefits of Genetic Algorithms
• Concept is easy to understand
• Modular, separate from application
• Supports multi-objective optimization
• Always an answer; answer gets better with
time.
• Easy to exploit previous or alternate solutions
• Flexible building blocks for hybrid applications.

You might also like