D Heuristic Search

53
Heuristic Search Heuristic Search Russell and Norvig: Chapter 4, Sect. 4.1 – 4.2 CS121 – Winter 2004

description

D-heuristic-search

Transcript of D Heuristic Search

Heuristic SearchHeuristic Search

Russell and Norvig:

Chapter 4, Sect. 4.1 – 4.2

CS121 – Winter 2004

Search AlgorithmSearch Algorithm

1. INSERT(initial-node,FRINGE)2. Repeat:

If FRINGE is empty then return failuren REMOVE(FRINGE)s STATE(n)For every state s’ in SUCCESSORS(s) Create a node n’ If GOAL?(s’) then return path or goal state INSERT(n’,FRINGE)

Current Bag of TricksCurrent Bag of Tricks

Modified Search AlgorithmModified Search Algorithm

1. INSERT(initial-node,FRINGE)2. Repeat:

If FRINGE is empty then return failuren REMOVE(FRINGE)s STATE(n)If GOAL?(s) then return path or goal stateFor every state s’ in SUCCESSORS(s) Create a node n’ INSERT(n’,FRINGE)

Current Bag of TricksCurrent Bag of Tricks

Current Bag of TricksCurrent Bag of Tricks

Search algorithm Modified search algorithm Avoiding repeated states

Best-First SearchBest-First Search

Define an evaluation function: f : node N real number f(state(N)) whose value depends on the state of N

Order the fringe in increasing f [the smaller f, the better]

f can be any function you want, but will it work?

Example of Evaluation Example of Evaluation FunctionFunction

f(N) = (sum of distances of each tile to its goal) + 3 x (sum of score functions for each tile)

where score function for a non-central tile is 2 if it is not followed by the correct tile in clockwise order and 0 otherwise

1 2 34 5 67 8

123

45

67

8

N goal

f(N) = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 3x(2 + 2 + 2 + 2 + 2 + 0 + 2) = 49

Heuristic FunctionHeuristic Function

Function h(N) that estimates 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

Heuristic FunctionHeuristic Function

Function h(N) that estimates 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

Robot NavigationRobot Navigation

h(N) = Straight-line distance to the goal = [(Xg – XN)

2 + (Yg – YN)2]1/2

XN

YN

N

Examples of Evaluation Examples of Evaluation functionsfunctions

Let g(N) be the cost of the best path found so far between the initial node and N

f(N) = h(N) greedy best-first

f(N) = g(N) + h(N)

8-Puzzle8-Puzzle

4

5

5

3

3

4

3 4

4

2 1

2

0

3

4

3

f(N) = h(N) = number of misplaced tiles

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

8-Puzzle8-Puzzle

5

6

6

4

4

2 1

2

0

5

5

3

f(N) = h(N) = distances of tiles to goal

Can we Prove Anything?Can we Prove Anything?

If the state space is finite and we avoid repeated states, the search is complete, but in general is not optimal

If the state space is finite and we do not avoid repeated states, the search is in general not complete

If the state space is infinite, the search is in general not complete

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

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

Robot navigationRobot navigation

Cost of one horizontal/vertical step = 1Cost of one diagonal step = 2

h(N) = straight-line distance to the goal is admissible

A* SearchA* Search Evaluation 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

0 < c(N,N’)

Then, best-first search with “modified search algorithm” is called A* search

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, A* is: complete optimal

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

Robot NavigationRobot Navigation

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

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

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

7+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

Robot navigationRobot navigation

Cost of one horizontal/vertical step = 1Cost of one diagonal step = 2

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

About Repeated StatesAbout Repeated States

N N1S S1

f(N)=g(N)+h(N)

f(N1)=g(N1)+h(N1)

• g(N1) < g(N)• h(N) < h(N1)• f(N) < f(N1)

N2

f(N2)=g(N2)+h(N)• g(N2) < g(N)

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

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’) h(N) – c(N,N’) h(N’) h(*N’)

N

N’ h(N)

h(N’)

c(N,N’)

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

N

N’ h(N)

h(N’)

c(N,N’)

f(N) = g(N) + h(N)f(N’) = g(N) + c(N,N’) + h(N’) f(N)f(N’) = max{f(N), g(N’)+h(N’)}

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

Robot navigationRobot navigation

Cost of one horizontal/vertical step = 1Cost of one diagonal step = 2

h(N) = straight-line distance to the goal is consistent

Claim 2:

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

N N1S S1

N2

The path to N is the optimal path to S

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

HeuristicHeuristic AccuracyAccuracyh(N) = 0 for all nodes is admissible and consistent. Hence, breadth-first and uniform-cost are specific A* !!!Let h1 and h2 be two admissible and consistent heuristics such that for all nodes N: h1(N) h2(N). h2 is more informed (or more accurate) than h1.

Claim 3: Every node expanded by A* using h2 is also expanded by A* using h1.

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

8-Puzzle8-Puzzle

4

6

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

Cutoff=4

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=4

6

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=4

6

5

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=4

6

5

5

4

8-Puzzle8-Puzzle

4

6

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

Cutoff=4

6

5

56

8-Puzzle8-Puzzle

4

6

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

Cutoff=5

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=5

6

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=5

6

5

8-Puzzle8-Puzzle

4

4

6

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

Cutoff=5

6

5

7

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

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

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

About HeuristicsAbout HeuristicsHeuristics 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

Robot NavigationRobot Navigation

f(N) = h(N) = straight distance to the goal

Local-minimum problem

What’s the Issue?What’s the Issue?

Search is an iterative local procedure

Good heuristics should provide global look-ahead (at low computational cost)

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

1. 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

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

and There exist “good” heuristics

SummarySummary

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