Heuristic Search: BestFS and A* Computer Science cpsc322, Lecture 8

Slides:



Advertisements
Similar presentations
Review: Search problem formulation
Advertisements

An Introduction to Artificial Intelligence
Heuristic Search Jim Little UBC CS 322 – Search 4 September 17, 2014 Textbook §
Greedy best-first search Use the heuristic function to rank the nodes Search strategy –Expand node with lowest h-value Greedily trying to find the least-cost.
Solving Problem by Searching
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
Problem Solving and Search in AI Part I Search and Intelligence Search is one of the most powerful approaches to problem solving in AI Search is a universal.
Slide 1 Heuristic Search: BestFS and A * Jim Little UBC CS 322 – Search 5 September 19, 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 10Slide 1 Finish Search Computer Science cpsc322, Lecture 10 (Textbook Chpt 3.6) January, 25, 2010.
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 22, 2010.
Review: Search problem formulation
CPSC 322, Lecture 8Slide 1 Heuristic Search: BestFS and A * Computer Science cpsc322, Lecture 8 (Textbook Chpt 3.5) January, 21, 2009.
CPSC 322, Lecture 8Slide 1 Heuristic Search: BestFS and A * Computer Science cpsc322, Lecture 8 (Textbook Chpt 3.6) Sept, 23, 2013.
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.
Computer Science CPSC 322 Lecture 9 (Ch , 3.7.6) Slide 1.
Search with Costs and Heuristic Search 1 CPSC 322 – Search 3 January 17, 2011 Textbook §3.5.3, Taught by: Mike Chiang.
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
1 Solving problems by searching 171, Class 2 Chapter 3.
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)
CPSC 322, Lecture 8Slide 1 Heuristic Search: BestFS and A * Computer Science cpsc322, Lecture 8 (Textbook Chpt 3.6) Sept, 21, 2010.
Heuristic Functions. A Heuristic is a function that, when applied to a state, returns a number that is an estimate of the merit of the state, with respect.
CPSC 322, Lecture 6Slide 1 Uniformed Search (cont.) Computer Science cpsc322, Lecture 6 (Textbook finish 3.5) Sept, 17, 2012.
A* optimality proof, cycle checking CPSC 322 – Search 5 Textbook § 3.6 and January 21, 2011 Taught by Mike Chiang.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
CPSC 322, Lecture 7Slide 1 Heuristic Search Computer Science cpsc322, Lecture 7 (Textbook Chpt 3.6) Sept, 20, 2013.
Computer Science CPSC 322 Lecture 6 Analysis of A*, Search Refinements (Ch ) Slide 1.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Computer Science CPSC 322 Lecture 5 Heuristic Search and A* (Ch: 3.6, 3.6.1) Slide 1.
Solving problems by searching Chapter 3. Types of agents Reflex agent Consider how the world IS Choose action based on current percept Do not consider.
Computer Science cpsc322, Lecture 7
Review: Tree search Initialize the frontier using the starting state
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
Solving problems by searching
Computer Science cpsc322, Lecture 4
Search: Advanced Topics Computer Science cpsc322, Lecture 9
Last time: Problem-Solving
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Heuristic Functions.
Artificial Intelligence (CS 370D)
Department of Computer Science
Heuristic Search Introduction to Artificial Intelligence
Artificial Intelligence Problem solving by searching CSC 361
Search: Advanced Topics Computer Science cpsc322, Lecture 9
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Discussion on Greedy Search and A*
Discussion on Greedy Search and A*
Computer Science cpsc322, Lecture 2
Lecture 1B: Search.
CS 4100 Artificial Intelligence
Problem Solving and Searching
EA C461 – Artificial Intelligence
Informed search algorithms
Informed search algorithms
Problem Solving and Searching
Search: Advanced Topics Computer Science cpsc322, Lecture 9
Iterative Deepening CPSC 322 – Search 6 Textbook § 3.7.3
Chap 4: Searching Techniques
Solving problems by searching
HW 1: Warmup Missionaries and Cannibals
Informed Search Idea: be smart about what paths to try.
Iterative Deepening and Branch & Bound
HW 1: Warmup Missionaries and Cannibals
Solving problems by searching
Reading: Chapter 4.5 HW#2 out today, due Oct 5th
Informed Search Idea: be smart about what paths to try.
Presentation transcript:

Heuristic Search: BestFS and A* Computer Science cpsc322, Lecture 8 (Textbook Chpt 3.6) May, 23, 2017 Lecture 8 CPSC 322, Lecture 8

Recap / Finish Heuristic Function Best First Search A* Lecture Overview Recap / Finish Heuristic Function Best First Search A* CPSC 322, Lecture 8

How to Combine Heuristics If h1(n) is admissible and h2(n) is also admissible then min( h1(n), h2(n)) is also admissible and dominates its components sum( h1(n), h2(n)) is also admissible and dominates its components avg( h1(n), h2(n)) is also admissible and dominates its components None of the above Not looking inside state at the end of the path Asking: How close is this to the goal? CPSC 322, Lecture 6

Combining Admissible Heuristics How to combine heuristics when there is no dominance? If h1(n) is admissible and h2(n) is also admissible then h(n)= ____________________________is also admissible … and dominates all its components max (h1(n) , h2(n) ) CPSC 322, Lecture 3

Example Heuristic Functions Another one we can use the number of moves between each tile's current position and its position in the solution Which one is better? E.g., for the 8-puzzle: h1(n) = number of misplaced tiles h2(n) = total Manhattan distance (i.e., no. of squares from desired location of each tile) h1(S) = ? 8 h2(S) = ? 3+1+2+2+2+3+3+2 = 18 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 CPSC 322, Lecture 3

Another approach to construct heuristics Solution cost for a subproblem SubProblem Original Problem 1 3 8 2 5 7 6 4 1 3 @ 2 4 Current node Substantially more accurate than Manhattan distance in some cases So the two can be combined as described before 1 2 3 @ 4 1 2 3 8 4 7 6 5 Goal node CPSC 322, Lecture 3

Combining Heuristics: Example In 8-puzzle, solution cost for the 1,2,3,4 subproblem is substantially more accurate than sum of Manhattan distance of each tile from its goal position in some cases So….. Substantially more accurate than Manhattan distance in some cases So the two can be combined as described before L2 6 subp CPSC 322, Lecture 3

Admissible heuristic for Vacuum world? States if the world had n locations? Some simplifications wrt real world Discrete location Discrete dirt Reliable cleaning Room never gets messed up once cleaned states? Where it is dirty and robot location actions? Left, Right, Suck Possible goal test? no dirt at all locations CPSC 322, Lecture 3

Admissible heuristic for Vacuum world? States if the world had n locations? Some simplifications wrt real world Discrete location Discrete dirt Reliable cleaning Room never gets messed up once cleaned states? Where it is dirty and robot location actions? Left, Right, Suck Possible goal test? no dirt at all locations CPSC 322, Lecture 6

Recap Heuristic Function Best First Search A* Lecture Overview Recap Heuristic Function Best First Search A* CPSC 322, Lecture 8

Best-First Search Idea: select the path whose end is closest to a goal according to the heuristic function. Best-First search selects a path on the frontier with minimal h-value (for the end node). It treats the frontier as a priority queue ordered by h. (similar to ?) This is a greedy approach: it always takes the path which appears locally best CPSC 322, Lecture 7

Analysis of Best-First Search Not Complete : a low heuristic value can mean that a cycle gets followed forever. Optimal: no (why not?) Time complexity is O(bm) Space complexity is O(bm) Misleading heuristic demo (sample Aispace problem) Search with cost example, make MP a goal (USE FINE STEP!) !) KD heuristics 3.5 and also cost to goal from KD = 3.5 CPSC 322, Lecture 7

Recap Heuristic Function Best First Search A* Search Strategy Lecture Overview Recap Heuristic Function Best First Search A* Search Strategy CPSC 322, Lecture 8

How can we effectively use h(n) Maybe we should combine it with the cost. How? Shall we select from the frontier the path p with: Lowest cost(p) – h(p) Highest cost(p) – h(p) Highest cost(p)+h(p) Lowest cost(p)+h(p) Not looking inside state at the end of the path Asking: How close is this to the goal? CPSC 322, Lecture 6

