0% found this document useful (0 votes)
17 views41 pages

BIM309 AI Week5a

Uploaded by

gtuguz
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
0% found this document useful (0 votes)
17 views41 pages

BIM309 AI Week5a

Uploaded by

gtuguz
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/ 41

22.10.

2024

BIM309 Artificial Intelligence


Week 5 – Search Agents & Informed (Heuristic) Search

Outline

§ Heuristic Search

§ Greedy Search Algorithms

§ A* Search and Optimality

§ Recap of Search Algorithms

1
22.10.2024

Informed Search
Basic Idea: Beyond the definition of the problem itself use domain knowledge!
we may have about the problem to guide the search
§ Are we getting close to the goal?
§ What if we know something about the search?
§ How should we include that knowledge?
§ In what form should it be expressed to be useful?
§ Use a heuristic function that estimates how close a state is to the goal
§ A heuristic is designed for a particular search problem
§ Problem specific (hence informed)
§ Example: Manhattan distance, Euclidean distance for pathing
§ A heuristic does NOT have to be perfect!
§ Example of informed search strategies:
1. Greedy best-first search
2. A* search
3. IDA*

Example Heuristic: Straight Line Distance (SLD)


Heuristic!
Straigh-Line Distance
to Bucharest
Arad 366
Heuristic functions Bucharest
Craiova
0
160

§ Most common form for Drobeta


Eforie
Fagaras
242
161
176
additional knowledge of the Giurgiu 77
Hirsova 151
problem is imparted to the Iasi
Lugoj
226
244
search algorithm Mehadia
Neamt
241
234
Oradea 380
§ Considered as arbitrary, Pitesti 100
Rimnicu Vilcea 193
nonnegative, problem-specific Sibiu
Timisoara
253
329
functions, with one constraint: Urziceni
Valui
80
199
if n is a goal node, then h(n) = 0 Zerind 374

§ Cannot be computed from the


problem description itself Straight- line distance heuristic can be used for route-finding
problem in Romania. The goal is to get Bucharest, so all the
distances are from each city to Bucharest - h(In(Arad))=366
4

2
22.10.2024

Greedy Best-First Search


n1 n2

h1(n)
§ Evaluation function h(n) (heuristic)
goal h2(n)
§ h(n) = estimates the cost from n to the closest goal
§ Example: ℎ!"# (𝑛) = straight-line distance from n to Bucharest

§ Greedy search expands the node that appears to be closest to goal


§ Keep nodes on a priority queue sorted by their heuristic value only
§ Priority queue sort function = h(n)

§ Compute heuristic function h(n) when a node is placed in the frontier


§ Expand the node that appears to be closest to the goal

Greedy Best-First Search

3
22.10.2024

Example:
Greedy Best-First Search
(a) The initial state Nodes are labeled
with their h-values

Example:
Greedy Best-First Search
(b) After expanding Arad

4
22.10.2024

Example:
Greedy Best-First Search
(c) After expanding Sibiu

Example:
Greedy Best-First Search
(d) After expanding Fagaras

Path: Arad à Sibiu à Fagaras à Bucharest

140 + 99 + 211 = 450

10

5
22.10.2024

Order of node expansion: S A D S A D S A D. . .


Path found none, Cost of path found none

Greedy Search Criteria


§ Complete No
§ Tree version can get stuck in loops
§ Graph version is complete in finite spaces with
repeated-state checking
§ Time 𝑂(𝑏 ! )
§ But a good heuristic can give dramatic improvement
§ Space 𝑂(𝑏 ! )
§ Keeps all nodes in memory
§ Optimal No
§ E.g., “Arad à Sibiu à Rimnicu Vilcea à Pitesti à
Bucharest” is shorter!

11

A* Search g(n)

n
§ Minimize the total estimated solution cost h(n)
§ Use a heuristic, but consider the path cost for each node goal
§ Optimal if heuristic is admissible (tree search)/consistent (graph search)
§ Combines:
ü g(n): cost to reach node n
ü h(n): cost to get from n to the goal
ü f(n) = g(n) + h(n) ß Evaluation Function

