100% found this document useful (1 vote)
402 views

Module 3 AI BAD402

ai mod 3

Uploaded by

A.P Ramya Shetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
402 views

Module 3 AI BAD402

ai mod 3

Uploaded by

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

Module 3: Informed Search Techniques and Logical Agents

Subject Code: 22BAD402


Logical Agents: Knowledge-based agents, The Wumpus world, Logic, Propositional logic, Reasoning
patterns in Propositional Logic
6/11/2024

Rao Bahadur Y Mahabaleswarappa Engineering College Ballari


Dr Shiva Prasad KM, Associate Professor Department of CSE, RYMEC Ballari
Module 3: Informed Search Techniques and Logical Agents

Module 3: Informed Search Techniques in AI


3.1. Heuristic Functions in AI:
Heuristic functions play a crucial role in artificial intelligence (AI), particularly
in the context of search algorithms and problem-solving. They provide a way to
estimate the "goodness" of a state in search algorithms, helping to guide the
search process more efficiently towards a goal.

A heuristic function, often denoted as h(n), is a function that estimates the cost
of the cheapest path from a given node n to the goal node in a search problem.
It is used to provide an educated guess about which path to take, rather than
exploring all possible paths.

Characteristics of Good Heuristics:

1. Admissibility: A heuristic is admissible if it never overestimates the cost


to reach the goal, i.e., h(n)≤h∗(n) for all nodes n, where h∗(n) is the true
cost to reach the goal from n. Admissibility ensures that an algorithm
like A* will find the optimal solution.
2. Consistency (Monotonicity): A heuristic is consistent if, for every node
n and every successor n′ of n, the estimated cost of reaching the goal
from n is no greater than the cost of getting from n to n′ plus the
estimated cost from n′ to the goal.

Common Heuristic Functions:


Different problems require different heuristics. Here are some commonly used heuristic
functions in various domains:

1. Grid-Based Pathfinding

i. Manhattan Distance: Used in a grid where movement is restricted to


horizontal and vertical steps. It is calculated as:

𝒉(𝒏) = |𝒙𝟏 − 𝒙𝟐 | + |𝒚𝟏 − 𝒚𝟐 |

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 2


Module 3: Informed Search Techniques and Logical Agents

 where (x1,y1) and (x2,y2) are the coordinates of the current state and
the goal state, respectively.

ii. Euclidean Distance: Used when diagonal movement is allowed. It is calculated as:

𝒉(𝒏) = (𝒙𝟏 − 𝒙𝟐 )𝟐 + (𝒚𝟏 − 𝒚𝟐 )𝟐

 where (x1,y1) and (x2,y2) are the coordinates of the current state and
the goal state, respectively.

2. 8 Puzzle Problem using Heuristic Functions

i. Misplaced Tiles: Counts the number of tiles that are not in their goal
position:

h(n)= number of misplaced tiles

ii. Manhattan Distance: The sum of the Manhattan distances of each tile from its goal
position:
𝟖

𝒉(𝒏) = (|𝒙𝒊 − 𝒙∗𝒊 | + |𝒚𝒊 − 𝒚∗𝒊 |)


𝒊 𝟏

 where (xi,yi) is the current position of tile i and (𝒙∗𝒊 , 𝒚∗𝒊 ) is its goal
position.

Example: Heuristic Functions for the 8-Puzzle Problem

Consider the 8-puzzle problem, where the goal is to move tiles on a 3x3 board
to achieve a specific configuration, typically with the blank space in the
bottom-right corner. Two common heuristics for this problem are the number
of misplaced tiles and the Manhattan distance.

Number of Misplaced Tiles Heuristic

This heuristic counts how many tiles are not in their goal position. It is simple
but not always very informative.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 3


Module 3: Informed Search Techniques and Logical Agents

Figure 1: Misplaced Tiles Count

Manhattan Distance Heuristic

This heuristic sums the distances each tile is from its goal position, measured
in grid moves.

Calculation Example:

Figure: Manhattan Distance Heuristic

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 4


Module 3: Informed Search Techniques and Logical Agents

3.2. Informed Search Strategies:

Informed search strategies, also known as heuristic search strategies, are a


class of algorithms in artificial intelligence (AI) that use domain-specific
knowledge to find solutions more efficiently than uninformed search
techniques. These strategies use heuristic functions to estimate the cost of
reaching the goal from a given state, guiding the search process towards more
promising paths and reducing the search space.

Key Concepts in Informed Search

