Le Lecture ture 5 Le Leas ast t Co Cost st an and d In - - PowerPoint PPT Presentation

le lecture ture 5 le leas ast t co cost st an and d in
SMART_READER_LITE
LIVE PREVIEW

Le Lecture ture 5 Le Leas ast t Co Cost st an and d In - - PowerPoint PPT Presentation

Computer Science CPSC 322 Le Lecture ture 5 Le Leas ast t Co Cost st an and d In Info form rmed ed Se Search arch (Ch: h: 3.6 .6, , 3.6 .6.1) .1) 1 Announcements nouncements Assignment 1 posted today Due Tuesday


slide-1
SLIDE 1

Computer Science CPSC 322

Le Lecture ture 5 Le Leas ast t Co Cost st an and d In Info form rmed ed Se Search arch

(Ch: h: 3.6 .6, , 3.6 .6.1) .1)

1

slide-2
SLIDE 2

Announcements nouncements

  • Assignment 1 posted today
  • Due Tuesday Oct 3, 11:59pm
  • You can do this assignment in pairs
  • Please caref

efully read and follow w the instructions on cover sheet

  • If you have not done them yet, do all the

“Graph Searching exercises” available at http://www.aispace.org/exercises.shtml

  • Suggestion: look at solutions only after you have tried

hard to solve them!

  • Midterm is Oct Tuesday 24

2

slide-3
SLIDE 3

Lecture cture Ov Overvie rview

  • Recap of Lecture 4
  • Least Cost First Search
  • Heuristic (Informed) Search
  • Best First
  • A*
  • Branch and Bound (time permitting)

3

slide-4
SLIDE 4
  • A. Check what node on a path is the goal
  • B. Initialize the frontier
  • C. Add/remove paths from the frontier
  • D. Check if a state is a goal

Search Strategies are different with respect to how they:

4

slide-5
SLIDE 5

5

slide-6
SLIDE 6
  • A. Check what node on a path is the goal
  • B. Initialize the frontier

C.

  • C. Add/r

/remo emove ve paths s from

  • m the front

ntier ier

  • D. Check if a state is a goal

Search Strategies are different with respect to how they:

6

slide-7
SLIDE 7

DFS FS

Depth-First Search, DFS

  • explores each path on the frontier until its end (or until a

goal is found) before considering any other path.

  • the frontier is a last-in-first-out stack

7

slide-8
SLIDE 8

Breadth eadth-first first search arch (BFS) FS)

  • BFS explores all paths of length l on the frontier,

before looking at path of length l + 1

  • The frontier is a first-in-first-out queue

8

slide-9
SLIDE 9

DFS FS vs. . BFS FS

How can we achieve an acceptable (linear) space complexity while maintaining completeness and optimality? Key Idea: re-compute elements of the frontier rather than saving them. Complete Optimal Time Space DFS NO NO O(bm) O(bm) BFS YES YES O(bm) O(bm) ????? ????? YES YES O(bm) O(bm)

9

slide-10
SLIDE 10

depth = 1 depth = 2 depth = 3

. . .

Iterative Deepening DFS (IDS) in a Nutshell

  • Use DFS to look for solutions at depth 1, then 2, then 3, etc

– For depth D, ignore any paths with longer length – Depth-bounded depth-first search

If no goal l re-star art t from scratc atch h and get to depth h 2 If no goal l re-star art t from scratc atch h and d get to depth th 3 If no goal l re-star art t from scratc atch h and d get to depth th 4

10

slide-11
SLIDE 11

An Analys ysis is of Iter erativ ative e Deepen enin ing g DFS FS (IDS) S)

  • Time complexity: we showed that it is still O(bm),

with limited overhead compared to BSF

  • Space complexity: it does DFS
  • Complete?
  • Optimal?

11

slide-12
SLIDE 12

DFS FS vs. . BFS FS

