Heuristic in AI (Rule of thumb) [what, why, how] What: Mental shortcuts that ease the cognitive load of making a decision. Why: Solve problems and speed up our decision-making process How: Eucledian Distance, Manhattan Distance, etc

abihanaqvi8 6 views 55 slides Sep 01, 2025
Slide 1
Slide 1 of 55
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55

About This Presentation

Estimated cost (or distance) of minimal cost path from start to a goal state.
h(n) → a heuristic function
Purpose of heuristic function is to guide the search process in the most profitable path among all that are available


Slide Content

Intelligent Systems Course No. CS 6109 / CE 7205

Objective Introduction Informed Search Strategies Heuristic Search & Function Greedy best-first search A* search

Introduction Search with domain knowledge. Uninformed (blind) searches are normally very inefficient. Why?????? Adding domain knowledge can improve the search process. Heuristic Search Greedy Best-First Search A* Search

Informed methods add domain-specific information Estimated cost (or distance) of minimal cost path from start to a goal state. h(n) → a heuristic function Purpose of heuristic function is to guide the search process in the most profitable path among all that are available

Heuristic Solution Heuristic in AI (Rule of thumb) [what, why, how] What : Mental shortcuts that ease the cognitive load of making a decision. Why : Solve problems and speed up our decision-making process How: Eucledian Distance, Manhattan Distance, etc It is a provide the Good Solution. But not provides the guarantee of the optimal solution .

Eucledian Distance Calculate Distance using Pythagoras theorem. X-Axis Y-Axis (x 1 ,y 1 ) (x 2 ,y 2 ) A B C AC 2 = AB 2 + BC 2 AC = AB 2 + BC 2 AC = (x 2 -x 1 ) 2 + (y 2 -y 1 ) 2 x 1 x 2 y 1 y 2

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1 2 1

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1 2 3 1 1

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1 2 3 4 1 1 2

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1 2 3 4 5 1 1 2

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1 2 3 4 5 6 1 1 2 2

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1 2 3 4 5 6 7 1 1 2 2 2

Manhattan Distance Taking 8–Puzzle Problem 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Start State Goal 1 2 3 4 5 6 7 8 1 1 2 2 2 Manhattan Distance: 0+1+1+2+0+2+2+0 = 8

Manhattan Distance Method 1 Calculate MD value 1 3 2 6 5 4 8 7 Start State Goal 1 3 2 5 4 6 8 7 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Move UP: 0+1+1+2+0+3+2+0 = 9 Move Right: 0+1+1+2+0+2+2+1 = 9

Manhattan Distance Method 2 Calculate Misplaced Tile 1 3 2 6 5 4 8 7 Start State Goal 1 3 2 5 4 6 8 7 1 3 2 6 5 4 8 7 1 2 3 4 5 6 7 8 Move UP: 0+1+1+1+0+1+1+0 = 5 Move Right: 0+1+1+1+0+1+1+1 = 6

8-Puzzle Problem with Heuristic 1 2 3 4 6 7 5 8 1 2 3 7 4 6 5 8 1 2 3 4 6 7 5 8 1 2 3 4 6 7 5 8 2 3 1 4 6 7 5 8 1 2 3 4 6 7 5 8 1 2 3 4 5 6 7 8 Start State Goal Move UP h=4 Move Down h=4 Move Right h =2 Move Left (NA) h =Nil Initial h=3

8-Puzzle Problem with Heuristic 1 2 3 4 6 7 5 8 1 2 3 4 5 6 7 8 1 2 3 4 6 7 5 8 1 2 3 4 6 7 5 8 1 3 4 2 6 7 5 8 1 2 3 4 6 7 5 8 1 2 3 4 5 6 7 8 Start State Goal Move UP h=3 Move Down h=1 Move Right h =3 Move Left h =3 Previous h=2

8-Puzzle Problem with Heuristic 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 6 7 5 8 1 2 3 4 6 7 5 8 1 2 3 4 5 6 7 8 Start State Goal Move UP h=2 Move Down (NA) h=Nil Move Right h =0 Move Left h =1 Previous h=1 1 2 3 4 5 6 7 8

Heuristic Search - Characteristics Has some domain knowledge Usually more efficient than blind searches Also called informed search Heuristic searches work by deciding which is the next best node to expand (there is no guarantee that it is the best node)

Greedy Best-First Search Greedy best-first search algorithm always selects the path which appears best at that moment. It is the combination of depth-first search and breadth-first search algorithms. It uses the heuristic function and search. Best-first search allows us to take the advantages of both algorithms .

Greedy Best-First Search Expand the node with the lowest expected cost. Not always guaranteed to find an optimal solution . Behaves like DFS: follows to depth paths that look promising. Advantage : moves quickly towards the goal. Disadvantage : can get stuck in deep paths.

GBS – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes Node H(n) Closed List Open List

GBS – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes Node S H(n) 7 Closed List Open List Distance:

GBS – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 Node A B H(n) 9 8 Closed List Open List Distance:

