0% found this document useful (0 votes)
12 views48 pages

Unit 5 - Informed Search

The document discusses various search algorithms used in artificial intelligence including uninformed and informed searches. It provides details on uniform cost search, heuristics, best first search, and A* search. Examples are given to illustrate how these algorithms work on problems like the 8 puzzle and finding routes on a map.

Uploaded by

simoncowelliam
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)
12 views48 pages

Unit 5 - Informed Search

The document discusses various search algorithms used in artificial intelligence including uninformed and informed searches. It provides details on uniform cost search, heuristics, best first search, and A* search. Examples are given to illustrate how these algorithms work on problems like the 8 puzzle and finding routes on a map.

Uploaded by

simoncowelliam
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/ 48

INTRODUCTION TO

ARTIFICIAL
INTELLIGENCE
Unit 5
05/06/2024 Spring' 2024 2

Outline
• Uninformed Search
• Uniform Cost Search
• Informed Search
• Introduction
• Heuristics
• Best First Greedy Search
• A* Search
05/06/2024 Spring' 2024 3

Acknowledgment
• Some of the slides of this lecture have been taken from:
• The lecture slides of CS188 – “Introduction to Artificial Intelligence”
UC Berkeley
05/06/2024 Spring' 2024 4

Uniform Cost Search UCS


• Uniform-cost search is a searching algorithm used for traversing
a weighted tree or graph. This algorithm comes into play when a
different cost is available for each edge. The primary goal of
the uniform-cost search is to find a path to the goal node which
has the lowest cumulative cost.

• UCS can be applied to find the least-cost path through a graph by


maintaining an ordered list / priority list of nodes in order of
descending cost.

• Uniform-cost search is an uninformed search method because no


heuristic is actually used.

• The algorithm measures the actual cost of the path without


attempting to estimate it.
05/06/2024 Spring' 2024 5

Uniform Cost Search


05/06/2024 Spring' 2024 6
05/06/2024 Spring' 2024 7
05/06/2024 Spring' 2024 8
05/06/2024 Spring' 2024 9
05/06/2024 Spring' 2024 10
05/06/2024 Spring' 2024 11
05/06/2024 Spring' 2024 12
05/06/2024 Spring' 2024 13
05/06/2024 Spring' 2024 14
05/06/2024 Spring' 2024 15
05/06/2024 Spring' 2024 16
05/06/2024 Spring' 2024 17

Example Graph
05/06/2024 Spring' 2024 18

UCS Algorithm
05/06/2024 Spring' 2024 19

UCS Example

• It is important to note in this example that the USC does not stop
until the goal node is the top most node of the list. Which means
that we have found the optimal path.
05/06/2024 Spring' 2024 20

UCS Properties

• What nodes does UCS expand?


• Processes all nodes with cost less than cheapest solution!
• If that solution costs C* and arcs cost at least  , then the “effective
depth” is roughly C*/
• Takes time O(bC*/) (exponential in effective depth)

• How much space does the fringe take?


• Has roughly the last tier, so O(bC*/)

• Is it complete?
• Assuming best solution has a finite cost and minimum arc cost is
positive, yes!

• Is it optimal?
05/06/2024 Spring' 2024 21

Romania, use UCS


05/06/2024 Spring' 2024 22

Informed Searches
05/06/2024 Spring' 2024 23

Informed vs. Uniformed Search


• A search method or heuristic is informed if it
uses additional information about nodes that
have not yet been explored to decide which
nodes to examine next.

• If a method is not informed, it is uninformed or


blind.

• The more informed a search method is, the more


efficiently it will search.
05/06/2024 Spring' 2024 24

The 8-puzzle
• The puzzle consists of a 3 x 3 grid, with the
numbers 1 through 8 on tiles within the grid and
one blank square.
• Tiles can be slid about within the grid, but a tile
can only be moved into the empty square if it is
adjacent to the empty square.
• The start state of the puzzle is a random
configuration, and the goal state is as shown in
the picture below.

Goal State
05/06/2024 Spring' 2024 25

Heuristic Function
• Heuristic is an “estimate of the proximity of the goal”.

• A heuristic is a rule of thumb that may help solve a given


problem. Heuristics take problem knowledge into
consideration to help guide the search within the domain.

• A heuristic evaluation function is a function that when


applied to a node gives a value that represents a good
estimate of the distance of the node from the goal.

• For two nodes m and n, and a heuristic function f, if f(m) <


f(n), then it should be the case that m is more likely to be
on an optimal path to the goal node than n.
05/06/2024 Spring' 2024 26

Heuristics
( Source: Wikipedia)
• Heuristic refers to experience-based techniques for
problem solving, learning, and discovery.

