Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014

Slides:



Advertisements
Similar presentations
Uninformed search strategies
Advertisements

Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 14, 2012.
CPSC 322, Lecture 4Slide 1 Search: Intro Computer Science cpsc322, Lecture 4 (Textbook Chpt ) Sept, 11, 2013.
Problem Solving and Search Andrea Danyluk September 9, 2013.
Part2 AI as Representation and Search
Problem Solving Agents A problem solving agent is one which decides what actions and states to consider in completing a goal Examples: Finding the shortest.
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
CS 480 Lec 3 Sept 11, 09 Goals: Chapter 3 (uninformed search) project # 1 and # 2 Chapter 4 (heuristic search)
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
Implementation and Evaluation of Search Methods. Use a stack data structure. 1. Push root node of tree on the stack. 2. Pop the top node off the stack.
Artificial Intelligence (CS 461D)
Search: Representation and General Search Procedure Jim Little UBC CS 322 – Search 1 September 10, 2014 Textbook § 3.0 –
Slide 1 Heuristic Search: BestFS and A * Jim Little UBC CS 322 – Search 5 September 19, 2014 Textbook § 3.6.
Slide 1 Search: Advanced Topics Jim Little UBC CS 322 – Search 5 September 22, 2014 Textbook § 3.6.
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 23, 2009.
CPSC 322, Lecture 4Slide 1 Search: Intro Computer Science cpsc322, Lecture 4 (Textbook Chpt ) January, 12, 2009.
Search: Representation and General Search Procedure CPSC 322 – Search 1 January 12, 2011 Textbook § 3.0 –
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 22, 2010.
Review: Search problem formulation
Searching the search space graph
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.3 [P]: Searching Fall 2009 Marco Valtorta.
1 Lecture 3 Uninformed Search. 2 Complexity Recap (app.A) We often want to characterize algorithms independent of their implementation. “This algorithm.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
CPSC 322, Lecture 8Slide 1 Heuristic Search: BestFS and A * Computer Science cpsc322, Lecture 8 (Textbook Chpt 3.5) January, 21, 2009.
CS 188: Artificial Intelligence Spring 2006 Lecture 2: Queue-Based Search 8/31/2006 Dan Klein – UC Berkeley Many slides over the course adapted from either.
Announcements Project 0: Python Tutorial
Uninformed Search (cont.)
Solving Problems by Searching
Multiple Path Pruning, Iterative Deepening CPSC 322 – Search 7 Textbook § January 26, 2011.
Review: Search problem formulation Initial state Actions Transition model Goal state (or goal test) Path cost What is the optimal solution? What is the.
1 Problem Solving and Searching CS 171/271 (Chapter 3) Some text and images in these slides were drawn from Russel & Norvig’s published material.
Problem Solving and Search Andrea Danyluk September 11, 2013.
Uninformed Search Strategies CPSC 322 – Search 2 January 14, 2011 Textbook §3.5 1.
Computer Science CPSC 322 Lecture 4 Search: Intro (textbook Ch: ) 1.
CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #3 Instructor: Eyal Amir Grad TAs: Wen Pu, Yonatan Bisk Undergrad TAs: Sam.
Computer Science CPSC 322 Lecture Heuristic Search (Ch: 3.6, 3.6.1) Slide 1.
Computer Science CPSC 322 Lecture A* and Search Refinements (Ch 3.6.1, 3.7.1, 3.7.2) Slide 1.
Lecture 2 Search (textbook Ch: 3)
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning.
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l all learning algorithms,
Computer Science CPSC 322 Lecture 9 (Ch , 3.7.6) Slide 1.
CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.
Search with Costs and Heuristic Search 1 CPSC 322 – Search 3 January 17, 2011 Textbook §3.5.3, Taught by: Mike Chiang.
Lecture 3: Uninformed Search
Heuristic Search: A* 1 CPSC 322 – Search 4 January 19, 2011 Textbook §3.6 Taught by: Vasanth.
Computer Science CPSC 322 Lecture 6 Iterative Deepening and Search with Costs (Ch: 3.7.3, 3.5.3)
Goal-based Problem Solving Goal formation Based upon the current situation and performance measures. Result is moving into a desirable state (goal state).
CSCI 4310 Lecture 2: Search. Search Techniques Search is Fundamental to Many AI Techniques.
Uninformed search strategies A search strategy is defined by picking the order of node expansion Uninformed search strategies use only the information.
CPSC 322, Lecture 6Slide 1 Uniformed Search (cont.) Computer Science cpsc322, Lecture 6 (Textbook finish 3.5) Sept, 17, 2012.
CPSC 322, Lecture 4Slide 1 Search: Intro Computer Science cpsc322, Lecture 4 (Textbook Chpt ) Sept, 12, 2012.
A* optimality proof, cycle checking CPSC 322 – Search 5 Textbook § 3.6 and January 21, 2011 Taught by Mike Chiang.
Fahiem Bacchus © 2005 University of Toronto 1 CSC384: Intro to Artificial Intelligence Search II ● Announcements.
Solving problems by searching A I C h a p t e r 3.
Artificial Intelligence Search Problem. Search is a problem-solving technique to explores successive stages in problem- solving process.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Brian Williams, Fall 041 Analysis of Uninformed Search Methods Brian C. Williams Sep 21 st, 2004 Slides adapted from: Tomas Lozano Perez,
Artificial Intelligence Solving problems by searching.
Lecture 3: Uninformed Search
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
Search: Advanced Topics Computer Science cpsc322, Lecture 9
Search: Advanced Topics Computer Science cpsc322, Lecture 9
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
Computer Science cpsc322, Lecture 2
Problem Solving and Searching
Searching for Solutions
Artificial Intelligence
Problem Solving and Searching
Presentation transcript:

Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014 Textbook §3.5

Recap Search is a key computational mechanism in many AI agents We will study the basic principles of search on the simple deterministic planning agent model Generic search approach: define a search space graph, start from current state, incrementally explore paths from current state until goal state is reached. CPSC 322, Lecture 4

Searching: Graph Search Algorithm with three bugs  Input: a graph, a start node, Boolean procedure goal(n) that tests if n is a goal node. frontier := { g: g is a goal node }; while frontier is not empty: select and remove path n0, n1, …, nk from frontier; if goal(nk) return nk ; for every neighbor n of nk add  n0, n1, …, nk  to frontier; end while No solution found Discuss In groups - Give a few mins After the algorithm returns, it can be asked for more answers and the procedure continues. The goal function defines what is a solution. The neighbor relationship defines the graph. Which path is selected from the frontier defines the search strategy. CPSC 322, Lecture 5

Criteria to compare Search Strategies Lecture Overview Recap Criteria to compare Search Strategies Simple (Uninformed) Search Strategies Depth First Breadth First CPSC 322, Lecture 5

Comparing Searching Algorithms: will it find a solution? the best one? Def. (complete): A search algorithm is complete if, whenever at least one solution exists, the algorithm is guaranteed to find a solution within a finite amount of time. Def. (optimal): A search algorithm is optimal if, when it finds a solution , it is the best solution Lecture slides DO NOT contain everything that is said in class, but you are still responsible for this content So, make sure you bring yourself up-to-date if you miss a class CPSC 322, Lecture 5

Comparing Searching Algorithms: Complexity Def. (time complexity) The time complexity of a search algorithm is an expression for the worst-case amount of time it will take to run, expressed in terms of the maximum path length m and the maximum branching factor b. Def. (space complexity) : The space complexity of a search algorithm is an expression for the worst-case amount of memory that the algorithm will use (number of nodes), Also expressed in terms of m and b. m maximum depth of the search tree CPSC 322, Lecture 5

Criteria to compare Search Strategies Lecture Overview Recap Criteria to compare Search Strategies Simple (Uninformed) Search Strategies Depth First Breadth First CPSC 322, Lecture 5

Depth-first Search: DFS Depth-first search treats the frontier as a stack It always selects one of the last elements added to the frontier. Example: the frontier is [p1, p2, …, pr ] neighbors of last node of p1 (its end) are {n1, …, nk} What happens? p1 is selected, and its end is tested for being a goal. New paths are created attaching {n1, …, nk} to p1 These “replace” p1 at the beginning of the frontier. Thus, the frontier is now [(p1, n1), …, (p1, nk), p2, …, pr] . NOTE: p2 is only selected when all paths extending p1 have been explored. CPSC 322, Lecture 5

Depth-first search: Illustrative Graph --- Depth-first Search Frontier The longest path is expanded CPSC 322, Lecture 5

Depth-first Search: Analysis of DFS Is DFS complete? Is DFS optimal? Show AI space: Depth-first search isn't guaranteed to halt on graphs with cycles. Space complexity is linear CPSC 322, Lecture 5

