informed search · 2004-02-16 · informed search reading: chapter 4, paper hw#1 due today hw#2 out...

36
1 Informed Search Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th

Upload: others

Post on 02-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

1

Informed SearchInformed Search

Reading: Chapter 4, paperHW#1 due todayHW#2 out today, due Feb. 19th

Page 2: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

2

HeuristicsHeuristics

� Suppose 8-puzzle off by one (demo)

� 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 3: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

3

Nature of heuristicsNature 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 4: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

4

Heuristic for the 8Heuristic for the 8--puzzlepuzzle

� # 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 5: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

5

087

654

321

807

654

321

507

824

631

Goal State

h1=1h2=1

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

Page 6: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

6

Best first searchesBest 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 7: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

7

Greedy searchGreedy search

� Evaluation function = heuristic function

� Expand the node that appears to be closest to the goal

Page 8: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

8

Greedy SearchGreedy 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 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 9: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

9

DemoDemo

Page 10: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

10

Analysis of Greedy SearchAnalysis of Greedy Search

� Which uninformed search algorithm is it closest to?

� Optimal?� Complete?� Space?� Time?

Page 11: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

11

A* SearchA* 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 12: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

12

AdmissableAdmissable heuristicsheuristics

� A heuristic that never overestimates the cost to the goal

� h1 and h2 are admissable heuristics

� Consistency: the estimated cost of reaching the goal form 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 13: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

13

Which heuristic is better?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 14: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

14

DemoDemo

Page 15: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

15

Page 16: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

16

Relaxed ProblemsRelaxed 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 17: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

17

087

654

321

807

654

321

507

824

631

Goal State

h1=1h2=1

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

Page 18: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

18

Heuristics for other problemsHeuristics for other problems

� Shortest path from one city to another� Straight line distance

� Touring problem: visit every city exactly once

� Cryptograms

Page 19: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

19

Page 20: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

20

Page 21: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

21

Page 22: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

22

Page 23: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

23

Page 24: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

24

Page 25: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

25

Page 26: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

26

Page 27: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

27

Page 28: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

28

Page 29: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

29

Page 30: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

30

Online SearchOnline Search

� Agent operates by interleaving computation and action

� No time for thinking

� The agent only knows� Actions (s)� The step-cost function c(s,a,s’)� Goal-text (s)

� Cannot access the successors of a state without trying all actions

Page 31: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

31

AssumptionsAssumptions

� Agent recognizes a state it has seen before

� Actions are deterministic

� Admissable heuristics� Competitive ratio: Compare cost that agent

actually travels with cost of the actual shortest path

Page 32: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

32

What properties of search are What properties of search are desirable?desirable?� Will A* work?

� Expand nodes in a local order� Depth first� Variant of greedy search

� Difference from offline search:� Agent must physically backtrack� Record states to which agent can backtrack and has not

yet explored

Page 33: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

33

DepthDepth--firstfirst

� 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� Put remaining successors on left end of OPEN

� End while

Page 34: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

34

Online DFS Online DFS -- setupsetup

� Inputs: s’, a percept that identifies the current state

Static: � result, a table indexed by action and state,

initially empty� unexplored: a table that lists, for each visited

state, the actions not yet tried� unbacktracked: a table that lists, for each

visited state, the backtracks not yet tried� s,a: the previous state and action, initially null

Page 35: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

35

Online DFS Online DFS –– the algorithmthe algorithm� If Goal-test(s’) then return stop� If s’ is a new state then unexplored[s’] � actions(s’)� If s is not null then do

� result[a,s]�s’� Add s to the front of unbacktracked[s’]

� If unexplored[s’] is empty� Then return stop� Else a� action b such that

result[b,s’]=pop(unbacktracked[s’])� Else a�pop(unexplored[s’])� s� s’� Return a

Page 36: Informed Search · 2004-02-16 · Informed Search Reading: Chapter 4, paper HW#1 due today HW#2 out today, due Feb. 19th. 2 Heuristics Suppose 8-puzzle off by one (demo) Is there

36

HomeworkHomework