0% found this document useful (0 votes)
9 views

Lec 4

Uploaded by

kuberkumarjha516
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lec 4

Uploaded by

kuberkumarjha516
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

ARTIFICIAL INTELLIGENCE

A Course under Centre of Excellence as Initiative of Department of Science and


Technology, Government of Bihar

GOVERNMENT POLYTECHNIC SAHARSA


Presenter:
Prof. Shubham
HoD(Computer Science and Engineering)
Todays Class
➢Informed Search Techniques
➢Best First Search
➢A* Algorithm
➢Greedy Search
Heuristics in Artificial Intelligence
• It is a technique designed to solve a problem quickly.
• Heuristics is an approach to problem-solving in which the
objective is to produce a working solution within a
reasonable time frame.
• Heuristics are used in machine learning (ML) and artificial
intelligence (AI) when it's impractical to solve a particular
problem with a step-by-step algorithm.
• To solve NP problems in Polynomial time.
• It gives good solution but does not guarantee optimal
solution.
Why Heuristics Are Used?

• Heuristics usually occurs when one of five conditions are met


(Pratkanis, 1989):
• When one is faced with too much information
• When the time to make a decision is limited
• When the decision to be made is unimportant
• When there is access to very little information to use in making
the decision
• When an appropriate heuristic happens to come to mind in the
same moment
Heuristics vs. algorithms
• An algorithm provides step-by-step instructions for how to
solve a specific problem in a finite number of steps. The
resulting outcome is predictable and can be reliably
reproduced when using the same input.
• In contrast, heuristic outcomes are simply educated
guesses. Heuristic outcomes cannot be predicted or
reproduced reliably.
• Heuristics are methods or strategies which often lead to problem
solution but are not guaranteed to succeed. They can be
distinguished from algorithms, which are methods or procedures
that will always produce a solution sooner or later.
• For example, if you are thoughtfully reading every line of this article,
you are using an algorithm.
• On the other hand, if you are quickly skimming each section for
important information or perhaps focusing only on sections you
don’t already understand, you are using a heuristic!
Best First Search(Greedy Search)
• Greedy best-first search algorithm always selects the path which
appears best at that moment.
• It uses the heuristic function and search.(Ex: Eucledian Distance)
• It uses the heuristic function and search. It is the combination of
depth-first search and breadth-first search algorithms.Best-first
search allows us to take the advantages of both algorithms.
• 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, i.e.
Algorithm:
• Step 1: Place the starting node into the OPEN list.
• Step 2: If the OPEN list is empty, Stop and return failure.
• Step 3: Remove the node n, from the OPEN list which has the lowest value
of h(n), and places it in the CLOSED list.
• Step 4: Expand the node n, and generate the successors of node n.
• Step 5: Check each successor of node n, and find whether any node is a
goal node or not. If any successor node is goal node, then return success
and terminate the search, else proceed to Step 6.
• Step 6: For each successor node, algorithm checks for evaluation function
f(n), and then check if the node has been in either OPEN or CLOSED list. If
the node has not been in both list, then add it to the OPEN list.
• Step 7: Return to Step 2.
• 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.
A* Algorithm
• It uses heuristic function h(n), and cost to reach the node n from the start state
g(n).
• A* search algorithm finds the shortest path through the search space using the
heuristic function.
• This search algorithm expands less search tree and provides optimal result faster.
• A* algorithm is similar to UCS except that it uses f(n)=g(n)+h(n) instead of g(n).
• F(n)=Actual cost from start node to n
• G(n)= Estimated cost from n to goal node
• In A* search algorithm, we use search heuristic as well as the cost to reach the
node. Hence we can combine both costs as following, and this sum is called as
a fitness number.
Algorithm of A* search:

• Step1: Place the starting node in the OPEN list.


• Step 2: Check if the OPEN list is empty or not, if the list is empty then
return failure and stops.
• Step 3: Select the node from the OPEN list which has the smallest value of
evaluation function (g+h), if node n is goal node then return success and
stop, otherwise
• Step 4: Expand node n and generate all of its successors, and put n into the
closed list. For each successor n', check whether n' is already in the OPEN
or CLOSED list, if not then compute evaluation function for n' and place
into Open list.
• Step 5: Else if node n' is already in OPEN and CLOSED, then it should be
attached to the back pointer which reflects the lowest g(n') value.
• Step 6: Return to Step 2.
Example
Initialization: {(S, 5)}
Iteration1: {(S--> A, 4), (S-->G, 10)}
Iteration2: {(S--> A-->C, 4), (S--> A-
->B, 7), (S-->G, 10)}
Iteration3: {(S--> A-->C--->G, 6),
(S--> A-->C--->D, 11), (S--> A-->B,
7), (S-->G, 10)}
Iteration 4 will give the final
result, as S--->A--->C--->G it
provides the optimal path with
cost 6.
• Advantages:
• A* search algorithm is the best algorithm than other search algorithms.
• A* search algorithm is optimal and complete.
• This algorithm can solve very complex problems.
• Disadvantages:
• It does not always produce the shortest path as it mostly based on
heuristics and approximation.
• A* search algorithm has some complexity issues.
• The main drawback of A* is memory requirement as it keeps all generated
nodes in the memory, so it is not practical for various large-scale problems.

You might also like