Genetic algorithm in Artificial Intelligence with example
supriyaDicholkar1
54 views
32 slides
Jun 19, 2024
Slide 1 of 32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
About This Presentation
Genetic Algorithm
Size: 164.59 KB
Language: en
Added: Jun 19, 2024
Slides: 32 pages
Slide Content
Lecture 2:
CanonicalGenetic
Algorithms
Suggested reading: D. E. Goldberg, Genetic Algorithm in Search, Optimization, and
Machine Learning,
Addison Wesley Publishing Company, January 1989
2
What Are Genetic Algorithms?
„
Genetic algorithms are optimization algorithm
inspired from natural selection and genetics
„
A candidate solution is referred to as an individual
„
Process
…
Parent individuals generate offspring individuals
…
The resultant offspring are evaluated for their
fitness
…
The fittest offspring individuals survive and
become parents
…
The process is repeated
3
History of Genetic Algorithms „
In 1960’s
…
Rechenberg: “evolution strategies ”
„
Optimization method for real-valued parameters
…
Fogel, Owens, and Walsh: “evolutionary programming”
„
Real-valued parameters evolve using random mutation
„
In 1970’s
…
John Holland and his colleagues at University of Michigan
developed “genetic algorithms(GA)”
…
Holland’s1975 book “Adaptation in Natural and Artificial
Systems”is the beginning of the GA
…
Holland introduced “schemas,”the framework of most
theoretical analysis of GAs.
4
„
In 1990’s
…
John Koza: “genetic programming”used genetic
algorithms to evolve programs for solving certain tasks
„
It is generally accepted to call these techniques as evolutionary
computation
„
Strong interaction among the different evolutionary
computation methods makes it hard to make strict distinction
among GAs, evolution strategies, evolutionary programming
and other evolutionary techniques
5
Differences Between GAsand
Traditional Methods
„
GAsoperate on encodings of the parameters values,
not necessarily the actual parameter values
„
GAsoperate on a population of solutions, not a
single solution
„
GAsonly use the fitness values based on the
objective functions
„
GAsuse probabilistic computations, not
deterministic computations
„
GAsare efficient in handling problems with a
discrete or mixed search spaces
The Canonical GA
7
Canonical GA „
The canonical genetic algorithmrefers to the GA
proposed by John Holland in 1965
START
END
STOP?
Initialization
Fitness evaluation
Selection Crossover
Mutation
8
Gene Representation „
Parameter values are encoded into binary strings of
fixedand finitelength
…
Gene: each bit of the binary string
…
Chromosome: a binary string
…
Individual: a set of one or multiple chromosomes, a
prospective solutionto the given problem
…
Population: a group of individuals
„
Longer string lengths
…
Improve resolution
…
Requires more computation time
9
Binary Representation „
Suppose we wish to maximize
„
Where
„
Binary representation
„
We map to
„
Thus
)(xf
[
]
max min
x x x
,
;
=
Ω
Ω∈
[
]
max min
x x
,
[
]
1 2,0−
l
[
]
1 2 1
bb bb x
ll binary
L
−
∈
∑
=
−
−
−
+ =
l
i
i
i
l
min max
min
b
x x
x x
1
1
2
1 2
10
Example „
Letl = 5,Ω= [-5, 20]
„
Then
[]
[]
[]
3226 .10
1 2
)5( 20
)2 2 2(5 1 1 0 0 1
20 1 1 1 1 1
5 0 0 0 0 0
5
0 1 4
binary
binary
binary
=
−
−−
+ + +−= ⇒ =
= ⇒ =
−= ⇒ =
x x
x x
x x
11
Fitness Evaluation
„
Each individual xis assigned with a fitness value
f(x) as the measure of performance
„
It is assumed that the fitness value is positive and
the better the individual as a solution, the fitness
value is more positive
„
The objective function can be the fitness function
itself if it is properly defined
12
Example 1 „
Consider the problem
„
A fitness function
max g(x) = -x
2
+ 4x, x ∈[1, 5]
f(x) =-g(x)+100= -x
2
+ 4x + 100
13
Example 2 „
Consider the problem
„
A fitness function
min g(x) = x
2
, x ∈[-10, 10]
f(x) = 1/(g(x) + 0.1) = 1/(x
2
+ 0.1)
14
Selection „
Chooses individuals from the current population to
constitute a mating pool for reproduction
„
Fitness proportional selection methods
…
Each individual xis selected and copied in the
mating pool with the pr obability proportional to
fitness (f(x) / Σf(x))
15
Roulette Wheel Selection
Winner
19
76
44
27
8
53
31
76
Individuals with
fitness values
Assign a piece
proportional to the
fitness value
Mating pool
16
Crossover
„
Single-point crossoveris assumed
„
Two parent individuals are selected from mating pool
„
Crossover operation is executed with the probability p
c
„
Crossover point is randomly chosen and the strings are
swapped with respect the crossover point between the
two parents
18
Mutation „
Mutation operator is applied gene-wise, that is, each
gene undergoes mutation with the probability p
m
„
When the mutation operationoccurs to a gene, its
gene value is flipped
0 11 0
1
1
0
0
1
0
1
1
1
0
0
0
1
1
1
1
Mutation points
19
Overview of Canonical GA
Initial
population
Mating pool
Mutation Crossover
Selection
19
76
44
27
8
53
31
76
Fitness
Evaluation
f (x)
22
Problem Description „
Consider the following maximization problem
max f(x) = x
2
where xis an integer between 0 and 31
0
5
10
15
20
25
30
0
100200300400500600700800900
1000
x
f(x)
f(x) = x
2
has its maximum value 961 at x = 31
23
„
Before applying GA, a representation method must be
defined
„
Use unsigned binary integer of length 5
„
A five-bit unsigned binary integer can have values
between 0(0000) and 31(11111)
Gene Representation
10110
1⋅2
4
+ 0⋅2
3
+ 1⋅2
2
+ 1⋅2
1
+ 0⋅2
0
= 22
24
Canonical GA Execution Flow
START
END
STOP?
Initialization
Fitness evaluation
Selection Crossover
Mutation
25
Initialization „
Initial populations are randomly generated
„
Suppose that the population size is 4
„
An example initial population
19 1 0 0 1 1 4
8 0 1 0 0 0 3
24 1 1 0 0 0 2
13 0 1 1 0 1 1
xvalue
Initial
population
Individual
No.
26
Fitness Evaluation „
Evaluate the fitness of initial population
„
The objective function f(x) is used as the fitness
function
„
Each individual is decoded to integer and the fitness
function value is calculated