1 of 38

Introduction to Artificial Intelligence

By:

Dr. Mohammad Shoab

Week 4

2 of 38

Informed search

  • Idea: give the algorithm “hints” about the desirability of different states
    • Use an evaluation function to rank nodes and select the most promising one for expansion

  • Greedy best-first search
  • A* search

Introduction to Artificial Intelligence

Department of Computer Science

3 of 38

Heuristic function

  • Heuristic function h(n) estimates the cost of reaching goal from node n
  • Example:

Start state

Goal state

Introduction to Artificial Intelligence

Department of Computer Science

4 of 38

Heuristic for the Romania problem

Introduction to Artificial Intelligence

Department of Computer Science

5 of 38

Greedy best-first search

  • Expand the node that has the lowest value of the heuristic function h(n)

Introduction to Artificial Intelligence

Department of Computer Science

6 of 38

Greedy best-first search example

Introduction to Artificial Intelligence

Department of Computer Science

7 of 38

Greedy best-first search example

Introduction to Artificial Intelligence

Department of Computer Science

8 of 38

Greedy best-first search example

Introduction to Artificial Intelligence

Department of Computer Science

9 of 38

Greedy best-first search example

Introduction to Artificial Intelligence

Department of Computer Science

10 of 38

Properties of greedy best-first search

  • Complete?

No – can get stuck in loops

start

goal

Introduction to Artificial Intelligence

Department of Computer Science

11 of 38

Properties of greedy best-first search

  • Complete?

No – can get stuck in loops

  • Optimal?

No

Introduction to Artificial Intelligence

Department of Computer Science

12 of 38

Properties of greedy best-first search

  • Complete?

No – can get stuck in loops

  • Optimal?

No

  • Time?

Worst case: O(bm)

Best case: O(bd) – If h(n) is 100% accurate

  • Space?

Worst case: O(bm)

Introduction to Artificial Intelligence

Department of Computer Science

13 of 38

A* search

  • Idea: avoid expanding paths that are already expensive
  • The evaluation function f(n) is the estimated total cost of the path through node n to the goal:�

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

g(n): cost so far to reach n (path cost)

h(n): estimated cost from n to goal (heuristic)

Introduction to Artificial Intelligence

Department of Computer Science

14 of 38

A* search example

Introduction to Artificial Intelligence

Department of Computer Science

15 of 38

A* search example

Introduction to Artificial Intelligence

Department of Computer Science

16 of 38

A* search example

Introduction to Artificial Intelligence

Department of Computer Science

17 of 38

A* search example

Introduction to Artificial Intelligence

Department of Computer Science

18 of 38

A* search example

Introduction to Artificial Intelligence

Department of Computer Science

19 of 38

A* search example

Introduction to Artificial Intelligence

Department of Computer Science

20 of 38

Another example

Introduction to Artificial Intelligence

Department of Computer Science

21 of 38

Admissible heuristics

  • A heuristic h(n) is admissible if for every node n, �h(n) ≤ h*(n), where h*(n) is the true cost to reach �the goal state from n
  • An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimistic
  • Example: straight line distance never overestimates the actual road distance
  • Theorem: If h(n) is admissible, A* is optimal

Introduction to Artificial Intelligence

Department of Computer Science

22 of 38

Optimality of A*

  • Suppose A* terminates its search at n*
  • It has found a path whose actual cost f(n*) = g(n*) is lower than the estimated cost f(n) of any path going through any fringe node
  • Since f(n) is an optimistic estimate, there is no way n can have a successor goal state n’ with g(n’) < C*

n

n*

f(n*) = C*

f(n) > C*

n'

