You are on page 1of 27

Lecture 15

Local Search Algorithms &


Optimization Problems
Artificial Intelligence
COSC-3112

Ms. Humaira Anwer


Humaira.anwer@kfueit.edu.pk

Lecture 15 Local Search Algorithms &


1
Optimization
Today’s Agenda
• Local Search Algorithms
• Local Beam Search
• Genetic Algorithms (GAs)

Lecture 15 Local Search Algorithms &


2
Optimization
Local Beam Search
• Keeps track of k states rather than just one.

• Working
• Begins with randomly generated k states.
• At each step, all the successors of all k states are
generated.
• If any one is a goal, the algorithm halts.
• Otherwise, it selects the k best successors from the
complete list and repeats.
• Is this the same as running k greedy searches in the
parallel?

Lecture 15 Local Search Algorithms &


3
Optimization
Lecture 15 Local Search Algorithms &
4
Optimization
Local Beam Search
• Advantages
• Possibility of searching bigger search space

• Drawbacks
• Suffers from a lack of diversity among the k states
• Successors can become concentrated in a small part of state
space

Lecture 15 Local Search Algorithms &


5
Optimization
Variant of Local Beam Search
• Stochastic Beam Search
• Helps alleviate the problem of successor concentration
• Stochastic beam search chooses k successors at random
• Selects a successor being an increasing function of its value.

Lecture 15 Local Search Algorithms &


6
Optimization
Genetic Algorithms
• Genetic Algorithm (GA) is a search-based optimization
technique
• Based on the principles of Genetics and Natural
Selection
• Nature Inspired Approach-> Darwin’s Law of survival
• Uses bio-inspired operations
• Crossover
• Mutation
• GAs are a subset of a much larger branch of
computation known as Evolutionary Computation.
• GAs were developed by John Holland and his students
and colleagues at the University of Michigan

Lecture 15 Local Search Algorithms &


7
Optimization
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.

Lecture 15 Local Search Algorithms &


8
Optimization
Basic Terminology

Lecture 15 Local Search Algorithms &


9
Optimization
Genetic Algorithm
Initialization

Fitness
Selection
Calculation

Crossover

Mutation

Evaluate

End

Lecture 15 Local Search Algorithms &


10
Optimization
Genetic Algorithm: Worked Example
MaxOne Example

• Lets consider a simple example of coin tossing.


• Heads -> 1
• Tails -> 0
• Total 60 times (in set of 10s)
• Binary problem
• In optimization problems our aim is to maximize success
• Thus we will apply genetic algorithm to maximize no of ones
(success)

Lecture 15 Local Search Algorithms &


11
Optimization
Step 1-Initialization
Initialization

Fitness
Selection
S1 1111010101 Calculation

S2 0111000101
N= 60 Crossover
S3 1110110101
L =10
S4 0100010011
S5 1110111101 Mutation

S6 0100110000
Evaluate

End
Population

Lecture 15 Local Search Algorithms &


12
Optimization
Step-2 Fitness Calculation Initialization
• Measure to calculate fitness of
Fitness
Selection
chromosome. Calculation

• In this example desired output is 1. Crossover


f(x)
S1 1111010101 f(S1)=7 Mutation
S2 0111000101 f(S2)=5
S3 1110110101 f(S3)=7
Evaluate
S4 0100010011 f(S4)=4
S5 1110111101 f(S5)=8
End
S6 0100110000 f(S6)=3
Total 34

Lecture 15 Local Search Algorithms &


13
Optimization
Step-3 Selection
Initialization
• Select chromosomes pair. Fitness
Calculation
• Arrange chromosomes in Selection
ascending order of their fitness
function. Crossover
• Rename them
Old New f(x)
S5 S1’ 1110111101 f(S5)=8 Mutation
P1
S1 S2’ 1111010101 f(S1)=7
S3 S3’ 1110110101 f(S3)=7 Evaluate
P2
S2 S4’ 0111000101 f(S2)=5
S4 S5’ 0100010011 f(S4)=4 End
P3
S6 S6’ 0100110000 f(S6)=3
Total 34

Lecture 15 Local Search Algorithms &


14
Optimization
Step 4- Crossover
Original Chromosome (P1) After Crossover (P1)

S1’ 1 1 1 0 1 1 1 1 0 1 S1’’ 1 1 1 1 0 1 0 1 0 1

