search tamara berg cs 560 artificial intelligence many slides throughout the course adapted from dan...

62
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

Upload: polly-walton

Post on 03-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

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

Search

Tamara BergCS 560 Artificial Intelligence

Many slides throughout the course adapted from Dan Klein, Stuart Russell, Andrew Moore, Svetlana Lazebnik, Percy Liang, Luke Zettlemoyer

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

Course Information

• Instructor: Tamara Berg ([email protected])• Office Hours: FB 236, Mon/Wed 11:25-12:25pm• Course website: http://tamaraberg.com/teaching/Fall_15/• Course mailing list: [email protected]

• TA: Patrick (Ric) PoirsonTA 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!

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

Announcements for today

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

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

Recall from last class

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

Search problem components• Initial state• Actions• Transition model

– What state results fromperforming 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

Initialstate

Goal state

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

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)

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

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

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

Vacuum world state space graph

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

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!

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

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

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

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

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

Tree search example

Start: AradGoal: Bucharest

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

Tree search example

Start: AradGoal: Bucharest

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

Tree search example

Start: AradGoal: Bucharest

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

Tree search example

Start: AradGoal: Bucharest

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

Tree search example

Start: AradGoal: Bucharest

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

Tree search example

Start: AradGoal: Bucharest

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

Tree search example

Start: AradGoal: Bucharest

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

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

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

Search without repeated states

Start: AradGoal: Bucharest

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

Search without repeated states

Start: AradGoal: Bucharest

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

Search without repeated states

Start: AradGoal: Bucharest

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

Search without repeated states

Start: AradGoal: Bucharest

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

Search without repeated states

Start: AradGoal: Bucharest

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

Search without repeated states

Start: AradGoal: Bucharest

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

Search without repeated states

Start: AradGoal: Bucharest

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

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 oneRemaining question: What should our search strategy be,

ie how do we choose which frontier node to expand?

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

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

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

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

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

Uninformed search

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

Breadth-first search

• Expand shallowest node in the frontier

Example state space graph for a tiny search

problem

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

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)

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

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)

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

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)

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

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)

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

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)

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

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)

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

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)

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

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)

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

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)

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

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)

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

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

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

Depth-first search

• Expand deepest node in the frontier

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

Depth-first search

• Expansion order: (S,d,b,a,c,a,e,h,p,q,q, r,f,c,a,G)

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

Depth-first search

• Expansion order: (S,d,b,a,c,a,e,h,p,q,q, r,f,c,a,G)

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

Depth-first search

• Expansion order: (S,d,b,a,c,a,e,h,p,q,q, r,f,c,a,G)

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

Depth-first search

• Expansion order: (S,d,b,a,c,a,e,h,p,q,q, r,f,c,a,G)

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

Depth-first search

• Expansion order: (S,d,b,a,c,a,e,h,p,q,q, r,f,c,a,G)

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

Depth-first search

• Expansion order: (S,d,b,a,c,a,e,h,p,q,q, r,f,c,a,G)

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

Depth-first search

• Expansion order: (S,d,b,a,c,a,e,h,p,q,q,r,f,c,a,G)

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

Depth-first search

• Expand deepest unexpanded node• Implementation: frontier is a LIFO queue

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

http://xkcd.com/761/

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

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)

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

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 oneYes – if all actions have same cost

• Time? Number of nodes in a b-ary tree of depth d: O(bd)(d is the depth of the optimal solution)

• Space? O(bd)

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

BFS

Depth Nodes Time Memory

2 110 0.11 ms 107 kilobytes

4 11,110 11 ms 10.6 megabytes

6 10^6 1.1 s 1 gigabyte

8 10^8 2 min 103 gigabytes

10 10^10 3 hrs 10 terabytes

12 10^12 13 days 1 petabyte

14 10^14 3.5 years 99 petabytes

16 10^16 350 years 10 exabytes

Time and Space requirements for BFS with b=10; 1 million nodes/second; 1000 bytes/node

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

Properties of depth-first search

• Complete?Fails in infinite-depth spaces, spaces with loopsModify 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(bm) nodes, m=max depth of any nodeTerrible if m is much larger than d

• Space? O(bm), i.e., linear space!

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

Iterative deepening search

• Use DFS as a subroutine1. Check the root2. Do a DFS with depth limit 13. If there is no path of length 1, do a DFS search

with depth limit 24. If there is no path of length 2, do a DFS with

depth limit 3.5. And so on…

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

Iterative deepening search

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

Iterative deepening search

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

Iterative deepening search

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

Iterative deepening search

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

Properties of iterative deepening search

• Complete?Yes

• Optimal?Not generally – the shallowest goal node is not

necessarily the optimal oneYes – if all actions have same cost

• Time?(d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)

• Space?O(bd)