Presentation is loading. Please wait.

Presentation is loading. Please wait.

Search Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Dan Klein, Stuart Russell, Andrew Moore, Svetlana Lazebnik,

Similar presentations


Presentation on theme: "Search Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Dan Klein, Stuart Russell, Andrew Moore, Svetlana Lazebnik,"— Presentation transcript:

1 Search Tamara Berg CS 560 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 (tlberg@cs.unc.edu)tlberg@cs.unc.edu Office Hours: FB 236, Mon/Wed 11:25-12:25pm Course website: http://tamaraberg.com/teaching/Fall_15/http://tamaraberg.com/teaching/Fall_15/ Course mailing list: comp560@cs.unc.educomp560@cs.unc.edu TA: Patrick (Ric) Poirson TA office hours: SN 109, Tues/Thurs 4-5pm Announcements, readings, schedule, etc, will all be posted to the course webpage. Schedule may be modified as needed over the semester. Check frequently!

3 Announcements for today HW1 will be released on the course website later today, due Sept 10, 11:59pm. – Start early!

4 Recall from last class

5 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

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

7 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

8 Vacuum world state space graph

9 Search Given: – Initial state – Actions – Transition model – Goal state – Path cost How do we find the optimal solution? – How about building the state space graph 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!

10 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

11 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

12 Tree search example Start: Arad Goal: Bucharest

13 Tree search example Start: Arad Goal: Bucharest

14 Tree search example Start: Arad Goal: Bucharest

15 Tree search example Start: Arad Goal: Bucharest

16 Tree search example Start: Arad Goal: Bucharest

17 Tree search example Start: Arad Goal: Bucharest

18 Tree search example Start: Arad Goal: Bucharest

19 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 – Every time you expand a node, add that state to the explored set; do not put explored states on the frontier again – Every time you add a node to the frontier, check whether it already exists in the frontier with a higher path cost, and if yes, replace that node with the new one

20 Search without repeated states Start: Arad Goal: Bucharest

21 Search without repeated states Start: Arad Goal: Bucharest

22 Search without repeated states Start: Arad Goal: Bucharest

23 Search without repeated states Start: Arad Goal: Bucharest

24 Search without repeated states Start: Arad Goal: Bucharest

25 Search without repeated states Start: Arad Goal: Bucharest

26 Search without repeated states Start: Arad Goal: Bucharest

27 Searching 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 – Every time you expand a node, add that state to the explored set; do not put explored states on the frontier again – Every time you add a node to the frontier, check whether it already exists in the frontier with a higher path cost, and if yes, replace that node with the new one Remaining question: What should our search strategy be, ie how do we choose which frontier node to expand?

28 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

29 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

30 Uninformed search

31 Breadth-first search Expand shallowest node in the frontier Example state space graph for a tiny search problem

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

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

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

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

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

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

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

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

43 Depth-first search Expand deepest node in the frontier

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

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

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

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

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

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 Expand deepest unexpanded node Implementation: frontier is a LIFO queue

52 http://xkcd.com/761/

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

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

55 BFS DepthNodesTimeMemory 21100.11 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

56 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!

57 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…

58 Iterative deepening search

59

60

61

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


Download ppt "Search Tamara Berg CS 560 Artificial Intelligence Many slides throughout the course adapted from Dan Klein, Stuart Russell, Andrew Moore, Svetlana Lazebnik,"

Similar presentations


Ads by Google