Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artificial Intelligence Second Term Fourth Year (07 Batch) Knowledge Representation.

Similar presentations


Presentation on theme: "Artificial Intelligence Second Term Fourth Year (07 Batch) Knowledge Representation."— Presentation transcript:

1

2 Artificial Intelligence Second Term Fourth Year (07 Batch) Knowledge Representation

3 Terminology State: A state is a situation that an agent can find itself in. Types of States:  World States: The actual concrete situations in the real world.  Representational States: The abstract descriptions of the real world that are used by the agent in deliberating about what to do. State Space: is a graph whose nodes are the set of all states, and whose links are the actions that transform one state into another.

4 Terminology Search Tree: A search tree is a tree in which the root node is the start state and the set of children for each node consists of the states reachable by taking any action. Search Node: A search node is a node in the search tree. Goal: A goal is a state that the agent is trying to reach. Action: An action is something that the agent can choose to do. Successor Function: A successor function describes the agent’s options: given a state, it returns a set of (action, state) pairs, where each state is the state reachable by taking the action. The Branching Factor: The branching factor in a search tree is the number of actions available to the agent.

5 To Solve a Problem: 1.Define the problem precisely. 2.Analyze the problem. 3.Isolate and represent the task knowledge. 4.Choose the best problem-solving technique and apply it.

6 Problems There are 3 general categories of problems in AI: Single-agent path-finding problems. Two-player games. Constraint satisfaction problems.

7 Single Agent Pathfinding Problem In these problems, in each case, we have a single problem- solver making the decisions, and the task is to find a sequence of primitive steps that take us from the initial location to the goal location. Famous examples: – Rubik’s Cube (Erno Rubik, 1975). – Sliding-Tile puzzle. – Navigation - Travelling Salesman Problem.

8 Two Player Games In a two-player game, one must consider the moves of an opponent, and the ultimate goal is a strategy that will guarantee a win whenever possible. Two-player perfect information have received the most attention of the researchers till now. But, nowadays, researchers are starting to consider more complex games, many of them involve an element of chance. The best Chess, Checkers, and Othello players in the world are computer programs!

9 Constraint-Satisfaction Problems In these problems, we also have a single-agent making all the decisions, but here we are not concerned with the sequence of steps required to reach the solution, but simply the solution itself. The task is to identify a state of the problem, such that all the constraints of the problem are satisfied. Famous Examples: – Eight Queens Problem. – Number Partitioning.

10 The Problem Spaces A problem space consists of a set of states of a problem and a set of operators that change the state. – State : a symbolic structure that represents a single configuration of the problem in a sufficient detail to allow problem solving to proceed. – Operator : a function that takes a state and maps it to another state.

11 A problem (or, more precisely, a problem instance) consists of: – A problem space – An initial state – A set of goal states » explicitly or implicitly characterized – A solution, i.e., » a sequence of operator applications leading from the initial state to a goal state » or, a path through the state space from initial to final state.

12 Representing State At any moment, the relevant world is represented as a state – Initial (start) state: S – An action (or an operation) changes the current state to another state (if it is applied): state transition – An action can be taken (applicable) only if its precondition is met by the current state – For a given state, there might be more than one applicable actions – Goal state: a state satisfies the goal description or passes the goal test – Dead-end state: a non-goal state to which no action is applicable

13 Representing States The state-space representation of a problem is a triplet (I, O, G) – where: I - initial state, O - a set of operators on states, G - goal states A state space can be organized as a graph: nodes: states in the space arcs: actions/operations A solution is a path from the initial state to a goal state. The size of a problem is usually described in terms of the number of states (or the size of the state space) that are possible. Chess has about states in a typical game.

14 Some Example Problems 8 - Puzzle Given an initial configuration of 8 numbered tiles on a 3 x 3 board, move the tiles in such a way so as to produce a desired goal configuration of the tiles.

15 8 - Puzzle State: 3 x 3 array configuration of the tiles on the board. Operators: Blank moves Left, Right, Up or Down. Initial State: A particular configuration of the board. Goal: A particular configuration of the board. Path Cost: each step costs 1, so the path cost is just the length of the path.

16 A portion of the state space representation of a 8-Puzzle problem

