You are on page 1of 88

Problem Solving by Searching:

Informed Search Techniques


Greedy Best First Search
A* Algorithm
Hill Climbing
Simulated Annealing
Genetic Algorithm
Root node

Node 1

Node 2

Uninformed Search : explores all nodes


systematically

Informed Search: Explores the nodes


selectively on the basis of problem specific
knowledge

vandana, CSIS, BITS PILANI, BITS


September 2016 2
F444/ CS F407
Initial state

Best node

Best node is selected on the basis of the evaluation


function computed for all nodes yet to be expanded

vandana, CSIS, BITS PILANI, BITS


September 2016 3
F444/ CS F407
Heuristic function
• The state of the node is evaluated for its
closeness to the goal state.
• The heuristic or a logic is defined carefully which
decides the node to choose at any depth of the
search tree to expand
• h(n) = estimated cost of the cheapest path from
the nth state to the goal state
• Example: a state of 8-puzzle can have a heuristic
function defined as the total number of tiles not
at the lace where they should be in the goal state
vandana, CSIS, BITS PILANI, BITS
September 2016 4
F444/ CS F407
1 2 3

1 2 3 4 5 6

7 5 7 8
Initial State
8 4 6 Goal
state

Left Down
Right Up

1 2 3 1 2 3 1 3 1 2 3

7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6

h=6 h=5 h=7 h=6

The next node to expand with the heuristic function defined as total
number of tiles not in place, is the node with h = 5

vandana, CSIS, BITS PILANI, BITS


September 2016 5
F444/ CS F407
1 2 3
7 5 Initial State
8 4 6

Left
Down
Right Up

1 2 3 1 2 3 1 3 1 2 3

7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
h=1+1+1+1+
h= 2+1+1+2+1 = 8 h=2+0+1+1+ h=1+2+1+1+
1=5
1=5 1+1=7
Define a heuristic function as the total number of squares the tile
may have to move from its position at the goal

Let us choose the second node to expand

Class work: As you expand down this node, you may or may nor
vandana, CSIS, BITS PILANI, BITS
Septemberreach
2016 closer to the goal 6
F444/ CS F407
Heuristic function
• The problem specific information is gathered in the
heuristic function.
• The value of h(n) at goal state = 0
• Example heuristic functions are:
– The distance from a city to the destination (TSP)
– The number of tiles not located appropriately (8-puzzle)
– Number of pairs in consecutive order (8-puzzle)
• A node is chosen to be expanded with maximum or
minimum heuristic function value across all nodes in
the fringe depending upon the subjective quality of the
function

vandana, CSIS, BITS PILANI, BITS


September 2016 7
F444/ CS F407
h(n) = pairs in consecutive 1 2 3
order 7 5
Initial State
8 4 6

Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
h=3 h=4 h=2 Left
h=5
up
Right
1 2 33 1 2 3 1 2 3
7 4 55 7 4 5 7 5
8 66 8 6 8 4 6
Right
h=4
Up
1 2 3 1 2 3 h=4 h=4
7 4 5 4 5
8 6 7 8 6

Right Up Down
11 2 33 2 3 1 2 3
44 55 1 4 5 7 4 5
77 8 66 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
CLASS ASSIGNMENT: work out the
4 5 4 5 3 4 5 6 number of moves through other
7 8 6 7 8 6 7 8
September 2016
vandana, CSIS, BITS PILANI, BITS nodes 8
F444/ CS F407
Computations in DEEP BLUE
• Executed on parallel computer with 30 IBM
RS/6000 processors running the software search
• 480 custom VLSI chess processors that performed
move generation
• Deep Blue search 126 million nodes per second
• It generated 30 billion positions per move
• Reached depth 14
• Used iterative deepening alpha beta search
• Evaluation function had 8000 features describing
highly specific patterns of pieces
vandana, CSIS, BITS PILANI, BITS
September 2016 9
F444/ CS F407
Greedy Best First Search
• This technique expands the node that is closest to the
goal
• It assumes that the solution can be reached though the
selected node quickly.
• It resembles DFS, as follows a single path.
• It may lead to a more expensive solution by only
looking at the instant benefits and cannot see far
beyond the current level of expansion
• The goal may not be reached choosing a node greedily,
while a little costlier choice may lead to the goal
• The selection criterion is thus local minima or local
maxima
vandana, CSIS, BITS PILANI, BITS
September 2016 10
F444/ CS F407
Greedy Best First Search
• The technique is not optimal as it does not
take into account the cost of reaching the goal
state.
• It is incomplete as it may not come back to
explore other options.
• Worst case time and space complexity: O(bm),
where m is the maximum depth of the search
space

