0% found this document useful (0 votes)
81 views23 pages

Unit - 2 Heuristic Functions, Best First Search

The document discusses heuristic functions and best-first search algorithms. It provides examples of how Manhattan distance can be used as a heuristic function in k-nearest neighbors algorithms. It also explains that best-first search is a combination of depth-first and breadth-first search that uses heuristic functions to select the most promising node at each step. Finally, it discusses properties of best-first search like completeness and quality of solutions.

Uploaded by

thummalavasanth5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views23 pages

Unit - 2 Heuristic Functions, Best First Search

The document discusses heuristic functions and best-first search algorithms. It provides examples of how Manhattan distance can be used as a heuristic function in k-nearest neighbors algorithms. It also explains that best-first search is a combination of depth-first and breadth-first search that uses heuristic functions to select the most promising node at each step. Finally, it discusses properties of best-first search like completeness and quality of solutions.

Uploaded by

thummalavasanth5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

UNIT - 2

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.

• It is the combination of depth-first search and breadth-first search


algorithms. It uses the heuristic function and search.

• Best-first search allows us to take the advantages of both algorithms.


With the help of best-first search, at each step, we can choose the most
promising node.

• 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).

• For finite state spaces – completeness depends on quality of heuristic function.


• If h(n) is good – search will home into goal.
• If h(n) is yields no info – behaves like DFS, BFS (Breadth F S).
QUALITY OF SOLUTION
• QOS = in terms of length, no. of moves
required to reach goal.

• BFS choses longer solution,


in terms of no. of hops.

• Metric = other than no. of steps.

• 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.

2.Initialize a closed list (set) to keep track of visited nodes as empty.

3.While the open list is not empty:


a. Pop the node with the lowest estimated cost (based on the heuristic
function) from the open list. This node is the current node.
b. If the current node is the goal node, then you have found the shortest path.
Exit the algorithm.
c. Otherwise, move the current node to the closed list to mark it as visited.
d. Generate the neighbors (adjacent nodes) of the current node that have not
been visited and are not in the closed list.
• e. For each neighbor node:
• i. Calculate the cost to reach that neighbor node from the start node
(usually the cost of the current path plus the cost from the current node to
the neighbor).
• ii. Calculate the estimated cost from the neighbor node to the goal node
using the heuristic function.
• iii. Add the neighbor node to the open list with the calculated cost as its
priority.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy