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

Unit1 Class3.3 Informed Search

The document discusses different types of informed search algorithms used in machine intelligence including informed search strategy, heuristic functions, greedy best first search, and A* search. It provides examples and analyses the advantages and disadvantages of each approach.

Uploaded by

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

Unit1 Class3.3 Informed Search

The document discusses different types of informed search algorithms used in machine intelligence including informed search strategy, heuristic functions, greedy best first search, and A* search. It provides examples and analyses the advantages and disadvantages of each approach.

Uploaded by

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

Machine Intelligence

Preethi.P
Department of Computer Science & Engineering
Machine Intelligence
Informed Search Strategy

• Informed Search algorithms have information on the goal state which helps in
more efficient searching. This information is obtained by a function f(n) that
estimates how close a state is to the goal state
• The evaluation function f(n) is a function that takes a node as a input and
gives out a positive number similar to the g(n) function we used in UCS.

• For example, when searching on google maps you give the search algorithm
information like a place you plan to visit from your current location for it to
accurately navigate the distance, the time taken and real-time traffic updates
on that particular route. This is all driven by complex Informed search
algorithms powering google maps search functionality.
Machine Intelligence
Informed Search vs Uninformed Search
Machine Intelligence
Heuristic function h(n)

h(n)= estimated cost of the cheapest path from the state at node n to a goal state

• Heuristic functions are the most common form in which additional


knowledge of the problem is imparted to the search algorithm.
• Basically Heuristic is what you call as
• Lets now convince ourselves for the below mentioned about HEURISTIC
FUNCTION

It is a arbitrary, non negative, problem-specific functions, with one


constraint: if n is a goal node, then h(n)=0.
Machine Intelligence
Best First Search

• Best first search uses the concept of a priority queue and heuristic search.
It is a search algorithm that works on a specific rule. The aim is to reach
the goal from the initial state via the shortest path
• The efficiency of the greedy best-first algorithm depends on how good the
heuristic function is.

• Idea: use an evaluation function f(n) for each node


f(n) provides an estimate for the total cost.
Expand the node n with smallest f(n).

• Implementation: Order the nodes in increasing order of cost.

• Special cases:
• Greedy best-first search
• A* search
Machine Intelligence
Greedy Best First Search

• Greedy best-first search tries to expand the node that is closest to the
goal, on the grounds that this is likely to lead to a solution quickly.
• Thus, it evaluates nodes by using just the heuristic function f(n)=h(n).
• The greedy best first algorithm is implemented by the priority queue.
• Psuedo Code
Machine Intelligence
Greedy Best First Search - Example

Adrad-->>>Bucharest

notice
The
the
yes
we
we will
h that
will
GOAL!!!
task
LSDnowtothe
use
explore
now
table values
find
straight
explore
begin
we of
isadrad
route
given
found
withhSLD
line
sibiu
from
and
for
the cannot
exploration
distance
and
example
choose
goal
ADRAD be
proceed
and computed
heuristic
the
from
h(adrad)=366
return
to one from
BURACHEST
with
adrad
with
the
same
paththe problem
lowest
stepshLSD (n)description itself
further

ad
ra
36
d 6
ti
mi
- 32 ze
rin
37
so
9 d 4
ar
a
si
bi
25
u 3
ri
ad
ra
36 or
ad
38 mi 19
ne
d 6 ea 0 u 3
fa
ga 17
ra
s 6

si 25 buch
bi
arest 0
u 3
Machine Intelligence
Lets Analyse

• The search cost found is not optimal,


however: the path via Sibiu and
Fagaras to Bucharest is 32 kilometers
longer than the path through Rimnicu
Vilcea and Pitesti. This shows why the
algorithm is called “greedy”—at each
step it tries to get as close to the goal
as it can.
• Greedy best-first tree search is also
incomplete even in a finite state
space, much like depth-first search.
Machine Intelligence
Lets Analyse

From Iasi to Fagaras