But what if we have costs associated with search actions (arcs in the search space? Complete Optimal Time Space DFS NO NO O(bm) O(bm) BFS YES YES O(bm) O(bm) IDS YES YES O(bm) O(bm)

12

slide-13
SLIDE 13

Lecture cture Ov Overvie rview

  • Recap of Lecture 4
  • Least Cost First Search
  • Heuristic (Informed) Search
  • Best First
  • A*
  • Branch and Bound (time permitting)

13

slide-14
SLIDE 14

Search h wi with Co Costs ts

In this setting we usually want to find the solution that minimizes cost  

) , cost( , , cost

1 1

 

k i i i k

n n n n 

Def.: The cost of a path is the sum

  • f the costs of its arcs

Def.: A search algorithm is optimal if when it finds a solution, it is the best one: it has the lowest path cost

Slide 14

slide-15
SLIDE 15
  • Lowest-cost-first search finds the path with the lowest

cost to a goal node

  • At each stage, it selects the path with the lowest cost on

the frontier.

  • The frontier is implemented as a priority queue ordered by

path cost.

Lowest west-Cost Cost-First First Search rch (LCFS) CFS)

Let’s see how this works in AIspace: in the Search Applet toolbar

  • select the “Vancouver Neighborhood Graph” problem
  • set “Search Options -> Search Algorithms” to “Lowest-Cost-First ”.
  • select “Show Edge Costs” under “View”
  • Create a new arc from UBC to SP with cost 20 and run LCFS

15

slide-16
SLIDE 16
  • Lowest

est-cost cost-firs rst search arch finds the path with the lowest cost to a goal node

  • At each stage, it selects the path with the lowest cost on the frontier.
  • The frontier is implemented as a priority queue ordered by path cost.

Lowest-Cost-First Search (LCFS)

16

slide-17
SLIDE 17
  • When arc costs are equal LCFS is equivalent to..
  • A. DFS
  • B. BFS
  • C. IDS
  • D. None of the Above

18

slide-18
SLIDE 18

19

slide-19
SLIDE 19
  • When arc costs are equal LCFS is equivalent to..
  • A. DFS
  • B. BFS
  • C. IDS
  • D. None of the Above

20

slide-20
SLIDE 20

Analysi alysis s of f Lowest west-Cost Cost Search arch (1)

  • Is LCFS complete?
  • not in general: for instance, a cycle with zero or

negative arc costs could be followed forever. see how this works in AIspace:

  • e.g, add arc with cost -20 to the simple search graph from N4 to S in Simple

Search Tree

*If costs along an infinite path can become infinitively small, their sum can be

finite (e.g. series σ𝑗=1

∞ 1 2𝑗 < 1) and the path can trap LCFS

  • yes, as long as arc costs are strictly positive, greater

than a given constant ε*

21

slide-21
SLIDE 21

Analysi alysis s of f Lowest west-Cost Cost Search arch (1)

  • Is LCFS complete?
  • not in general: for instance, a cycle with zero or

negative arc costs could be followed forever. see how this works in AIspace:

  • e.g, add arc with cost -20 to the simple search graph from N4 to S in Simple

Search Tree

*If costs along an infinite path can become infinitively small, their sum can be

finite (e.g. series σ𝑗=1

∞ 1 2𝑗 < 1) and the path can trap LCFS

  • yes, as long as arc costs are strictly positive, greater

than a given constant ε*

  • Is LCFS optimal?

22

slide-22
SLIDE 22

23

slide-23
SLIDE 23

Analysi alysis s of f Lowest west-Cost Cost Search arch (1)

  • Is LCFS complete?
  • not in general: for instance, a cycle with zero or

negative arc costs could be followed forever.

  • yes, as long as arc costs are strictly positive yes,

greater than a given constant ε *

  • Is LCFS optimal?
  • Not in general.
  • Arc costs could be negative: a path that initially

looks high-cost could end up getting a ``refund''.

  • However, LCFS is

is optimal if arc costs are guaranteed to be ≥ 0

see how this works in AIspace:

  • e.g, add arc with cost -20 to the simple search graph from N4 to S

*If costs along an infinite path can become infinitively small, their sum can be

finite (e.g. series σ𝑗=1

∞ 1 2𝑗 < 1)

24

slide-24
SLIDE 24

Analysi alysis s of f Lowest west-Cost Cost Search arch

  • Time complexity: if the maximum path length is m

and the maximum branching factor is b

  • The time complexity is O(bm)
  • In worst case, must examine every node in the tree

because it generates all paths from the start that cost less than the cost of the solution

25

slide-25
SLIDE 25

Analysi alysis s of f Lowest west-Cost Cost Search arch

  • Space complexity
  • Space complexity is O(bm):
  • E.g. uniform cost: just like BFS, in worst case frontier

has to store all nodes that are m-1 steps away from the start node

26

slide-26
SLIDE 26

Summary mary of f Uninformed informed Search arch

Complete Optimal Time Space DFS N N O(bm) O(mb) BFS Y Y (shortest) O(bm) O(bm) IDS Y Y (shortest) O(bm) O(mb) LCFS Y Costs > ε > Y (Least Cost) Costs >=0 O(bm) O(bm)

Slide 27

slide-27
SLIDE 27

Su Summary y of Uninfo nforme med d Se Search h (cont. nt.)

  • Why are all the search strategies seen so far are

called uninformed?

  • Because they do not consider any information about the

states and the goals to decide which path to expand first

  • n the frontier
  • They are blind to the goal
  • In other words, they are general and do not take into

account the specific nature of the problem.

Slide 28

slide-28
SLIDE 28

Lecture cture Ov Overvie rview

  • Recap of Lecture 4
  • Least Cost First Search
  • Heuristic (Informed) Search
  • Best First
  • A*
  • Branch and Bound (time permitting)

29

slide-29
SLIDE 29
  • Blind search algorithms do not take into

account the goal until they are at a goal node.

  • Often there is extra knowledge that can be

used to guide the search:

  • an estimate of the distance/cost from node n to a

goal node.

  • This estimate is called a search heuristic.

He Heur uristic stic Se Sear arch ch

30

slide-30
SLIDE 30

Mo More fo e forma mally lly

Def.: A search heuristic h(n) is an estimate of the cost of the

  • ptimal (cheapest) path from node n to a goal node.

Estimate: h(n1) Estimate: h(n2) Estimate: h(n3) n3 n2 n1

  • h can be extended to paths: h(n0,…,nk) = h(nk)
  • h(n) should leverage readily obtainable information

(easy to compute) about a node.

Slide 31

slide-31
SLIDE 31

Example: mple: fi finding ing routes utes

  • What could we use as h(n)?

32

slide-32
SLIDE 32

Example: mple: fi finding ing routes utes

  • What could we use as h(n)? E.g., the straight-line

(Euclidian) distance between source and goal node

33

slide-33
SLIDE 33

Example mple 2

Search problem: robot has to find a route from start to goal location on a grid with obstacles Actions: move up, down, left, right from tile to tile Cost : number of moves Possible h(n)?

1 2 3 4 5 6

G

4 3 2 1

S

Slide 34

slide-34
SLIDE 34

Example mple 2

Search problem: robot has to find a route from start to goal location on a grid with obstacles Actions: move up, down, left, right from tile to tile Cost : number of moves Possible h(n)? Manhattan distance (L1 distance) between two points (x1, y1), (x2, y2):

  • sum of the (absolute) difference of their coordinates

|x2 – x1| + |y2 - y1|

1 2 3 4 5 6

G

4 3 2 1

Slide 35

slide-35
SLIDE 35

Lecture cture Ov Overvie rview

  • Recap of Lecture 4
  • Least Cost First Search
  • Heuristic (Informed) Search
  • Best First
  • A*
  • Branch and Bound (time permitting)