17 The 8 Queens Problem The goal of 8-Queen problem is to place eight queens on a chessboard such that no queen attacks any other. ( A queen attacks any piece in the same row, column or diagonal). States: any arrangement of 0 to 8 queens on board. Operators: add a queen to any square. Goal Test: 8 queens on board, none attacked.

18 Cryptarithmetic In crypt-arithmetic problems, letters stand for digits and the aim is to find a substitution of digits for letters such that the resulting sum is arithmetically correct. Example: FORTYSolution: 29786F=2, O=9, R=7, etc. + TEN SIXTY 31486

19 Cryptarithmetic States: a cryptarithmetic puzzle with some letters replaced by digits. Operators: replace all occurrences of a letter with a digit not already appearing in the puzzle. Goal Test: puzzle only contains digits, and represents a correct sum.

20 Missionaries and Cannibals Three cannibals and three missionaries come to a crocodile infested river. There is a boat on their side that can be used by either one or two persons. If cannibals outnumber the missionaries at any time, the cannibals eat the missionaries. How can they use the boat to cross the river so that all missionaries survive ? There are 3 missionaries, 3 cannibals, and 1 boat that can carry up to two people on one side of a river. Goal: Move all the missionaries and cannibals across the river. Constraint: Missionaries can never be outnumbered by cannibals on either side of river, or else the missionaries are killed. State: configuration of missionaries and cannibals and boat on each side of river. Operators: Move boat containing some set of occupants across the river (in either direction) to the other side.

21 Travelling Salesman Problem Given a road map of n cities, find the shortest tour which visits every city on the map exactly once and then return to the original city (Hamiltonian circuit) (Geometric version): – a complete graph of n vertices. – n!/2n legal tours – Find one legal tour that is shortest

22 An instance of the travelling salesman problem

23 Search of the traveling salesperson problem.

24 Remove 5 Sticks Given the following configuration of sticks, remove exactly 5 sticks in such a way that the remaining configuration forms exactly 3 squares.

25 Real World Problems: Route finding VLSI Layout Robot Navigation etc.

26 State-space search is the process of searching through a state space for a solution by making explicit a sufficient portion of an implicit state-space graph to include a goal node. – Hence, initially V={S}, where S is the start node; when S is expanded, its successors are generated and those nodes are added to V and the associated arcs are added to E. This process continues until a goal node is generated (included in V) and identified (by goal test) During search, a node can be in one of the three categories: – Not generated yet (has not been made explicit yet) – OPEN: generated but not expanded – CLOSED: expanded – Search strategies differ mainly on how to select an OPEN node for expansion at each step of search

27 A General State Space Search Algorithm Node n – state description – parent (may use a backpointer)(if needed) – Operator used to generate n(optional) – Depth of n(optional) – Path cost from S to n(if available) OPEN list – initialization: {S} – node insertion/removal depends on specific search strategy CLOSED list – initialization: {} – organized by backpointers

28 open := {S}; closed :={ }; repeat n := select(open); /* select one node from open for expansion */ if n is a goal then exit with success; /* delayed goal testing */ expand(n) /* generate all children of n put these newly generated nodes in open (check duplicates) put n in closed (check duplicates) */ until open = {}; exit with failure

29 Search Strategies Search Directions The objective of search procedure is to discover a path through a problem spaces from an initial configuration to a goal state. There are two directions in which a search could proceed: – Forward, from that start states – Backward, from the goal states

30 Forward Search: (Data-directed / Data-Driven Reasoning / Forward Chaining) This search starts from available information and tries to draw conclusion regarding the situation or the goal attainment. This process continues until (hopefully) it generates a path that satisfies the goal condition.

31 Backward Search: (Goal directed/driven / Backward Chaining) This search starts from expectations of what the goal is or what is to happen (hypothesis), then it seeks evidence that supports (or contradicts) those expectations (or hypothesis). The problem solver begins with the goal to be solved, then finds rules or moves that could be used to generate this goal and determine what conditions must be true to use them. These conditions become the new goals, sub goals, for the search. This process continues, working backward through successive sub goals, until (hopefully) a path is generated that leads back to the facts of the problem.

