Informed search Lirong Xia Spring, 2017 Last class Search - - PowerPoint PPT Presentation

informed search
SMART_READER_LITE
LIVE PREVIEW

Informed search Lirong Xia Spring, 2017 Last class Search - - PowerPoint PPT Presentation

Informed search Lirong Xia Spring, 2017 Last class Search problems state space graph: modeling the problem search tree: scratch paper for solving the problem Uninformed search BFS DFS 2 Todays schedule More on


slide-1
SLIDE 1

Lirong Xia

Informed search

Spring, 2017

slide-2
SLIDE 2

ØSearch problems

  • state space graph: modeling the problem
  • search tree: scratch paper for solving the problem

ØUninformed search

  • BFS
  • DFS

2

Last class

slide-3
SLIDE 3

ØMore on uninformed search

  • iterative deepening: BFS + DFS
  • uniform cost search (UCS)
  • searching backwards from the goal

ØInformed search

  • best first (greedy)
  • A*

3

Today’s schedule

slide-4
SLIDE 4

Combining good properties of BFS and DFS

Ø Iterative deepening DFS:

  • Call limited depth DFS with depth 0;
  • If unsuccessful, call with depth 1;
  • If unsuccessful, call with depth 2;
  • Etc.

Ø Complete, finds shallowest solution Ø Flexible time-space tradeoff Ø May seem wasteful timewise because replicating effort

slide-5
SLIDE 5

5

Costs on Actions

S a b c d e G 1 5 1 1 3 2 1

slide-6
SLIDE 6

Uniform-Cost Search (UCS)

ØBFS: finds shallowest solution ØUniform-cost search (UCS): work on the lowest- cost node first

  • so that all states in the fringe have more or less the

same cost, therefore “uniform cost”

ØIf it finds a solution, it will be an optimal one ØWill often pursue lots of short steps first ØProject 1 Q3

slide-7
SLIDE 7

7

Example

S a b c d e G 1 1 5 1 1 3 2

slide-8
SLIDE 8

Priority Queue Refresher

8

  • A priority queue is a data structure in which you can insert

and retrieve (key, value) pairs with the following operations:

  • Insertions aren’t constant time, usually
  • We’ll need priority queues for cost-sensitive search methods

pq.push(key, value) Inserts (key, value) into the queue. pq.pop() returns the key with the lowest value, and removes it from the queue

slide-9
SLIDE 9

ØThe good: UCS is

  • complete: if a solution exists, one will

be found

  • optimal: always find the solution with

the lowest cost

  • really?

§ yes, for cases where all costs are positive

ØThe bad

  • explores every direction
  • no information about the goal location

9

Uniform-Cost Search

slide-10
SLIDE 10

Searching backwards from the goal

ØSwitch the role of START and GOAL ØReverse the edges in the problem graph ØNeed to be able to compute predecessors instead

  • f successors

Start b GOAL c d e f g …

slide-11
SLIDE 11

Informed search

ØSo far, have assumed that no non-goal state looks better than another ØUnrealistic

  • Even without knowing the road structure, some locations seem

closer to the goal than others

ØMakes sense to expand seemingly closer nodes first

.

slide-12
SLIDE 12
  • Any estimate of how close a state is to a goal
  • Designed for a particular search problem
  • Examples: Manhattan distance, Euclidean distance

Search Heuristics

12

slide-13
SLIDE 13

Best First (Greedy)

13

  • Strategy: expand a node that you think is closest

to a goal state

  • Heuristic function: estimate of distance to nearest goal for

each state

  • h(n)
  • Often easy to compute
  • A common case:
  • Best-first takes you straight to the (wrong) goal
  • Worst-case: like a badly-guided DFS
slide-14
SLIDE 14

14

Example

Start c d e GOAL 1 1 1 1 2 a 1 b f g 1 1 1 h(b) = h(c) = h(d) = h(e) = h(f) = h(g) =1 h(a) = 2

slide-15
SLIDE 15

Ø Greedy will choose SbcdG Ø Optimal: SaG Ø Should we stop when the fringe is empty?

15

A more problematic example

Start c d GOAL 1 1 1 1 2 a b h(b) = h(c) = h(d)=1 h(a) = 2 h(G) = 0 1

slide-16
SLIDE 16

16

A*

slide-17
SLIDE 17

A*: Combining UCS and Greedy

17

  • Uniform-cost orders by path cost
  • Greedy orders by goal proximity, or forward cost
  • A* search orders by the sum:

( )

h n

( )

g n

( ) ( ) ( )

f n g n h n = +

slide-18
SLIDE 18

When should A* terminate?

18

  • Should we stop when we add a goal to the fringe?
  • No: only stop when a goal pops from the fringe

S a 2 h(a)=2 h(S)=7 c 2 h(b)=0 b 3 h(G)=0 2

slide-19
SLIDE 19

Ø Never expand a node whose state has been visited Ø Fringe can be maintained as a priority queue Ø Maintain a set of visited states

Ø fringe := {node corresponding to initial state} Ø loop:

  • if fringe empty, declare failure
  • choose and remove the top node v from fringe
  • check if v’s state s is a goal state; if so, declare success
  • if v’s state has been visited before, skip
  • if not, expand v, insert resulting nodes with f(v)=g(v)+h(v) to fringe