DFS in AI Space Go to: http://www.aispace.org/mainTools.shtml Click on “Graph Searching” to get to the Search Applet Select the “Solve” tab in the applet Select one of the available examples via “File -> Load Sample Problem (good idea to start with the “Simple Tree” problem) Make sure that “Search Options -> Search Algorithms” in the toolbar is set to “Depth-First Search”. Step through the algorithm with the “Fine Step” or “Step” buttons in the toolbar The panel above the graph panel verbally describes what is happening during each step The panel at the bottom shows how the frontier evolves See available help pages and video tutorials for more details on how to use the Search applet (http://www.aispace.org/search/index.shtml) [(p1, n1), …, (p1, nk), p2, …, pr] .

Depth-first Search: Analysis of DFS What is the time complexity, if the maximum path length is m and the maximum branching factor is b ? What is the space complexity? O(b+m) O(bm) O(mb) Show AI space: Depth-first search isn't guaranteed to halt on graphs with cycles. Space complexity is linear O(b+m) O(bm) O(mb) CPSC 322, Lecture 5

Depth-first Search: Analysis of DFS Summary Is DFS complete? Depth-first search isn't guaranteed to halt on graphs with cycles. However, DFS is complete for finite acyclic graphs. Is DFS optimal? What is the time complexity, if the maximum path length is m and the maximum branching factor is b ? The time complexity is ? ?: must examine every node in the tree. Search is unconstrained by the goal until it happens to stumble on the goal. What is the space complexity? Space complexity is ? ? the longest possible path is m, and for every node in that path must maintain a fringe of size b. Show AI space: Depth-first search isn't guaranteed to halt on graphs with cycles. Space complexity is linear CPSC 322, Lecture 5

Analysis of DFS Def. : A search algorithm is complete if whenever there is at least one solution, the algorithm is guaranteed to find it within a finite amount of time. Is DFS complete? No If there are cycles in the graph, DFS may get “stuck” in one of them see this in AISpace by adding a cycle to “Simple Tree” e.g., click on “Create” tab, create a new edge from N7 to N1, go back to “Solve” and see what happens

Analysis of DFS Def.: A search algorithm is optimal if when it finds a solution, it is the best one (e.g., the shortest) Is DFS optimal? Yes No E.g., goal nodes: red boxes

Analysis of DFS Def.: A search algorithm is optimal if when it finds a solution, it is the best one (e.g., the shortest) Is DFS optimal? No It can “stumble” on longer solution paths before it gets to shorter ones. E.g., goal nodes: red boxes see this in AISpace by loading “Extended Tree Graph” and set N6 as a goal e.g., click on “Create” tab, right-click on N6 and select “set as a goal node”

Analysis of DFS O(bm) O(mb) O(bm) O(b+m) Def.: The time complexity of a search algorithm is the worst-case amount of time it will take to run, expressed in terms of maximum path length m maximum forward branching factor b. What is DFS’s time complexity, in terms of m and b ? O(bm) O(mb) O(bm) O(b+m) E.g., single goal node -> red box

Analysis of DFS Def.: The time complexity of a search algorithm is the worst-case amount of time it will take to run, expressed in terms of maximum path length m maximum forward branching factor b. What is DFS’s time complexity, in terms of m and b ? O(bm) In the worst case, must examine every node in the tree E.g., single goal node -> red box

Analysis of DFS O(bm) O(mb) O(bm) O(b+m) Def.: The space complexity of a search algorithm is the worst-case amount of memory that the algorithm will use (i.e., the maximal number of nodes on the frontier), expressed in terms of maximum path length m maximum forward branching factor b. What is DFS’s space complexity, in terms of m and b ? O(bm) O(mb) O(bm) O(b+m) See how this works in

Analysis of DFS Def.: The space complexity of a search algorithm is the worst-case amount of memory that the algorithm will use (i.e., the maximum number of nodes on the frontier), expressed in terms of maximum path length m maximum forward branching factor b. What is DFS’s space complexity, in terms of m and b ? for every node in the path currently explored, DFS maintains a path to its unexplored siblings in the search tree Alternative paths that DFS needs to explore The longest possible path is m, with a maximum of b-1 alterative paths per node O(bm) See how this works in

Depth-first Search: When it is appropriate? Space is restricted (complex state representation e.g., robotics) There are many solutions, perhaps with long path lengths, particularly for the case in which all paths lead to a solution Inappropriate Cycles There are shallow solutions Show AI space: Depth-first search isn't guaranteed to halt on graphs with cycles. Space complexity is linear Ordering heuristic is weak CPSC 322, Lecture 5