32 Goal-driven search uses knowledge of the goal to guide the search. Use goal-driven search if; A goal or hypothesis is given in the problem or can easily be formulated. There are a large number of rules that match the facts of the problem and thus produce an increasing number of conclusions or goals. (inefficient) Problem data are not given but must be acquired by the problem solver. (impossible)

33 Data-driven search uses knowledge and constraints found in the given data to search along lines known to be true. Use data-driven search if: All or most of the data are given in the initial problem statement. There are a large number of potential goals, but there are only a few ways to use the facts and the given information of a particular problem. It is difficult to form a goal or hypothesis.

34 Evaluating Search Strategies Completeness – Guarantees finding a solution whenever one exists Time Complexity – How long (worst or average case) does it take to find a solution? Usually measured in terms of the number of nodes expanded Space Complexity – How much space is used by the algorithm? Usually measured in terms of the maximum size that the “OPEN" list becomes during the search Optimality/Admissibility – If a solution is found, is it guaranteed to be an optimal or highest quality solution among several different solutions? For example, is it the one with minimum cost?

35 Uninformed vs. informed Search Uninformed Search Strategies (Blind Search) – Breadth-First search – Depth-First search – Uniform-Cost search – Depth-First Iterative Deepening search Informed Search Strategies (Heuristic Search) – Hill climbing – Best-first search – Greedy Search – Beam search – Algorithm A – Algorithm A*

36 Blind Search/Uninformed Search A blind search is a search that has no information about its domain. The only thing that a blind search can do is to distinguish a non-goal state from a goal state.

37 Breadth First Search (BFS) Breadth First Search explores the state space in a level by level fashion. Only when there are no more states to be explored at a given level does the algorithm move onto the next level.

38 BFS Goal …

39 BFS

40 Time Complexity and Space Complexity: - If we look at how BFS expands from the root we see that it first expands on a set number of nodes, say b. - On the second level it becomes b 2. - On the third level it becomes b 3. - And so on until it reaches bd for some depth d. 1+ b + b 2 + b b d which is O(b d ) Since all leaf nodes need to be stored in memory, space complexity is the same as time complexity.

41 BFS As you can see BFS is:  Very systematic  Guaranteed to find a solution  What does this mean? From the four criteria, it means  BFS is complete. If there exists an answer, it will be found (b should be finite).  BFS is optimal (if cost = 1 per step). The path from initial state to goal state is shallow.

42 41 Undirected Breadth First Search F A BCG DE H

43 42 Undirected Breadth First Search F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)

44 43 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: Active 0 F 1 F discovered

45 44 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: F Active 0 1 B 1 B discovered

46 45 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: F B Active C 1 C discovered

47 46 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: F B C Active G 1 G discovered

48 47 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: F B C G Active get A finished

49 48 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: B C G Active A already visited

50 49 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: B C G Active D 2 D discovered

51 50 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: B C G D Active E 2 E discovered

52 51 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: B C G D E Active get F finished

53 52 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: C G D E Active

54 53 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: C G D E Active A already visited

55 54 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: C G D E Active get B finished

56 55 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: G D E Active A already visited

57 56 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: G D E Active get C finished

58 57 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: D E Active A already visited

59 58 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: D E Active E already visited

60 59 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: D E Active get G finished

61 60 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: E Active E already visited

62 61 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: E Active F already visited

63 62 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: E Active get D finished

64 63 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: Active D already visited

65 64 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: Active F already visited

66 65 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: Active G already visited

67 66 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: Active H 3 H discovered

68 67 Undirected Breadth First Search F A BCG DE Undiscovered Fringe Finished Queue: H Active get H 3 E finished

69 68 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: Active E already visited

70 69 Undirected Breadth First Search F A BCG DE H Undiscovered Fringe Finished Queue: Active STOP H finished

71 70 Undirected Breadth First Search F A BCG DE H distance from A

72 Breadth First Search AB F I EH DC G FIFO Queue - front

73 Breadth First Search AB F I EH DC G A FIFO Queue - front enqueue source node

74 Breadth First Search AB F I EH DC G A FIFO Queue - front dequeue next vertex

75 Breadth First Search front visit neighbors of A AB F I EH DC G - FIFO Queue

76 Breadth First Search front visit neighbors of A AB F I EH DC G - FIFO Queue

