Download presentation

Presentation is loading. Please wait.

Published byHerbert McCormick Modified about 1 year ago

1
Search Tamara Berg CS Artificial Intelligence Many slides throughout the course adapted from Dan Klein, Stuart Russell, Andrew Moore, Svetlana Lazebnik, Percy Liang, Luke Zettlemoyer

2
Course Information Instructor: Tamara Berg Course website: TAs: Shubham Gupta & Rohit Gupta Office Hours (Tamara): Tuesdays/Thursdays 4:45-5:45pm FB 236 Office Hours (Shubham): Mondays 4-5pm & Friday 3-4pm SN 307 Office Hours (Rohit): Wednesday 4-5pm & Friday 4-5pm SN 312 See website & previous slides for additional important course information.

3
Announcements for today Sign up for the class piazza mailing list here: – piazza.com/unc/spring2014/comp Reminder: This is a 3 credit course. If you are enrolled for 1 credit, please change to 3 credits. HW1 will be released on the course website tonight (Shubham/Rohit will give a short overview at the end of class)

4
Recall from last class

5
Agents An agent is anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators

6
Rational agents For each possible percept sequence, a rational agent should select an action that is expected to maximize its performance measure, given the evidence provided by the percept sequence and the agent’s built-in knowledge Performance measure (utility function): An objective criterion for success of an agent's behavior

7
Types of agents Reflex agent Consider how the world IS Choose action based on current percept (and maybe memory or a model of the world’s current state) Do not consider the future consequences of their actions Planning agent Consider how the world WOULD BE Decisions based on (hypothesized) consequences of actions Must have a model of how the world evolves in response to actions Must formulate a goal (test)

8
Search We will consider the problem of designing goal-based agents in fully observable, deterministic, discrete, known environments Start state Goal state

9
Search problem components Initial state Actions Transition model – What state results from performing a given action in a given state? Goal state Path cost – Assume that it is a sum of nonnegative step costs The optimal solution is the sequence of actions that gives the lowest path cost for reaching the goal Initial state Goal state

10
Example: Romania On vacation in Romania; currently in Arad Flight leaves tomorrow from Bucharest Initial state – Arad Actions – Go from one city to another Transition model – If you go from city A to city B, you end up in city B Goal state – Bucharest Path cost – Sum of edge costs (total distance traveled)

11
State space The initial state, actions, and transition model define the state space of the problem – The set of all states reachable from initial state by any sequence of actions – Can be represented as a directed graph where the nodes are states and links between nodes are actions

12
Vacuum world state space graph

13
Search Given: – Initial state – Actions – Transition model – Goal state – Path cost How do we find the optimal solution? – How about building the state space and then using Dijkstra’s shortest path algorithm? Complexity of Dijkstra’s is O(E + V log V), where V is the size of the state space The state space may be huge!

14
Search: Basic idea Let’s begin at the start state and expand it by making a list of all possible successor states Maintain a frontier – the set of all leaf nodes available for expansion at any point At each step, pick a state from the frontier to expand Keep going until you reach a goal state or there are no more states to explore. Try to expand as few states as possible

15
Search tree “What if” tree of sequences of actions and outcomes The root node corresponds to the starting state The children of a node correspond to the successor states of that node’s state A path through the tree corresponds to a sequence of actions – A solution is a path ending in a goal state Edges are labeled with actions and costs ……… … Starting state Successor state Action Goal state

16

17

18
Tree Search Algorithm Outline Initialize the frontier using the start state While the frontier is not empty – Choose a frontier node to expand according to search strategy and take it off the frontier – If the node contains the goal state, return solution – Else expand the node and add its children to the frontier

19
Tree search example Start: Arad Goal: Bucharest

20
Tree search example Start: Arad Goal: Bucharest

21
Tree search example Start: Arad Goal: Bucharest

22
Tree search example Start: Arad Goal: Bucharest

23
Tree search example Start: Arad Goal: Bucharest

