0% found this document useful (0 votes)
9 views54 pages

ECI770-Intelligent Systems - Week 03

The document provides an overview of evolutionary computation and genetic algorithms (GA), detailing their principles, processes, and applications across various fields such as optimization, machine learning, and healthcare. It explains key concepts including population, chromosomes, fitness functions, and genetic operators like selection, crossover, and mutation. Additionally, it outlines the steps involved in implementing a GA, including initialization, evaluation, and termination conditions, along with examples such as solving the 8-Queen problem and the Knapsack problem.

Uploaded by

fayazcui24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views54 pages

ECI770-Intelligent Systems - Week 03

The document provides an overview of evolutionary computation and genetic algorithms (GA), detailing their principles, processes, and applications across various fields such as optimization, machine learning, and healthcare. It explains key concepts including population, chromosomes, fitness functions, and genetic operators like selection, crossover, and mutation. Additionally, it outlines the steps involved in implementing a GA, including initialization, evaluation, and termination conditions, along with examples such as solving the 8-Queen problem and the Knapsack problem.

Uploaded by

fayazcui24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Introduction

• Evolutionary computation
• a group of problem-solving techniques
• theory of biological evolution,
• genetic inheritance and natural selection..

• Evolutionary algorithm (EA)


• Inspired by nature and solves problems through processes that emulate
the behaviors of living organisms.
• EA is a component of both evolutionary computing and bio-inspired
computing.
• EAs are inspired by the concepts in Darwinian Evolution..
Evolutionary Computation
What is GA
• A genetic algorithm (or GA) is a search technique used in
computing to find true or approximate solutions to
optimization and search problems.
• Genetic algorithms are categorized as global search
heuristics.
• Genetic algorithms are a particular class of evolutionary
algorithms that use techniques inspired by evolutionary
biology such as inheritance, mutation, selection, and
crossover (also called recombination).
Key Applications of Genetic Algorithms (GA)

• Optimization Problems: Engineering, Transportation, Scheduling


• Machine Learning: Feature Selection, Hyperparameter Tuning
• Robotics: Path Planning, Control System Optimization
• Bioinformatics: Protein Structure Prediction, Gene Sequencing
• Financial Markets: Portfolio Optimization, Algorithmic Trading
• Telecommunications: Network Routing, Frequency Assignment
• Healthcare: Medical Imaging, Drug Design
• Energy Systems: Power Grid Optimization, Renewable Energy Design
• Manufacturing: Production Scheduling, Resource Allocation
• Urban Planning: Land Use Optimization, Traffic Control
Basic Terminology
• Population − It is a subset of all the possible (encoded) solutions to the
given problem. The population for a GA is analogous to the population for
human beings except that instead of human beings, we have Candidate
Solutions representing human beings.
• Chromosomes − A chromosome is one such solution to the given problem.
• Gene − A gene is one element position of a chromosome.
• Allele − It is the value a gene takes for a particular chromosome.
• Fitness Function − A fitness function simply defined is a function
which takes the solution as input and produces the suitability of the
solution as the output. In some cases, the fitness function and the
objective function may be the same, while in others it might be
different based on the problem.
• Genetic Operators − These alter the genetic composition of the
offspring. These include crossover, mutation, selection, etc.
Genetic Algorithms
• Based on the process of natural selection.
• Take fundamental properties of natural selection to apply them
to problems of different nature.
• Basic process of GA
• Initialization
• Evaluation
• Selection
• Crossover
• Mutation
Representation

• One of the most important decisions to make while implementing a


genetic algorithm is deciding the representation that we will use to
represent our solutions. It has been observed that improper
representation can lead to poor performance of the GA.
• Commonly used representation for genetic algorithms.
• Binary representation

• Real Valued representation

• Integer Representation
Population Initialization

There are two primary methods to initialize a population in a GA. They


are −
• Random Initialization − Populate the initial population with
completely random solutions.
• Heuristicinitialization − Populate the initial population using a
known heuristic for the problem.
Fitness Function
The fitness function simply defined is a function which takes
a candidate solution to the problem as input and produces as
output how “fit” our how “good” the solution is with respect to the
problem in consideration.
A fitness function should possess the following characteristics −
• The fitness function should be sufficiently fast to compute.
• It must quantitatively measure how fit a given solution is or how fit
individuals can be produced from the given solution.
Parent Selection

Parent Selection is the process of selecting parents which mate and


recombine to create off-springs for the next generation. Parent
selection is very crucial to the convergence rate of the GA as good
parents drive individuals to a better and fitter solutions.
Fitness Proportionate Selection