• The heuristic suggests that Neamt be
expanded first because it is closest to
Fagaras, but it is a dead end
• The solution is to go first to Vaslui—a step
that is actually farther from the goal
according to the heuristic—and then to
continue to Urziceni, Bucharest, and
Fagaras.
• This algorithm will never find this solution,
because expanding Neamt puts Iasi back
into the frontier, Iasi is closer to Fagaras
than Vaslui is, and so Iasi will be expanded
again, leading to an infinite loop.
Machine Intelligence
How good is it???

TIME
COMPLETE SPACE OPTIMALIT
COMPLEXI
NESS COMPLEXITY Y
TY

No – O(bm), but a good O(bm)


can get stuck heuristic --
No
in loops, can give dramatic keeps all nodes
complete improvement in memory
Machine Intelligence
Greedy Best First Search

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
Machine Intelligence
A* Search

• The most widely known form of best-first search is called A* search


• The A* algorithm uses a heuristic function to help decide which path to
follow next.
• The heuristic function provides an estimate of the minimum cost between
a given node and the target node. The algorithm will combine the actual
cost from the start node - referred to as g(n) - with the estimated cost to
the target node - referred to as h(n) - and uses the result to select the
next node to evaluate
Machine Intelligence
Conditions for optimality

For A* search to be optimal, the heuristic function, h(n), should be:


Admissible and Consistent

Admissibility
• An admissible heuristic is one that never overestimates EXAMPLE:
the cost to reach the goal. straight-line distance hSLD
Straight-line distance is
• A heuristic h(n) is admissible if for every node n, h(n) ≤ admissible because the
shortest path between any
h*(n), where h*(n) is the true cost to reach the goal state
two
from n points is a straight line, so
the
• Admissible heuristics are by nature optimistic because straight line cannot be an
they think the cost of solving the problem is less than it overestimate.

actually is.
Machine Intelligence
Conditions for optimality

Consistency / Monotone
• A heuristic h(n) is consistent , if its
estimate is always less than or equal to the
estimated distance from any neighboring
vertex to the goal, plus the cost of reaching
that neighbor
• Consistent heuristic is also admissible
• Consistency is therefore a stricter
requirement than admissibility,
Machine Intelligence
A* Search - Example

now we add A to visited along wit its A* score


For
we
wethe
since
and
now
we
nowgiven
have
that
choose
G2
among graph
calculate
three
number
is ourBB of
with
andwith
GOAL!!!!
the
them
is sdon't
as start states and G isas agoal state,apply it A* search to reach one of the goal from S
we
we
Atwhile
and see
don't
since
now
this exploring
begin
now wethat
go
point
andall
have
with for
every
choose
ofwe
sincethemAD
four
the
have
A isan
low
D
start
C A*
since
we
node
paths
have
with
G2with
notwith
estimate
score
A*the
its
is
state
two
same12
score
less
nowalgorithm
lowest
with and
we
already
go
,since
with
goal less
A* of
A*
for
A*
weand
choose
12
wechoose
what
A*score
its proceed
associated
S scorestops
,one
go cost
visited
since of
C
score
not the13
since
withand
node
already
with
exploreof with
with
goal
we
12A with
C
between
we
is
least
13
and Bsame
with
already
is
return
number
state visited
visited
choose
and A*
we lowest
that
steps
score
one
G2 forthe
expand
calculate visited
state
with
A*
with
A* path
score
and
A*
we
score
14 and score
choose
one
of 5 of
mark ofthe
as E
11 goal
visited
score
S 1
S,5 D
5 , ,
A 6 6
5 6
, 3 9 C 2 2
A,7 1 1 1 7 B ,
2 E
B,3 D,6 1 4
2 2 2 9 2 , 7 ,
3 F 5
5 , 7
6 8
G1,
0 G2, G3,
1 1 0
1 G1, 1 C,4 E,5 0
B,3
0 2 3
1 4

G3, 1
1 0
C,4 G2, 1 5
3 F,6 21
0 3

S,0, A,7, B,3, D,6, C,4, E,5,


5 12 11 12 12 13
Machine Intelligence
A* Search Psuedo-Code
Machine Intelligence
How good is it??