24
Tree search example Start: Arad Goal: Bucharest

25
Tree search example Start: Arad Goal: Bucharest

26
Handling repeated states Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search strategy and take it off the frontier – If the node contains the goal state, return solution – Else expand the node and add its children to the frontier To handle repeated states: – Keep an explored set; which remembers every expanded node – Newly generated nodes already in the explored set or frontier can be discarded instead of added to the frontier

27
Search without repeated states Start: Arad Goal: Bucharest

28
Search without repeated states Start: Arad Goal: Bucharest

29
Search without repeated states Start: Arad Goal: Bucharest

30
Search without repeated states Start: Arad Goal: Bucharest

31
Search without repeated states Start: Arad Goal: Bucharest

32
Search without repeated states Start: Arad Goal: Bucharest

33
Search without repeated states Start: Arad Goal: Bucharest

34
Tree Search Algorithm Outline Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search strategy and take it off the frontier – If the node contains the goal state, return solution – Else expand the node and add its children to the frontier Main question: What should our search strategy be, ie how do we choose which frontier node to expand?

35
Uninformed search strategies A search strategy is defined by picking the order of node expansion Uninformed search strategies use only the information available in the problem definition – Breadth-first search – Depth-first search – Iterative deepening search – Uniform-cost search

36
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select the most promising one for expansion Greedy best-first search A* search

37
Uninformed search

38
Breadth-first search Expand shallowest node in the frontier Example state space graph for a tiny search problem Example from P. Abbeel and D. Klein

39
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

40
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

41
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

42
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

43
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

44
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

45
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

46
Breadth-first search Expansion order: (S,d,e,p,b,c,e,h,r,q,a,a, h,r,p,q,f,p,q,f,q,c,G)

47
Breadth-first search Expand shallowest node in the frontier Implementation: frontier is a FIFO queue Example state space graph for a tiny search problem Example from P. Abbeel and D. Klein

48
Depth-first search Expand deepest node in the frontier

49
Depth-first search Expansion order: (S,d,b,a,c,a,e,h,p,q, q, r,f,c,a,G)

50
Depth-first search Expansion order: (S,d,b,a,c,a,e,h,p,q, q, r,f,c,a,G)

51
Depth-first search Expansion order: (S,d,b,a,c,a,e,h,p,q, q, r,f,c,a,G)

52
Depth-first search Expansion order: (S,d,b,a,c,a,e,h,p,q, q, r,f,c,a,G)

53
Depth-first search Expansion order: (S,d,b,a,c,a,e,h,p,q, q, r,f,c,a,G)

54
Depth-first search Expansion order: (S,d,b,a,c,a,e,h,p,q, q, r,f,c,a,G)

55
Depth-first search Expansion order: (S,d,b,a,c,a,e,h,p,q, q,r,f,c,a,G)

56
Depth-first search Expand deepest unexpanded node Implementation: frontier is a LIFO queue

57

58
Analysis of search strategies Strategies are evaluated along the following criteria: – Completeness does it always find a solution if one exists? – Optimality does it always find a least-cost solution? – Time complexity how long does it take to find a solution? – Space complexity maximum number of nodes in memory Time and space complexity are measured in terms of – b: maximum branching factor of the search tree – d: depth of the optimal solution – m: maximum length of any path in the state space (may be infinite)

59
Properties of breadth-first search Complete? Yes (if branching factor b is finite) Optimal? Not generally – the shallowest goal node is not necessarily the optimal one Yes – if all actions have same cost Time? Number of nodes in a b-ary tree of depth d: O(b d ) (d is the depth of the optimal solution) Space? O(bd)O(bd)

60
BFS DepthNodesTimeMemory ms107 kilobytes 411,11011 ms10.6 megabytes 610^61.1 s1 gigabyte 810^82 min103 gigabytes 1010^103 hrs10 terabytes 1210^1213 days1 petabyte 1410^143.5 years99 petabytes 1610^16350 years10 exabytes Time and Space requirements for BFS with b=10; 1 million nodes/second; 1000 bytes/node

