0% found this document useful (0 votes)
160 views32 pages

Genetic Algorithms (GA)

Artificial Intelligence is a course of computer science and engineering department in all countries.

Uploaded by

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

Genetic Algorithms (GA)

Artificial Intelligence is a course of computer science and engineering department in all countries.

Uploaded by

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

Genetic Algorithms (GA)

Abu Saleh Musa Miah


Assist. Professor, Dept. of CSE, BAUST, Bangladesh
email: [email protected], tel: +8801734264899
web: www.baust.edu.bd/cse

1
What is genetic algorithm?

 A genetic algorithm is a heuristic search method used in artificial


intelligence and computing.

 It is used for finding optimized solutions to search problems based


on the theory of natural selection and evolutionary biology
Genetic Algorithms (GA) OVERVIEW
Genetic Algorithms were invented to mimic some of the
processes observed in natural evolution.
A class of probabilistic optimization algorithms
Inspired by the biological evolution process
Uses concepts of “Natural Selection” and “Genetic
Inheritance” (Darwin 1859)
Many people, biologists included, are astonished that life at
the level of complexity that we observe could have evolved in
the relatively short time suggested by the fossil record.
The idea with GA is to use this power of evolution to solve
optimization problems.
Widely-used in business, science and engineering
Originally developed by John Holland (1975) 3
Classes of Search Techniques
Search Techniqes

Calculus Base Guided random search Uninformed


Techniques techniqes search

Fibonacci Sort Dynamic BFS


DFS Programming

Tabu Search Evolutionary


Hill Climbing Simulated
Anealing Algorithms

Genetic Genetic
Programming Algorithms

Introduction to Genetic Algorithms 4


Search Space
 The GA aims to use selective `breeding' of the solutions to
produce `offspring' better than the parents by combining
information from the chromosomes.

The GA maintains a population of n chromosomes (solutions) with associated fitness values.


Parents are selected to mate, on the basis of their fitness, producing offspring via a reproductive
plan. Consequently highly fit solutions are given more opportunities to reproduce, so that
offspring inherit characteristics from each parent. As parents mate and produce offspring, room
must be made for the new arrivals since the population is kept at a static size. Individuals in the
population die and are replaced by the new solutions, eventually creating a new generation once
all mating opportunities in the old population have been exhausted. In this way it is hoped that
over successive generations better solutions will thrive while the least fit solutions die out.
Introduction to Genetic Algorithms 8
Implementation Details
Based on Natural Selection
After an initial population is randomly generated, the algorithm
evolves the through three operators:

1. selection which equates to survival of the fittest;


2. crossover which represents mating between individuals;
3. mutation which introduces random modifications.

Introduction to Genetic Algorithms 9


1. Selection Operator

Selection replicates the most successful solutions found


in a population at a rate proportional to their relative
quality.
key idea: pass on their genes to the next generation.
The goodness of each individual depends on its fitness.
Fitness may be determined by an objective function or by
a subjective judgment.

Introduction to Genetic Algorithms 10


2. Crossover Operator
Recombination/Crossover decomposes two distinct solutions and then
randomly mixes their parts to form novel solutions

Prime distinguished factor of GA from other optimization techniques


Two individuals are chosen from the population using the selection
operator
A crossover site along the bit strings is randomly chosen
The values of the two strings are exchanged up to this point
If S1=000000 and s2=111111 and the crossover point is 2 then S1'=001111
and s2'=110000
The two new offspring created from this mating are put into the next
generation of the population
By recombining portions of good individuals, this process is likely to create
even better individuals

Introduction to Genetic Algorithms 11


2. Crossover Operator

Introduction to Genetic Algorithms 12


3. Mutation Operator
Mutation randomly perturbs a candidate solution
With some low probability, a portion of the new
individuals will have some of their bits flipped.
Its purpose is to maintain diversity within the
population and inhibit premature convergence.
Mutation alone induces a random walk through
the search space
Mutation and selection (without crossover)
create a parallel, noise-tolerant, hill-climbing
algorithms

Introduction to Genetic Algorithms 13


3. Mutation Operator

Introduction to Genetic Algorithms 14


Effects of Genetic Operators
Using selection alone will tend to fill the
population with copies of the best
individual from the population
Using selection and crossover operators
will tend to cause the algorithms to
converge on a good but sub-optimal
solution
Using mutation alone induces a random
walk through the search space.
Using selection and mutation creates a
parallel, noise-tolerant, hill climbing
Introduction to Genetic Algorithms 15
Simple Genetic Algorithm

1. randomly initialize population(t)


2. determine fitness of population(t)
3. repeat
1. select parents from population(t)
2. perform crossover on parents
creating population(t+1)
3. perform mutation of population(t+1)
4. determine fitness of population(t+1)
4. until best individual is good enough
Introduction to Genetic Algorithms 16
Figure 1: A flowchart of working principle of a genetic algorithm

Introduction to Genetic Algorithms 17


