Professional Documents
Culture Documents
Node 1
Node 2
Best node
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
The next node to expand with the heuristic function defined as total
number of tiles not in place, is the node with h = 5
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
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
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
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
Path 2
Path 1
Path 3
• 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>
Evaluation function is
minimum
Local Maxima
Global Minima
Local
minimum
global minimum
x1
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)
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(x)
x1
September 2016
x2 vandana, CSIS, BITS PILANI, BITS
44
F444/ CS F407
Another possible surface
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
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
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
Path 1 Path 2
goal
<1,7>
Heuristic: distance
<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
5 8 100 3 2 100 2
6 5 4 3 3 100 3
8 5 4 5 4 5 4
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
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
Heuristics Differ
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 )
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
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
5 30 12 25 c5 c6 c7 c8
(a) (b)
(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) 44 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