* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download CS 415 – A.I.
Embodied cognitive science wikipedia , lookup
History of artificial intelligence wikipedia , lookup
Philosophy of artificial intelligence wikipedia , lookup
Ethics of artificial intelligence wikipedia , lookup
Intelligence explosion wikipedia , lookup
Existential risk from artificial general intelligence wikipedia , lookup
CS 415 – A.I. Slide Set 6 Chapter 4 – Heuristic Search Heuristic – the study of the methods and rules of discovery and invention State Space Heuristics – Formalized as rules for choosing those branches in a state space that are most likely to lead to an acceptable problem solution Apply Heuristics When: 1. 2. A problem is ambiguous and may not have an EXACT solution The computational cost of finding an exact solution is prohibitive Simplifying Tic-Tac-Toe Brute Force – 9! total states First use symmetry to reduce the number of states (see next slide) 7x12 states Simple Heuristic Put X where it has the most winning possibilities See Figure 4.2 and Figure 4.3 This “prunes” the search space In the first level, pick one of three, ignore the subtrees for the other two Approx. 25 total states to consider Fig 4.1 First three levels of the tic-tac-toe state space reduced by symmetry Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 2 Fig 4.2 The “most wins” heuristic applied to the first children in tic-tac-toe. Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 3 Fig 4.3 Heuristically reduced state space for tic-tac-toe. Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 4 Hill-Climbing and Dynamic Programming Hill-Climbing Expand the current state and evaluate its children Pick the best child Mountain climbing Go as steep as you can for as long as you can. Problem: Keeps no backtracking info Becomes stuck at “local maxima” Example: 8-square problem Dynamic Programming Dynamic Programming Don’t solve subproblems multiple times Instead, keep track of the solutions to these subproblems Memoizing – subproblem solution caching Two Examples Finding an optimal global alignment 2. Finding the minimum edit distance between two strings 1. Optimal Global Alignment Small Example String #1 BAADDCABDDA String #2 BBADCBA Rules Cannot change order of respective elements Can have spaces between elements Possible solutions How do we figure out optimal solution? Fig 4.5 The initialization stage and first step in completing the array for character alignment using dynamic programming. Let’s create a matrix •The value of each element reflects the global alignment success to that point in the matching process •Our “cost” scheme •1 – if an element has to be shifted along the shorter string for better alignment •Cost recorded in col •1 – if a new character is inserted •Cost recorded in row •2 – different characters, shift and insert cost 2 •0 – if elements are identical • Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 6 The forward stage Fill the array from the upper left corner The value of (x,y) is a function (min cost) of either (x-1,y), (x-1,y-1), or (x, y-1) If there is a match Add 0 to (x-1,y-1) If there is no match Add 2 to (x-1,y-1) If we shift Add 1 to the previous column If we insert a character Add 1 to the previous row Fig 4.6 The completed array reflecting the maximum alignment information for the strings. Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 7 The backward stage Once the matrix is filled From the best alignment count, we produce a specific alignment of characters Begin at the lower right-hand corner Move back through the matrix Each step, select one of the immediate state’s predecessors (previous diagonal, row, or column) Choose the minimum Fig 4.7 A completed backward component of the dynamic programming example giving one (of several possible) string alignments. Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 8 Example #2 – Min Edit Distance Spell Checker What words from our dictionary best approximate a word we do not recognize (misspelled word) We need to know the “distance” between two words Minimum edit distance The number of insertions, deletions and replacements to turn the source word into the target word intention – source word execution – target word Our “cost” 1 for a character insertion or deletion 2 for a replacement (deletion + insertion) Fig 4.8 Initialization of minimum edit difference matrix between intention and execution (adapted from Jurafsky and Martin, 2000). • Beginning state • a sequence of insertions is needed beginning at null to make either word look like the other • (2,2) is cost 2 because a replacement is required to make an i be an e Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 9 Complete array of minimum edit difference between intention and execution (adapted from Jurafsky and Martin, 2000) (of several possible) string alignments. The value at each (x,y) is the cost of minimum editing to that point, plus the minimum cost of either an insertion, deletion, or replacement • • In other words, cost of (x,y) is the minimum of •Cost of (x-1,y) + insertion •Cost of (x-1,y-1) + replacement •Cost of (x, y-1) + deletion Finally, the backward part will select a list of optimal changes •Bold text near the diagonal •Not strictly required for spell-check case • Intention ntention delete I, cost 1 etention replace n with e, cost 2 exention replace t with x, cost 2 exenution insert u, cost 1 execution replace n with c, cost 2 Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 11 Why Dynamic Programming? What’s the cost of DP? n2 where n is the size of the longest string What is the cost of exhaustive search? n3 in the worst case if we need to consider other row/col values to determine the current state Between 2n and 3n Useful heuristics for DP Usually the solution lies near the horizontal Prune the considerations if the cost passes a predetermined threshold Best-First Search Algorithm Need to have a good evaluation function Avoid Local maxima Dead-ends Anomalies in search space Return to general form of state space search algorithm Lists open – states we haven’t explored closed – states we have explored Now, order states in open according to some heuristic Thus, each loop considers the most “promising” state first Keeps track of ancestor information to ensure that we can check to see if state already reached and so we can return the chosen path at the end Can make use of a “priority queue” Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 12 Fig 4.10 Heuristic search of a hypothetical state space. Notice how states are selected for next examination. Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 13 A trace of the execution of best_first_search for Figure 4.4 Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 14 Implementing Heuristic Evaluation Functions Evaluate the performance of heuristics for solving 8-puzzle. Ideas? Count number of tiles out of place 1. Doesn’t consider how far out of place they are Get a total distance out of place 2. But what if tiles are right next to each other but out of order Very difficult to switch tiles Examining these Heuristics Fig 4.12 The start state, first moves, and goal state for an example-8 puzzle. Which seems closest? What the Heuristics Give Us Fig 4.14 Three heuristics applied to states in the 8-puzzle. What if two states have (nearly) the same heuristic evaluation? The heuristic f applied to states in the 8-puzzle. How Good is a Heuristic? Evaluated along several dimensions Goals? Guaranteed Solution? Shortest Path? Better heuristics Shortest path heuristics are said to be admissible Concept of informedness When a state is found is there a guarantee that a better state won’t be found later in the search? Concept of monotonicity Admissibility Measures Admissible – guaranteed to find a minimal path to a solution if it exists Example: BFS Use the function f(n) = g(n) + h(n) f(n) = evaluation function g(n) = actual length from any state n to the start state h(n) = heuristic estimate from any state n to the goal Using f(n) to discuss admissibility f(n) estimates the total cost of the path from the start state through n to the goal state Define f*(n) = g*(n) + h*(n) All the same, but now only dealing with the shortest path from start to n and from n to goal f*(n) is often called an oracle Often do not exist for most real problems Still we want f to be a close estimate to f* Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 5 Examples BFS is an A* algorithm in which f(n) = g(n) + 0 The decision for considering a state is based solely on the distance from the start state Several Heuristics from 8-Puzzle are A* Can’t always compute value of h*(n), but we can bound a heuristic cost above by the actual shortest-path cost A* Examples for 8-puzzle Counting the number of tiles out of place is always less than or equal to the number of moves to move them to their goal Thus: heuristic is admissible The sum of the direct distances of tiles out of place is also less than or equal to the minimum actual path Thus: heuristic is admissible Monotonicity The definition of A* does not require that g(n) = g*(n) So, A* algorithms may initially reach non-goal states along sub-optimal paths before eventually finding an optimal path Monotonicity – property that guarantees that the heuristic is “locally optimal” Consistently follows only the optimal path Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 6 Monotonicity is possible when: Search space is everywhere locally consistent with the heuristic employed The difference between a heuristic measure of a state and any of its successors is bound by the actual cost of moving from predecessor to successor states As the path is followed when using a monotone heuristic value of f is monotonically nondecreasing (hence the name) Monotonicity and Admissibility All monotone heuristics are admissible In fact, monotonicity is a refinement of admissibility Not all admissible heuristics are monotone Relatively Better Heuristics Informedness Example BFS is equivalent to A* with heuristic h1 such that h1(x)=0 for all states x This is always less than h*(x) Lets call the number of tiles out of place, h2 This is also less than h* But, we have h1<=h2<=h* Thus, h2 is “more informed” than h1 Additionally, we can argue that calculation of direct distance of out of place tiles is more informed than h2