77 Breadth First Search B front B discovered AB F I EH DC G - A FIFO Queue

78 Breadth First Search B front visit neighbors of A A F I EH DC G - B A FIFO Queue

79 Breadth First Search B I front I discovered A F I EH DC G - B A A FIFO Queue

80 Undirectional Breadth First Search B I front finished with A A F I EH DC G - B A A FIFO Queue

81 Undirectional Breadth First Search B I front F I EH DC G - B A A dequeue next vertex FIFO Queue A

82 Undirectional Breadth First Search I front F I EH DC G - B A A visit neighbors of B FIFO Queue A

83 Breadth First Search I front F I EH DC G - B A A visit neighbors of B FIFO Queue A

84 Breadth First Search I F front F I EH DC G - B A A F discovered B FIFO Queue A

85 Undirectional Breadth First Search I F front F I EH DC G - B A A visit neighbors of B B FIFO Queue A

86 Breadth First Search I F front F I EH DC G - B A A A already discovered B FIFO Queue A

87 Breadth First Search I F front F I EH DC G - B A A finished with B B FIFO Queue A

88 Breadth First Search I F front F I EH DC G - A A dequeue next vertex B FIFO Queue BA

89 Breadth First Search F front F I EH DC G - A A visit neighbors of I B FIFO Queue BA

90 Breadth First Search F front F I EH DC G - A A visit neighbors of I B FIFO Queue BA

91 Breadth First Search F front F I EH DC G - A A A already discovered B FIFO Queue BA

92 Breadth First Search F front F I EH DC G - A A visit neighbors of I B FIFO Queue BA

93 Breadth First Search F E front F I EH DC G - A A E discovered B I FIFO Queue BA

94 Breadth First Search F E front F I EH DC G - A A visit neighbors of I B I FIFO Queue BA

95 Breadth First Search F E front F I EH DC G - A A F already discovered B I FIFO Queue BA

96 Breadth First Search F E front F I EH DC G - A A I finished B I FIFO Queue BA

97 Breadth First Search F E front FEH DC G - A A dequeue next vertex B I FIFO Queue BA I

98 Breadth First Search E front FEH DC G - A A visit neighbors of F B I FIFO Queue BA I

99 Breadth First Search E G front FEH DC G - A A G discovered B I F FIFO Queue BA I

100 Breadth First Search E G front FEH DC G - A A F finished B I F FIFO Queue BA I

101 Breadth First Search E G front EH DC G - A A dequeue next vertex B I F FIFO Queue I F BA

102 Breadth First Search G front EH DC G - A A visit neighbors of E B I F FIFO Queue I F BA

103 Breadth First Search G front H DC G - A A E finished B I F FIFO Queue I F BA E

104 Breadth First Search G front H DC G - A A dequeue next vertex B I F FIFO Queue I F BA E

105 Breadth First Search front H DC G - A A visit neighbors of G B I F FIFO Queue I F BA E

106 Breadth First Search C front H DC G - A A C discovered B I F G FIFO Queue I F BA E

107 Breadth First Search C front H DC G - A A visit neighbors of G B I F G FIFO Queue I F BA E

108 Breadth First Search C H front H DC G - A A H discovered B I F G G FIFO Queue I F BA E

109 Breadth First Search C H front H DC G - A A G finished B I F G G FIFO Queue I F BA E

110 Breadth First Search C H front H DC - A A dequeue next vertex B I F G G FIFO Queue I F BA EG

111 Breadth First Search H front H DC - A A visit neighbors of C B I F G G FIFO Queue I F BA EG

112 Breadth First Search H D front H DC - A A D discovered B I F G G C FIFO Queue I F BA EG

113 Breadth First Search H D front H DC - A A C finished B I F G G C FIFO Queue I F BA EG

114 Breadth First Search H D front H D - A A get next vertex B I F G G C FIFO Queue I F BA EG C

115 Breadth First Search D front H D - A A visit neighbors of H B I F G G C FIFO Queue I F BA EG C

116 Breadth First Search D front D - A A finished H B I F G G C FIFO Queue I F BA EGH C

117 Breadth First Search D front D - A A dequeue next vertex B I F G G C FIFO Queue I F BA EGH C