g(n') ≥ f(n) > C*

Introduction to Artificial Intelligence

Department of Computer Science

23 of 38

Optimality of A*

  • A* is optimally efficient – no other tree-based algorithm that uses the same heuristic can expand fewer nodes and still be guaranteed to find the optimal solution
    • Any algorithm that does not expand all nodes with f(n) < C* risks missing the optimal solution

Introduction to Artificial Intelligence

Department of Computer Science

24 of 38

Properties of A*

  • Complete?

Yes – unless there are infinitely many nodes with f(n) ≤ C*

  • Optimal?

Yes

  • Time?

Number of nodes for which f(n) ≤ C* (exponential)

  • Space?

Exponential

Introduction to Artificial Intelligence

Department of Computer Science

25 of 38

Designing heuristic functions

  • Heuristics for the 8-puzzle

h1(n) = number of misplaced tiles

h2(n) = total Manhattan distance (number of squares from desired location of each tile)�

h1(start) = 8

h2(start) = 3+1+2+2+2+3+3+2 = 18

  • Are h1 and h2 admissible?

Introduction to Artificial Intelligence

Department of Computer Science

26 of 38

Heuristics from relaxed problems

  • A problem with fewer restrictions on the actions is called a relaxed problem
  • The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem
  • If the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then h1(n) gives the shortest solution
  • If the rules are relaxed so that a tile can move to any adjacent square, then h2(n) gives the shortest solution

Introduction to Artificial Intelligence

Department of Computer Science

27 of 38

Heuristics from subproblems

  • Let h3(n) be the cost of getting a subset of tiles �(say, 1,2,3,4) into their correct positions
  • Can precompute and save the exact solution cost for every possible subproblem instance – pattern database

Introduction to Artificial Intelligence

Department of Computer Science

28 of 38

Dominance

  • If h1 and h2 are both admissible heuristics andh2(n) ≥ h1(n) for all n, (both admissible) then �h2 dominates h1
  • Which one is better for search?
    • A* search expands every node with f(n) < C* or�h(n) < C* – g(n)
    • Therefore, A* search with h1 will expand more nodes

Introduction to Artificial Intelligence

Department of Computer Science

29 of 38

Dominance

  • Typical search costs for the 8-puzzle (average number of nodes expanded for different solution depths):

  • d=12 IDS = 3,644,035 nodes� A*(h1) = 227 nodes � A*(h2) = 73 nodes

  • d=24 IDS ≈ 54,000,000,000 nodes � A*(h1) = 39,135 nodes � A*(h2) = 1,641 nodes

Introduction to Artificial Intelligence

Department of Computer Science

30 of 38

Combining heuristics

  • Suppose we have a collection of admissible heuristics h1(n), h2(n), …, hm(n), but none of them dominates the others
  • How can we combine them?

h(n) = max{h1(n), h2(n), …, hm(n)}

Introduction to Artificial Intelligence

Department of Computer Science

31 of 38

Weighted A* search

  • Idea: speed up search at the expense of optimality
  • Take an admissible heuristic, “inflate” it by a multiple α > 1, and then perform A* search as usual
  • Fewer nodes tend to get expanded, but the resulting solution may be suboptimal (its cost will be at most α times the cost of the optimal solution)

Introduction to Artificial Intelligence

Department of Computer Science

32 of 38

Example of weighted A* search

Heuristic: 5 * Euclidean distance from goal

Introduction to Artificial Intelligence

Department of Computer Science

33 of 38

Example of weighted A* search

Heuristic: 5 * Euclidean distance �from goal

Compare: Exact A*

Introduction to Artificial Intelligence

Department of Computer Science

34 of 38

Memory-bounded search

  • The memory usage of A* can still be exorbitant
  • How to make A* more memory-efficient while maintaining completeness and optimality?

  • Iterative deepening A* search
  • Recursive best-first search, SMA*
    • Forget some subtrees but remember the best f-value in these subtrees and regenerate them later if necessary

  • Problems: memory-bounded strategies can be complicated to implement, suffer from “thrashing”

Introduction to Artificial Intelligence

Department of Computer Science

35 of 38

The End

35

Introduction to Artificial Intelligence

Department of Computer Science

36 of 38

Exercise

Q1. What is informed search?

Q2. What is heuristic function?

Q3. Explain properties of greedy best first search.

Q4. Explain A* search.

Q5. What are admissible heuristics?

Q6. Explain memory bound search.

36

Introduction to Artificial Intelligence

Department of Computer Science

37 of 38

Q7. Which search use an evaluation function to rank nodes and select the most promising one for expansion?

  1. Iterative deepening search
  2. Uninformed search
  3. Informed Search
  4. None of the above

Q8. Which search algorithm expand the node that has the lowest value of the heuristic function h(n)?

  1. A* search
  2. Greedy Best First Search
  3. Percept
  4. None of the above

37

Introduction to Artificial Intelligence

Department of Computer Science

38 of 38

Q9. Which search algorithm avoid expanding paths that are already expensive?

  1. A* search
  2. Greedy Best First Search
  3. Percept
  4. None of the above

Q10. Which search algorithm speed up search at the expense of optimality?

  1. A* search
  2. Greedy Best First Search
  3. Weighted A* search
  4. None of the above

38

Introduction to Artificial Intelligence

Department of Computer Science