36

slide-36
SLIDE 36
  • Idea: always choose the path on the frontier with the

smallest h value.

  • BestFS treats the frontier as a priority queue ordered by

h.

  • Greedy approach: expand path whose last node seems

closest to the goal - chose the solution that is locally the best.

Be Best Fi First t Se Sear arch h (Be BestFS tFS)

Let’s see how this works in AIspace: in the Search Applet toolbar

  • select the “Vancouver Neighborhood Graph” problem
  • set “Search Options -> Search Algorithms” to “Best-First ”.
  • select “Show Node Heuristics” under “View”
  • compare number of nodes expanded by BestFS and LCFS

37

slide-37
SLIDE 37
  • Complete?

Anal alysi ysis s of f BestFS tFS

  • A. YES
  • B. NO

39

slide-38
SLIDE 38
  • Complete?

Anal alysi ysis s of f BestFS tFS

  • B. NO
  • See the “misleading heuristics demo”

example in AISPACE

40

slide-39
SLIDE 39
  • Optimal?

Anal alysi ysis s of f BestFS tFS

  • A. YES
  • B. NO

41

slide-40
SLIDE 40
  • Optimal?

Anal alysi ysis s of f BestFS tFS

  • B. NO
  • Try this example in AISPACE or example “ex-best.txt”

from schedule page (save it and then load using “load from file” option)

42

slide-41
SLIDE 41
  • Time and space Complexity: O(bm)
  • Worst case (bad h(n)): has to explore all nodes and keep

related partial paths on the frontier

  • Why would one want to use Best First Search ?
  • Because if the heuristics is good it can find the solution very

fast.

  • For another example, see AIspace, Delivery problem graph

with C1 linked to o123 (cost 3.0)

Anal alysi ysis s of f BestFS tFS

43

slide-42
SLIDE 42
  • Thus, having estimates of the distance to the

goal can speed things up a lot

  • but by itself it can also mislead the search (i.e. Best

First Search)

  • On the other hand, taking only path costs into

account allows LCSF to find the optimal solution

  • but the search process is still uniformed as far as

distance to the goal goes.

What’s Next?

44

slide-43
SLIDE 43

How can we more effec fective tively ly use h(p) ) and cost st(p (p)? )? Shall we select from the frontier the path p with:

  • A. Lowest

cost(p) – h(p)

  • B. Highest cost(p) – h(p)
  • C. Highest cost(p)+h(p)
  • D. Lowest cost(p)+h(p)

45

slide-44
SLIDE 44

46

slide-45
SLIDE 45

How can we more effec fective tively ly use h(p) ) and cost st(p (p)? )? Shall we select from the frontier the path p with:

  • A. Lowest

cost(p) – h(p)

  • B. Highest cost(p) – h(p)
  • C. Highest cost(p)+h(p)
  • D. Lowest cost(p)+h(p)

47

slide-46
SLIDE 46

Lecture cture Ov Overvie rview

  • Recap of Lecture 4
  • Least Cost First Search
  • Heuristic (Informed) Search
  • Best First
  • A*
  • Branch and Bound (time permitting)

48

slide-47
SLIDE 47
  • A* search takes into account both
  • the cost of the path p to a node c(p)
  • the heuristic value of that path h(p) (i.e. the h value of the

node n at the end of p)

  • Let f(p) = c(p) + h(p).
  • f(p) is an estimate of the cost of a path from the start to a

goal via p.

A* Search arch

c(p) h(p)

f(p)

A* always chooses the path on the frontier with the lowest estimated distance from the start to a goal node constrained to go via that path.

49

slide-48
SLIDE 48

f value of ubc  kd  jb? A.6 C.10

  • D. 11
  • B. 9

Compu mputing ting f-valu alues es

50

slide-49
SLIDE 49

51

slide-50
SLIDE 50

f value of ubc  kd  jb? C.10