Advantages of GA

 GA have various advantages which have made them immensely


popular. These include −
 Does not require any derivative information (which may not be
available for many real-world problems).
 Is faster and more efficient as compared to the traditional methods.
 Has very good parallel capabilities.
 Optimizes both continuous and discrete functions and also multi-
objective problems.
 Provides a list of “good” solutions and not just a single solution.
 Always gets an answer to the problem, which gets better over the
time.
 Useful when the search space is very large and there are a large
number of parameters involved.
Problem:

The three major operation in genetic algorithm.


The initial population in

(a) Is ranked by the fitness function


(b) Resulting in pairs for mating
(c) They produce offspring
(d) Which are subject to mutation
(e) Th -15
solve
Figure 4.15 The genetic algorithm.
The initial population in (a)
is ranked by the fitness function in (b),
resulting in pairs for mating in (c).
They produce offspring in (d),
which are subject to mutation in (e).

Each state, or individual, is represented as a string over a finite alphabet-


Total non-attacking pair: 24+23+20+11=78
Th-15, last number not count because 11 less than
15.
Now—
1. (24/78)*100% = 31%
2.(23/78)*100% =29%
3.(20/78)* 100% = 26%
Figure 1: A flowchart of working principle of a genetic algorithm

Introduction to Genetic Algorithms 24


Problem:

The three major operation in genetic algorithm.


The initial population in
(a) Is ranked by the fitness function
(b) Resulting in pairs for mating
(c) They produce offspring
(d) Which are subject to mutation
(e) Th -15
q1=3
q2=3 solve
q3=3
q4=3
q5=4
q6=3
q7=3
q8=2

q1=2
q2=3
q3=2
q4=2
q5=4
q6=2
q7=2
q8=3
Total non-attacking pair: 24+23+20+11=78
Th-15, last number not count because 11 less than
15.
Now—
1. (24/78)*100% = 31%
2.(23/78)*100% =29%
3.(20/78)* 100% = 26%
Genetic Algorithms

Figure 4.15 The genetic algorithm. The initial population in (a) is ranked by the fitness
function in (b), resulting in pairs for mating in (c). They produce offspring in (d), which
are subject to mutation in (e).

Each state, or individual, is represented as a string over a finite alphabet-most


commonly, a string of 0s and 1s.

Introduction to Genetic Algorithms 28


Genetic Algorithms
Suppose a genetic algorithm uses chromosomes of the form x = abcdefgh with a fixed length
of eight genes. Each gene can be any digit between 0 and 9. Let the fitness of individual x be
calculated as:

f(x) = (a + b) - (c + d) + (e + f) - (g + h)

and let the initial population consist of four individuals with the following
chromosomes:
x1 = 6 5 4 1 3 5 3 2
x2 = 8 7 1 2 6 6 0 1
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4

a) Evaluate the fitness of each individual, showing all your workings, and
arrange them in order with the fittest first and the least fit last.
f(x1) = (6 + 5) - (4 + 1) + (3 + 5) - (3 + 2) = 9
f(x2)=23
f(x3)=-16
f(x4)=-19
The order is x2, x1, x3 and x4.
29
Genetic Algorithms
f(x) = (a + b) - (c + d) + (e + f) - (g + h)

x1 = 6 5 4 1 3 5 3 2
x2 = 8 7 1 2 6 6 0 1
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4

b. Cross the fittest two individuals using one–point crossover at the middle point.

c. Cross the second and third fittest individuals using a two–point


crossover (points b and f)

30
Genetic Algorithms
f(x) = (a + b) - (c + d) + (e + f) - (g + h)

x1 = 6 5 4 1 3 5 3 2
x2 = 8 7 1 2 6 6 0 1
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4

c.Cross the first and third fittest individuals (ranked 1st and 3rd) using a uniform crossover.

In the simplest case uniform crossover means just a random exchange of genes between two
parents. For example, we may swap genes at positions a, d and f of parents x2 and x3:

31
Genetic Algorithms
x1 = 6 5 4 1 3 5 3 2
f(x) = (a + b) - (c + d) + (e + f) - (g + h) x2 = 8 7 1 2 6 6 0 1 The new population is:
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4

Now apply the fitness function f(x) = (a+b)-(c+d)+(e+f)-(g+h):

f(O1) = (8 + 7) - (1 + 2) + (3 + 5) - (3 + 2) = 15
f(O2) = (6 + 5) - (4 + 1) + (6 + 6) - (0 + 1) = 17
f(O3) = (6 + 5) - (9 + 2) + (1 + 2) - (3 + 2) = -2
f(O4) = (2 + 3) - (4 + 1) + (3 + 5) - (8 + 5) = -5
f(O5) = (2 + 7) - (1 + 2) + (6 + 2) - (0 + 1) = 13
f(O6) = (8 + 3) - (9 + 2) + (1 + 6) - (8 + 5) = -6
32

You might also like