Presentation on theme: "CSNB234 ARTIFICIAL INTELLIGENCE"— Presentation transcript:
1 CSNB234 ARTIFICIAL INTELLIGENCE Chapter 5State Space SearchInstructor: Alicia Tang Y. C.
2 State Space Representation A state space can be considered as consisting of a collection of points, each point corresponding to a state of a problem. So there will be as many number of points in the state space as the number of different possible states of the problem. Thus, a state space is the collection of all possible states, a problem can have. States can be represented as nodes of a tree. The searching of a goal node is by traversing the tree’s nodes using some well-established algorithms.
3 Defining A Search Problem State Spaceis described byan initial state spacea set of possible actions (operators)goal statePathis any sequence of actions that lead from a state to another state and finally reached (hopefully) the goal node
4 Defining a Search Problem Other considerations are:Path cost: it is only relevant if there exists more than one path leading to the goal state.& certainly that we want the shortest pathGoal test: it is applicable to single state problem, I.e. only one goal is found in the state space problem
5 Relationship between Initial states, actions and goal(s) ControlStrategy
6 Why ‘Search’?Search is an important (and powerful ) aspect in AI problem solvingSearch willwill help to explore alternatives in treewill find sequence of steps in a planning situation/caseAll goal-driven activities (such as one used in B. C. reasoning) occur in a state space, and we call the problem a state space problem
7 Classical Search Domains 8-PuzzleWater JugBlocks WorldTravelling SalesmanMazeChessTower of Hanoietc.
8 An Example of Search Preparation 2481877326InitialStateGoalState156345Initial State: The location of each of the 8-puzzle in one of thenine squaresPath cost: Each step costs 1 point, total path cost will beequal to the number of steps takenGoal test: State matches the goal configuration (given board pattern)Operators: blank moves  Left,  Right,  Up &  Down.
9 Blind optimal partial Good enough optimal S e a r c complete h A p o s Search ProcessTestSolutioncompleteComparisonsstopwhen allcheckedAll possiblesolutions arecheckedBlindoptimalpartialCheck onlysomealternativesBestamongalternativesComparisonsStop whensolution isgoodenoughGoodenoughHeuristicsOnlypromisingsolutionsGenerateimprovedsolutionsStop when noimprovementis possibleOptimisationoptimal
10 Methods of Search (I) Popular blind search methods are Depth-first Breadth-firstBi-directionalIterative deepeningDepth-limitedUniform cost
11 Methods of Search (II) Heuristic Search Optimal Searching Hill-climbingBest-firstGenerate & testInductionGreedy searchOptimal SearchingA* search
12 Methods of search at the first glance Depth-firstexplores search tree branch by branchBreadth-firstexamines search tree row by rowHill-climbingit is depth first but most promising child node is examined firstBest-firstexpands the most promising partial path of all those so far discoveredA*Best-first and Branch and bound algorithmTo becalculatedDecision required
13 .… Blind…. The entire search tree is examined in an orderly manner. It can be classified as exhaustive or partial.Two well-known partial methods arebreadth-firstdepth-first
14 DEPTH-FIRST SEARCH (DFS) A ~ begins at the root node andworks downward to successivelydeeper level.This process continues until a solution is found or backtrackingis forced by reaching a dead end.Blind ....
15 DEPTH-FIRST SEARCH Delete FIRSTNODE from start of QUEUE Basic steps usedDelete FIRSTNODE from start of QUEUETake children of FIRSTNODEAdd to the front of QUEUEPut result in NEWQUEUE
20 Heuristics SearchHeuristics search is designed to reduce the amount of search for a solution.It is based on rule-of-thumb principle.When a problem is presented, such as a goal state is given, this approach tries to reduce the size of the search tree by pruning non promising or inferior nodes.It can normally speed up the search process in obtaining a good enough solution.
21 Benefits of Heuristics It has inherent flexibilityIt is better when an optimal/best solution is too costly to generateeven though it can only produce “good enough” answerSimpler for decision maker to understand (especially the managers)because they think in the same way as “heuristics” does
22 A heuristics search in general Problem: Tic-Tac-Toexxxooxxoooooooxoxxxxxxxxxxxxxxx
23 Consider the Tic-Tac-Toe game Blind search is surely not practical…Each nine first moves has eight possible responses,which in turn have seven continuing moves, and so on.A simple analysis tells that the number of states to be considered in an exhaustive search is 9 * 8 * 7 *… or 9!However, symmetry reduction in second level leads to only 12 * 7! (much smaller than above), further reduction in search space will further reduce the number or search required
24 HILL-CLIMBING SEARCH Delete FIRSTNODE from start of QUEUE Main steps usedDelete FIRSTNODE from start of QUEUETake children of FIRSTNODEOrder children with most promising firstPlace them at the front of QUEUEPut result in NEWQUEUE
26 Hill-ClimbingHill-climbing combines depth-first search with a method for ordering the alternatives by measuring the probability of success at each decision point. In other word it tries to reach a goal by choosing those nodes which are predicted to be nearest to the goal. Quality measurements turn depth-first search into hill-climbing.
27 Hill-ClimbingIt is about fin ding the shortest h(n)Earlier slide says that it is quite similar to depth-first blind search.However, paths are not selected arbitrarily, but in relationship to their proximity to the desired goal (i.e. how close to it)let’s take a look at this tree:notice that there are numbers attached nodesthose are potential numbers of defects in a product
28 Apply hill-climbing search to find ‘1’ defect node STARTAIIIIIIB13CD8114E3FG5H72I1J
29 Each production process I, II and III can continue for several stages. If this is done by depth-first, it goes to I then to II and then to III .In Hill-climbing method, nodes B, C and D are compared, and it starts in branch I (lowest, 8 here).Since one defect was not found, backtracking is exercised to branch III. (branch III is done before II, why)?The search goes to D and H; backtracking is then done and D, G, J path leads to the desired solution.Path A--C--F was not visitedtherefore much time and cost are savedThis is exactly the aims of ‘heuristics’!
30 Hill-climbingFew more words on hill-climbing method: If we imagine the goal as the top of hill, h(n) as the difference in heights between n and the top, the hill-climbing procedure corresponds to climbing the hill by always going upwards.
31 Problems with hill-climbing: Foothill problem.Go up to the top of a hill and not advancing further. - misses the overall maximumPlateau problem.Problem with multidimensional problem space, i.e. no hill to climb (is flat). Gradient equals to zero. - not informativeRidges.Where there are steep slopes and the search direction is not towards the way up (but side)
32 Some solutions to hill-climbing problems are: Random restart hill-climbingwhere random initial states are generatedSimulated annealingallow for bad moves as well, where the probability of such a move decreases exponentially with its badness
33 BEST-FIRST SEARCH Based on some heuristics evaluation function More flexible than hill-climbingAn evaluation function is used to assign a score to each candidate nodeNext move is made by selecting the best value nodeIt expands the best partial path, for that It could lead to “shortsighted” situation
34 BEST-FIRST SEARCHBest-first search has been used in such applications as games and web crawlersIn a web crawler, each web page is treated as a node, and all the hyperlinks on the page are treated as unvisited successor nodes in the search space.A crawler that uses best-first search generally uses an evaluation function that assigns priority to links based on how closely the contents of their parent page resemble the search query
35 BEST-FIRST SEARCH Delete FIRSTNODE from start of QUEUE Take children of FIRSTNODEAppend children to QUEUEOrder result with most promising firstPut ordered result in NEWQUEUE
36 Apply best-first search to find ‘3’ defect in a production [B D C][E I D C][I D C][D C][H G C][G C][J C][A][B D C][D C E I][H G C E I][G C E I][J C E I]AB13CD811EI141623FG5H7Traversing order (i.e. the search path) isA B D H G J3JIf hill climbing is used, the solution path will beA B E I D H G J (it is longer, less ‘intelligent’)
37 Optimal Search Will produce optimal (best) answer Based on some optimisation functionMathematical functions are usedfor improvementsfor “optimisation”
38 BRANCH AND BOUND ALGORITHM One way to find optimal paths with less work is to use branch-and-bound.It always keeps track of all partial paths contending for further consideration.The shortest one is extended one level, creating as many new partial paths.Next, these new paths are considered, along with the remaining old ones, again, the shortest is extended.The process is repeated until the goal is reached along some path.
39 Branch-and-Bound Keys to remember: To turn likely to certain, you have to extend all partial paths until they are as long or longer than the complete path. The reason is that the last step in reaching the goal may be long enough to make the supposed solution longer than one or more partial paths.It might be that only a tiny step would extend one of the partial paths to the solution node.To be sure that this is not so, instead of terminating when a path is found, you terminate when the shortest partial path is longer than the shortest complete path
40 An Example for B-N-B S D A E F B 15 G 15 The length of the complete path from S to G,S-D-E-F-G is 15.Similarly, the length of thepartial path S-D-A-B also 15and any additional movement along a branch will make it longer than 15.Accordingly, there is no needto try S-D-A-B any further.Because it will be longerthan the complete pathalready known.Only other paths emerging from S and from S-D-E have to be considered, as they may provide a shorter path.SDAEFB15G15
41 To conduct a branch-and-bound search: Form a one-element queue consisting of zero length path (only root node)Until the first path in the queue terminated at the goal node or the queue is empty,remove the first path from the queue; create new paths by extending the first path to all the neighbours of the terminal nodereject all paths with loopsadd the reaming new paths, if any, to the queuesort the entire queue by path length with least-cost paths in frontIf the goal is found, announce success; otherwise announce failure.
43 Solution Search path to goal node: [S(0)] [B(1) A(4)] [E(3) A(4) F(4)][A(4) F(4) I(6) H(7)][F(4) C(5) I(6) D(6) H(7)][G(5) C(5) I(6) D(6) J(6) H(7)]Goal node reached and stopped.Use your tie breaker solution
44 A* Search All A* algorithms are admissible A search algorithm is admissible if it always produces an optimal solutionThe A* search is branch-and-bound, with an estimate of remaining cost combined with dynamic programming principleTheorem of A* algorithmFor each node n, let h*(n) denote the cost of an optimal path from n to a goal nodeThe algorithm uses a heuristic function h that satisfies h(n) <= h*(n) for all n in the state space, is admissible
45 A* SEARCH Delete FIRSTNODE from start of QUEUE Append children of FIRSTNODEOrder resulting list according tocost-so-far + underestimate of remaining costPut result in NEWQUEUE
47 To conduct a A* search:Form a one-element queue consisting of zero length path (only root node)Until the first path in the queue terminated at the goal node or the queue is empty,remove the first path from the queue; create new paths by extending the first path to all the neighbours of the terminal nodereject all paths with loopsif two or more paths reach a common node, delete all those paths except the one that reaches the common node with the minimum costsort the entire queue by SUM of the path length and a lower-bound estimate of the cost remaining, with least-cost paths in frontIf the goal is found, announce success; otherwise announce failure.
48 Function definition in A* Consider the evaluation functionf(n) = g(n) + h(n)where n is any state in the searchg(n) is the cost from the start stateh(n) is the heuristic estimate of the costgoing from n state to goal node
49 Using A* in 8-puzzle problem Figure 1 shows a start state and the first set of moves283START16475283283283First level ofThe tree search141641647657575A2A3A1Which one will the A* takes?& Why? On what basis it is chosen?
50 What is the GOAL we wanted to achieve? i.e. what is the question?To reach this GOAL state12384765Many levels of search and many solutions are possibleto reach the goal state
51 Using A* in 8-puzzle problem Figure 2 : Three heuristics applied to states in the 8-puzzle28356Recall the goal state1647512384283347651476528356164Tilesout ofplaceSum ofdistancesout of place2 * the no.of direct tilesreversalsThese are potentialCriteria for the A* formula75
52 Using A* in 8-puzzle problem Figure 3 : The heuristic f applied to states in the 8-puzzle283g(n) = 016475283283283g(n)=11641416475765756f(n)46f(n) = g(n) + h(n)where g(n) actual distance from n (cost from start state)h(n) the no. of tiles out of place12384GOAL765
53 List 2(two) limitations of heuristics search methods Exercise #1List 4(four) criteria that are normally used to evaluate search methodsExercise #2List 2(two) limitations of heuristics search methods
54 Answer to Exercise #1 Completeness Space complexity Time complexity will the solution be eventually found? if there is one at all?Space complexityhow much memory will it need or is necessary?Time complexityhow long will it take to complete the search?Optimalitywill the search method find the highest quality of solution path when there are several.
56 Properties of Search Algorithms Breadth-first Depth-first A* GreedyComplete Yes No Yes NoSpace Exponential Linear Exponential LinearTime Exponential Exponential Exponential ExponentialOptimal Yes No Yes No
57 Bi-directional Search Blind Search..It searches both forward and backward in the same state space (run simultaneously).It stops when the two moves meet in the middle.StartGoalA schematic view of ~ that when a branch from the start node meets aBranch of the goal node, it stops
58 Iterative Deepening (Korf 1987) As depth-first search gets quickly into a deep level in the search space. Depth-first search can get lost deep in the search tree/graph. It may also stuck in infinite path that does not lead to a goal.A compromise is to use a depth bound on depth-first :the depth bound forces failure on a search path once it gets below certain levelBlind Search..
59 Iterative Deepening (Korf 1987) Blind Search..Iterative Deepening (Korf 1987)The hard part of Depth-limit search is to determine what limit is “good” limit.Iterative deepening tries all possible depth limits and pick up the best one!Thus:It is optimal and complete.It uses modest memory.
60 Blind Search..Depth-Limited searchSimilar to DFS, except that it avoids the pitfalls of DFS by imposing a cut off on the maximum depth of a given pathDrawback:if a chosen limit is too small, the scheme is not “complete”optimality = no
61 Blind Search..Uniform Cost SearchWe learnt that BFS finds the shallowest path leading to the goal stateuniform cost search modifies BFS by expanding only the lowest cost node (n)the cost of a path should remain low but not decreasing hence the term “uniform”Note that if all step costs are equal, this is identical to BFS
62 Comparison of 6 Blind search methods Breadth Depth Depth Bi-directional Iterative Uniformfirst first limited costTime bd bm bl bd/ bd bdSpace bd bm bl bd/ bd bdComplete yes no yes, l d yes yes yesOptimal yes no no yes yes yes
63 Heuristics …InductionInduction means to generalise from a smaller version of the same problemTwo essential featuresproblem must be modelled in terms of the associated datainduced result must be tested against real examples
64 Generate & TestHeuristics …The basic idea is to generate possible solutions and devise a test to determine if the solutions are indeed good, i.e. acceptable.Steps:add a specification criteriontry to open a path that satisfies the specificationdetermine whether the path is plausible, prune it if it is not plausiblemove to the next pathcheck whether all specifications have been mentioned. If not, add the next specification and reiterate the steps by returning to first step
65 Heuristics …Greedy SearchThere is a heuristic function, h(n), which serves to hold values of prediction of path-cost left to the goalGreedy search is to minimise the estimated cost to reach the goalTherefore, the node (state) closest to the goal will be expanded first
66 Heuristics …Greedy SearchIt resembles DFS in the way that it follows a single path all the way to the goal, if there is no dead endThus, it is incomplete and not optimalWith good quality heuristic function, however, the space an time complexity can be reduced