Computing mputing f-vale aleues ues

52

slide-51
SLIDE 51

53

slide-52
SLIDE 52

Compare A* and LCFS on the Vancouver graph

  • A* search takes into account both
  • the cost of the path to a node c(p)
  • the heuristic value of that path h(p).
  • Let f(p) = c(p) + h(p).
  • f(p) is an estimate of the cost of a path from the start to a

goal via p.

A* Search arch

c(p) h(p)

f(p)

A* always chooses the path on the frontier with the lowest estimated distance from the start to a goal node constrained to go via that path.

54

slide-53
SLIDE 53

A* is complete (finds a solution, if one exists) and optimal (finds the optimal path to a goal) if

  • arc costs are > ε > 0
  • h(n) is admissible

The book also mentions explicitly that the branching factor b has to be finite, which we have been assuming by default (without this condition even BFS would not be complete)

Op Opti timal mality ity of f A*

55

slide-54
SLIDE 54

Admissibi issibility lity of f a he heuristi uristic

Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal.

  • Example: is the

straight-line distance (SLD) admissible?

56

slide-55
SLIDE 55

Admissibi issibility lity of f a he heuristi uristic

Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal.

  • Example: is the

straight-line distance admissible?

  • The shortest

distance between two points is a line. YES YES

57

slide-56
SLIDE 56

Admissibi issibility lity of f a he heuristi uristic

Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal.

exampl ple: :

the goal is Urzizeni (red box), but all we know is the straight-line distances (sld) to Bucharest (green box)

  • Possible h(n) = sld(n, Bucharest) + cost(Bucharest, Urzineni)
  • Admissible?
  • A. Yes
  • C. It depends
  • B. No

58

slide-57
SLIDE 57

59

slide-58
SLIDE 58

Admissibi issibility lity of f a he heuristi uristic

Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal. exampl ple:

the goal is Urzizeni (red box), but all we know is the straight-line distances to Bucharest (green box)

NO NO

  • Possible h(n) = sld(n, Bucharest) + cost(Bucharest, Urzineni)
  • Admissible?
  • Actual cost of going from Vast

stul ul to Urz rzineni ineni is shorter than this estimate

60

slide-59
SLIDE 59

Example mple 2

  • Search problem: robot has to find a route from start to goal location on

a grid with obstacles

  • Actions: move up, down, left, right from tile to tile
  • Cost : number of moves
  • Possible h(n)? Manhattan distance (L1 distance) between two points

(x1, y1), (x2, y2):

  • sum of the (absolute) difference of their coordinates

|x2 – x1| + |y2 - y1| ADMISSIBLE? 1 2 3 4 5 6

G

4 3 2 1

Slide 61

slide-60
SLIDE 60

Example mple 2

  • Search problem: robot has to find a route from start to goal location on

a grid with obstacles

  • Actions: move up, down, left, right from tile to tile
  • Cost : number of moves
  • Possible h(n)? Manhattan distance (L1 distance) between two points

(x1, y1), (x2, y2):

  • sum of the (absolute) difference of their coordinates

|x2 – x1| + |y2 - y1| ADMISSIBLE? 1 2 3 4 5 6

G

4 3 2 1

  • Yes. Manhattan distance is

the shortest path between any two tiles of the grid given the actions available and no walls. Including the walls will force the agent to take some extra steps to avoid them

Slide 62

slide-61
SLIDE 61

Heuri uristic stic Function ction fo for 8-puzzle puzzle

An admissible heuristics for the 8-puzzle is?

  • A. Number of misplaced tiles plus number of correctly place

tiles

  • B. Number of misplaced tiles
  • C. Number of correctly placed tiles
  • D. None of the above

63

slide-62
SLIDE 62

64

slide-63
SLIDE 63

Ex Exam ampl ple e 3: 3: Ei Eigh ght Pu Puzzle le

  • Admissible h(n):