1. Heuristic Function (h(n)): An estimate of the cost to reach the goal from
node n. The quality of the heuristic function significantly impacts the
efficiency of the search.
2. Evaluation Function (f(n)): Combines the cost to reach the node and the
heuristic estimate. For example, in A* search, the evaluation function is
f(n)=g(n)+h(n)f(n) where g(n) is the cost to reach node n from the start
node.
3. Admissibility: A heuristic is admissible if it never overestimates the cost
to reach the goal, i.e., h(n)≤h∗(n) for all nodes n, where h∗(n) is the true
cost to reach the goal from n.
4. Consistency (Monotonicity): A heuristic is consistent if, for every node
n and every successor n′ of n, the estimated cost of reaching the goal
from n is no greater than the cost of getting from n to n′ plus the
estimated cost from n′ to the goal.

Commonly used Informed Search Algorithms are:


1. Greedy Best-First Search
2. A* Search

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 5


Module 3: Informed Search Techniques and Logical Agents

3.1. Greedy Best First Search Algorithm:

Greedy Best-First Search (GBFS) is a search algorithm in artificial intelligence


that aims to find the shortest path to a goal by expanding the most
promising nodes first, as determined by a heuristic function. Unlike
algorithms like A*, which consider both the cost to reach a node and the
estimated cost from that node to the goal, GBFS only considers the heuristic
estimate to the goal.

It is the combination of boh depth first search and breadth first search
algorithms and uses the heuristic value for searching operation from the node
n to goal node.

In the best first search algorithm we expand the node which is closest to the
goal node and the minimum cost is estimated using the heuristic function.

Characteristics of Greedy Best-First Search


1. Heuristic-Based: GBFS relies solely on the heuristic function
h(n)h(n)h(n) to evaluate the "promise" of a node.
2. Non-Optimal: The algorithm is not guaranteed to find the shortest path
or even a path to the goal, as it might get stuck in loops or dead-ends.
3. Non-Complete: GBFS is not guaranteed to find a solution if one exists,
especially in infinite search spaces.
4. Efficiency: It can be faster than other search methods since it prioritizes
nodes that appear closer to the goal based on the heuristic.

Algorithm of GBFS:
1. Initialize the open list with the initial state.
2. Loop until the open list is empty or the goal is found:
o Select the node with the lowest heuristic value h(n) from the open
list.
o If this node is the goal, return the path to the goal.
o Otherwise, expand the node and add its successors to the open
list.
3. If the open list is empty and the goal is not found, return failure.

The formula of Greedy best first search Algorithm (GBFS) is represented as

𝒇(𝒏) = 𝒉(𝒏)

Where h(n) is the estimated heuristic cost from node n to the goal node and
that cost is an approximate cost but not an actual cost.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 6


Module 3: Informed Search Techniques and Logical Agents

Example of GBFS algorithm:


An example of the best-first search algorithm is below graph, suppose we
have to find the path from A to G:

Iteration 1:

1) We are starting from A , so from A there are direct path to node B


(with heuristics value of 32 ) , from A to C ( with heuristics value of 25 )
and from A to D( with heuristics value of 35 ) .
2) So as per best first search algorithm choose the path with lowest
heuristics value , currently C has lowest value among above node . So
we will go from A to C.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 7


Module 3: Informed Search Techniques and Logical Agents

Iteration 2:

Now from C we have direct paths as C to F(with heuristics value of 17 )


and C to E ( with heuristics value of 19) , so currently F has lowest
value among above node , we will go from C to F.

Iteration 3:

Now from F we have direct path to go to the goal node G ( with


heuristics value of 0 ) , so we will go from F to G.

So now the goal node G has been reached and the path we will follow is A->C-
>F->G.

So the Path Cost from A->C->F->G= 25+17+0=42, Since the distance


values are not represented in the above graph we cant calculate the
distance cost.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 8


Module 3: Informed Search Techniques and Logical Agents

Example 2: Assignment on Greedy best first search Algorithm

Consider the following graph and find the minimum cost to reach the
goal node I from the start node A using GBFS technique?

3.2. A* Algorithm:
 A* Algorithm is a searching algorithm that is used to find the shortest path
between the source node to the destination node.
 It is a handy algorithm that is often used for map traversal to find the
shortest path from source to the destination.
 This algorithm is used for development of games and web based maps to
find the shortest path efficiently.
 A* Algorithm is one of the best and popular technique used for path finding
and graph traversal. Since it finds the goal node from the source node it is
considered as optimal and complete.
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

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 9


Module 3: Informed Search Techniques and Logical Agents

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.

The formula of A* algorithm is represented as:


f(n)= g(n)+h(n)
Where:
– f(n): is represented as Cost function.
– g(n): is represented as path weight.
– h(n): is represented as heuristic value.
■ Advantages of A* Algorithm :
– 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 of A* Algorithm:
– It does not always produce the shortest path as it mostly based on
heuristics and approximation.
– A* search algorithm has some complexity issues.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 10


Module 3: Informed Search Techniques and Logical Agents

– 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.
Example 1: Consider the graph with actual cost g(n) and heuristic cost
h(n) and find the optimal solution using A* algorithm where start state is
A and goal state is J?

Sol: Iteration 1: We start the traversal from the start state A, Since A is the
start state the Actual cost g(n) is 0 and the estimated cost as shown in the
graph is 10. Using the formula f(n)=h(n)+g(n) we need to calculate the cost
function

f(A)=g(A)+h(A)= 0+10=10---(1)

Now from A we can traverse towards B or F, i:e AB or AF. Considering both
the paths we need to find the cost function.

f(AB)= g(B)+h(B)= 6 +8=14---(2)

f(AF)=g(F)+h(F)=3+6=09---(3)

Comparing above two cost functions of (2) and (3) we need to consider the
lowest cost function and neglect the other cost function which is maximum.
Here the lowest cost function is 9 from the path (AF).

3
A F
10 6

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 11


Module 3: Informed Search Techniques and Logical Agents

Iteration 2: Now we need to traverse from F to either H or G i:e AFH or


AFG. Using the formula f(n)=h(n)+g(n) we need to calculate the cost
function

f(AFH)= g(H)+h(H)=7+3=10---(4)

f(AFG)= g(G)+h(G)= 1+5=6---(5)

Comparing above two cost functions of (4) and (5), Here the lowest cost
function is 9 from the path (AFG).

10 3 6

A F

5 G
Iteration 3: Now we need to traverse from G to I i:e AFGI. Using the
formula f(n)=h(n)+g(n) we need to calculate the cost function.

f(AFGI)=g(I)+h(I) =3+1=4---(6)

Since we have only one path from G to I we need to consider the above cost
function for further traversal. Here the lowest cost function is 4 from the path
(AFGI).

10 3 6
A F

5
G

I 1

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 12


Module 3: Informed Search Techniques and Logical Agents

Iteration 4: Now we need to traverse from I to either J or E or H i:e


AFGIJ or AFGIE or AFGIH . Using the formula
f(n)=h(n)+g(n) we need to calculate the cost function.

f(AFGIJ)=g(J)+h(J)= 3+0=3---(7)

f(AFGIE)=g(E)+h(E)=5+3=8---(8)

f(AFGIJ)=g(J)+h(J)= 2+3=5---(9)

from the above cost function we have identified that the lowest cost function is
3 and hence the traversal takes place from AFGIJ. Hence we have
reached the goal state J.

10 3 6

A F
1

G
3

J
0

Finally the path traversal taken place from AFGIJ.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 13


Module 3: Informed Search Techniques and Logical Agents

3.3. AO* Algorithm:

■ AO* algorithm is a best first search algorithm. This algorithm uses the
concept of AND_OR graphs to decompose any given complex problem, into
set of smaller problems which can be solved easily.

■ Once all the smaller problems are solved these solved problem solutions are
combined together to provide the final result.

■ The complex problem can be broken down into smaller problems using the
logic of AND-OR graph technique.

■ This algorithm uses the method of backtracking technique.

The formula of AO* algorithm is represented as:

f(n)= g(n)+h(n)

Where:

 g(n): is the actual cost of traversal from initial state to the current state.
 h(n): is the estimated cost of the traversal from current state to the goal
state.
 f(n): is the actual cost of the traversal from initial state to the goal state.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 14


Module 3: Informed Search Techniques and Logical Agents

Advantages/Key Features of AO* Algorithm:

1. Anytime Nature:
AO* provides solutions incrementally, allowing users to interrupt the
search at any time and retrieve the best solution found so far. This
feature is crucial in real-time systems where immediate responses are
necessary.
2. Optimistic Search:
AO* maintains an "optimistic" cost estimate for each state, which serves
as a lower bound on the true cost. This estimate helps prioritize
promising paths during the search.
3. Adaptive Behaviour:
AO* can adapt its search strategy based on the available computational
resources and user requirements. It can allocate more time for an
exhaustive search if needed or return a solution quickly when
computational resources are limited.
4. Heuristic Function:
Like other informed search algorithms, AO* relies on a heuristic function
that estimates the cost from the current state to the goal state. This
function guides the search by prioritizing states that appear more
promising.

Dr Shiva Prasad KM Associate Professor Dept of CSE RYMEC M: 7899964163 Page 15

You might also like