• Fitness Proportionate Selection is one of the most popular ways of parent


selection. In this every individual can become a parent with a probability
which is proportional to its fitness.
• Consider a circular wheel. The wheel is divided into n pies, where n is the
number of individuals in the population. Each individual gets a portion of the
circle which is proportional to its fitness value.
• Two implementations of fitness proportionate selection are possible
• Roulette Wheel Selection
• Stochastic Universal Sampling
Roulette Wheel Selection

• In a roulette wheel selection, the circular wheel is divided as


described before. A fixed point is chosen on the wheel circumference
as shown and the wheel is rotated. The region of the wheel which
comes in front of the fixed point is chosen as the parent. For the
second parent, the same process is repeated.
Stochastic Universal Sampling (SUS)

Stochastic Universal Sampling is quite similar to Roulette wheel


selection, however instead of having just one fixed point, we have
multiple fixed points as shown in the following image. Therefore, all the
parents are chosen in just one spin of the wheel. Also, such a setup
encourages the highly fit individuals to be chosen at least once.
Tournament Selection
In K-Way tournament selection, we select K individuals from the
population at random and select the best out of these to become a
parent. The same process is repeated for selecting the next parent.
Tournament Selection is also extremely popular in literature as it can
even work with negative fitness values.
Rank Selection
• Rank Selection also works with negative fitness values and is mostly
used when the individuals in the population have very close fitness
values.
Crossover

• The crossover operator is analogous to reproduction and biological


crossover. In this more than one parent is selected and one or more
off-springs are produced using the genetic material of the parents.
Crossover is usually applied in a GA with a high probability – pc .
One point crossover

• In this one-point crossover, a random crossover point is selected and


the tails of its two parents are swapped to get new off-springs.
Multi Point Crossover
• Multi point crossover is a generalization of the one-point crossover
wherein alternating segments are swapped to get new off-springs.
Uniform Crossover

• In a uniform crossover, we don’t divide the chromosome into


segments, rather we treat each gene separately. In this, we
essentially flip a coin for each chromosome to decide whether or not
it’ll be included in the off-spring.
Mutation

• In simple terms, mutation may be defined as a small random tweak in


the chromosome, to get a new solution. It is used to maintain and
introduce diversity in the genetic population and is usually applied
with a low probability – pm.
Bit Flip Mutation
• In this bit flip mutation, we select one or more random bits and flip them. This is
used for binary encoded GAs.

Swap Mutation
• In swap mutation, we select two positions on the chromosome at random, and
interchange the values. This is common in permutation based encodings.
Survivor Selection
• The Survivor Selection Policy determines which individuals are to be kicked
out and which are to be kept in the next generation. It is crucial as it should
ensure that the fitter individuals are not kicked out of the population, while
at the same time diversity should be maintained in the population.
• Age based Selection
• Fitness based Selection
Termination Condition

• The termination condition of a Genetic Algorithm is important in


determining when a GA run will end. It has been observed that
initially, the GA progresses very fast with better solutions coming in
every few iterations, but this tends to saturate in the later stages
where the improvements are very small.
• When there has been no improvement in the population for X iterations.
• When we reach an absolute number of generations.
• When the objective function value has reached a certain pre-defined value.
Solving 8-Queen problem using GA

1. Representing individuals
2. Generating the initial population
3. Applying fitness function
4. Selecting parents for mating in accordance with their fitness
5. Crossover of parents to produce new generation
6. Mutation of new generation to produce diversity
Step 1: Representing individuals

• Formulate an appropriate method to


represent individuals of population
• Array
• Index: Column
• Value: Row
Step 2: Generate initial population

• Generate random arrangements of 8 queens on standard chessboard


Step 3: Apply fitness function
Apply fitness function (cont)
Step 4: Selection

• There are various method of selection


• Roulette wheel, tournament, rank etc.
• Population is divided on a wheel according to their respective percentage of
fitness and two fixed point are placed.
• Wheel is spun and those individuals are selected at which the fixed points
are pointing when the wheel stops.
Step 4 : Selection (cont)
Step 5: Crossover
Step 6 : Mutation
Step 7 : Repeat

• All steps are repeated until best solution is reached.


• Best solution = highest fitness score i.e. 28.
Basic Genetic Algorithm.
Each iteration is called
generation.
Entire set of generation is called
run.
At the end of run we expect to
find one or more highly fit
chromosomes.
• Find the maximum value of the function 15𝑥 − 𝑥 2

Example- GA • where parameter x varies between 0 and 15.