vandana, CSIS, BITS PILANI, BITS


September 2016 11
F444/ CS F407
A* Search
• Let g(n) be the cost to reach the node
• And h(n) be the cost to get from the node to
the goal
• Define a heuristic function
f(n) = g(n) + h(n)
• f(n) is the least cost to reach the goal from the
start state.

vandana, CSIS, BITS PILANI, BITS


September 2016 12
F444/ CS F407
8-puzzle problem
• Given
g(n) = cost to reach the node n from the root
h(n) = cost to reach the goal node from node
n
• Define heuristic for the 8-puzzle problem
g(n) = No of hops
h(n) = No of hops
f(n) = g(n) + h(n)
vandana, CSIS, BITS PILANI, BITS
September 2016 13
F444/ CS F407
h(n) = pairs in consecutive 1 2 3
order 7 5
Initial State
8 4 6

Left Down g(n) = 1


Right Up
h(n) = 5
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
h=3 h=4 h=2 Left
h=5
up
Right
1 2 33 1 2 3 1 2 3
7 4 55 7 4 5 7 5
8 66 8 6 8 4 6
Right
h=4
Up
1 2 3 1 2 3 h=4 h=4
7 4 5 4 5
8 6 7 8 6

Right Up Down
11 2 33 2 3 1 2 3
44 55 1 4 5 7 4 5
77 8 66 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
4 5 4 5 3 4 5 6
7 8 6 7 8 6 7 CSIS,
8
vandana, BITS PILANI, BITS
September 2016 14
F444/ CS F407
h(n) = pairs in consecutive 1 2 3
order 7 5
Initial State
8 4 6

Left Down g(n) = 1


Right Up
h(n) = 5
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
h=3 h=4 h=2 Left
h=5
up
Right
1 2 33 1 2 3 1 2 3
7 4 55 7 4 5 7 5
8 66 8 6 8 4 6
Right
h=4
Up
1 2 3 1 2 3 h=4 h=4
7 4 5 4 5
8 6 7 8 6
g(n) = 4
h(n) = 2 Right Up Down
11 2 33 2 3 1 2 3
7 4 5
g(n) = 4
44 55 1 4 5
77 8 66 7 8 6 8 6 h(n) = 4
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
4 5 4 5 3 4 5 6
7 8 6 7 8 6 7 CSIS,
8
vandana, BITS PILANI, BITS
September 2016 15
F444/ CS F407
A* algorithm
• Takes exponential time
• Keeps all nodes in memory
• Is complete
• Is optimal

vandana, CSIS, BITS PILANI, BITS


September 2016 16
F444/ CS F407
Performance of informed search
techniques
• Depends heavily on the design of heuristic
functions
• The search may get lost in local minimum cost
or local maximum profit if heuristic function
not defined properly.
• If the evaluation function or heuristic
overestimates, the search may get struck in an
infinite loop.

vandana, CSIS, BITS PILANI, BITS


September 2016 17
F444/ CS F407
The approach so far…
• To reach the goal state from the initial state
• To reach the goal by exploring the nodes in the
search tree
• The path is maintained in the memory
• The nodes not yet expanded are kept in the
memory
• Path is important to maintain
– NEXT…….When the path is not required, and only the
objective of reaching the goal is important at
whichever cost. Example: 8-queens problem.

vandana, CSIS, BITS PILANI, BITS