g(n) gives the path cost from the start node to node n, and
h(n) is the estimated cost of the cheapest path from n to the goal, so
f(n) is the estimated cost of the cheapest solution through n

12

6
22.10.2024

A* Search

13

Example: Frontier Queue

A* Search Arad 366

(a) The initial state

Nodes are labeled


with f=g+h

14

7
22.10.2024

Example: Frontier Queue

A* Search Sibiu 393


Timisoara 447
Zerind 449
(b) After expanding Arad

16

Example: Frontier Queue


Rimnicu Vilcea 413
A* Search Fagaras 415
Timisoara 447
(c) After expanding Sibiu Zerind 449
Oradea 671

393=140+253

17

8
22.10.2024

Example: Frontier Queue


Fagaras 415
A* Search Pitesti 417
Timisoara 447
(d) After expanding Rimnicu Vilcea Zerind 449
Craiova 526
Oradea 671

413=220+193

18

Example:
A* Search
(e) After expanding Fagaras

415=239+176 Frontier Queue


Pitesti 417
Timisoara 447
Zerind 449
Bucharest 450
Craiova 526
Oradea 671

19

9
22.10.2024

Example: Frontier Queue


Bucharest 418
A* Search Timisoara 447
Zerind 449
(f) After expanding Pitesti Craiova 526
Rim. Vilcea 607
Oradea 671

417=317+100

20

Admissible Heuristics

A good heuristic can be powerful.

Only if it is of a “good quality”

A good heuristic must be admissible

21

10
22.10.2024

Admissible Heuristics
§ An admissible heuristic never overestimates the cost to reach the
goal, that is, it is optimistic
§ A heuristic h is admissible if
∀ 𝑛𝑜𝑑𝑒 𝑛, ℎ 𝑛 ≤ ℎ∗ (𝑛)
where 𝒉∗ is true cost to reach the goal from n
§ Example
ℎ"#$ (used as a heuristic in the map example) is admissible, because
it is by definition the shortest distance between two points
§ Never overestimates the actual road distance

22

A* Search Criteria
§ Complete Yes
§ Time exponential (depends on heuristic)
§ Space Keeps every node in memory (the biggest problem)
§ Optimal Yes

23

11
22.10.2024

Example: Admissible Heuristics for the 8-


puzzle
§ The solution is 26 steps long
§ ℎ% (𝑛) = number of misplaced tiles
§ ℎ& (𝑛) = total Manhattan distance
(i.e., no. of squares from desired
location of each tile - sum of the
horizontal and vertical distances)

§ 𝒉𝟏 (𝒏) = ??
§ 𝒉𝟐 (𝒏) = ??

24

Example: Admissible Heuristics for the 8-


puzzle
§ The solution is 26 steps long
§ ℎ% (𝑛) = number of misplaced tiles
§ ℎ& (𝑛) = total Manhattan distance
(i.e., no. of squares from desired
location of each tile - sum of the
horizontal and vertical distances)

§ 𝒉𝟏 (𝑺) = 8
§ 𝒉𝟐 (𝑺) = Tiles 1 to 8 in the start state gives:
𝒉𝟐 (𝑺) = 3+1+2+2+2+3+3+2 = 18
which does not overestimate the true solution

25

12
22.10.2024

Search Algorithms: Recap


§ Uninformed Search: Use no domain knowledge
BFS, DFS, DLS, IDS, UCS

§ Informed Search: Use a heuristic function that estimates how close a


state is to the goal
Greedy search, A*, IDA*

27

DFS

28

13
22.10.2024

DFS

29

DFS

30

14
22.10.2024

DFS

31

DFS

32

15
22.10.2024

DFS

33

DFS

34

16
22.10.2024

DFS

35

DFS

36

17
22.10.2024

IDS

37

IDS

38

18
22.10.2024

IDS

39

IDS

40

19
22.10.2024

