heuristic search russell and norvig: chapter 4 slides adapted from:...

38
Heuristic Search Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/200 3/home.htm

Upload: zaria-gane

Post on 11-Dec-2015

230 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Heuristic SearchHeuristic Search

Russell and Norvig: Chapter 4

Slides adapted from:robotics.stanford.edu/~latombe/cs121/2003/home.htm

Page 2: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Heuristic Search

Blind search totally ignores where the goals are.A heuristic function that gives us an estimate of how far we are from a goal. Example:

How do we use heuristics?

432

1

32

0

434

2 1

5

Page 3: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Heuristic FunctionHeuristic Function

Function h(N) that estimate the cost of the cheapest path from node N to goal node. Example: 8-puzzle

1 2 34 5 67 8

123

45

67

8

N goal

h(N) = number of misplaced tiles = 6

Page 4: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Heuristic FunctionHeuristic Function

Function h(N) that estimate the cost of the cheapest path from node N to goal node. Example: 8-puzzle

1 2 34 5 67 8

123

45

67

8

N goal

h(N) = sum of the distances of every tile to its goal position = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 = 13

Page 5: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Greedy Best-First SearchGreedy Best-First SearchPath search(start, operators, is_goal) { fringe = makeList(start); while (state=fringe.popFirst()) { if (is_goal(state)) return pathTo(state); S = successors(state, operators);

fringe = insert(S, fringe); } return NULL;}

Order the nodes in the fringe in increasing values of h(N)

Page 6: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Robot NavigationRobot Navigation

Page 7: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 8: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

7

0

Page 9: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Properties of the Greedy Properties of the Greedy Best-First SearchBest-First Search

If the state space is finite and we avoid repeated states, the best-first search is complete, but in general is not optimalIf the state space is finite and we do not avoid repeated states, the search is in general not completeIf the state space is infinite, the search is in general not complete

Page 10: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 11: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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• h3(N) = (sum of distances of each tile to goal) + 3 x (sum of score functions for each tile) = 49 is not admissible

Page 12: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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)

Page 13: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Claim 1: If there is a path from the initial to a goal node, A* (with no removal of repeated states) terminates by finding the best path, hence is: complete optimal

Page 14: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

0+4

1+5

1+5

1+3

3+3

3+4

3+4

3+2 4+1

5+2

5+0

2+3

2+4

2+3

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

goal

Page 15: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Robot NavigationRobot Navigation

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

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

57+0

6+1

6+1

8+1

7+0

7+2

6+1

7+2

6+1

8+1

7+2

8+3

7+26+36+35+45+44+54+53+63+62+7

8+37+47+46+5

5+6

6+35+6

2+73+8

4+7

5+64+7

3+8

4+73+83+82+92+93+10

2+9

3+8

2+91+101+100+11

Page 16: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Robot navigationRobot navigation

Cost of one horizontal/vertical step = 1

Cost of one diagonal step = 2

f(N) = g(N) + h(N), with h(N) = straight-line distance from N to goal

Page 17: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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)

N

N’ h(N)

h(N’)

c(N,N’)

Page 18: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 19: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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’)

Page 20: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 21: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

Complexity of Consistent Complexity of Consistent A*A*

Let s be the size of the state space Let r be the maximal number of states that can be attained in one step from any stateAssume that the time needed to test if a state is in CLOSED is O(1)The time complexity of A* is O(s r

log s)

Page 22: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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?

Page 23: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 24: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

6

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

Cutoff=4

Page 25: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=4

6

Page 26: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=4

6

5

Page 27: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=4

6

5

5

Page 28: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

4

8-Puzzle8-Puzzle

4

6

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

Cutoff=4

6

5

56

Page 29: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

6

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

Cutoff=5

Page 30: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=5

6

Page 31: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=5

6

5

Page 32: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=5

6

5

7

Page 33: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 34: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 35: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 36: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

Page 37: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

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

The search space is small, and There is 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

Page 38: Heuristic Search Russell and Norvig: Chapter 4 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm

SummarySummary

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