• Heuristic methods are used to speed up the process


of finding a good enough solution, where an
exhaustive search is impractical. Examples of this
method include using a "rule of thumb", an educated
guess, an intuitive judgment, or common sense.
05/06/2024 Spring' 2024 27

Basic Idea Behind a Heuristic Search


• We assume that we have a heuristic (evaluation)
function, f, to help decide which node is the
best one to expand next. This function is based
on information specific to the problem domain.

• Expand next node, n, having the smallest value of


f(n). Resolve ties arbitrarily.

• Terminate when the node to be expanded next is


a goal node.
05/06/2024 Spring' 2024 28

Heuristic # 1
• The first heuristic we consider is to count
how many tiles are in the wrong place.
We will call this heuristic, h1(node).

• In the case of the first state shown in


Figure, h1 (node) = 8 because all the
tiles are in the wrong place.

• However, this is misleading because we


could imagine a state with a heuristic
value of 8 but where each tile could be
moved to its correct place in one move.
05/06/2024 Spring' 2024 29

Heuristic # 2
• An improved heuristic, h2, takes into account
how far each tile had to move to get to its correct
state.
• This is achieved by summing the Manhattan
distances of each tile from its correct position.
• Manhattan distance is the sum of the horizontal
and vertical moves that need to be made to get
from one position to another, named after the
grid system of roads used in Manhattan.
• h2 (node) = 2 + 2 + 2 + 2 + 3 + 3 + 1 + 3 = 18
• It is worth noting that h2 (node) ≥ h1 (node) for
any node. This means that h2 dominates h1,
implying that a search method using heuristic h2
will always perform more efficiently than the
same search method using h1.
05/06/2024 Spring' 2024 30

Best-first search
• Best-first search expands the node that appears to be
closest to goal
• Evaluation function f(n) = h(n) (heuristic)
• = estimate of cost from n to goal
05/06/2024 Spring' 2024 31

Best-first Search
(Using Heuristic # 1)

Goal State
05/06/2024 Spring' 2024 32

Best-first Search
(Using Heuristic # 2)
2 8 3
1 6 4
7 5
Goal State

• Expand the tree


05/06/2024 Spring' 2024 33

Romania with step costs in km (Russell &


Norvig)
05/06/2024 Spring' 2024 34

Best-first search example


05/06/2024 Spring' 2024 35

Best-first search example


05/06/2024 Spring' 2024 36

Best-first search example


05/06/2024 Spring' 2024 37

Best-first search example


05/06/2024 Spring' 2024 38

A* search
Idea: avoid expanding paths that are already expensive
• Evaluation function f(n) = g(n) + h(n)
• g(n) = cost so far to reach n
• h(n) = estimated cost from n to goal
• f(n) = estimated total cost of path through n to goal
05/06/2024 Spring' 2024 39

Romania with step costs in km


(Russell & Norvig)
05/06/2024 Spring' 2024 40

A* search example
05/06/2024 Spring' 2024 41

A* search example
05/06/2024 Spring' 2024 42

A* search example
05/06/2024 Spring' 2024 43

A* search example
05/06/2024 Spring' 2024 44

A* search example
05/06/2024 Spring' 2024 45

A* search example
05/06/2024 Spring' 2024 46

Combining UCS and Greedy


• Uniform-cost orders by path cost, or backward cost
g(n)
• Greedy orders by goal proximity, or forward cost
h(n) 8

e h=1
1
1 3 2
S a d G
h=6 1 h=5 h=2 h=0
1
c b
h=7 h=6

• A* Search orders by the sum: f(n) = g(n) + h(n)


05/06/2024 Spring' 2024 47

Admissibility of a heuristic
• A heuristic h is admissible (optimistic) if:

where is the true cost to a nearest goal

• Example:

• Coming up with admissible heuristics is most of what’s


involved in using A* in practice.
05/06/2024 Spring' 2024 48

Playing with A* Heuristics

• The heuristic can be used to control A*’s behavior.


• If h(n) is always ≤ the cost of moving from n to the goal, then A* is
guaranteed to find a shortest path. The lower h(n) is, the more node A*
expands, making it slower.

• If h(n) is exactly equal to the cost of moving from n to the goal, then A*
will only follow the best path and never expand anything else, making it
very fast. It’s nice to know that given perfect information, A* will behave
perfectly.

• If h(n) is sometimes ˃ the cost of moving from n to the goal, then A* is


not guaranteed to find a shortest path, but it can run faster.

• At the other extreme, if h(n) is very high relative to g(n), then


only h(n) plays a role, and A* turns into Best-First-Search.

You might also like