GBS – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 Node A B H(n) 9 8 Closed List Open List Distance:

GBS – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 B/8 Node A C G H(n) 9 5 Closed List Open List Distance: 1 +

GBS – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 B/8 Node A C G H(n) 9 5 Closed List Open List Distance: 1 +

GBS – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 B/8 G/0 Node A C H(n) 9 5 Closed List Open List Distance: 1 + 12 = 13

GBS – Exampl e 2

A* Search A * algorithm is a searching algorithm that searches for the shortest path between the initial and the final state. f(n) =g(n) + h(n) g(n) = Actual cost from Start node to n node h(n) = Estimation Cost from n to Goal node. Time complexity = O(Node + Edges) = O(b d ) Space complexity = O(b d )

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes Nodes S h(n) 7 g(n) f(n) 7 Closed List Open List F(n) = g(n) + h(n) F(S) = 0 + 7 = 7 For Node S, g(n)= 0 h(n)=7

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 Nodes S h(n) 7 g(n) f(n) 7 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 Nodes SA SB h(n) g(n) f(n) Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 Nodes SA SB h(n) 9 g(n) 1 f(n) 10 Closed List Open List F(n) = g(n) + h(n) F(A) = 1 + 9 = 10 For Node A, g(n)=1 h(n)=9

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 Nodes SA SB h(n) 9 g(n) 1 f(n) 10 Closed List Open List F(n) = g(n) + h(n) F(A) = 1 + 9 = 10 For Node A, g(n)=1 h(n)=9

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 Nodes SA SB h(n) 9 8 g(n) 1 1 f(n) 10 9 Closed List Open List F(n) = g(n) + h(n) F(B) = 1 + 8 = 9 For Node B, g(n)=1 h(n)=8

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 Nodes SA SB h(n) 9 8 g(n) 1 1 f(n) 10 9 Closed List Open List F(n) = g(n) + h(n) F(B) = 1 + 8 = 9 For Node B, g(n)=1 h(n)=8

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 Nodes SA SBC SBG h(n) 9 g(n) 1 f(n) 10 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 Nodes SA SBC SBG h(n) 9 5 g(n) 1 1+6 f(n) 10 12 Closed List Open List F(n) = g(n) + h(n) F(C) = 1 + 6 + 5 = 12 For Node C, g(n)=1+6 h(n)=5

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 Nodes SA SBC SBG h(n) 9 5 g(n) 1 1+6 1+12 f(n) 10 12 13 Closed List Open List F(n) = g(n) + h(n) F(G) = 1 + 12 + 0 = 13 For Node G, g(n)=1+6 h(n)=0

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 Nodes SA SBC SBG h(n) 9 5 g(n) 1 1+6 1+12 f(n) 10 12 13 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 Nodes SBC SBG SAB h(n) 5 g(n) 1+6 1+12 f(n) 12 13 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 Nodes SBC SBG SAB h(n) 5 8 g(n) 1+6 1+12 1+9 f(n) 12 13 18 Closed List Open List F(n) = g(n) + h(n) F(G) = 1 + 9 + 8 = 18 For Node B, g(n)=1+9 h(n)=8

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 SBC/12 Nodes SBC SBG SAB h(n) 5 8 g(n) 1+6 1+12 1+9 f(n) 12 13 18 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 SBC/12 Nodes SBG SAB h(n) 8 g(n) 1+12 1+9 f(n) 13 18 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 SBC/12 Nodes SBG SAB SBCG h(n) 8 g(n) 1+12 1+9 f(n) 13 18 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 SBC/12 Nodes SBG SAB SBCG h(n) 8 g(n) 1+12 1+9 1+6+5 f(n) 13 18 12 Closed List Open List F(n) = g(n) + h(n) F(G) = 1 + 6 + 5 = 12 For Node G, g(n)=1+6+5 h(n)=0

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 SBC/12 SBCG/12 Nodes SBG SAB SBCG h(n) 8 g(n) 1+12 1+9 1+6+5 f(n) 13 18 12 Closed List Open List F(n) = g(n) + h(n) F(G) = 1 + 6 + 5 = 12 For Node G, g(n)=1+6+5 h(n)=0

A* – Exampl e 1 Path H(n) Cost S->A 7 1 S->B 7 1 A->B 9 9 B->C 8 6 B->G 8 12 C->G 5 5 S/7 B/8 A/9 C/5 G/0 1 1 9 12 6 5 Nodes S/7 SB/9 SA/10 SBC/12 SBCG12 Nodes SBG SAB h(n) 8 g(n) 1+12 1+9 f(n) 13 18 Closed List Open List F(n) = g(n) + h(n) . .

A* – Exampl e 2

Summary Greedy search: Estimated cost of reaching goal from current state – Heuristic evaluation functions, h(n). A* search: f(n) = g(n) + h(n). A* uses both backward costs and (estimates of) forward costs. Admissibility: h(n)never overestimates the actual cost of getting to the goal state.

Query Regarding Lecture Email: [email protected]

Thanks Email: [email protected]