September 2016 18
F444/ CS F407
Algorithms to reach the goal state when
path is not important
• These techniques are based on local search
– Hill Climbing Search
– Simulated Annealing
– Local Beam Search
– Genetic Algorithms
• Based on expanding only single current node
without looking back to any other state node
• Hence memory requirements are the least
vandana, CSIS, BITS PILANI, BITS
September 2016 19
F444/ CS F407
Local Search techniques
• The paths followed by the search are not
retained. This reduces memory requirement.
• Only the current node is retained.
• These are not systematic techniques.
• Can find reasonable solutions in large search
spaces where systematic algorithms may not.
• The algorithms are useful for solving pure
optimization problems where the aim is to find
the best state according to the objective function.

vandana, CSIS, BITS PILANI, BITS


September 2016 20
F444/ CS F407
Search space landscape

• For simplicity, let us define a state as a two tuple <x1, x2>


• Example problem: A two dimensional maze.

State: Position on the 2D cartesian Path 1 Path 2


plane goal
Move : one step any direction <1,7>
Current state <4,3>

Path 2

start <5,1> Path 3


g(n) = 2
h(n) = 5 <x,y>
f(n) = 7
vandana, CSIS, BITS PILANI, BITS
September 2016 21
F444/ CS F407
Search space landscape

• For simplicity, let us define a state as a two tuple <x1, x2>


• Example problem: A two dimensional maze.

State: Position on the 2D cartesian Path 1 Path 2


plane goal
Move : one step any direction <1,7>
Current state <4,3>

Path 1

start <5,1> Path 3


g(n) = 2
h(n) = 9 <x,y>
f(n) = 11
vandana, CSIS, BITS PILANI, BITS
September 2016 22
F444/ CS F407
Search space landscape

• For simplicity, let us define a state as a two tuple <x1, x2>


• Example problem: A two dimensional maze.

State: Position on the 2D cartesian Path 1 Path 2


plane goal
Move : one step any direction <1,7>
Current state <4,3>

Path 3

start <5,1> Path 3


g(n) = 2
h(n) = 8 <x,y>
f(n) = 10
vandana, CSIS, BITS PILANI, BITS
September 2016 23
F444/ CS F407
Search space landscape

• Select the min cost path from the current state <4,3>
• Path = Min (Path cost of path i)
•Select the node with f(n) = 7 Path 1 Path 2
•Action goal
•Select the best node <1,7>

Path 1 cost at <x,y> = 11


start <5,1> Path 3
Path 2 cost at <x,y> = 7
<x,y>
Path 3 cost at <x,y> = 10
vandana, CSIS, BITS PILANI, BITS
September 2016 24
F444/ CS F407
Looking for a minimum or a maximum
• Consider the algorithm to be at node n (state
x,y) at a Cartesian point x,y on the 2D Search
space.
• There are many options to move to other
points with less or more value of the
evaluation function.
• In greedy approach, the maximum difference
node is considered as the best node.

vandana, CSIS, BITS PILANI, BITS


September 2016 25
F444/ CS F407
Going Downhill
Costlier solution from
previous state

Current State (node in


the search tree)

Evaluation function is
minimum

vandana, CSIS, BITS PILANI, BITS


September 2016 Solution with
F444/ CS F407
least cost 26
Local Minima/Maxima
Global Maxima
Local Minima

Local Maxima

Global Minima

vandana, CSIS, BITS PILANI, BITS


September 2016 27
F444/ CS F407
Current
state

vandana, CSIS, BITS PILANI, BITS


September 2016 28
F444/ CS F407
State Space Landscape
global maximum

Evaluation function Local


maximum

Local
minimum

global minimum

x1

vandana, CSIS, BITS PILANI, BITS


September 2016 29
F444/ CS F407
Single dimensional space

x=5
vandana, CSIS, BITS PILANI, BITS
September 2016 30
F444/ CS F407
Single dimensional space

x=5
vandana, CSIS, BITS PILANI, BITS
September 2016 31
F444/ CS F407
Two dimensional search space
h(a,b) = a*mod (2) + b*mod(3)

Initial state = (3,3)