A* Search Algorithm A* is a mix of: lowest-cost-first and best-first search A* treats the frontier as a priority queue ordered by f(p)= It always selects the node on the frontier with the ………….. estimated …………….distance. Lowest estimated total cost CPSC 322, Lecture 8

Computing f-values f-value of UBC  KD JB? 6 9 10 11

Analysis of A* If the heuristic is completely uninformative and the edge costs are all the same, A* is equivalent to…. BFS LCFS DFS None of the Above Not looking inside state at the end of the path Asking: How close is this to the goal? CPSC 322, Lecture 6

Analysis of A* Let's assume that arc costs are strictly positive. Time complexity is O(bm) the heuristic could be completely uninformative and the edge costs could all be the same, meaning that A* does the same thing as…. Space complexity is O(bm) like ….., A* maintains a frontier which grows with the size of the tree Completeness: yes. Optimality: ?? DFS BFS LCFS Complete it is always testing shorter underestimate of the total cost So it is not missing anything CPSC 322, Lecture 8

Optimality of A* If A* returns a solution, that solution is guaranteed to be optimal, as long as When the branching factor is finite arc costs are strictly positive h(n) is an underestimate of the length of the shortest path from n to a goal node, and is non-negative Theorem If A* selects a path p as the solution, p is the shortest (i.e., lowest-cost) path. CPSC 322, Lecture 8

Why is A* optimal? p p'' p' A* returns p Assume for contradiction that some other path p' is actually the shortest path to a goal Consider the moment when p is chosen from the frontier. Some part of path p' will also be on the frontier; let's call this partial path p''. p p' p'' CPSC 322, Lecture 8