S2’ 1 1 1 1 0 1 0 1 0 1 S2’’ 1 1 1 0 1 1 1 1 0 1

Original Chromosome (P2) After Crossover (P2)

S3’ 1 1 1 0 1 1 0 1 0 1 S3’’ 1 1 1 0 1 0 0 1 0 1

S4’ 0 1 1 1 0 0 0 1 0 1 S4’’ 0 1 1 1 0 1 0 1 0 1

Lecture 15 Local Search Algorithms &


15
Optimization
Initialization

Fitness Selection
Calculation

Crossover

Mutation

Evaluate

End

Lecture 15 Local Search Algorithms &


16
Optimization
Step 5- Mutation Initialization

• Change at gene level. Fitness


Calculation
Selection

Before Mutation After Mutation Crossover


S1’’ 1111010101 S1’’’ 1111010101
S2’’ 1110111101 S2’’’ 1110111101 Mutation
S3’’ 1110100101 S3’’’ 1111101101
S4’’ 0111010101 S4’’’ 0111110001
Evaluate
S5’’ 0100010000 S5’’’ 0110010100
S6’’ 0100110011 S6’’’ 1100111011
Generate

End
Lecture 15 Local Search Algorithms &
17
Optimization
Step-6 Evaluation Initialization
Fitness
Calculation
Selection

After Mutation f(x)


Crossover
S1’’’ 1111010101 7
S2’’’ 1110111101 8
Mutation
Accuracy = (Obtained Score/ Total)*100
S3’’’ 1111101101 8
= (39/60)*100 S4’’’ 0111110001 6
= 65%
Evaluate
S5’’’ 0110010100 4
S6’’’ 1100111011 6
Total 39 End
Fitness Calculation of Original Population = 34
14.70% Increase
Lecture 15 Local Search Algorithms &
18
Optimization
When to Stop?
• When target is achieved
OR
• You can run it to its maximum.

Accuracy >= 75%


then we will stop at 45

Lecture 15 Local Search Algorithms &


19
Optimization
Genetic Algorithms
• Quicker but randomized searching for an optimal
parameter vector

• Operations
• Crossover (2 parents -> 2 children)
• Mutation (one bit)

• Basic structure
• Create population
• Perform crossover & mutation (on fittest)
• Keep only fittest children
Lecture 15 Local Search Algorithms &
20
Optimization
Genetic Algorithms
• Children carry parts of their parents’ data

• Only “good” parents can reproduce


• Children are at least as “good” as parents?
• No, but “worse” children don’t last long
• Survival of the fittest

• Large population allows many “current points” in


search
• Can consider several regions (watersheds) at once

Lecture 15 Local Search Algorithms &


21
Optimization
Crossover
• Crossover is a genetic operator
• It is used to vary the programming of a
chromosome or chromosomes from one generation
to the next.
• Two strings are picked from the pool at random to
crossover in order to produce superior offspring.
• The method chosen depends on the Encoding
Method.
• Single Point Crossover
• Two point Crossover
• Uniform Crossover

Lecture 15 Local Search Algorithms &


22
Optimization
Single Point Crossover

Lecture 15 Local Search Algorithms &


23
Optimization
Genetic Algorithms
• Representation
• Children (after crossover) should be similar to parent,
not random
• Need “reasonable” breakpoints for crossover
• “Cover”
• Population should be large enough to “cover” the range
of possibilities
• Information shouldn’t be lost too soon
• Mutation helps with this issue

Lecture 15 Local Search Algorithms &


24
Optimization
Experimenting With GAs
• Be sure you have a reasonable “goodness” criterion
• Choose a good representation (including methods
for crossover and mutation)
• Generate a sufficiently random, large enough
population
• Run the algorithm “long enough”
• Find the “winners” among the population
• Variations: multiple populations, keeping vs. not
keeping parents, “immigration / emigration”,
mutation rate, etc.
Lecture 15 Local Search Algorithms &
25
Optimization
GAs
• The whole algorithm can be summarized as:

Lecture 15 Local Search Algorithms &


26
Optimization
Properties of GAs
• Why Use GAs
• They are Robust
• Provide optimization over large space state.
• Unlike traditional AI, they do not break on slight change
in input or presence of noise
• Application of Genetic Algorithms
• Recurrent Neural Network
• Mutation testing
• Code breaking
• Filtering and signal processing
• Learning fuzzy rule base etc

Lecture 15 Local Search Algorithms &


27
Optimization

You might also like