IDS

41

IDS

42

20
22.10.2024

IDS

43

IDS

44

21
22.10.2024

IDS

45

IDS

46

22
22.10.2024

IDS

47

IDS

48

23
22.10.2024

IDS

49

IDS

50

24
22.10.2024

BFS

51

BFS

52

25
22.10.2024

BFS

53

BFS

54

26
22.10.2024

BFS

55

BFS

56

27
22.10.2024

BFS

57

BFS

58

28
22.10.2024

BFS

59

BFS

60

29
22.10.2024

BFS

61

BFS

62

30
22.10.2024

BFS

63

UCS

64

31
22.10.2024

UCS

65

UCS

66

32
22.10.2024

UCS

67

UCS

68

33
22.10.2024

UCS

69

UCS

70

34
22.10.2024

UCS

71

UCS

72

35
22.10.2024

UCS

73

UCS

74

36
22.10.2024

UCS

75

UCS

76

37
22.10.2024

UCS

77

UCS

78

38
22.10.2024

Recap
We can organize the algorithms into pairs where the first proceeds by
layers, and the other proceeds by subtrees

(1) Iterate on Node Depth:


§ BFS searches layers of increasing node depth
§ IDS searches subtrees of increasing node depth

(2) Iterate on Path Cost + Heuristic Function:


§ A* searches layers of increasing path cost + heuristic function
§ IDA* searches subtrees of increasing path cost + heuristic function

79

Recap
Which cost function?

§ UCS searches layers of increasing path cost - g

§ Greedy best first search searches layers of increasing heuristic function - h

§ A* search searches layers of increasing path cost + heuristic function

f = g + h
the path from the the estimated costs from
root to the node the node to the goal

80

39
22.10.2024

Summary
§ Before an agent can start searching for solutions, a goal must be identified
and a well-defined problem must be formulated
§ A problem consists of five parts:
§ the initial state
§ a set of actions
§ a transition model describing the results of those actions
§ a goal test function
§ a path cost function
§ The environment of the problem is represented by a state space
§ A path through the state space from the initial state to a goal state is a solution
§ Search algorithms treat states and actions as atomic: they do not consider
any internal structure they might possess
§ A general TREE-SEARCH algorithm considers all possible paths to find a
solution, whereas a GRAPH-SEARCH algorithm avoids consideration of
redundant paths

81

Summary
§ Search algorithms are judged on the basis of completeness, optimality, time
complexity, and space complexity
§ Complexity depends on b - the branching factor in the state space, and d - the depth of
the shallowest solution
§ Uninformed search methods have access only to the problem definition
§ Breadth-first search (BFS) expands the shallowest nodes first; it is complete, optimal
for unit step costs, but has exponential space complexity
§ Uniform-cost search (UCS) expands the node with lowest path cost, g(n), and is
optimal for general step costs
§ Depth-first search (DFS) expands the deepest unexpanded node first, neither
complete nor optimal, but has linear space complexity
§ Depth-limited search (DLS) adds a depth bound
§ Iterative deepening search (IDS) calls depth-first search with increasing depth limits
until a goal is found. It is complete, optimal for unit step costs, has time complexity
comparable to breadth-first search, and has linear space complexity
§ Bidirectional search can enormously reduce time complexity, but it is not always
applicable and may require too much space
82

40
22.10.2024

Summary
§ Informed search methods may have access to a heuristic function h(n)
that estimates the cost of a solution from n
§ The generic best-first search algorithm selects a node for expansion according
to an evaluation function
§ Greedy best-first search expands nodes with minimal h(n)
§ It is not optimal but is often efficient
§ A∗ search expands nodes with minimal f(n) = g(n) + h(n)
§ A∗ is complete and optimal, provided that h(n) is admissible (for TREE-SEARCH) or
consistent (for GRAPH-SEARCH)
§ The space complexity of A∗ is still prohibitive
§ The performance of heuristic search algorithms depends on the quality
of the heuristic function

83

41

You might also like