Why is A* optimal? (cont’) Because p was expanded before p'', Because p is a goal, Thus Because h is admissible, cost(p'') + h(p'')  for any path p' to a goal that extends p'' Thus for any other path p' to a goal. Because p was expanded before p'', f(p)  f(p''). Because p is a goal, h(p)=0. Thus cost(p)  cost(p'') + h(p''). Because h is admissible, cost(p'') + h(p'')  cost(p') for any path p' to a goal that extends p'' Thus cost(p)  cost(p') for any other path p' to a goal. This contradicts our assumption that p' is the shortest path. This contradicts our assumption that p' is the shortest path. CPSC 322, Lecture 8

Optimal efficiency of A* In fact, we can prove something even stronger about A*: in a sense (given the particular heuristic that is available) no search algorithm could do better! Optimal Efficiency: Among all optimal algorithms that start from the same start node and use the same heuristic h, A* expands the minimal number of paths. In fact, we can prove something even stronger about A*: in a sense (given the particular heuristic that is available) no search algorithm could do better! problem: A* could be unlucky about how it breaks ties. So let's define optimal efficiency as expanding the minimal number of paths p for which f(p) < f*, where f* is the cost of the optimal solution. CPSC 322, Lecture 8

Samples A* applications An Efficient A* Search Algorithm For Statistical Machine Translation. 2001 The Generalized A* Architecture. Journal of Artificial Intelligence Research (2007) Machine Vision … Here we consider a new compositional model for finding salient curves. Factored A*search for models over sequences and trees International Conference on AI. 2003…. It starts saying… The primary challenge when using A* search is to find heuristic functions that simultaneously are admissible, close to actual completion costs, and efficient to calculate… applied to NLP and BioInformatics title: An Efficient A* Search Algorithm For Statistical Machine Translation authors: Och, Franz Josef (RWTH Aachen University, Aachen Germany), Ueffing, Nicola (RWTH Aachen University, Aachen Germany), Ney, Hermann (RWTH Aachen University, Aachen Germany) venue: Workshop On Data-Driven Methods In Machine Translation year: 2001 Journal of Artificial Intelligence Research 29 (2007) 153-190 Submitted 10/06; published 06/07 The Generalized A* Architecture Pedro F. Felzenszwalb pff@cs.uchicago.edu Department of Computer Science University of Chicago Chicago, IL 60637 David McAllester mcallester@tti-c.org Toyota Technological Institute at Chicago Chicago, IL 60637 vision Here we consider a new compositional model for finding salient curves. Dan Klein and Chris Manning. 2003b. Factored A* search for models over sequences and trees. In Proceedings of the International Joint Conference on Artificial Intelligence (IJCAI). The primary challenge when using A* search is to find heuristic functions that simultaneously are admissible, close to actual completion costs, and efficient to calculate. In this paper, we describe a family of tree and sequence models in which path costs are either defined as or bounded by a combination of simpler component models, each of which scores some projection of the full structure. In such models, we can exploit the decoupled behavior over each projection to give sharp heuristics for the combined space. While we focus on models of trees and sequences within NLP applications, the approach can be applied more generally (and already has been, in the case of biological sequencemodels). All the concrete cases we consider here involve search over spaces which are equivalent to dynamic programming lattices, though this detail, too, is somewhat peripheral to the basic ideas. CPSC 322, Lecture 9

Samples A* applications (cont’) Aker, A., Cohn, T., Gaizauskas, R.: Multi-document summarization using A* search and discriminative training. Proceedings of the 2010 Conference on Empirical Methods in Natural Language Processing.. ACL (2010) CPSC 322, Lecture 8

Samples A* applications (cont’) EMNLP 2014 A* CCG Parsing with a Supertag-factored Model M. Lewis, M. Steedman We introduce a new CCG parsing model which is factored on lexical category assignments. Parsing is then simply a deterministic search for the most probable category sequence that supports a CCG derivation. The parser is extremely simple, with a tiny feature set, no POS tagger, and no statistical model of the derivation or dependencies. Formulating the model in this way allows a highly effective heuristic for A∗ parsing, which makes parsing extremely fast. Compared to the standard C&C CCG parser, our model is more accurate out-of-domain, is four times faster, has higher coverage, and is greatly simplified. We also show that using our parser improves the performance of a state-of-the-art question answering system Follow up ACL 2017 (main NLP conference – will be in Vancouver in August!) A* CCG Parsing with a Supertag and Dependency Factored Model Masashi Yoshikawa, Hiroshi Noji, Yuji Matsumoto We introduce a new CCG parsing model which is factored on lexical category assignments. Parsing is then simply a deterministic search for the most probable category sequence that supports a CCG derivation. The parser is extremely simple, with a tiny feature set, no POS tagger, and no statistical model of the derivation or dependencies. Formulating the model in this way allows a highly effective heuristic for A∗ parsing, which makes parsing extremely fast. Compared to the standard C&C CCG parser, our model is more ac-curate out-of-domain, is four times faster, has higher coverage, and is greatly simplified. We also show that using our parser improves the performance of a state-of-the-art question answering system CPSC 322, Lecture 8

DFS, BFS, A* Animation Example The AI-Search animation system http://www.cs.rmit.edu.au/AI-Search/Product/ DEPRECATED  To examine Search strategies when they are applied to the 8puzzle Compare only DFS, BFS and A* (with only the two heuristics we saw in class ) With default start state and goal DFS will find Solution at depth 32 BFS will find Optimal solution depth 6 A* will also find opt. sol. expanding much less nodes CPSC 322, Lecture 8

nPuzzles are not always solvable Half of the starting positions for the n-puzzle are impossible to solve (for more info on 8puzzle) So experiment with the AI-Search animation system (DEPRECATED) with the default configurations. If you want to try new ones keep in mind that you may pick unsolvable problems http://www.isle.org/~sbay/ics171/project/unsolvable Here is a simple rule for telling if an 8 puzzle is solvable. We can call this violation of the order an "inversion". If the number of inversions is even then the puzzle is solvable. If the number of inversions is odd then the puzzle is unsolvable. CPSC 322, Lecture 9

Learning Goals for today’s class Define/read/write/trace/debug & Compare different search algorithms With / Without cost Informed / Uninformed Formally prove A* optimality. CPSC 322, Lecture 7

Next class Finish Search (finish Chpt 3) Branch-and-Bound A* enhancements Non-heuristic Pruning Dynamic Programming CPSC 322, Lecture 8