460 likes | 471 Views
Learn about the hill-climbing and dynamic programming techniques used in heuristic search algorithms in Artificial Intelligence. Understand the importance of heuristics in reducing the search space and approximating solutions for complex problems. Explore the challenges of local maxima in hill-climbing and the efficiency of dynamic programming in solving problems like string matching and global alignment.
E N D
Chapter 4 HEURISTIC SEARCH Contents • Hill-climbing • Dynamic programming • Heuristic search algorithm • Admissibility, Monotonicity, and Informedness • Using Heuristics In Games • Complexity Issues Artificial Intelligence
Heuristics • Rules for choosing paths in a state space that most likely lead to an acceptable problem solution • Purpose • Reduce the search space • Reasons • May not have exact solutions, need approximations • Computational cost is too high Artificial Intelligence
First three levels of the tic-tac-toe state space reduced by symmetry Artificial Intelligence
The “most wins” heuristic applied to the first children in tic-tac-toe Artificial Intelligence
Heuristically reduced state space for tic-tac-toe Artificial Intelligence
Hill-Climbing • Analog • Go uphill along the steepest possible path until no farther up • Principle • Expand the current state of the search and evaluate its children • Select the best child, ignore its siblings and parent • No history for backtracking • Problem • Local maxima – not the best solution Artificial Intelligence
The local maximum problem for hill-climbing with 3-level look ahead Artificial Intelligence
Dynamic Programming • Forward-backward searching • Divide-and-conquer: Divided problems into multiple interacting and related subproblems • Address issues of reusing subproblems solutions • An example: Fibonacci series • F(0) = 1; F(1)=1; F(n)=F(n-1)+F(n-2) • Keep track of the computation F(n-1) and F(n-2), and reuse their results to compute F(n) • Compare with recursion, much more efficient • Applications: • String matching • Spell checking • Nature language processing and understanding • planning Artificial Intelligence
Global Alignment of Strings • Find an optimal global alignment of two character strings • Data structure: (n+1)(m+1) array, each element reflects the global alignment success to that point • Three possible costs for the current state • If a character is shifted along in the shorter string for better possible alignment, the cost is 1 and recorded in the column score; and If a new character is inserted, cost is 1 and reflected in the row score • If the characters to be aligned are different, shift and insert, the cost is 2 • If identical, the cost is 0 • The initialization stage and first step in completing the array for character alignment using dynamic programming. Artificial Intelligence
The initialization stage and first step in completing the array for character alignment using dynamic programming. Artificial Intelligence
The completed array reflecting the maximum alignment information for the strings. Artificial Intelligence
A completed backward component of the dynamic programming example giving one (of several possible) string alignments. Artificial Intelligence
Minimum Edit Difference • Determine the best approximate words of s misspelling word in spelling checker • Specified as the number of character insertion, deletion, and replacements necessary to turn the first string into the second • Cost: 1 for insertion and deletion, and 2 for replacement • Determine the minimum cost difference • Data structure: array Artificial Intelligence
Initialization of minimum edit difference matrix between intention and execution Artificial Intelligence
Array elements are the costs of the minimum editing to that point plus the minimum cost of either an insertion, deletion or replacement Cost(x, y) = min{ Cost(x-1, y) + 1 (insertion cost), Cost(x-1, y-1) + 2 (replacement cost), Cost(x, y-1) + 1 (deletion cost) } Artificial Intelligence
Complete array of minimum edit difference between intention and execution (of several possible) string alignments. 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 Artificial Intelligence
The Best-First Search • Also heuristic search – use heuristic (evaluation) function to select the best state to explore • Can be implemented with a priority queue • Breadth-first implemented with a queue • Depth-first implemented with a stack Artificial Intelligence
The best-first search algorithm Artificial Intelligence
Heuristic search of a hypothetical state space Artificial Intelligence 13
A trace of the execution of best-first-search Artificial Intelligence
Heuristic search of a hypothetical state space with open and closed states highlighted Artificial Intelligence
Implement Heuristic Evaluation Function • Heuristics can be evaluated in different ways • 8-puzzle problem • Heuristic 1: count the tiles out of places compared with the goal state • Heuristic 2: sum all the distances by which the tiles are out of pace, one for each square a tile must be moved to reach its position in the goal state • Heuristic 3: multiply a small number (say, 2) times each direct tile reversal (where two adjacent tiles must be exchanged to be in the order of the goal) Artificial Intelligence
The start state, first moves, and goal state for an example-8 puzzle Artificial Intelligence
Three heuristics applied to states in the 8-puzzle Artificial Intelligence
Heuristic Design • Use the limited information available in a single state to make intelligent choices • Empirical, judgment, and intuition • Must be its actual performance on problem instances • The solution path consists of two parts: from the starting state to the current state, and from the current state to the goal state • The first part can be evaluated using the known information • The second part must be estimated using unknown information • The total evaluation can be f(n) = g(n) + h(n) g(n) – from the starting state to the current state n h(n) – from the current state n to the goal state Artificial Intelligence
The heuristic f applied to states in the 8-puzzle Artificial Intelligence
State space generated in heuristic search of the 8-puzzle graph Artificial Intelligence
The successive stages of open and closed that generate the graph are: Artificial Intelligence
Open and closed as they appear after the 3rd iteration of heuristic search Artificial Intelligence
Heuristic Design Summary • f(n) is computed as the sum of g(n) and h(n) • g(n) is the depth of n in the search space and has the search more of a breadth-first flavor. • h(n) is the heuristic estimate of the distance from n to a goal • The h value guides search toward heuristically promising states • The g value grows to determine h and force search back to a shorter path, and thus prevents search from persisting indefinitely on a fruitless path Artificial Intelligence
Admissibility, Monotonicity, and Informedness • A best-first search algorithm guarantee to find a best path, if exists, if the algorithm is admissible • A best-first search algorithm is admissible if its heuristic function h is monotone Artificial Intelligence
Admissibility and Algorithm A* Artificial Intelligence
Monotonicity and Informedness Artificial Intelligence
Comparison of state space searched using heuristic search with space searched by breadth-first search. The proportion of the graph searched heuristically is shaded. The optimal search selection is in bold. Heuristic used is f(n) = g(n) + h(n) where h(n) is tiles out of place. Artificial Intelligence
Minimax Procedure • Games • Two players attempting to win • Two opponents are referred to as MAX and MIN • A variant of game nim • A number of tokens on a table between the 2 opponents • Each player divides a pile of tokens into two nonempty piles of different sizes • The player who cannot make division losses Artificial Intelligence
Exhaustive Search State space for a variant of nim. Each state partitions the seven matches into one or more piles Artificial Intelligence
Maxmin Search • Principles • MAX tries to win by maximizing her score, moves to a state that is best for MAX • MIN, the opponent, tries to minimize the MAX’s score, moves to a state that is worst for MAX • Both share the same information • MIN moves first • The terminating state that MAX wins is scored 1, otherwise 0 • Other states are valued by propagating the value of terminating states • Value propagating rules • If the parent state is a MAX node, it is given the maximum value among its children • If the parent state is a MIN state, it is given the minimum value of its children Artificial Intelligence
Exhaustive minimax for the game of nim. Bold lines indicate forced win for MAX. Each node is marked with its derived value (0 or 1) under minimax. Artificial Intelligence
Minmaxing to Fixed Ply Depth • If cannot expand the state space to terminating (leaf) nodes (explosive), can use the fixed ply depth • Search to a predefined number, n, of levels from the starting state, n-ply look-ahead • The problem ishow to value the nodes at the predefined level – heuristics • Propagating values is similar • Maximum children for MAX nodes • Minimum children for MIN nodes Artificial Intelligence
Minimax to a hypothetical state space. Leaf states show heuristic values; internal states show backed-up values. Artificial Intelligence
Heuristic measuring conflict applied to states of tic-tac-toe Artificial Intelligence
Two-ply minimax applied to the opening move of tic-tac-toe Artificial Intelligence
Two ply minimax, and one of two possible MAX second moves Artificial Intelligence
Two-ply minimax applied to X’s move near the end of the game Artificial Intelligence
Alpha-Beta Procedure • Alpha-beta pruning to improve search efficiency • Proceeds in a depth-first fashion and creates two values alpha and beta during the search • Alpha associated with MAX nodes, and never decreases • Beta associated with MIN nodes, never increases • To begin, descend to full ply depth in a depth-first search, and apply heuristic evaluation to a state and all its siblings. The value propagation is the same as minimax procedure • Next, descend to other grandchildren and terminate exploration if any of their values is >= this beta value • Terminating criteria • Below any MIN node having beta <= alpha of any of its MAX ancestors • Below any MAX node having alpha >= beta of any of its MIN ancestors Artificial Intelligence
Alpha-beta pruning applied. States without numbers are not evaluated. Artificial Intelligence