TIME SPACE
COMPLETE
COMPLEXIT COMPLEXIT
NESS OPTIMALITY
Y Y

Yes
(unless there
are infinitely Keeps all nodes
Exponential YES
many in memory
nodes with
f ≤ f(G) )
Machine Intelligence
Applications of A*

• A* is often used for the common pathfinding problem in


applications such as video games, but was originally
designed as a general graph traversal algorithm.
• It finds applications in diverse problems, including the
problem of parsing using stochastic grammars in NLP.
• Other cases include an Informational search with online
learning.
Machine Intelligence
Heuristic is the controller of A*

• A* Algorithm is one of the best path finding algorithms.


• But it does not produce the shortest path always.
• This is because it heavily depends on heuristics.
• Using h ≡ 0 assures admissibility but results in a uniform-
cost search and is thus usually inefficient.
• In selecting the heuristic function, we must take into
consideration the amount of effort involved in calculating it
Machine Intelligence
Heuristic is the controller of A*

• In the Eight-puzzle, for example, the function h(n)=W(n) (where W (n) is the
number of tiles in the wrong place) is a lower bound on h (n), but it does not
provide a very good estimate of the difficulty (in terms of number of steps to
the goal) of a tile configuration.
• A better estimate is the function h(n)=P(n), where P(n) is the sum of the
(Manhattan) distances that each tile is from “home” (ignoring intervening
pieces)

Let’s see how to calculate this manhattan


distance
Machine Intelligence
Manhattan Distance

Manhattan Distance

7 2 4 1 2
5 6 3 4 5
8 3 1 6 7 8

GOAL STATE

1 2 3 4 5 6 7 8
We calculate the distance between all the tiles from the goal state

h2 (S) = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18
Similarly we calculate the distance between the remaining slides and their sum
gives the manhattan distance
Machine Intelligence
Choice of a Heuristic

• On a grid, there are well-known heuristic functions to use.


• On a square grid that allows 4 directions of movement, use Manhattan distance (L1).
• On a square grid that allows 8 directions of movement, use Diagonal distance (L∞).
• On a square grid that allows any direction of movement, you might or might not want
Euclidean distance (L2). If A* is finding paths on the grid but you are allowing movement
not on the grid, you may want to consider other representations of the map.
• On a hexagon grid that allows 6 directions of movement, use Manhattan distance adapted
to hexagonal grids.
• If you want to search for any of several goals, construct a heuristic h'(x) that is the minimum
of h1(x), h2(x), h3(x), ... where h1, h2, h3 are heuristics to each of the nearby spots.
Machine Intelligence
Choice of a Heuristic

Let’s consider a 2D Grid having several obstacles and starting from a


source cell (coloured red below) to reach towards a goal cell
(coloured green below)
Machine Intelligence
Choice of a Heuristic - Manhattan Distance

It is the sum of absolute values of differences in the goal’s x and y


coordinates and the current cell’s x and y coordinates respectively, i.e.,

h = abs (current_cell.x – goal.x) + abs (current_cell.y – goal.y)


Machine Intelligence
Choice of a Heuristic - Diagonal Distance

It is the maximum of absolute values of differences in the goal’s x and y


coordinates and the current cell’s x and y coordinates respectively, i.e.,
dx = abs(current_cell.x – goal.x)
dy = abs(current_cell.y – goal.y)

h = D * (dx + dy) + (D2 - 2 * D) * min(dx, dy)

where D is length of each node(usually = 1) and D2 is diagonal distance


between each node (usually = sqrt(2) ).
Machine Intelligence
Choice of a Heuristic - Euclidean Distance

It is the distance between the current cell and the goal cell using the
distance formula

h = sqrt ( (current_cell.x – goal.x)2 + (current_cell.y – goal.y)2 )


Machine Intelligence
A* Search

Use the A* algorithm to find the shortest path from A to F.


Machine Intelligence
A* Search

Use the A* algorithm to find the shortest path from A to J.


THANK YOU

Nishtha Varshney
Department of Computer Science & Engineering
[email protected]

You might also like