61
Properties of depth-first search Complete? Fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path complete in finite spaces Optimal? No – returns the first solution it finds Time? May generate all of the O(b m ) nodes, m=max depth of any node Terrible if m is much larger than d Space? O(bm), i.e., linear space!

62
Iterative deepening search Use DFS as a subroutine 1.Check the root 2.Do a DFS with depth limit 1 3.If there is no path of length 1, do a DFS search with depth limit 2 4.If there is no path of length 2, do a DFS with depth limit 3. 5.And so on…

63
Iterative deepening search

64

65

66

67
Properties of iterative deepening search Complete? Yes Optimal? Not generally – the shallowest goal node is not necessarily the optimal one Yes – if all actions have same cost Time? (d+1)b 0 + d b 1 + (d-1)b 2 + … + b d = O(b d ) Space? O(bd)

68
Search with varying step costs BFS finds the path with the fewest steps, but does not always find the cheapest path

69
Uniform-cost search For each frontier node, save the total cost of the path from the initial state to that node Expand the frontier node with the lowest path cost Implementation: frontier is a priority queue ordered by path cost Equivalent to breadth-first if step costs all equal

70
Uniform-cost search example

71
Expansion order: (S,p,d,b,e,a,r,f,e,G)

72
Uniform-cost search example Expansion order: (S,p,d,b,e,a,r,f,e,G)

73
Uniform-cost search example Expansion order: (S,p,d,b,e,a,r,f,e,G)

74
Uniform-cost search example Expansion order: (S,p,d,b,e,a,r,f,e,G)

75
Uniform-cost search example Expansion order: (S,p,d,b,e,a,r,f,e,G)

76
Another example of uniform-cost search Source: WikipediaWikipedia

77
Optimality of uniform-cost search Graph separation property: every path from the initial state to an unexplored state has to pass through a state on the frontier – Proved inductively Optimality of UCS: proof by contradiction – Suppose UCS terminates at goal state n with path cost g(n) = C but there exists another goal state n’ with g(n’) < C – Then there must exist a node n” on the frontier that is on the optimal path to n’ – But because g(n”) ≤ g(n’) < g(n), n” should have been expanded first!

78
Properties of uniform-cost search Complete? Yes, if step cost is greater than some positive constant ε (gets stuck in infinite loop if there is a path with inifinite sequence of zero-cost actions) Optimal? Yes – nodes expanded in increasing order of path cost Time? Number of nodes with path cost ≤ cost of optimal solution (C*), O(b C*/ ε ) This can be greater than O(b d ): the search can explore long paths consisting of small steps before exploring shorter paths consisting of larger steps Space? O(b C*/ ε )

79
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select the most promising one for expansion Greedy best-first search A* search

80
Heuristic function Heuristic function h(n) estimates the cost of reaching goal from node n Example: Start state Goal state

81
Heuristic for the Romania problem

82
Greedy best-first search Expand the node that has the lowest value of the heuristic function h(n)

83
Greedy best-first search example

84

85

86

87
Properties of greedy best-first search Complete? No – can get stuck in loops start goal

88

89
Properties of greedy best-first search Complete? No – can get stuck in loops Optimal? No

90
Properties of greedy best-first search Complete? No – can get stuck in loops Optimal? No Time? Worst case: O(b m ) Can be much better with a good heuristic Space? Worst case: O(b m )

91
How can we fix the greedy problem?

92
A * search Idea: avoid expanding paths that are already expensive The evaluation function f(n) is the estimated total cost of the path through node n to the goal: f(n) = g(n) + h(n) g(n): cost so far to reach n (path cost) h(n): estimated cost from n to goal (heuristic)

93
A * search example

94

95

96

97

98

99
Another example Source: WikipediaWikipedia