vandana, CSIS, BITS PILANI, BITS
September 2016 32
F444/ CS F407
h(a,b) = a*mod (20) + b*mod(30)

vandana, CSIS, BITS PILANI, BITS


September 2016 33
F444/ CS F407
Hyper-dimensional search space
• 8-puzzle problem has a state (say x) <x1, x2, x3, x4, x5,
x6, x7, x8, x9>
• Visualize a 10-diemensional space with the 10th
dimension representing value of the heuristic function.
• Now the search problem is reduced to an optimization
problem
Minimize h(x)  find highest peak in the search
landscape.
• How do you find the solution to the 8-puzzle problem.

vandana, CSIS, BITS PILANI, BITS


September 2016 34
F444/ CS F407
Hill Climbing Search
• Starts with the initial state .
• The node with evaluation value larger than
that of initial state is chosen (steepest ascent)
• The process repeats continuously expanding
the selected node and moving uphill (choosing
next node to explore with larger evaluation
value.
• Hill climbing is referred to as greedy local
search.
vandana, CSIS, BITS PILANI, BITS
September 2016 35
F444/ CS F407
Hill climbing get stuck with
• Local maxima- (8-puzzle problem)
• Ridges- explain in terms of the 8-puzzle
problem
• Plateau

vandana, CSIS, BITS PILANI, BITS


September 2016 36
F444/ CS F407
Class Assignment
• Consider the 8-puzzle problem and workout
hill climbing algorithm to reach the goal state.

vandana, CSIS, BITS PILANI, BITS


September 2016 37
F444/ CS F407
1 2 3

1 2 3 4 5 6

7 5 7 8
Initial State
8 4 6 Goal
state

Left Down
Right Up

1 2 3 1 2 3 1 3 1 2 3

7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6

h=6 h=5 h=7 h=6

Define your own heuristic function

vandana, CSIS, BITS PILANI, BITS


September 2016 38
F444/ CS F407
Hill climbing
• Random Initial state
• Move in the direction of steepest descent/ascent -The
node with evaluation value larger than that of initial
state is chosen (steepest ascent)
• Only neighbor information is required. (immediate
moves)
• Memory- constant (no backtracking), does not maintain
a search tree, state description is sufficient to identify
next possible moves
• Path – not maintained
• Goal- deepest/highest point in the landscape

vandana, CSIS, BITS PILANI, BITS


September 2016 39
F444/ CS F407
Hill Climbing
• Entire search landscape is not generated, only
‘b’ number of n-dimensional points (new
states after a move) are created at each move,
where ‘b’ is the branching factor/max number
of possible moves
• Search is incomplete.
• Depends mainly on the initial start state

vandana, CSIS, BITS PILANI, BITS


September 2016 40
F444/ CS F407
Hill Climbing
• Entire search landscape is not generated, only
‘b’ number of n-dimensional points (new
states after a move) are created at each move,
where ‘b’ is the branching factor/max number
of possible moves
• Search is incomplete.
• Depends mainly on the initial start state

vandana, CSIS, BITS PILANI, BITS


September 2016 41
F444/ CS F407
Hill Climbing Search Method

 A loop continuously moves in the direction of increasing


value
 Search terminates when a peak is reached
 Value can be either the objective function value or the
heuristic function value.
 Hill climbing does not look ahead of the immediate
neighbors of the current state.
 Can randomly choose among the set of best successors, if
multiple have the best value.
 Can be viewed as “trying to find the top of Mount Everest
while in a thick fog”

vandana, CSIS, BITS PILANI, BITS


September 2016 42
F444/ CS F407
Limitations of Hill Climbing
• May get struck in Local optima, ridges or plateau.
• The Hill Climbing Algorithms are incomplete as
the goal state may never be reached.
• The algorithm can be modified to allow random
restart if it gets stuck with local optima.
• The success of Hill Climbing depends very much
on the shape of the search landscape.
• If there are few local minima or plateau, then
random restart hill climbing finds a good solution
quickly.

vandana, CSIS, BITS PILANI, BITS


September 2016 43
F444/ CS F407
Plotting y when y=h(x1,x2)

h(x)

x1

September 2016
x2 vandana, CSIS, BITS PILANI, BITS
44
F444/ CS F407
Another possible surface

Plotting y when y=h(x1,x2)

h(x)

Local
Minima

x1

Global Minima
September 2016
x2 vandana, CSIS, BITS PILANI, BITS
45
F444/ CS F407
Difficult to visualize when y=h(x1,x2, x3)

x3
h(x)

x1

September 2016
x2 vandana, CSIS, BITS PILANI, BITS
46
F444/ CS F407
We will visualize in 2D but will extend the
concept to n dimensions

h(x)

x1

Global Minima
September 2016
x2 vandana, CSIS, BITS PILANI, BITS
47
F444/ CS F407
Gradient Descent/Ascent

h(x)

Direction of
the tangent The blue dot must roll
(gradient) down against the
direction of the gradient

x1

Global Minima
September 2016
x2 vandana, CSIS, BITS PILANI, BITS
48
F444/ CS F407
Walk
If heuristic function is such
that we need to reach the
lowest point in the
landscape,
Then if
Hill Climbing does not
make any uphill moves
ever
h(x) Then
It can get stuck in local
Direction of minima.
the tangent
(gradient)
FAST LEARNING
SLOW LEARNING

x1

Global Minima
September 2016
x2 vandana, CSIS, BITS PILANI, BITS
49
F444/ CS F407
When path is not important…
• Randomly generate candidate solutions and evaluate
the heuristic function (8-queen’s problem)
• Is there a way to generate the possible solutions less
randomly?
• Find newer combinations. <3,1,4,6,7,2,8,5> may be the
best solution……

Game Search
Problem Problem Optimization Problem
in AI

Combinatorial Problem
vandana, CSIS, BITS PILANI, BITS
September 2016 50
F444/ CS F407
Local Search Algorithms
• Path to the goal is not relevant.
• Only the current node being searched is in the
memory.
• These algorithms explore the state space
landscape (discussed in the last class)
• Move only to neighboring states.
• Ignore paths.
• Can often find reasonable solutions in large or
infinite (continuous) state spaces

vandana, CSIS, BITS PILANI, BITS


September 2016 51
F444/ CS F407
Landscape of search

vandana, CSIS, BITS PILANI, BITS


September 2016 52
F444/ CS F407
Simulated Annealing
• Annealing, in metallurgy, is the process used
to temper or harden metals and glass by
heating them to a high temperature and then
gradually cooling them thus allowing the
material to crystallize with low energy.
• Simulated annealing is an optimization
technique inspired by the physical process of
“annealing”.

vandana, CSIS, BITS PILANI, BITS


September 2016 53
F444/ CS F407
Simulated Annealing: Process of gradually reducing the
rate of cooling the temperature

The blue dot must roll


down against the
direction of the gradient

w1

Global Minima
September 2016
w2 vandana, CSIS, BITS PILANI, BITS
54
F444/ CS F407
Simulated Annealing: Process of gradually reducing the
rate of cooling the temperature

•The blue dot rolls down


against the direction of
the gradient very slowly
•Cannot come out of the
local minima
w1

Global Minima
September 2016
w2 vandana, CSIS, BITS PILANI, BITS
55
F444/ CS F407
Simulated Annealing: Process of gradually reducing the
rate of cooling the temperature

•The blue dot rolls down


against the direction of
the gradient fast

•This means that if the


speed is increased, the
ball can be taken out of
w1
the local minima
Global Minima
September 2016
w2 vandana, CSIS, BITS PILANI, BITS
56
F444/ CS F407
Search space landscape

• For simplicity, let us define a state as a two tuple <x1, x2>


• Example problem: A two dimensional maze.

Path 1 Path 2
goal
<1,7>
Heuristic: distance

start <5,1> Path 3

<x,y>
vandana, CSIS, BITS PILANI, BITS
September 2016 57
F444/ CS F407
Construct the Search Space
Landscape for the Maze problem

6 5 4 3 2 1 0

6 100 100 100 2 1 1

5 8 100 3 2 100 2

6 5 4 3 3 100 3

8 5 4 5 4 5 4

vandana, CSIS, BITS PILANI, BITS


September 2016 58
F444/ CS F407
Search Space Landscape
Observe that
the search
Initial came out of
State the local
minima and
the ball rolled
to the global
minima

Goal
vandana, CSIS, BITS PILANI, State
BITS
September 2016 59
F444/ CS F407
Search space landscape
Visualize the selection of next state based on
Hill Climbing (Downhill)

6 5 4 3 2 1 0

6 100 100 100 2 1 1

5 8 100 3 2 100 2
Path 1 Path 2
6 5 4 3 3 100 3 goal
<1,7>
8 5 4 5 4 5 4

<5,1> Path 3
Visualize the selection of next
start
state based on Simulated
Annealing <x,y>
vandana, CSIS, BITS PILANI, BITS
September 2016 60
F444/ CS F407
Evolutionary Search

Search in Face Recognition Randomly Generated


Population Walks or
Flies

Heuristics Differ

vandana, CSIS, BITS PILANI, BITS


September 2016 61
F444/ CS F407
Hill Climbing

• Only uphill moves


• May get trapped in local optima
• Can we relax the uphill constraint in controlled
way?

vandana, CSIS, BITS PILANI, BITS


September 2016 62
F444/ CS F407
Variants of Hill Climbing
• Original Hill Climbing: Selects the next move most greedily
• Stochastic Hill Climbing: Selects randomly from among the
uphill moves using a probability measure proportional to
the steepness
• First Choice Hill Climbing: Generates the successors
randomly until one is generated that is better than the
current state, implements Stochastic Hill Climbing
• Random Restart Hill Climbing: Series of Hill Climbing
searches
• Simulated Annealing: Allows downhill movements
sometimes
vandana, CSIS, BITS PILANI, BITS
September 2016 63
F444/ CS F407
Simulated Annealing (SA)
• Simulated annealing is a variation of hill climbing.
• The selection of the node is not always the best as in
hill climbing.
• The criteria for selection of the node is based on the
concept of “temperature”.
• Instead of picking the best move, it picks the random
move.
• If the move improves the situation, it is accepted.
• If the randomly selected move is worse than the
current node, then it is accepted with a probability.

vandana, CSIS, BITS PILANI, BITS


September 2016 64
F444/ CS F407
Probability in SA

• Simulated Annealing algorithm accepts the bad move


with a probability between 0 and 1.
• The probability is calculated on the basis of the
temperature.
• Let ‘c’ denote the current node and ‘n’ denote the next
node.
• If the search is a maximization problem, then we expect
h(n) to be more than h(c). If a bad move is selected, then
h(n) < h(c)
• Let us define  E = h(n) - h(c)
• Then probability = exp ( E/T)
vandana, CSIS, BITS PILANI, BITS
September 2016 65
F444/ CS F407
Simulated Annealing Algorithm (For
Maximization problem)

vandana, CSIS, BITS PILANI, BITS


September 2016 66
F444/ CS F407
Effect of temperature on probability

T del E del E/T exp


100 -100 -1 0.367879441
90 -100 -1.11111111 0.329192988
80 -100 -1.25 0.286504797
70 -100 -1.42857143 0.239651036
60 -100 -1.66666667 0.188875603
50 -100 -2 0.135335283
40 -100 -2.5 0.082084999
30 -100 -3.33333333 0.035673993
20 -100 -5 0.006737947
10 -100 -10 4.53999E-05
1 -100 -100 3.72008E-44

vandana, CSIS, BITS PILANI, BITS


September 2016 67
F444/ CS F407
Bad Moves and their probabilities of
getting selected
Probability

Temperature T---
vandana, CSIS, BITS PILANI, BITS
September 2016 68
F444/ CS F407
Effect of next move on probability (with H( c ) =150 and
T = 50 )

h(n) del E del E/T exp


50 -100 -2 0.1353353
60 -90 -1.8 0.1652989
70 -80 -1.6 0.2018965
80 -70 -1.4 0.246597
90 -60 -1.2 0.3011942
100 -50 -1 0.3678794
110 -40 -0.8 0.449329
120 -30 -0.6 0.5488116
130 -20 -0.4 0.67032
140 -10 -0.2 0.8187308
September 2016 150 vandana,0CSIS, BITS PILANI,
F444/ CS F407
0 BITS 1 69
Simulated Annealing
• Initially the speed of cooling is fast which
gradually slows down so that the global maxima is
reached.
• If T decreases slowly enough, then simulated annealing search
will find a global optimum with probability approaching 1
(however, this may take VERY long)
• In any finite search space RANDOM GUESSING also will find a
global optimum with probability approaching 1 .

vandana, CSIS, BITS PILANI, BITS


September 2016 70
F444/ CS F407
Genetic Algorithm
Evolutionary Algorithms
• Nature inspired
• Used for optimization
• Use a heuristic
• Known as meta heuristic algorithms
• Major techniques – Genetic Algorithm,
Particle Swarm Optimization
• Other recent techniques – Firefly algorithm,
cuckoo search, bat search etc.
vandana, CSIS, BITS PILANI, BITS
September 2016 72
F444/ CS F407
Applications
• Game problems
• Function approximation
• Weight learning
• Unsupervised clustering
• Center selection of RBFNN
• Feature selection etc.

vandana, CSIS, BITS PILANI, BITS


September 2016 73
F444/ CS F407
Genetic Algorithm
• Population based algorithm
• Basic unit : chromosome – a bit string
representing hypothesis
• Current population of chromosomes produces
better offsprings
• The solution of the given problem refers to
the maximum fitness value corresponding to a
chromosome evolved after a number of
generations.
vandana, CSIS, BITS PILANI, BITS
September 2016 74
F444/ CS F407
How to use GA in problem solving
• Problem is represented as a search problem.
• The parameters of the search space represent the
dimensions of the hypothetical search space.
• An instance of all the parameters is represented
as a chromosome.
• Example :
101100011
010111001
1.2 2.3 3.4 5.4 2.9 1.0
vandana, CSIS, BITS PILANI, BITS
September 2016 75
F444/ CS F407
Chromosome
• The representation of chromosome is problem specific.
• It represents the parameter instances or problem solution if
optimal.
• Corresponding to each chromosome is an associated fitness
value.
• The chromosomes are said to be fit if they represent solution
close to the optimal solution.
• Chromosomes evolve over the generations.
• Each generation consists of obtaining new chromosome from
two fit parent chromosomes by applying crossover operation

vandana, CSIS, BITS PILANI, BITS


September 2016 76
F444/ CS F407
Fitness Values
• Game : How close are we to the goal
• Pattern Recognition: How large is the accuracy
of recognition
• Path finding: How less costly is the path.
• And so on…

vandana, CSIS, BITS PILANI, BITS


September 2016 77
F444/ CS F407
Genetic Algorithm : Operators
• Two operators known as crossover and
mutation are applied to the chromosomes to
obtain new generation chromosome.
• Crossover Operator: applied on two parent
chromosomes to obtain a new offspring.
• Mutation: applied on one chromosome to
exploit the neighborhood.

vandana, CSIS, BITS PILANI, BITS


September 2016 78
F444/ CS F407
Crossover Point First Parent

0
1 1 0 1 1 1 0 1 0 0 1 1 1 0 1

Second Parent

1
0 1 0 1 1 1 1 1 0 0 1 1 0 0 0

(a)
First Offspring
0
1 1 0 1 1 1 1 1 0 0 1 1 0 0 0

1
0 1 0 1 1 1 0 1 0 0 1 1 1 0 1

(b) Second Offspring

1
0 1 0 1 0 1 0 1 0 1 0 1 1 0 1

(c)

Crossover and Mutation (a) Previous Generation Parent Chromosomes selected for
Crossover (b) Two new off springs generated by crossover using one crossover
vandana, CSIS, BITS PILANI, BITS
September 2016 79
point. (c) Mutation applied at three places inF444/
second offspring
CS F407
Fittest Parents: Exploration
• Roulette wheel is one of the commonly used
methods to select the chromosomes to be
treated as fittest parents from the pool of fit
parent.
• The fitness values of all eligible chromosomes
(with fitness greater than a threshold) are added
and a random number decides the fittest parent
because of its high favorable chances due to its
individual large fitness value
vandana, CSIS, BITS PILANI, BITS
September 2016 80
F444/ CS F407
0
2
Roulette Wheel

14 5

chromosome fitness cumulative probability Cumulative prob.


1 2 2 2/20 = 0.1 0.1
2 3 5 3/20 =0.15 0.25
3 4 9 4/20 = 0.2 0.45
4 5 14 5/20 = 0.25 0.7
5 6 20 6/20 = 0.3 1.0
Generate a random number in [0,1] and select a fit parent according to its
probability
September 2016
vandana, CSIS, BITS PILANI, BITS
81
F444/ CS F407
Roulette wheel
sum = 0.0
for all members of population
sum += fitness of this individual
end for
sum of probabilities = 0.0
for all members of population
probability = sum of probabilities + (fitness / sum)
sum of probabilities += probability
end for
loop until new population is full
do this twice
number = Random between 0 and 1
for all members of population
if number > probability but less than next probability
then this member gets selected
end for
end
create offspring
end loop
vandana, CSIS, BITS PILANI, BITS
September 2016 82
F444/ CS F407
How many fit chromosomes should be
selected
• If the number of chromosomes with fitness
value greater than a specified threshold in
generation t is p and if the crossover
probability is pc , then pc  p chromosomes are
selected as parents
• These participate pair wise in crossover to
produce pair of offsprings of the new
generation.

vandana, CSIS, BITS PILANI, BITS


September 2016 83
F444/ CS F407
Mutation:Exploitation
• If the mutation probability is pm then pm p
chromosomes undergo the mutation process.

vandana, CSIS, BITS PILANI, BITS


September 2016 84
F444/ CS F407
Crossover operation
• One point crossover
• Two point crossover
• Crossover mask
• Uniform crossover – combines bits sampled
from the two parents

vandana, CSIS, BITS PILANI, BITS


September 2016 85
F444/ CS F407
Feature Selection
• Given a set of features, select few most
informative and discriminative features
• Class assignment:
– Represent as a search problem
– Represent as a chromosome
– Define fitness function

vandana, CSIS, BITS PILANI, BITS


September 2016 86
F444/ CS F407
23 29 10 2 c1 c2 c3 c4

5 30 12 25 c5 c6 c7 c8

52 16 9 2 c9 c10 c11 c12

15 11 12 13 c13 c14 c15 c16

(a) (b)

c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16

(c)
2
23 29 10 5 30 12 25 52 16 9 2 15 11 12 13

(d)
0
1 1 0 1 1 1 0 1 0 0 1 1 1 0 1

(e)
1
0 1 0 1 1 1 1 1 0 0 1 1 0 0 0

(f)

Genetic Encoding of Face Image (a) 44 window of 16 features as the initial pool of
features (b) coding of features (c) codes as a vector (d) Feature vector (e)and (f) Two
different Chromosomes with 1's representing inclusion of the corresponding features
vandana, CSIS, BITS PILANI, BITS
September 2016 87
F444/ CS F407
Comparison of the Evolutionary
Algorithms
Characteristic GA PSO FA

Population Chromosomes Particles Fireflies

Search Heuristic Survival of Fittest Swarm Behavior Attractiveness

Exploration Process Crossover Global Best Attractiveness

Exploitation Process Mutation Local Best Randomization

Modality Single Single Multiple

Convergence Slowest Slow Fast


Strong: Reaches Global,
Moderate: Only single
Overall merit in finding Weak: May get trapped Multimodal Optimal
optimal solution can be
optimal solution to Local Optima Solutions and is very
obtained
fast

vandana, CSIS, BITS PILANI, BITS


September 2016 88
F444/ CS F407

You might also like