118 Breadth First Search front D - A A visit neighbors of D B I F G G C FIFO Queue I F BA EGH C

119 Breadth First Search front - A A D finished B I F G G C FIFO Queue I F BA EGH CD

120 Breadth First Search front - A A dequeue next vertex B I F G G C FIFO Queue I F BA EGH CD

121 Breadth First Search front STOP EH D - A A B I F G G C FIFO Queue I F BA G C

122 Backwards Breadth First Search … SISI SGSG

123 Bi-Directional BFS SGSG SISI …

124 Uniform Cost Search Expands the least cost leaf node first. It is complete, and unlike BFS, is optimal even when operators have different costs. Its space and time complexity are the same as for breadth-first search.

125 Uniform Cost Search: Example A GBS C Solution: S 0 S A B C 11 S A B C G 11 S A B C G G 10 1 Solution is SBG

126 Depth First Search A depth first search begins at the root node (i.e. Initial node) and works downward to successively deeper levels. An operator is applied to the node to generate the next deeper node in sequence. This process continues until a solution is found or backtracking is forced by reaching a dead end.

127 14 Jan 2004CS Blind Search126 Depth-first search

128

129

130

131

132

133

134

135

136

137 Depth First Search A BC D E F G H I J K LMN O A BC D H I E J K F LM G N O

138 Depth-First Search … SISI Goal

139 Evaluation of DFS Since we don’t expand all nodes at a level, space complexity is modest. For branching factor b and depth d, we require bd number of nodes to be stored in memory. This is much better than b d. In some cases, DFS can be faster than BFS. However, the worse case is still O(b d ). If you have deep search trees (or infinite – which is quite possible), DFS may end up running off to infinity and may not be able to recover. Thus DFS is neither optimal nor complete.

140 Depth Limited Search Depth limited search avoids the pitfalls of depth search by imposing a cut-off on the maximum depth of a path. Depth limited search is complete but not optimal. If we choose a depth limit that is too small, then depth limited search is not even complete. The time and space complexity of depth limited search is similar to depth first search.

141 Depth First Iterative Deepening (DFID) BF and DF both have exponential time complexity O(b^d) BF is complete but has exponential space complexity DF has linear space complexity but is incomplete Space is often a harder resource constraint than time Can we have an algorithm that – Is complete – Has linear space complexity, and – Has time complexity of O(b^d) DFID by Korf in 1985 DFID Algorithm It involves repeatedly carrying out DFS on the tree, starting with a DFS limited to depth of one, then DFS of depth two, and so on, until a goal is found.

142 14 Jan 2004CS Blind Search141 Iterative deepening search l =0

143 14 Jan 2004CS Blind Search142 Iterative deepening search l =1

144 14 Jan 2004CS Blind Search143 Iterative deepening search l =2

145 14 Jan 2004CS Blind Search144 Iterative deepening search l =3

146 Iterative deepening search Number of nodes generated in a depth-limited search to depth d with branching factor b: N DLS = b 0 + b 1 + b 2 + … + b d-2 + b d-1 + b d Number of nodes generated in an iterative deepening search to depth d with branching factor b: N IDS = (d+1)b 0 + d b 1 + (d-1)b 2 + … + 3b d-2 +2b d-1 + 1b d For b = 10, d = 5, – N DLS = , , ,000 = 111,111 – N IDS = , , ,000 = 123,456 Overhead = (123, ,111)/111,111 = 11%

147 14 Jan 2004CS Blind Search146 Summary of algorithms CriterionBreadth FirstUniform Cost Depth FirstDepth Limited Iterative Deepening Complete?Yes No Yes TimeO(b d+1 ) Space Optimal?Yes No Yes

148 Repeated states Failure to detect repeated states can turn a linear problem into an exponential one!

149 How to deal with repeated states? Do not return to the state you just came from.  have the expand function refuse to generate any successor that is the same state as the node’s parent. Do not repeat paths with cycles in them.  have the expand function refuse to generate any successor of a node that is the same as any of the node’s ancestors. Do not generate any state that was ever generated before.


Download ppt "Artificial Intelligence Second Term Fourth Year (07 Batch) Knowledge Representation."

Similar presentations


Ads by Google