Unit - 2 Heuristic Functions, Best First Search
Unit - 2 Heuristic Functions, Best First Search
HEURISTIC FUNCTIONS
• In AI and machine learning, Manhattan distance is often used when the
underlying data has a grid-like structure or when the emphasis is on travel
along grid lines rather than a straight-line distance.
• For example, it can be used in k-nearest neighbors (KNN) algorithms for
classification, where data points are classified based on the distances to their
nearest neighbors.
• Manhattan distance can be more appropriate than Euclidean distance in
situations where movement can only occur along grid lines or when certain
features should be emphasized more than others.
• Greedy best-first search algorithm always selects the path which appears
best at that moment.
• In the best first search algorithm, we expand the node which is closest to
the goal node and the closest cost is estimated by heuristic function.
• Nodes on CLOSED denoted with double circles.
• Nodes on OPEN denoted with single circles.
• Both OPEN & CLOSED set of nodes are labelled with heuristic values.
• Labels near the nodes show the order in ehich the nodes are
expanded.
• Initially, heuristic function takes the search down a path that is not part of
solution.
• Nodes with labels 2,3,4 in search order, the search abandons the current
path and goes down a different path.
• There is a river on the way without a bridge at that point.
• Heuristic functions have the sense of direction.
• Thick edges with black arrows shows the path found by the search.
At each iteration, each node is expanded using evaluation function f(n)=h(n) ,
which is given in the above table.
Completeness
• BFS = complete (always) at least for 5 domains.
• Only change we are making is in the ordering of OPEN.
• It will report failure only after OPEN becomes empty.
• BFS is systematic (inspects all nodes before giving up).
• Other metrics (measures) = quality, it will be possible that algorithm picks sub-
optimal solution.
• This is because, the algorithm compares two states by estimating the distance,
without considering cost of reaching two states.
• Thus, if two states have same heuristic value, but one of them was more
expensive to achieve.
• The BFS do not discriminate b/w the two states.
Space Complexity
• Advantages:
• Best first search can switch between BFS and DFS by gaining the
advantages of both the algorithms.
• This algorithm is more efficient than BFS and DFS algorithms.
• Disadvantages:
• It can behave as an unguided depth-first search in the worst case scenario.
• It can get stuck in a loop as DFS.
• This algorithm is not optimal.
1.Initialize an open list (priority queue) with the start node and set its cost to
zero.