Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search...

49
Informed Search Reading: Chapter 4.5

Transcript of Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search...

Page 1: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

Informed Search

Reading: Chapter 4.5

Page 2: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

2

Agenda

Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search

Algorithm, admissable heuristics, optimality

Heuristics for other problems Homework

Page 3: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

3

8-puzzle URLS

http://www.permadi.com/java/puzzle8

http://www.cs.rmit.edu.au/AI-Search/Product

Page 4: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

4

Page 5: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

5

Breadth first Algorithm

Page 6: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

6

Page 7: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

7

Page 8: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

8

Page 9: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

9

Page 10: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

10

Depth-first Algorithm

Page 11: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

11

Page 12: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

12

Page 13: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

13

Page 14: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

14

Page 15: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

15

Page 16: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

16

Page 17: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

17

Page 18: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

18

Page 19: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

19

Heuristics

Suppose 8-puzzle off by one

Is there a way to choose the best move next?

Good news: Yes! We can use domain knowledge or

heuristic to choose the best move

Page 20: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

20

0 1 2

3 4 5

6 7

Page 21: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

21

Nature of heuristics

Domain knowledge: some knowledge about the game, the problem to choose

Heuristic: a guess about which is best, not exact

Heuristic function, h(n): estimate the distance from current node to goal

Page 22: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

22

Heuristic for the 8-puzzle

# tiles out of place (h1)

Manhattan distance (h2) Sum of the distance of each tile from its

goal position Tiles can only move up or down city

blocks

Page 23: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

23

0 1 2

3 4 5

6 7

0 1 2

3 4 5

6 7

0 2 5

3 1 7

6 4

Goal State

h1=1h2=1

h1=5h2=1+1+1+2+2=7

Page 24: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

24

Best first searches

A class of search functions Choose the “best” node to expand

next Use an evaluation function for each

node Estimate of desirability

Implementation: sort fringe, open in order of desirability

Today: greedy search, A* search

Page 25: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

25

Greedy search

Evaluation function = heuristic function

Expand the node that appears to be closest to the goal

Page 26: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

26

Greedy Search OPEN = start node; CLOSED = empty While OPEN is not empty do

Remove leftmost state from OPEN, call it X

If X = goal state, return success Put X on CLOSED

SUCCESSORS = Successor function (X) Remove any successors on OPEN or CLOSED Compute f=heuristic function for each node Put remaining successors on either end of OPEN Sort nodes on OPEN by value of heuristic function

End while

Page 27: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

27

8-puzzle URLS

http://www.permadi.com/java/puzzle8

http://www.cs.rmit.edu.au/AI-Search/Product

Page 28: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

28

Sodoku

Page 29: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

29

Page 30: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

30

Analysis of Greedy Search

Like depth-first

Not Optimal

Complete if space is finite

Page 31: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

31

A* Search

Try to expand node that is on least cost path to goal Evaluation function = f(n)

f(n)=g(n)+h(n) h(n) is heuristic function: cost from node to goal g(n) is cost from initial state to node

f(n) is the estimated cost of cheapest solution that passes through n

If h(n) is an underestimate of true cost to goal A* is complete A* is optimal A* is optimally efficient: no other algorithm using h(n) is

guaranteed to expand fewer states

Page 32: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

32

A* Search OPEN = start node; CLOSED = empty While OPEN is not empty do

Remove leftmost state from OPEN, call it X

If X = goal state, return success Put X on CLOSED

SUCCESSORS = Successor function (X) Remove any successors on OPEN or CLOSED Compute f(n)= g(n) + h(n) Put remaining successors on either end of OPEN Sort nodes on OPEN by value of heuristic function

End while

Page 33: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

33

8-puzzle URLS

http://www.permadi.com/java/puzzle8

http://www.cs.rmit.edu.au/AI-Search/Product

Page 34: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

34

Page 35: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

35

Page 36: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

36

Page 37: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

37

Admissable heuristics

A heuristic that never overestimates the cost to the goal

h1 and h2 for the 8 puzzle are admissable heuristics

Consistency: the estimated cost of reaching the goal from n is no greater than the step cost of getting to n’ plus estimated cost to goal from n’

h(n) <=c(n,a,n’)+h(n’)

Page 38: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

38

Which heuristic is better?

Better means that fewer nodes will be expanded in searches

h2 dominates h1 if h2 >= h1 for every node n

Intuitively, if both are underestimates, then h2 is more accurate

Using a more informed heuristic is guaranteed to expand fewer nodes of the search space

Which heuristic is better for the 8-puzzle?

Page 39: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

39

Page 40: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

40

Page 41: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

41

Relaxed Problems

Admissable heuristics can be derived from the exact solution cost of a relaxed version of the problem

If the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then h1 gives the shortest solution

If the rules are relaxed so that a tile can move to any adjacent square, then h2 gives the shortest solution

Key: the optimal solution cost of a relaxed problem is no greater than the optimal solution cost of the real problem.

Page 42: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

42

Heuristics for other problems

Problems

Shortest path from one city to another

Touring problem: visit every city exactly once

Challenge: Is there an admissable heuristic for sodoku?

Page 43: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

43

End of Class Questions

Page 44: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

44

Homework

Page 45: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

45

Homework

Page 46: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

46

Fill-In Station

Page 47: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

47

Language Models

Knowledge about what letters in words are most frequent

Based on a sample of language What is the probability that A is the first letter Having seen A, what do we predict is the next

letter?

Tune our language model to a situation 3 letter words only Medical vocabulary Newspaper text

Page 48: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

48

Formulation

Left-right, top-down as path

Choose a letter at a time

Heuristic: Based on language model Cost of choosing letter A first = 1 – probability of A

next Subtract subsequent probabilities

Successor function: Choose next best letter, if 3rd in a row, is it a word?

Goal test?

Page 49: Informed Search Reading: Chapter 4.5. 2 Agenda Introduction of heuristic search Greedy search Examples: 8 puzzle, word puzzle A* search Algorithm, admissable.

49

How does heuristic help us get there?