AI Lecture 9-10
AI Lecture 9-10
(CS-401)
Lecture 5:
Local Search Algorithms
In this lecture:
3
Local Search Algorithms
ِExamples:
– to reduce cost, as in cost functions
6
Search Landscape (two-dimension)
7
Search Landscape (three-dimensions)
8
Local Search Algorithms
In this lecture:
❑ Part 1: What/Why Local Search
❑ Part 2: Hill-Climbing Search
❑ Part 3: Simulated Annealing Search
9
Hill-Climbing Search
• Continually moves in the direction of increasing value (i.e., uphill).
• Terminates when it reaches a “peak”, no neighbor has a higher value.
• Only records the state and its objective function value.
• Does not look ahead beyond the immediate.
Sometimes called
Greedy Local Search
11
Hill-Climbing Search
S → B → E → G1
S SEARCH PATH = [S0, B1, E2, G13]
4 1 Cost = 1+2+3=6
A B
2 3
1 2 NOTE: The values on arcs are evaluation
function values or cost function values
C D E F (NOT heuristic estimate values).
4 3 2 1
NOTE: in Hill climbing NO revising or
backtracking. This is the only difference
H G1 I G2
b/w Hill climbing and Best first search.
12
Hill-Climbing Search Disadvantages
13
Hill-Climbing Search Algorithm
14
Local Search Algorithms
In this lecture:
❑ Part 1: What/Why Local Search
❑ Part 2: Hill-Climbing Search
❑ Part 3: Simulated Annealing Search
❑ Part 4: Genetic Algorithms
15
Simulated Annealing Search
16
Simulated Annealing Search
17
Simulated Annealing Search
18
Simulated Annealing Search
19
Simulated Annealing Search
20
Properties of Simulated Annealing Search
21
Local Search Algorithms
In this lecture:
❑ Part 1: What/Why Local Search
❑ Part 2: Hill-Climbing Search
❑ Part 3: Simulated Annealing Search
22
Genetic Algorithms
23
Genetic Algorithms
24
Genetic Algorithms
25
The 8-queen Problem
26
Initial Population
The process begins with a set of individuals which is called a
Population. Each individual is a solution to the problem you
want to solve.
An individual is characterized by a set of parameters
(variables) known as Genes. Genes are joined into a string to
form a Chromosome (solution).
In a genetic algorithm, the set of genes of an individual is
represented using a string, in terms of an alphabet. Usually,
binary values are used (string of 1s and 0s). We say that we
encode the genes in a chromosome.
27
Fitness Function
28
Selection
29
Crossover
• For each pair of parents to be mated, a
crossover point is chosen at random from
within the genes.
• For example, consider the crossover point to
be 3 as shown below.
• Offspring are created by exchanging the
genes of parents among themselves until the
crossover point is reached
• The new offspring are added to the
population.
30
Mutation
• In certain new offspring formed, some of their
genes can be subjected to a mutation with a
low random probability.
• This implies that some of the bits in the bit
string can be flipped.
• Mutation occurs to maintain diversity within
the population and prevent premature
convergence.
31
Termination
• The algorithm terminates if the population has
converged (does not produce offspring which
are significantly different from the previous
generation).
• Then it is said that the genetic algorithm has
provided a set of solutions to our problem.
32
Termination
33
Genetic Algorithm Pseudocode
34