19

A*

slide-20
SLIDE 20

Is A* Optimal?

20

S a G 3 1 5 h(a)=6 h(S)=7 h(G)=0

ØProblem: overestimate the true cost to a goal

  • so that the algorithm terminates without expanding

the actual optimal path

slide-21
SLIDE 21

Admissible Heuristics

21

  • A heuristic h is admissible if:

h(n) ≤ h*(n) where h*(n) is the true cost to a nearest goal

  • Examples:
  • h (n)=0
  • h(n) = h*(n)
  • another example
  • Coming up with admissible heuristics is most

challenging part in using A* in practice

slide-22
SLIDE 22

Is Admissibility enough?

22

S a G 5 1 5 h(a)=0 h(S)=7 h(G)=0

ØProblem: the first time to visit a state may not via the shortest path to it

c 1 h(b)=6 b 1 h(c)=0

slide-23
SLIDE 23

Consistency of Heuristics

23

  • Stronger than admissibility
  • Definition:
  • cost(a to c) + h(c) ≥ h(a)
  • Triangle inequality
  • Be careful about the edges
  • Consequences:
  • The f value along a path never

decreases

  • so that the first time to visit a

state corresponds to the shortest path

a G c 1 h(c)=1 h(a)=4

slide-24
SLIDE 24

Violation of consistency

24

S a G 5 1 5 h(a)=0 h(S)=7 h(G)=0

Øbà c

c 1 h(b)=6 b 1 h(c)=0

slide-25
SLIDE 25

Ø A* finds the optimal solution for consistent heuristics

  • but not for the admissible heuristics (as in the

previous example)

ØHowever, if we do not maintain a set of “visited” states, then admissible heuristics are good enough

25

Correctness of A*

slide-26
SLIDE 26

ØProof by contradiction: suppose the

  • utput is incorrect.
  • Let the optimal path be Sà aà … à G

§ for simplicity, assume it is unique

  • When G pops from the fringe, f(G) is no more

than f(v) for all v in the fringe.

  • Let v denote the state along the optimal path

in the fringe

§ guaranteed by consistency

  • Contradiction

§ addimisbility: f(G) <= f(v) <= g(v) + h*(v)

26

Proof

slide-27
SLIDE 27

Creating Admissible Heuristics

27

  • Most of the work in solving hard search problems
  • ptimally is in coming up with admissible heuristics

12.4

slide-28
SLIDE 28

Example: 8 Puzzle

28

  • What are the states?
  • How many states?
  • What are the actions?
  • What should the costs be?

Start State Goal State

slide-29
SLIDE 29

8 Puzzle I

29

  • Heuristic: Number of

tiles misplaced

  • Why is it admissible?
  • h(START) = 8

Start State Goal State Average nodes expanded when

  • ptimal path has length….

…4 steps …8 steps …12 steps UCS 112 6,300 3,600,000 TILES 13 39 227

slide-30
SLIDE 30

8 Puzzle II

30

  • What if we had an

easier 8-puzzle where any tile could slide any direction at any time ignoring other tiles?

  • Total Manhattan

distance

  • Why admissible?
  • h(START) = 3+2+…+18

Start State Goal State Average nodes expanded when

  • ptimal path has length….

…4 steps …8 steps …12 steps TILES 13 39 227

Manhattan 12

25 73

slide-31
SLIDE 31

8 Puzzle III

31

  • Total Manhattan distance for grid 1 and 2
  • Why admissible?
  • Is it consistent?
  • h(START) = 3+1=4

Start State Goal State

slide-32
SLIDE 32

8 Puzzle IV

32

  • How about using the actual cost as a

heuristic?

  • Would it be admissible?
  • Would we save on nodes expanded?
  • What’s wrong with it?
  • With A*: a trade-off between quality of

estimate and work per node!

slide-33
SLIDE 33

Other A* Applications

33

  • Pathing / routing problems
  • Resource planning problems
  • Robot motion planning
  • Language analysis
  • Machine translation
  • Speech recognition
  • Voting!
slide-34
SLIDE 34

ØA* uses both backward costs and (estimates of) forward costs ØA* computes an optimal solution with consistent heuristics ØHeuristic design is key

Features of A*

34

slide-35
SLIDE 35

ØMaintain a fringe and a set of visited states

Øfringe := {node corresponding to initial state} Øloop:

  • if fringe empty, declare failure
  • choose and remove the top node v from fringe
  • check if v’s state s is a goal state; if so, declare success
  • if v’s state has been visited before, skip
  • if not, expand v, insert resulting nodes to fringe

Ø Data structure for fringe

  • FIFO: BFS
  • Stack: DFS
  • Priority Queue: UCS (value = h(n)) and A* (value = g(n)+h(n))

35

Search algorithms

slide-36
SLIDE 36

ØNo information

  • BFS, DFS, UCS, iterative deepening,

backward search

ØWith some information

  • Design heuristics h(n)
  • A*, make sure that h is consistent
  • Never use Greedy!

36

Take-home message

slide-37
SLIDE 37

ØYou can start to work on UCS and A* parts ØStart early! ØAsk questions on Piazza

37

Project 1