Artificial Intelligence Unit 2 Syllabus Problem solving statespace
Artificial Intelligence Unit 2
Syllabus • Problem solving: state-space search and control strategies : Introduction, general problem solving, characteristics of problem, exhaustive searches, heuristic search techniques, iterative deepening a*, constraint satisfaction • Problem reduction and game playing: Introduction, problem reduction, game playing, alpha-beta pruning, two-player perfect information games
Problem Solving • A method of identifying the proper solution for specific problem. • Start State to the Desired Solution state • PS is most viewed and concentrated area of AI. • Propose a systematic search mechanism for to reach the goal state.
Conti. . . • Solve the task by series of actions. • For Example: Solving the problem of identifying the specific path from source to destination. • In AI, problems are defined in a state space where the solution is identified with specific flow of starting from start state to goal state.
Conti. . . • The group of states form a graph from start state to goal state by connecting different optimal paths also called as states. • There are two kinds of problem solving mechanisms. General purpose and special purpose. Which differ by the domain of implementation.
Conti. . . • General Purpose can be implemented on wide range of domains to obtain optimal solution path or steps to be followed. • Special purpose can be domain specific and restricted to implement on specific problem, but this can get very great solution path.
Heuristic Search • Criteria that to determine which among the several alternatives will be the most effective to achieve some goal state. • Improves the efficiency of search process by sacrificing claims of systematic and completeness. • But it will not guarantee to find best path but finds a very good solution.
Conti. . . • There are two kinds. General Purpose and Special Purpose • General purpose can be implemented for different domain of problem • Special purpose heuristics are domain specific.
Heuristic Search Techniques • Direct techniques (blind search) are not always possible (they require too much time or memory). • Weak techniques can be effective if applied correctly on the right kinds of tasks. – Typically require domain specific information. 9
Example: 8 Puzzle 1 2 3 7 8 4 6 5 1 2 3 8 4 7 6 5 10
1 2 3 8 GOAL 1 2 3 7 8 4 4 7 6 5 6 left 5 right up 1 2 3 7 8 4 7 6 5 6 8 5 6 5 4 Which move is best? 11
8 Puzzle Heuristics • Blind search techniques used an arbitrary ordering (priority) of operations. • Heuristic search techniques make use of domain specific information - a heuristic. • What heurisitic(s) can we use to decide which 8 -puzzle move is “best” (worth considering first). 12
8 Puzzle Heuristics • For now - we just want to establish some ordering to the possible moves (the values of our heuristic does not matter as long as it ranks the moves). • Later - we will worry about the actual values returned by the heuristic function. 13
A Simple 8 -puzzle heuristic • Number of tiles in the correct position. – The higher the number the better. – Easy to compute (fast and takes little memory). – Probably the simplest possible heuristic. 14
Another approach • Number of tiles in the incorrect position. – This can also be considered a lower bound on the number of moves from a solution! – The “best” move is the one with the lowest number returned by the heuristic. – Is this heuristic more than a heuristic (is it always correct? ). • Given any 2 states, does it always order them properly with respect to the minimum number of moves away from a solution? 15
1 2 3 8 GOAL 1 2 3 7 8 4 4 7 6 5 6 left 5 right up 1 2 3 7 8 4 7 6 5 6 8 5 6 5 h=2 h=4 4 h=3 16
Another 8 -puzzle heuristic • Count how far away (how many tile movements) each tile is from it’s correct position. • Sum up this count over all the tiles. • This is another estimate on the number of moves away from a solution. 17
1 2 3 8 GOAL 1 2 3 7 8 4 4 7 6 5 6 left 5 right up 1 2 3 7 8 4 7 6 5 6 8 5 6 5 h=2 h=4 4 h=4 18
Techniques • There a variety of search techniques that rely on the estimate provided by a heuristic function. • In all cases - the quality (accuracy) of the heuristic is important in real-life application of the technique! 19
Heuristic Function (GP) • It is important to keep performance stable while designing algorithms. • One of the important analysis of the search process is to find number of nodes in a complete search tree • Depth ‘d’ and branching factor ‘f’ and the function is f*d.
Conti. . . • Which motivates us to identify the upper bound of search time, which can be compared with exhaustive search procedures. • Search strategies which use some domain knowledge are called “informed Search Strategies”
Branch and Bound Search • 1. Place the start node of zero path length on the queue. 2. Until the queue is empty or a goal node has been found do the following: (i) Determine if the s first path in the queue contains a good node. (ii) If the first path contains a goal node exit with success. (iii) If the first path does not contain a good node remove the path from the queue and form new paths by extending the removed paths by on step. (iv) Compute the cost of the new paths and add them to the queue. (v) Sort the paths on the queue with lowest-cost path in front. 3. otherwise exit with failure.
Conti. . . • Depends on Cost function g(X) • It is designed that assigns cumulative expense to the path from start node to the current node X by applying the sequence of operators. • While generating search space, a least cost path obtained so far is expanded at each iteration till we reach to goal state.
Conti. . . • Since B and B expands the least cost partial path first, it is also called as “uniform cost search”. • For example Travelling sales person. • G(X) may be the actual distance travelled from start state to current node (X). • During search process, we might have different incomplete paths contending for further considerations
Conti. . . • Shortest one is always extended one level, by creating new level of branches. • The new one and the old one are compared with the cost function ‘g’. • Based on ‘g’ value paths are extended. • As we can get optimal solution we cannot guarantee that it will be obtained in shortest time.
Conti. . . • In B and B if g(X)=1 for all operators, then it degenerates to simple BFS • From AI point of view, its a bad approach. • This can be achieved by dynamic programming, that is delete nodes which are redundant.
Conti. . . • Now let us see how the branch - and -bound search could be used to find the shortest solution to the water - jug problem. Unfortunately although this algorithm is more efficient and simple. It require exponential time. The exact amount of time it saves for particular problem depends on the order in which the paths are explored. And also in this problem, there is a possibility that the algorithm enters into an indefinite loop. For example , consider the following configuration generated in the process of generating a path.
Hill Climbing • Quality measurement turns DFS into Hill Climbing.
Conti. . . • Given a large set of inputs and a good heuristic function, it tries to find a sufficiently good solution to the problem. This solution may not be the global optimal maximum. • In the above definition, mathematical optimization problems implies that hill climbing solves the problems where we need to maximize or minimize a given real function by choosing values from the given inputs. Example. Travelling salesman problem where we need to minimize the distance traveled by salesman. • ‘Heuristic search’ means that this search algorithm may not find the optimal solution to the problem. However, it will give a good solution in reasonable time. • A heuristic function is a function that will rank all the possible alternatives at any branching step in search algorithm based on the available information. It helps the algorithm to select the best route out of possible routes.
Conti. . . (Features of HC) • Features of Hill Climbing • Variant of generate and test algorithm : It is a variant of generate and test algorithm. The generate and test algorithm is as follows : 1. Generate a possible solutions. 2. Test to see if this is the expected solution. 3. If the solution has been found quit else go to step 1. • Hence we call Hill climbing as a variant of generate and test algorithm as it takes the feedback from test procedure. Then this feedback is utilized by the generator in deciding the next move in search space. • Uses the Greedy approach : At any point in state space, the search moves in that direction only which optimizes the cost of function with the hope of finding the optimal solution at the end.
Conti. . . (Types of HC) • • • Simple Hill climbing : It examines the neighboring nodes one by one and selects the first neighboring node which optimizes the current cost as next node. Algorithm for Simple Hill climbing : Step 1 : Evaluate the initial state. If it is a goal state then stop and return success. Otherwise, make initial state as current state. Step 2 : Loop until the solution state is found or there are no new operators present which can be applied to current state. a) Select a state that has not been yet applied to the current state and apply it to produce a new state. b) Perform these to evaluate new state i. If the current state is a goal state, then stop and return success. ii. If it is better than the current state, then make it current state and proceed further. iii. If it is not better than the current state, then continue in the loop until a solution is found. Step 3 : Exit.
Conti. . . • Steepest-Ascent Hill climbing : It first examines all the neighboring nodes and then selects the node closest to the solution state as next node. Step 1 : Evaluate the initial state. If it is goal state then exit else make the current state as initial state Step 2 : Repeat these steps until a solution is found or current state does not change • i. Let ‘target’ be a state such that any successor of the current state will be better than it; • ii. for each operator that applies to the current state a. apply the new operator and create a new state b. evaluate the new state c. if this state is goal state then quit else compare with ‘target’ d. if this state is better than ‘target’, set this state as ‘target’ e. if target is better than current state set current state to Target • Step 3 : Exit
Conti. . . • Stochastic hill climbing : It does not examine all the neighboring nodes before deciding which node to select. It just selects a neighboring node at random, and decides (based on the amount of improvement in that neighbor) whether to move to that neighbor or to examine another.
State Space diagram for Hill Climbing • State space diagram is a graphical representation of the set of states our search algorithm can reach vs the value of our objective function(the function which we wish to maximize). X-axis : denotes the state space ie states or configuration our algorithm may reach. Y-axis : denotes the values of objective function corresponding to to a particular state. The best solution will be that state space where objective function has maximum value(global maximum).
Conti. . . • Local maximum : It is a state which is better than its neighboring state however there exists a state which is better than it(global maximum). This state is better because here value of objective function is higher than its neighbors. • Global maximum : It is the best possible state in the state space diagram. This because at this state, objective function has highest value. • Plateua/flat local maximum : It is a flat region of state space where neighboring states have the same value. • Ridge : It is region which is higher than its neighbours but itself has a slope. It is a special kind of local maximum. • Current state : The region of state space diagram where we are currently present during the search. • Shoulder : It is a plateau that has an uphill edge.
Problems with HC • • • Problems in different regions in Hill climbing cannot reach the optimal/best state(global maximum) if it enters any of the following regions : Local maximum : At a local maximum all neighboring states have a values which is worse than the current state. Since hill climbing uses greedy approach, it will not move to the worse state and terminate itself. The process will end even though a better solution may exist. To overcome local maximum problem : Utilize backtracking technique. Maintain a list of visited states. If the search reaches an undesirable state, it can backtrack to the previous configuration and explore a new path. Plateau : On plateau all neighbors have same value. Hence, it is not possible to select the best direction. To overcome plateaus : Make a big jump. Randomly select a state far away from current state. Chances are that we will land at a nonplateau region Ridge : Any point on a ridge can look like peak because movement in all possible directions is downward. Hence the algorithm stops when it reaches this state. To overcome Ridge : In this kind of obstacle, use two or more rules before testing. It implies moving in several directions at once.
Beam Search • In computer science, beam search is a heuristic search algorithm that explores a graph by expanding the most promising node in a limited set. Beam search is an optimization of best-first search that reduces its memory requirements. Best-first search is a graph search which orders all partial solutions (states) according to some heuristic. But in beam search, only a predetermined number of best partial solutions are kept as candidates. It is thus a greedy algorithm.
Conti… • • • Beam search uses breadth-first search to build its search tree. At each level of the tree, it generates all successors of the states at the current level, sorting them in increasing order of heuristic cost. However, it only stores a predetermined number, {displaystyle beta }, of best states at each level (called the beam width). Only those states are expanded next. The greater the beam width, the fewer states are pruned. With an infinite beam width, no states are pruned and beam search is identical to breadth-first search. The beam width bounds the memory required to perform the search. Since a goal state could potentially be pruned, beam search sacrifices completeness (the guarantee that an algorithm will terminate with a solution, if one exists). Beam search is not optimal (that is, there is no guarantee that it will find the best solution). In general, beam search returns the first solution found. Beam search for machine translation is a different case: once reaching the configured maximum search depth (i. e. translation length), the algorithm will evaluate the solutions found during search at various depths and return the best one (the one with the highest probability). The beam width can either be fixed or variable. One approach that uses a variable beam width starts with the width at a minimum. If no solution is found, the beam is widened and the procedure is repeated
Best-first search • Idea: use an evaluation function f(n) for each node – f(n) provides an estimate for the total cost. Expand the node n with smallest f(n). • Implementation: Order the nodes in fringe increasing order of cost. • Special cases: – greedy best-first search – A* search
Romania with straight-line dist.
Greedy best-first search • f(n) = estimate of cost from n to goal • e. g. , f. SLD(n) = straight-line distance from n to Bucharest • Greedy best-first search expands the node that appears to be closest to goal.
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Properties of greedy best-first search • Complete? No – can get stuck in loops. • Time? O(bm), but a good heuristic can give dramatic improvement • Space? O(bm) - keeps all nodes in memory • Optimal? No e. g. Arad Sibiu Rimnicu Virea Pitesti Bucharest is shorter!
A* search • Idea: avoid expanding paths that are already expensive • Evaluation function f(n) = g(n) + h(n) • g(n) = cost so far to reach n • h(n) = estimated cost from n to goal • f(n) = estimated total cost of path through n to goal • Best First search has f(n)=h(n)
* A search example
A* search example
A* search example
A* search example
A* search example
A* search example
Iterative Deepening A* • Iterative deepening A* (IDA*) is a graph traversal and path search algorithm that can find the shortest path between a designated start node and any member of a set of goal nodes in a weighted graph. It is a variant of iterative deepening depth-first search that borrows the idea to use a heuristic function to evaluate the remaining cost to get to the goal from the A* search algorithm. Since it is a depth-first search algorithm, its memory usage is lower than in A*, but unlike ordinary iterative deepening search, it concentrates on exploring the most promising nodes and thus does not go to the same depth everywhere in the search tree. Unlike A*, IDA* does not utilize dynamic programming and therefore often ends up exploring the same nodes many times. • While the standard iterative deepening depth-first search uses search depth as the cutoff for each iteration, the IDA* uses the more informative f(n)=g(n)+h(n), where g(n)is the cost to travel from the root to node n and h(n) is a problem-specific heuristic estimate of the cost to travel from n to the goal. • The algorithm was first described by Richard Korf in 1985
Conti… • Iterative-deepening-A* works as follows: at each iteration, perform a depth-first search, cutting off a branch when its total cost f(n)=g(n)+h(n) exceeds a given threshold. This threshold starts at the estimate of the cost at the initial state, and increases for each iteration of the algorithm. At each iteration, the threshold used for the next iteration is the minimum cost of all values that exceeded the current threshold
Games vs Search Problems • "Unpredictable" opponent : specifying a move for every possible opponent reply • Time limits : unlikely to find goal, must approximate
Game Playing Strategy • Maximize winning possibility assuming that opponent will try to minimize (Minimax Algorithm) • Ignore the unwanted portion of the search tree (Alpha Beta Pruning) • Evaluation(Utility) Function – A measure of winning possibility of the player
Tic-Tac-Toe X O e(p) = 6 - 5 = 1 �Initial State: Board position of 3 x 3 matrix with 0 and X. �Operators: Putting 0’s or X’s in vacant positions alternatively �Terminal test: Which determines game is over �Utility function: e(p) = (No. of complete rows, columns or diagonals are still open for player ) – (No. of complete rows, columns or diagonals are still open for opponent )
Minimax Algorithm • Generate the game tree • Apply the utility function to each terminal state to get its value • Use these values to determine the utility of the nodes one level higher up in the search tree – From bottom to top – For a max level, select the maximum value of its successors – For a min level, select the minimum value of its successors • From root node select the move which leads to highest value
Game tree for Tic-Tac-Toe Courtesy : Artificial Intelligence and Soft Computing. Behavioural and Cognitive Modelling of the Human Brain
Courtesy : Principles of Artificial Intelligence , Nilsson
Properties of Minimax • Complete : Yes (if tree is finite) • Time complexity : O(bd) • Space complexity : O(bd) (depth-first exploration)
Observation • Minimax algorithm, presented above, requires expanding the entire state-space. • Severe limitation, especially for problems with a large state-space. • Some nodes in the search can be proven to be irrelevant to the outcome of the search
Alpha-Beta Strategy • Maintain two bounds: Alpha (α): a lower bound on best that the player to move can achieve Beta (β): an upper bound on what the opponent can achieve • Search, maintaining α and β • Whenever α ≥ βhigher, or β ≤ αhigher further search at this node is irrelevant
How to Prune the Unnecessary Path • If beta value of any MIN node below a MAX node is less than or equal to its alpha value, then prune the path below the MIN node. • If alpha value of any MAX node below a MIN node exceeds the beta value of the MIN node, then prune the nodes below the MAX node.
Example
Tic-Tac-Toe X : MAX player 0 : MIN player (MAX) Start e(p) = (rows + cols + diagonals open to ‘X’) – (Same to ‘ 0’) e(p) = 0 X X X e = 8 – 4 = 4 e = 8 – 5 = 3 X 0 e = 5 – 4 = 1 X’s Turn e = 8 – 6 = 2 X 0 e = 5 – 3 = 2 Courtesy : CS 621 -Artificial Intelligence , 2007, Prof. Pushpak Bhatacharya 0’s Turn
Alpha-Beta Search Algorithm • If the MAXIMIZER nodes already possess αmin values, then their current αmin value = Max (αmin value, α’min); on the other hand, if the MINIMIZER nodes already possess βmax values, then their current βmax value = Min (βmax value, β’max). • If the estimated βmax value of a MINIMIZER node N is less than the αmin value of its parent MAXIMIZER node N’ then there is no need to search below the node MINIMIZER node N. Similarly, if the αmin value of a MAXIMIZER node N is more than the βmax value of its parent node N’ then there is no need to search below node N.
Alpha-Beta Analysis • Pruning does not affect the final result. • Assume a fixed branching factor and a fixed depth • Best case: bd/2 + b(d/2)-1 • Approximate as bd/2 • Impact ? Minmax: 109 = 1, 000, 000 Alpha-beta: 105+ 104 = 110, 000 • But best-case analysis depends on choosing the best move first at cut nodes (not always possible) • The worst case : No cut-offs, and Alpha-Beta degrades to Minmax
AND OR GRAPH
AND OR Graph �OR graphs : generally used for data driven approach �AND OR graphs: used for Goal driven approach �Problems solvable by decomposing into sub problems some of which is to be solved. �Graph consisting of OR arcs and AND arcs �OR : the node has to be solved. �AND : all the nodes in the arc has to be solved Courtesy : Artificial Intelligence and Soft Computing. Behavioural and Cognitive Modelling of the Human Brain
How to explore • Expand nodes • Propagate values to ancestors • Futility – If the estimated cost of a solution becomes greater than futility then abandon the search – A threshold such that any solution with higher cost is too expensive to be practical
AO* (high level view) 1. Given the Goal node, find its possible off-springs. 2. Estimate the h values at the leaves. The cost of the parent of the leaf (leaves) is the minimum of the cost of the OR clauses plus one or the cost of the AND clauses plus the number of AND clauses. After the children with minimum h are estimated, a pointer is attached to point from the parent node to its promising children. 3. One of the unexpanded OR clauses / the set of unexpanded AND clauses, where the pointer points from its parent, is now expanded and the h of the newly generated children are estimated. The effect of this h has to be propagated up to the root by re-calculating the f of the parent or the parent of the parents of the newly created child /children clauses through a least cost path. Thus the pointers may be modified depending on the revised cost of the existing clauses.
AO* illustration Courtesy : Artificial Intelligence and Soft Computing. Behavioural and Cognitive Modelling of the Human Brain
- Slides: 75