100
Uniform cost search vs. A* search Source: WikipediaWikipedia

101
Admissible heuristics An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimistic A heuristic h(n) is admissible if for every node n, h(n) ≤ h * (n), where h * (n) is the true cost to reach the goal state from n Is straight line distance admissible? – Yes, straight line distance never overestimates the actual road distance

102
Optimality of A* Theorem: If h(n) is admissible, A * is optimal Proof by contradiction: – Suppose A* terminates at goal state n with f(n) = g(n) = C but there exists another goal state n’ with g(n’) < C – Then there must exist a node n” on the frontier that is on the optimal path to n’ – Because h is admissible, we must have f(n”) ≤ g(n’) – But then, f(n”) < C, so n” should have been expanded first!

103
Optimality of A* A* is optimally efficient – no other tree-based algorithm that uses the same heuristic can expand fewer nodes and still be guaranteed to find the optimal solution – Any algorithm that does not expand all nodes with f(n) ≤ C* risks missing the optimal solution

104
Properties of A* Complete? Yes – unless there are infinitely many nodes with f(n) ≤ C* Optimal? Yes Time? Number of nodes for which f(n) ≤ C* (exponential) Space? Exponential

105
Designing heuristic functions Heuristics for the 8-puzzle h 1 (n) = number of misplaced tiles h 2 (n) = total Manhattan distance (number of squares from desired location of each tile) h 1 (start) = 8 h 2 (start) = = 18 Are h 1 and h 2 admissible?

106
Dominance If h 1 and h 2 are both admissible heuristics and h 2 (n) ≥ h 1 (n) for all n, (both admissible) then h 2 dominates h 1 Which one is better for search? – A* search expands every node with f(n) < C* or h(n) < C* – g(n) – Therefore, A* search with h 1 will expand more nodes

107
Dominance Typical search costs for the 8-puzzle (average number of nodes expanded for different solution depths): d=12IDS = 3,644,035 nodes A * (h 1 ) = 227 nodes A * (h 2 ) = 73 nodes d=24 IDS ≈ 54,000,000,000 nodes A * (h 1 ) = 39,135 nodes A * (h 2 ) = 1,641 nodes

108
Heuristics from relaxed problems A problem with fewer restrictions on the actions is called a relaxed problem The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem If the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then h 1 (n) gives the shortest solution If the rules are relaxed so that a tile can move to any adjacent square, then h 2 (n) gives the shortest solution

109
Heuristics from subproblems Let h 3 (n) be the cost of getting a subset of tiles (say, 1,2,3,4) into their correct positions Can precompute and save the exact solution cost for every possible subproblem instance – pattern database

110
Combining heuristics Suppose we have a collection of admissible heuristics h 1 (n), h 2 (n), …, h m (n), but none of them dominates the others How can we combine them? h(n) = max{h 1 (n), h 2 (n), …, h m (n)}

111
Weighted A* search Idea: speed up search at the expense of optimality Take an admissible heuristic, “inflate” it by a multiple α > 1, and then perform A* search as usual Fewer nodes tend to get expanded, but the resulting solution may be suboptimal (its cost will be at most α times the cost of the optimal solution)

112
Example of weighted A* search Heuristic: 5 * Euclidean distance from goal Source: WikipediaWikipedia

113
Example of weighted A* search Heuristic: 5 * Euclidean distance from goal Source: WikipediaWikipedia Compare: Exact A*

114
Additional pointers Interactive path finding demo Variants of A* for path finding on grids

115
All search strategies AlgorithmComplete?Optimal? Time complexity Space complexity BFS DFS IDS UCS Greedy A* No Worst case: O(b m ) Yes Yes (if heuristic is admissible) Best case: O(bd) Number of nodes with g(n)+h(n) ≤ C* Yes No Yes If all step costs are equal Yes No O(b d ) O(b m ) O(b d ) O(bm) O(bd) Number of nodes with g(n) ≤ C*

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google