5, Informed Searching Algorithms-I
5, Informed Searching Algorithms-I
5, Informed Searching Algorithms-I
ALGORITHMS-I
(INTRODUCTION, HEURISTIC FUNCTIONS,
BEST FIRST, HILL CLIMBING, BEAM SEARCH)
Informed Search:
Searching with the information
Use knowledge to find steps to the solution
Quick solution
Less complexity
Examples are A*, Heuristic BFS, Heuristic DFS, Best first search.
HEURISTIC FUNCTIONS
The word heuristic has been derived from Greek word
eureka or eurisko, which means “I found” or “I have
found it”.
Heuristic functions in searching are human defined
functions that is an estimate of the cost or distance to
the goal from the node.
The idea of using heuristic function is to guide the
search, so that it has a tendency to explore the region
leading to the goal.
To incorporate heuristic values in search, the node pair
values in the search, the node pair representation will
be augmented with the heuristic value such as
searchNode=(currentState,parentState, heuristicValue)
HEURISTIC FUNCTION EXAMPLE 1- ROUTE
FINDING PROBLEMS
In a route finding problem in a city, the heuristic function
could be measure of a distance of the node from the goal node.
If the location of each node is in terms of its co-ordinates,
then one heuristic function could be Euclidean distance of
the node from goal node.
H(n)=Euclidean Distance(n ,goal)=
This function gives an estimate of the distance and the actual
distance may be more than the straight distance.
Another distance metric that could be used is the
Manhattan distance or the city block distance (assumes
edges from a grid as the streets in the Manhattan)
H(n)=Manhattan Distance(n ,goal)=|xgoal-xn|+|ygoal-yn|
Similarly, we can use other distance measure such as
Minkowski distance.
HEURISTIC FUNCTION EXAMPLE 2- EIGHT
PUZZLE PROBLEM
In a 8-puzzle problem, following heuristic functions can be defined:
H1(n): number of misplaced tiles in n as compared to the goal node.
H2(n): number of correctly placed tiles in n as compared to the goal
node.
H3(n):the sum of Manhattan distance of each tile from the destination.
For instance, for the node (n) and goal node given below,
2 3 1 2 3
Initial: 1 8 4 Goal: 8 4
7 6 5 7 6 5
The values of three heuristic function defined above are:
H1(n) = 3 (1,2, 8 are not at correct positions)
H2(n) = 5 (3,4,5,6,7 are at correct position)
H3(n) = 1 (for tile 1) + 1 (for tile 2) + 0 +0+0+0+0 +1 (for tile 8) =3
HOW TO DECIDE A HEURISTIC FUNCTION FOR A
PROBLEM?
In the previous examples, it is shown that there can be
more than one heuristic for a problem.
The heuristic function for a problem is generally
decided on the basis of average branching factor which
is computed as follows:
Numberofnodes exp anded
AverageBranchingFactor
PathofOptimalSolution
Ideal value of this factor is 1 and maximum value for a
particular problem is known (such as 4 for 8-puzzle
problem).
Thus, number of runs with different initial and goal
states are executed with all the heuristic functions and
one which gives best average branching factor is
considered.
HEURISTIC FUNCTIONS CONTD…..
Heuristic functions improve the searching efficiency
possibly by sacrificing the completeness and optimal
property of algorithms.
Beam Search
A* Searching
Iterative Deepening A* Searching
BEST FIRST SEARCH
The best first search algorithm picks the most
promising node (in terms of heuristic value) from the
OPEN list in every iteration until the goal node is
found.
It maintains the OPEN list as a priority queue sorted
on the heuristic value, so that the node with the best
heuristic value automatically comes to the head of the
list.
The algorithm then picks up the node from the head of
OPEN.
BEST FIRST SEARCH ALGORITHM:
2 3 1 2 3
1 8 4 8 4
7 6 5 7 6 5
2 3
(A,,3) 1 8 4
7 6 5
(E,B,1)
1 2 3
8 4
7 6 5
(F,E,0) (G,E,2)
1 2 3 1 2 3
8 4 7 8 4
7 6 5 6 5
PERFORMANCE OF BEST FIRST SEARCH
Completeness
The best first search is complete, at least for finite search space.
This is because it explores the nodes in search space until goal
is found or OPEN is empty. The only difference is it explore
nodes in order of their heuristic value.
For infinite search space, the completeness of best first search
depends upon the heuristic function. If the heuristic function is
good enough, the search will end up in goal state.
Optimality
The optimality of the best first algorithm also depends upon the
heuristic function.
The heuristic function may find the optimal path or sub optimal
path to problem.
If two nodes have same heuristic value but one node is
expensive to achieve, the best first search algorithm has no way
of discriminating it.
PERFORMANCE OF BEST FIRST SEARCH CONTD…
Space Complexity
The size of OPEN list depends upon the accuracy of
heuristic function.
If the heuristic function is accurate then the search will
find goal directly, and the OPEN will grow linearly.
Otherwise, the search algorithm may go down some path,
change its mind, and move to another branch in search
tree.
For most interesting problems, it is difficult to devise
accurate heuristic functions, and thus space grows
exponentially (depicted in the figure in next slide).
Worst case: O(bd) if heuristic function is not good.
Time Complexity
Like space complexity, time complexity is also dependent
on the accuracy of heuristic function and time may grow
exponentially.
PERFORMANCE OF BEST FIRST SEARCH CONTD…
HILL CLIMBING
The searching algorithm generally moves up in the
direction of better value of the heuristic function i.e.
uphill/downhill (uphill in maximization and downhill in
minimization) .
It breaks its “moving up/down loop” when it reaches its
peak i.e. no neighbor node has a better value.
It does not maintain a search tree.
It only looks for the immediate neighbor of the current
state. It only stores the current node state and its
heuristic function value.
There are two variants of Hill Climbing:
Simple Hill Climbing
Steepest Hill Climbing.
SIMPLE HILL CLIMBING
Local search algorithm, i.e. it has local domain knowledge
No backtrack.
SIMPLE HILL CLIMBING
It examines the neighboring nodes one by one and selects
the first neighboring node which optimizes the current
node as next node.
Simple Hill Climbing algorithm works as follows:
Chooses the head node of OPEN as current node.
If it is a goal node then it returns success.
Otherwise, it randomly generates a new next node and checks
if its value is better than current node or not. If it is better
than current then it is added to OPEN otherwise a different
operator/rule is applied to generate the new state.
The process continues until a new node is added to OPEN or
no operator is left to be applied.
SIMPLE HILL CLIMBING-FLOW CHART
Insert Start Node to OPEN
CURRENT Remove-Head(OPEN)
Another
YES O left?
NO
2 3 1 2 3
1 8 4 8 4
7 6 5 7 6 5
Step 2: I state:
2 3
1 8 4
7 6 5
HF = 1 (for 1) + 1 (for 8) =2
HF(I) < HF (initial state) . Therefore I state, is current state and new state is
produced after applying a valid operator.
SOLUTION- PROBLEM I CONTD….
Step 3: II State:
1 2 3
8 4
7 6 5 HF = 1 (for 8) = 1
HF(II) < HF(I) . Therefore II state, is current state and new state is produced after
applying a valid operator.
A D
D C
C B
B A
Better than initial state(No need to apply any rule). Therefore Current state=First State
Step 2: II state
HF = 1(A)-1 (B) +1(C) -1 (D) =0
C
B A D
Again HF(III)< HF(I) and no other operator is possible on state I. Therefore, return
fail. (Local Maxima)
The contents of OPEN and CLOSED at each step according to first
heuristic is:
Step OPEN CLOSED
1 {(S,,0)} { }
2 {(1,S,2)} {(S,,0)}
3 {} {(S,),(1,S)}
SOLUTION-PROBLEM II CONTD…
C
D B A
HF(II) = 0 (A) -0 (B) -1 (C) -0 (D) = -1
HF(II) > HF(I). Therefore II state is current state and an
operator is applied on it.
SOLUTION-PROBLEM II CONTD….
Step 3: III state
C D B A
Better YES
than Add NEXT to OPEN
current
NO
2 8 3 1 2 3
1 5 4 8 4
7 6 7 6 5
2 3
(E,B,1)
1 2 3 Step 3: OPEN={(E,B,1)} CLOSED=((A,),(B,A)}
8 4
7 6 5
(F,E,0) (G,E,2)
1 2 3 1 2 3
Step 4: OPEN={(F,E,0)} CLOSED=((A,),(B,A)(E,B)}
8 4 7 8 4
Step 5: OPEN={ } CLOSED=((A,),(B,A)(E,B)(F,E)}
7 6 5 6 5
PROBLEM- II
Find the solution to the following blocks world
problem using steepest hill method. State the
heuristics used.
C
A B
C B A
Let heuristic be :
+ score for block which is resting on the correct
support structure and that score is equal to
number of blocks below it.
- score for block which is resting on the incorrect
support structure and that score is equal to
number of blocks below it.
SOLUTION- PROBLEM -II
HF= -1-0-0 = -1 A State 1
C B
B
A
HF=0 State 2 HF= -3
C B A C
A B B C C
C B A C A C A B A B
HF= -1 HF= 1
State 3 HF= -1 HF= -1
HF= -1
C
B
A State 4
SOLUTION- PROBLEM -II
The contents of OPEN and CLOSED are as
follows:
Time Complexity:
In hill climbing algorithm, each node generate at the
most b nodes.
Therefore, the time complexity grows linearly and is of
the order O(bd) where b is the branching factor and d is
the depth at which solution lies.
BEAM SEARCH
Completeness:
In general, the Beam Search Algorithm is not complete.
Even given unlimited time and memory, it is possible for
the algorithm to miss the goal node when there is a path
from the start node to the goal node (example in next slide).
A more accurate heuristic function and a larger beam width
can improve Beam Search's chances of finding the goal.
Optimality
Just as the Algorithm is not complete, it is also not
guaranteed to be optimal.
This can happen because the beam width and an inaccurate
heuristic function may cause the algorithm to miss
expanding the shortest path.
A more precise heuristic function and a larger beam width
can make Beam Search more likely to find the optimal path
to the goal.
INCOMPLETE WITH =2 BUT COMPLETE WITH
=3
Steps:
A 1. OPEN= {(A,,0)}, CLOSED = { }
2. OPEN= {(B,A,1)(C,A,3)} CLOSED= {(A,)}
3. OPEN={(D,B,2)(E,B,2)} CLOSED = {(A,)(B,A)}
4. OPEN={(E,B,2)} CLOSED = {(A,)(B,A)(D,B)}
5. OPEN={ } CLOSED= {(A,)(B,A)(D,B)(E,B)}
B C
H=1 H= 3
D E F G
G
Path : A->C->F->G
h=0 But Optimal path is A->D->G
PERFORMANCE OF BEAM SEARCH CONTD…
Space Complexity:
The beam search algorithm has constant space complexity
as it needs to store nodes at each level.
Time Complexity:
The beam search at each level at the maximum generate
b nodes.
Therefore, the time complexity is of the order,
O(depth beam width branching factor)