Depth-first Search: When it is appropriate? Space is restricted (complex state representation e.g., robotics) There are many solutions, perhaps with long path lengths, particularly for the case in which all paths lead to a solution Inappropriate Cycles There are shallow solutions If you care about optimality! Show AI space: Depth-first search isn't guaranteed to halt on graphs with cycles. Space complexity is linear Ordering heuristic is weak CPSC 322, Lecture 5

Why study and understand DFS? It is simple enough to allow you to learn the basic aspects of searching (When compared with breadth first) It is the basis for a number of more sophisticated / useful search algorithms Show AI space: Depth-first search isn't guaranteed to halt on graphs with cycles. Space complexity is linear CPSC 322, Lecture 5

Simple (Uninformed) Search Strategies Lecture Overview Recap Simple (Uninformed) Search Strategies Depth First Breadth First CPSC 322, Lecture 5

Breadth-first Search: BFS Breadth-first search treats the frontier as a queue it always selects one of the earliest elements added to the frontier. Example: the frontier is [p1,p2, …, pr] neighbors of the last node of p1 are {n1, …, nk} What happens? p1 is selected, and its end tested for being a path to the goal. New paths are created attaching {n1, …, nk} to p1 These follow pr at the end of the frontier. Thus, the frontier is now [p2, …, pr, (p1, n1), …, (p1, nk)]. p2 is selected next. CPSC 322, Lecture 5

Breadth-first Search: BFS Breadth-first search treats the frontier as a queue it always selects one of the earliest elements added to the frontier. Example: the frontier is [p1,p2, …, pr] neighbors of the last node of p1 are {n1, …, nk} What happens? p1 is selected, and its end tested for being a path to the goal. New paths are created attaching {n1, …, nk} to p1 These follow pr at the end of the frontier. Thus, the frontier is now [p2, …, pr, (p1, n1), …, (p1, nk)]. p2 is selected next. CPSC 322, Lecture 5

Illustrative Graph - Breadth-first Search CPSC 322, Lecture 5

Breadth-first Search: Analysis of BFS Is BFS complete? Is BFS optimal? CPSC 322, Lecture 5

Analysis of Breadth-First Search Is BFS complete? Yes In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?) What is the time complexity, if the maximum path length is m and the maximum branching factor is b? The time complexity is ? ? must examine every node in the tree. The order in which we examine nodes (BFS or DFS) makes no difference to the worst case: search is unconstrained by the goal. What is the space complexity? Space complexity is ? ? Is BFS complete? (we are assuming finite branching factor) we must store the whole frontier in memory CPSC 322, Lecture 5

Using Breadth-first Search When is BFS appropriate? space is not a problem it's necessary to find the solution with the fewest arcs although all solutions may not be shallow, at least some are When is BFS inappropriate? space is limited all solutions tend to be located deep in the tree the branching factor is very large there may be infinite paths CPSC 322, Lecture 5

When to use BFS vs. DFS? BFS DFS BFS DFS BFS DFS BFS DFS BFS DFS The search graph has cycles or is infinite We need the shortest path to a solution There are only solutions at great depth There are some solutions at shallow depth Memory is limited BFS DFS BFS DFS BFS DFS BFS DFS BFS DFS

What have we done so far? GOAL: study search, a set of basic methods underlying many intelligent agents AI agents can be very complex and sophisticated Let’s start from a very simple one, the deterministic, goal-driven agent for which: he sequence of actions and their appropriate ordering is the solution We have looked at two search strategies DFS and BFS: To understand key properties of a search strategy They represent the basis for more sophisticated (heuristic / intelligent) search CPSC 322, Lecture 5

Learning Goals for today’s class Apply basic properties of search algorithms: completeness, optimality, time and space complexity of search algorithms. Select the most appropriate search algorithms for specific problems. BFS vs DFS vs IDS vs BidirS- LCFS vs. BFS – A* vs. B&B vs IDA* vs MBA* CPSC 322, Lecture 5

Next Class To test your understanding of today’s class Work on Practice Exercise 3.B http://www.aispace.org/exercises.shtml Next Class Iterative Deepening Search with cost (read textbook.: 3.7.3, 3.5.3) (maybe) Start Heuristic Search (textbook.: start 3.6) CPSC 322, Lecture 5

Recap: Comparison of DFS and BFS Complete Optimal Time Space DFS BFS N N O(bm) O(bm) No cycles,Y O(bm) Y Y O(bm) CPSC 322, Lecture 5