1 Heuristic Search Chapter 4. 2 Outline Heuristic function Greedy Best-first search Admissible...

53
1 Heuristic Search Heuristic Search Chapter 4

Transcript of 1 Heuristic Search Chapter 4. 2 Outline Heuristic function Greedy Best-first search Admissible...

1

Heuristic SearchHeuristic Search

Chapter 4

2

OutlineOutline

Heuristic function Greedy Best-first search Admissible heuristic and A* Properties of A* Algorithm IDA*

3

Heuristic Search

Heuristic: A rule of thumb generally based on expert experience, common sense to guide problem-solving process

In search, use a heuristic function that estimates how far we are from a goal.

How do we use heuristics?

4

Romania with step costs in km

5

Greedy best-first search example

6

Greedy best-first search example

7

Greedy best-first search example

8

Greedy best-first search example

9

Robot NavigationRobot Navigation

10

Robot NavigationRobot Navigation

0 211

58 7

7

3

4

7

6

7

6 3 2

8

6

45

23 3

36 5 24 43 5

54 6

5

6

4

5

f(N) = h(N), with h(N) = Manhattan distance to the goal

11

Properties of greedy best-first search

Complete? No – can get stuck in loops; Yes, if we can avoid repeated statesTime? O(bm), but a good heuristic can give dramatic improvementSpace? O(bm) -- keeps all nodes in memoryOptimal? No

12

A* SearchA* SearchA* search combines Uniform-cost and Greedy Best-first SearchEvaluation function: f(N) = g(N) + h(N) where: g(N) is the cost of the best path found so far

to N h(N) is an admissible heuristic f(N) is the estimated cost of cheapest solution

through N

0 < c(N,N’) (no negative cost steps).Order the nodes in the fringe in increasing values of f(N)

13

A* search example

14

A* search example

15

A* search example

16

A* search example

17

A* search example

18

A* search example

19

Admissible heuristicAdmissible heuristic

Let h*(N) be the cost of the optimal path from N to a goal node

Heuristic h(N) is admissible if:

0 h(N) h*(N)

An admissible heuristic is always optimistic

20

8-Puzzle8-Puzzle

1 2 3

4 5 6

7 8

12

3

4

5

67

8

N goal• h1(N) = number of misplaced tiles = 6 is admissible

• h2(N) = sum of distances of each tile to goal = 13 is admissible• What heuristics are overestimates?

21

Completeness & Optimality of Completeness & Optimality of A*A*

Claim: If there is a path from the initial to

a goal node, A* using TREE-SEARCH terminates by finding the best path, hence is: complete optimal

22

Optimality of A* (proof)

Suppose some suboptimal goal G2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G.

We can show f(n) < f(G2), so A* would not have selected G2.

23

Optimality of A* (proof)Cont’d:

f(G2) = g(G2) since h(G2) = 0

g(G2) > g(G) since G2 is suboptimal

f(G) = g(G) since h(G) = 0 f(G2) > f(G) from above

24

Optimality of A* (proof) Cont’d:

f(G2) > f(G) from above

h(n) ≤ h*(n) since h is admissibleg(n) + h(n) ≤ g(n) + h*(n) f(n) ≤ f(G)

Hence f(G2) > f(n), and A* will never select G2 for expansion

25

Exampel: Graph Search returns a suboptimal solution

h=7

2 15

4

h=6

h=1 h=0

S AB

G

h is admissible

26

Exampel: Graph Search returns a suboptimal solution

h=7

2 15

4

h=6

h=1 h=0

S AB

G

h is admissible

27

Exampel: Graph Search returns a suboptimal solution

h=7

2 15

4

h=6

h=1 h=0

S AB

G

h is admissible

28

Exampel: Graph Search returns a suboptimal solution

h=7

2 15

4

h=6

h=1 h=0

S AB

G

h is admissible

29

Exampel: Graph Search returns a suboptimal solution

h=7

2 15

4

h=6

h=1 h=0

S AB

G

h is admissible

30

Consistent HeuristicConsistent Heuristic

The admissible heuristic h is consistent (or satisfies the monotone restriction) if for every node N and every successor N’ of N:

h(N) c(N,N’) + h(N’)

(triangular inequality)A consisteny heuristic is admissible.

N

N’ h(N)

h(N’)

c(N,N’)

31

Exampel: Graph Search returns a suboptimal solution

h=7

2 15

4

h=6

h=1 h=0

S AB

G

h is admissible but not consistent; e.g. h(S)=7 c(S,A) + h(A) = 5 ?No.

32

8-Puzzle8-Puzzle

1 2 3

4 5 6

7 8

12

3

4

5

67

8

N goal

• h1(N) = number of misplaced tiles

• h2(N) = sum of distances of each tile to goal

are both consistent.

But do you see why?

33

ClaimsClaimsIf h is consistent, then the function f alongany path is non-decreasing:

f(N) = g(N) + h(N) f(N’) = g(N) +c(N,N’) + h(N’) h(N) c(N,N’) + h(N’) f(N) f(N’)

If h is consistent, then whenever A* expands a node it has already found an optimal path to the state associated with this node

N

N’ h(N)

h(N’)

c(N,N’)

34

Optimality of A*

A* expands nodes in order of increasing f value

Gradually adds "f-contours" of nodes Contour i has all nodes with f=fi, where fi < fi+1

35

Avoiding Repeated States in Avoiding Repeated States in A*A*

If the heuristic h is consistent, then:Let CLOSED be the list of states associated with expanded nodesWhen a new node N is generated: If its state is in CLOSED, then discard N If it has the same state as another

node in the fringe, then discard the node with the largest f

36

HeuristicHeuristic AccuracyAccuracy

h(N) = 0 for all nodes is admissible and consistent. Hence, breadth-first and uniform-cost are particular A* !!!Let h1 and h2 be two admissible and consistent heuristics such that for all nodes N: h1(N) h2(N).

Then, every node expanded by A* using h2 is also expanded by A* using h1.h2 is more informed than h1 h2 dominates h1

Which heuristic for 8-puzzle is better?

37

Complexity of A*Complexity of A*

Time: exponential

Space: can keep all nodes in memory

If we want save space, use IDA*

38

Iterative Deepening A* Iterative Deepening A* (IDA*)(IDA*)

Use f(N) = g(N) + h(N) with admissible and consistent hEach iteration is depth-first with cutoff on the value of f of expanded nodes

39

8-Puzzle8-Puzzle

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

40

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

41

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

5

42

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

5

5

43

4

8-Puzzle8-Puzzle

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

5

56

44

8-Puzzle8-Puzzle

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

45

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

46

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

47

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

48

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

5

49

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

5 5

50

8-Puzzle8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

5 5

51

About HeuristicsAbout Heuristics

Heuristics are intended to orient the search along promising pathsThe time spent computing heuristics must be recovered by a better searchAfter all, a heuristic function could consist of solving the problem; then it would perfectly guide the searchDeciding which node to expand is sometimes called meta-reasoningHeuristics may not always look like numbers and may involve large amount of knowledge

52

When to Use Search When to Use Search Techniques?Techniques?

The search space is small, and There are no other available techniques,

or It is not worth the effort to develop a

more efficient technique

The search space is large, and There is no other available techniques,

and There exist “good” heuristics

53

SummarySummary

Heuristic function Greedy Best-first search Admissible heuristic and A* A* is complete and optimal Consistent heuristic and repeated states Heuristic accuracy IDA*