Professional Documents
Culture Documents
Artificial Intelligence Informed Search Techniques (Heuristic Functions, Best First Search, 8-Puzzle Problem With Heuristics)
Artificial Intelligence Informed Search Techniques (Heuristic Functions, Best First Search, 8-Puzzle Problem With Heuristics)
Artificial Intelligence Informed Search Techniques (Heuristic Functions, Best First Search, 8-Puzzle Problem With Heuristics)
LECTURE 5
What is Heuristics??
It is a technique designed to solve a problem quickly. A heuristic is an approximate measure of
how close you are to the target. A heuristic guides you in the right direction.
e.g. in mathematics if question is given like selling price of an item is twice the cost or interest
rate is 5% so find out principal amount. To solve such type of questions we start by an
assumption that let x=100 and so on and this assumption is actually helping us to find out the
answer quickly.
Why Heuristics is used?
So, in AI as discussed in previous lecture that in uninformed search, we explore each and every
state of problem until we reach goal. The problem with this approach is that our problem grows
exponentially and it takes non polynomial time to reach at goal in worst case.
e.g. in 8 puzzle problem, in worst case, we may need to explore 320 states. In 15 puzzle it can
go upto 1013 and in chess it can be up to (3580) which is very huge numbers. So, this type of
problems are known as NP (non polynomial) problems.
If we want to solve our problem quickly i.e. in polynomial time then we need to use some greedy
method or some type of guess. This is possible by using heuristics. So, in informed search we
have heuristic values for our states and if we have multiple states to go then instead of exploring
all the states we explore those states having minimum heuristic value. e.g.
In all the informed search algorithms, We have some type of information to find our solution
quickly that information is Heuristics. The solution found using heuristics will always be a
good solution but it may or may not be optimal.
How to Calculate Heuristics?
- Using Euclidian Distance
Here in Figure,
0 (1 is at right place) + 0 + 0 + 1 (4 needs to move one step to be at right place) + 1 + 0 + 0 + 1
= 3
Calculate No. of misplaced Tiles:
In the given figure, The no. of misplaced tiles in initial state as compared to goal state are 3 as
tile no. 4, 5, and 8 are not at right places.
POINTS TO REMEMBER:
Uninformed search always generates guaranteed optimal solution. But informed search will
generate good solution but it does not give guarantee of optimal solution. The solution may or
may not be optimal. So, we use Heuristics to solve a problem quickly i.e. in polynomial time.
Let’s say, in the figure below, Straight line distance from S to G will be minmum. But, if a
hurdle arises along the path, then the path will not be optimal.
Path = A C F G
Cost = 14 + 10+ 20 = 44 (Check if it is optimal solution or not ???)
Optimality: Best first search with heuristics will always give a good solution but it will not
give an optimal solution always. E.g. in above example, cost of path ACEHG is 41 which is
less than the path generated by algorithm.
Time Complexity: In best case/average case, it will always be better than uninformed
search algorithms as its complexity will be polynomial. But in worst case it can also take
O(bd) time complexity and that depends upon heuristics. If heuristics is good then it will be
good but if you have bad heuristics then it will perform same like uninformed search
techniques.
e.g. If u go from one city to other and u don’t have google map then u will use heuristics i.e.
u will ask someone if that person will guide you right then that will be good heuristics and
you will reach your destination easily and if that person will not tell you right path then that
will be bad heuristics.
Discussion Questions:
What are Strengths and weaknesses of Best First Search?
How can we improve Best First Search?
By taking into account both the heuristic values and the actual costs of each node.
Note: See the initial state and goal state carefully all values except (4,5 and 8) are at their
respective places. So, the heuristic value for first node is 3.