Number of Misplaced Tiles: One needs at least that many moves to get the board in the goal state A and C clearly generate overestimates (e.g. when all tiles are in the correct position with respect to the goal above, except for 4 which is in the center)

Slide 65

slide-64
SLIDE 64

Ex Exam ampl ple e 3: 3: Ei Eigh ght Pu Puzzle le

  • Another possible h(n):

Sum of number of moves between each tile's current position and its goal position (we can move over other tiles in the grid) Sum ( 1 2 3 4 5 6 7 8

Slide 66

slide-65
SLIDE 65

Ex Exam ampl ple e 3: 3: Ei Eigh ght Pu Puzzle le

  • Another possible h(n):

Sum of number of moves between each tile's current position and its goal position

sum ( 2 3 3 2 4 2 0 2) = 18

Admissible?

1 2 3 4 5 6 7 8

  • A. Yes
  • C. It depends
  • B. No

Slide 67

slide-66
SLIDE 66

How w to to Construct nstruct an Ad Admissible missible Heuri uristic stic

  • Identify relaxed version of the problem:
  • where one or more constraints have been dropped
  • problem with fewer restrictions on the actions
  • Grid world: the agent can move through walls
  • Driver: the agent can move straight
  • 8 puzzle:
  • “number of misplaced tiles”:

tiles can move everywhere and occupy same spot as others

  • “sum of moves between current and goal position”:

tiles can ………………………..

Why does this lead to an admissible heuristic?

  • The problem only gets easier!
  • Less costly to solve it

68

slide-67
SLIDE 67

How w to to Construct nstruct a He Heuri uristic stic (cont

  • nt.)

.)

  • You should identify constraints which, when dropped, make

the problem easy to solve

  • important because heuristics are not useful if they're as

hard to solve as the original problem!

This was the case in our examples

Robot: allowing the agent to move through walls. Optimal solution to this relaxed problem is Manhattan distance Driver: allowing the agent to move straight. Optimal solution to this relaxed problem is straight-line distance 8puzzle: tiles can move anywhere. Optimal solution to this relaxed problem is number of misplaced tiles

69

slide-68
SLIDE 68

Apply basic properties of search algorithms:

  • completeness, optimality, time and space complexity

Complete Optimal Time Space DFS N (Y if no cycles) N O(bm) O(mb) BFS Y Y O(bm) O(bm) IDS Y Y O(bm) O(mb) LCFS (when arc costs available) Y Costs > ε Y Costs >=0 O(bm) O(bm) Best First (when h available)

Le Lear arni ning ng Goa

  • al fo

for r Sea earch ch

70

slide-69
SLIDE 69

Apply basic properties of search algorithms:

  • completeness, optimality, time and space complexity

Complete Optimal Time Space DFS N (Y if no cycles) N O(bm) O(mb) BFS Y Y O(bm) O(bm) IDS Y Y O(bm) O(mb) LCFS (when arc costs available) Y Costs > ε Y Costs >=0 O(bm) O(bm) Best First (when h available) N N O(bm) O(bm)

Le Lear arni ning ng Goa

  • al fo

for r Sea earch ch

71

slide-70
SLIDE 70
  • Apply basic properties of search algorithms:
  • completeness, optimality
  • time and space complexity
  • Select the most appropriate search algorithms for specific

problems.

  • Depth-First Search vs. Bredth-First Search vs. Iterative Deepening
  • vs. Least-Cost-First Search, Best Fir

irst t Sear arch ch

  • Define/read/write/trace/debug different search algorithms
  • Co

Constr truct uct heuristi istic functio ctions s and disc iscuss s their ir admissib issibil ilit ity for r specifi ific search ch problem lems s

Learning Goals for Search (up to today)

72

slide-71
SLIDE 71
  • Do practice excercises 3C and 3D
  • Read Ch 3.7 (More sophisticated search)

TO TODO

  • Start working on Assignment 1! You can already do

many of the questions

73