1、Lecture Notes on AI-NN,Chapter 5Information Processing& Utilization,Categories of Information Processing- Problem-Solving- Game-Playing- Theorem-Proving- Logic-Deduction,Section 5.1 Problem-Solving5-1 IntroductionDescription of a problem: Problem defining: the start - goal conditionsRule defining: a
2、 set of IF-THENStrategy-finding: rule-application controlling,Example The Water Jug ProblemInitial Base: There are 2 jugs, a 4-kilo jug and a 3-kilo jug. Neither has any measurementmarks on it. Rule Base: (1) There is a pump that can be used to fill the jug with water, or(2) You can pour water from
3、jug on the ground or into another jug. Question: How to get exactly 2-kilo of water intothe 4-kilo jug ?,Representation and Solution:Kilos in 4-kilo jug kilos in 3-kilo jug0 00 33 03 34 20 22 0,R1,R2,R1,3,R2,1,R2,2,2,R2,It is clear that the Production System is suitable means of representation for P
4、roblem-Solving.Procedure PRODUCTION1. DATA initial database 2. Until DATA satisfies the termination condition, do:i) beginii) select some rule, R, in the set of rules that can be applied to DATAiii) DATA result of applying R to DATA,In most of AI applications, the information available to the contro
5、l strategy is usually not sufficient to permit selection of the most appropriate rule on every stage. The operation of AI production system can thus be characterized as a SEARCH PROCESS in which rules are tried until some sequence of them is found that produces a database satisfying the termination
6、conditionFurther, if the database of the problem to be solved is represented by means of graph, the search is called GRAPH-SEARCH.,Procedure GRAPH-SEARCH1. Create a search graph, G, consisting sole of the startnode, S. Put S on OPEN (OPEN: a list of nodes justgenerated but not examined yet). 2. Crea
7、te a list, CLOSED, that is initially empty. (CLOSED is a list of nodes examined already) 3. LOOP: if OPEN is empty, exit with failure. 4. Select the first node on OPEN, remove it from OPENto CLOSED, Call it node n. 5. Examine n: if n is a goal node, exit with success. The solution is obtained by tra
8、cing a path along the pointers from n back to S in G.,6. Expand n (Apply a rule to n), generating the set, M, of its successors that are not ancestors of n. Install these members of M as successors of n. 7. Establish a pointer to n from these members of M that were not already on either OPEN or CLOS
9、ED.Add these members of M to OPEN. For each memberof M that was already on OPEN or CLOSED, decide whether or not to redirect its pointer to n. For eachmember of M already on CLOSED, decide for each ofits descendants in G whether or not to redirect itspointer. 8. Reorder the list OPEN according to a
10、certain rule. 9. Go LOOP,S,Node on CLOSED,Node on OPEN,1=n,2,3,5,4,6,Pointers need to be redirected to,Redirection,The crucial factor in search process is the ordering regulation that determines the fashion of the selection of nodes for expansion next.The search efficiency is dependent on the utilit
11、y of problem information in node selection. In accord with the utility of problem information in node selection, search strategy can be divided into:a) Blind Search, and b) Heuristic Search,5-1-1 Blind Search on Tree1) Breadth-First Search Node ordering: FIFO Procedure BFS 1. Put start node s on OPE
12、N. Set pointer P=0 2. If OPEN=NIL, failure. 3. Select the first node on OPEN. Put it on CLOSED,Call it node n. 4. If n=g, successful. The solution is obtained by tracinga path along the pointers from g to s in G. 5. Expand n. If it has no successors, go to step 2. Or, generate all its successors, ad
13、d them successively tothe end on OPEN, and establish pointers from them to n; go to step 2.,Example: BFS,123,8 4,765,283,164,7 5,1=S,46=g,283,164,75,283,164,75,283,1 4,765,283,64,175,2,3,4,5,6,7,8,9,10,11,34,35,36,37,38,283,14,765,2 3,184,765,283,14,765,283,16,754,19,See Nilsson p.71Fu p.37,The shor
14、test solution path,45,39,44,20,33,83,264,175,283,6 4,175,83,214,765,283,714,65,23,184,765,23,184,765,28,143,765,283,145,76,283,1 6,754,28,163,754,8 3,264,175,123,84,765,2 3,684,175,283,64,175,283,674,1 5,8 3,214,765,283,714,6 5,83,264,175,40,41,42,43,234,18,765,2 8,143,765,283,145,7 6,2 8,163,754,2
15、3,186,754,283,156,7 4,16,283,754,21,32,22,23,24,25,26,27,28,29,30,31,Comments on BFS:It is guaranteed to find a optimal solution because of its systematic search feature.The major weakness with BFS is its inability to use the information related to the problem and thus a) It requires a large memory
16、to store the great number of the nodes; b) It require a great amount of work to examine thegreat number of the nodes c) As result, BFS has low efficiency of search., 5-1-2 Depth First Search: Node Ordering: LIFOProcedure DFS 1. Put start node s on OPEN. Set d(s)=0, P=0 2. If OPEN=NIL, F. 3. Select t
17、he first node on OPEN. Put it on CLOSED.Call it node n. 4. If n=g, S. 5. If d(n)=d , go to step 2. 6. If n is not expandable, go to step 2. 7. Expand node n, generating all its successors. Establish pointers from them to n. Letd(successor)=d(n)+1. Add them to the front on OPEN in any order, then go
18、to step 2.,B,Example: DFSd =5,283,184,765,283,164,7 5,1=S,283,164,75,283,164,75,283,1 4,765,283,64,175,2,3,4,5,6,7,8,9,10,11,283,14,765,2 3,765,283,714,765,283,14,765,See Nilsson p.70Fu p.42,The solution path,B,83,264,175,18,83,264,175,863,2 4,175,8 3,264,175,12,13,14,15,16,17,83,214,8 3,214,83,214,
19、813,2 4,765,19,20,21,22,23,6 4,175,684,175,23,684,175,23,684,175,64,175,28,643,175,283,645,17,283,674,1 5,283,674,15,283,674,15,2 3,765,283,65,283,714,6 5,283,7 4,615,283,714,65,123,8 4,765,123,784,65,8 4,23,184,765,123,84,765,24,25,26,27,28,29,30,31,Compared with BFS, DFS has the following features
20、: 1) If d is too small, the goal node may be missed, if toolarge, the greater amount of storage is needed. 2) DFS may find the goal faster than BFS, while the the solution path may not be the shortest one if thereare more than one goal node. 3) DFS can often be carried out using a reasonably small a
21、mount of storage.,B,g,g,5-1-3 Informed (Heuristic) Search on Tree,(1) General Remarks- The weakness in blind search: ignoring the information associated with the problem inselecting node for expansion next.- Solution: Try to use the heuristic information innode ordering on OPEN - Heuristic Search.-
22、The heuristic information is used in terms ofEvaluation Function, f(.):f(n): node n Real numbermapping nodes to their promising values.,For any node n on a tree, let g*(n) be the actual cost of a minimal cost path froms to n. h*(n) be the cost of minimal cost path from n to g. f*(n) = g*(n) + h*(n)
23、be the cost of an optimal path from s to g constrained to going through n.Let again g be an estimation of g*, h be an estimation of h*, andf(n) = g(n) + h(n) be an estimation of f*(n), which can be used as an evaluation function for ordering nodes on OPEN.,Practically, g(n): the sum of the arc costs
24、 encountered while tracing the pointers from n to s. h(n): a function based on heuristic information fromthe problem, hence is called Heuristic Function.The practical regulation isIf h(n) is very high, node n may be ignored;If h(n) is low, node n may be chosen to expand next.,(2) Algorithm A and Alg
25、orithm A* on TreeAlgorithm A is a special Tree-Search using evaluation function f(n) for ordering nodes on OPEN and always selecting for expansion the nodewith the lowest value of f(n).The key for Algorithm A is the settings of h and g: When h=0, g=d, it reduces to BFS;h=0, g=0, random search;h=1/d,
26、 g=0, DFS;hh*, the optimal path may be lost;hh*, some search may be redundant, but optimal path can be found.,Algorithm A with h(n) h2(n) h1(n)for all non-goal node n.,Example of A*: 8-Puzzle Problem Let f(n) = g(n) + h(n) = d(n) + w(n)d(n): depth of node n on search treew(n): number of misplaced di
27、gits at node n,283,184,283,164,7 5,283,164,75,164,75,283,1 4,765,283,14,765,765,283,765,283,14,765,83,184,214,23,2 3,765,714,65,123,8 4,765,123,784,65,8 4,23,184,765,123,84,765,1#,0+4=4,2#,3#,4#,6#,7#,8#,12#,13#,14#,15#,26#,27#,1+5=6,1+3=4,1+5=6,2+3=5,2+3=5,2+4=6,3+3=6,3+4=7,3+2=5,3+4=7,4+1=5,5+0=5,
28、Algorithm A* with h(n) = w(n) is more informed than BFS which uses h(n) = 0.h(n) = w(n) is a lower bound on the exact number of steps needed to reach the goal, h*(n), hence it is an Algorithm A*.However, w(n) does not provide good-enough estimate of h*(n). The information of “following order” is not
29、 utilized in w(n).,A better estimate of h*(n) is h(n) = P(n) + 3S(n) P(n): the sum of the absolute distances that a digit isfrom “home”; S(n): a sequence score, taking value2, for each non-central digit not proper followed 1, if a digit in the center0, for other digits E.g., for s = and g = , we hav
30、e,216,4 8,753,123,8 4,765,P(s) = (3x1) + (3x2) + (1x3) + (1x0) = 12(1,2,5) (3,4,8) (6) (7) S(s) = 8x2 = 16,By using this h(n), we have f(n) = g(n) + P(n) +3S(n) with g(n) = d(n) and the above problem will find the same optimal path but with fewer nodes expanded:,283,184,283,164,7 5,283,164,75,164,75
31、,283,1 4,765,283,14,765,765,283,14,765,184,23,2 3,765,123,8 4,765,123,784,65,8 4,23,184,765,123,84,765,Since 0 w(n) h*(n) P(n) + 3S(n), the solution path found happens to be of minimal path, although we were not guaranteed of finding an optimal path.Summary: From the example above, we can see that t
32、he key in heuristic search is to determine the form of estimation function f(n) by utilizing heuristic information.As is seen, the crucial difference between blind search and heuristic search is the ordering regulation. In Heuristic search, the node with the smallest value of evaluation function wil
33、l be chosen to be expanded first.,(3) Algorithm A* for Graph Search1. s OPEN. Set g(s)=0, f(s)=h(s)=whatever, P=0, CLOSED=NIL 2. If OPEN=NIL, F 3. Take first node on OPEN, call it Best-Node (BN),BN CLOSED 4. If BN=g, S 5. If BN not expandable, go to step 2 6. Expand BN, generating successors (SUCs)
34、and do:(1) Set P: SUC BN(2) Compute g(SUC)=g(BN)+g(BN, SUC)(3) If SUC=old node (OLD) on OPEN, add OLD to the list of BNs successors,If g(SUC)g(OLD), do nothing(4) If SUC= old node (OLD) on CLOSED, add OLD tothe list of BNs successors; do the same thing as in step 6(3), set the parent link and g and
35、f valuesappropriately; However, if g(SUC)g(OLD), the improvement must be propagate to OLDs successors. 7. Go to step 2.,(4) Heuristic PowerThe total cost of heuristic search consists of two parts: (a) Path cost = (path length) x unit length cost (b) Search cost spent for searching the solution path,
36、(a),(b),Costs,Informed-ness,(5) Measures of Heuristic Performance(a) Penetrance, P, of A SearchP is the extent to which the search has focused toa goal, rather than wandered off: P = L / T whereL: the length of the path found to the goalT: the total number of nodes generated during thesearch (includ
37、ing the goal node but not including the start node)Hence, P can be considered as a measure of searchefficiency.,(b) Effective Branching factor, B, of A SearchB is defined by the equation:B + B + + B = T (total number of nodes)Hence T =,2,L,(B - 1) B,L,B - 1,P = =,L,T,L (B - 1),B(B - 1),L,Where the a
38、ssumptions are made: (1) The depth of the search tree = the length of path L (2) T = the number of nodes generated during search (3) B is a constant for all nodes in the tree,Home-Works 1. Propose two h functions for the traveling salesmanproblem. Is either these h functions a lower bound on h*? Whi
39、ch of them would result in more efficientsearch ? Apply algorithm A with these h functionsto the TSP problem.2. Use the evaluation function f(n)=d(n)+w(n) with algorithm A to search backward from the goal to the start node in the 8-puzzle problem.3. Discuss ways in which an h function might be impro
40、ved during a search., 5-2 Game-Playing: AND/OR Graph SearchI. Game-Playing and AO GraphTwo-Person-Zero-Sum-Perfect Information GamesExample: Grundys GameTwo Players, Max and Min, have a pile of pennies. The first player, Min, divides the original pile into two piles that must be unequal. Each player
41、 alternatively thereafter does the same to some single pile when it is his turn to play. The game proceeds until every pile has either just one penny or two. The player who first can not play is the loser.,7; Min,5,2;Max,6,1;Max,4,3;Max,5,1,1;Min,4,2,1;Min,3,2,2;Min,3,3,1;Min,3,2,1,1;Max,4,1,1,1;Max
42、,2,2,2,1;Max,2,2,1,1,1;Min,3,1,1,1,1;Min,2,1,1,1,1,1;Max,Wining path for Max,AND/ORGraph,From Maxs point of view, a win must be obtainable from all of Mins successors and from at least one of Maxs successors. It is an AND/OR graph.In AND/OR graphs, there are hyper-arcs connecting a parent node with
43、a set of its successors. The hyper-arcs are called connectors. Each k-connector is directed from a parent node to a set of k successor nodes.,II. Features of AND/OR Graph SearchThe choice of the node to expand next must depend not only on the f value of that node itself, but also on whether that nod
44、e is part of the current best path from the initial node. E.g.,A,B,C,D,h=5 3 4,9,A,B,C,D,J,I,H,G,F,E,5,10,3,4,3,4,17,18,9,9,20,Thus, to search an AND/OR graph, it needs to do three things at each step: 1) Traverse the graph, starting at the initial node and following the current best path, and accum
45、ulate the set of nodes that are on that path and havent been expanded. 2) Pick one of these nodes and expand it. Add to the graph its successors, compute f for each of them. 3) Change the f value of the newly expanded node to reflect the new information provided by successors. Propagate this change
46、backward through the graph. At each node that is visited while going up the graph, decide which of its successor arcs is the most promising and mark it as part of the current best path.,A,A,B,B,C,D,C,D,E,F,3,4,5,9,6,4,4,10,9,3,4,A,B,C,D,G,H,E,F,5,7,4,4,10,4,6,12,This may cause the current best path
47、to change.,Thus, an important feature in AND/OR graph search is that one must search a solution graph each time from the start node to the terminal node and needs to frequently check to see if the start node solvable.The definition of solvable node in AND/OR graph: 1) Terminal node is solvable node;
48、 2) An OR node is solvable iff at least one of its successorsis solvable; 3) An AND node is solvable iff all its successors solvable.,III. Procedure AO* (1) Create a search graph, G, consisting solely of thestart node, s. Compute h(s). If s is a terminal node,h(s)=0, label s SOLVED. (2) Until s is l
49、abeled SOLVED, do: (3) Begin (4) Compute a partial solution graph, G, in G by tracing down the marked connectors in G from s. (5) Select any non-terminal tip node, n, of G. (6) Expand n generating all its successors and installthese in G as successors of n. For each successor,n , not already occurring in G, computing h(n ).Label SOLVED any of these successors that areterminal nodes.,