• For simplicity, we may assume that x takes only integer values. Thus,
chromosomes can be built with only four genes:

Suppose the size of chromosomes population N is 6.


Crossover probability pc is 0.7
Mutation probability is pm0.001
The initial randomly generated population of
chromosomes.
What is the average fitness?
Selection
How can we maintain the size of the population constant, and at the same time improve its
average fitness?
Crossover and Mutation
Using genetic algorithm maximize f(x) = x2 over {0 , 1, 2, …… 31} with initial x values of (13,
24, 8, 16). Show one crossover operation. Use crossover point as {4,4,2,2}.
Calculate the σ 𝑓(𝑥), and 𝑓 ҧ before and after the crossover.
String. No. x-value Innitial f(x) = x2 P select i Expected Actual count
Population count from Roulette
fi /σ 𝒇
Wheel
fi /f
1

σ 𝑓(𝑥) = _________________ 𝑓 ҧ = ______________________


Mating Crossover New x-value f(x) = x2
pool for point (as Population
reproducti given
on above)

σ 𝑓(𝑥) = _________________ 𝑓 ҧ = ______________________


Genetic Algorithm
(Knapsack Problem)
Knapsack Problem
Problem Description:

• You are going on a picnic.


• And have a number of items that you could
take along.
• Each item has a weight and a benefit or
value.
• You can take one of each item at most.
• There is a capacity limit on the weight you
can carry.
• You should carry items with max. values.
Knapsack Problem
Example:

• Item: 1 2 3 4 5 6 7
• Benefit: 5 8 3 2 7 9 4
• Weight: 7 8 4 10 4 6 4
• Knapsack holds a maximum of 22 pounds
• Fill it to get the maximum benefit
Genetic Algorithm
Outline of the Basic Genetic Algoritm

1. [Start]
✓ Encoding: represent the individual.
✓ Generate random population of n chromosomes
(suitable solutions for the problem).
2. [Fitness] Evaluate the fitness of each chromosome.
3. [New population] repeating following steps until
the new population is complete.
4. [Selection] Select the best two parents.
5. [Crossover] cross over the parents to form a new
offspring (children).
Genetic Algorithm
Outline of the Basic Genetic Algoritm Cont.

6. [Mutation] With a mutation probability.


7. [Accepting] Place new offspring in a new
population.
8. [Replace] Use new generated population
for a further run of algorithm.
9. [Test] If the end condition is satisfied,
then stop.
10. [Loop] Go to step 2 .
Basic Steps
Start

• Encoding: 0 = not exist, 1 = exist in the Knapsack


Chromosome: 1010110

Item. 1 2 3 4 5 6 7
Chro 1 0 1 0 1 1 0
Exist? y n y n y y n
=> Items taken: 1, 3 , 5, 6.
• Generate random population of n chromosomes:
a) 0101010
b) 1100100
c) 0100011
Basic Steps Cont.
Fitness & Selection

a) 0101010: Benefit= 19, Weight= 24 


Item 1 2 3 4 5 6 7
Chro 0 1 0 1 0 1 0
Benefit 5 8 3 2 7 9 4
Weight 7 8 4 10 4 6 4


b) 1100100: Benefit= 20, Weight= 19. ✓
c) 0100011: Benefit= 21, Weight= 18.
=> We select Chromosomes b & c.
Basic Steps Cont.
Crossover & Mutation

Parent 1 1 1 0 0 1 0 0

Parent 2 0 1 0 0 0 1 1

Child 1 1 1 0 0 0 1 1

Child 2 0 1 0 0 1 0 01 Mutation
Basic Steps Cont.
Accepting, Replacing & Testing

✓Place new offspring in a new population.


✓Use new generated population for a further
run of algorithm.
✓If the end condition is satisfied, then stop.
End conditions:
▪ Number of populations.
▪ Improvement of the best solution.

✓Else, return to step 2 [Fitness].


Genetic Algorithm
Conclusion

• GA is nondeterministic – two runs


may end with different results

• There’s no indication whether best


individual is optimal
Consider a scenario where a thief is attempting to maximize his loot from
a collection of valuable items. Each item has a weight (wi​) and a value
(vi​). However, he has a limited capacity (W) that he can carry in his
knapsack. The goal is to determine the maximum total value of items he
can steal without exceeding the knapsack capacity.

Item Weight (wi) Value (vi)


A 2 6
B 5 3
C 10 5
D 5 8
E 3 2
If the knapsack has a capacity of W=10, determine the optimal selection of items to maximize the
total value. Show the selected items and the total value using the tabular method.
Thank you for
your attention

You might also like