Ai Units 1 and 2

February 26, 2017 | Author: raqmail1475 | Category: N/A
Share Embed Donate


Short Description

Download Ai Units 1 and 2...

Description

Artificial Intelligence

Artificial intelligence Master of Computer Applications

GVR & S College of Engineering and Technology Budampadu, Guntur Affiliated to Acharya Nagarjuna University

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

1

Artificial Intelligence

CHAPTER-1 WHAT IS ARTIFICIAL INTELLIGENCE Artificial Intelligence(AI) is the key technology in many of today’s Novell applications, ranging from banking system that detect attempted credit card framed, to telephone systems that understand speech, to s/w systems that notice when you are having problems and offer appropriate advice. These technologies would not exist today without the sustained federal of fundamental AI research over the past 3 decades. There is no clear definition of A.I .even the name is controversial, some people prefer to call the subject of “computational Intelligence”. The term A.I was coined in 1957 at a conference at Dartmouth New Hampshire convened to discuss the possibilities of simulating human intelligence and thinking in computers. Today, AI is a well-established, natural and scaling branch of computer science. A.I is the part of computer science concerned with designing intelligent computer systems, that is, computer systems that exhibit the characteristics we associate with intelligence in human behavior understanding language, learning, reasoning and solving problems. The study of AI by considering a number of alternative definitions. 1) AI is the study of how to make computers do things which at the moment people do better. It refers to the current state of computer science and if excludes a major area of problems that can not be solved well either by computers or by people at the moment. 2) AI is a field of study that encompasses computational techniques for performing tasks that apparently require intelligence when performed by humans. 3) AI is about generating representations and procedures that automatically solve problems which can be solved by humans. 4) AI is the part of computer science concerned with designing intelligent computer systems that is computer systems that exhibit the characteristics we associate with intelligence in human behavior-understanding language, learning, reasoning and solving problems. In practical terms, intelligence of a computer system provides:

Ability to automatically perform tasks that currently requires human operators.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

2

Artificial Intelligence



More autonomy in computer systems, less requirement for human intervention or monitoring.



Feasibility in dealing with variability in the environment in an appropriate manner.



Ability to understand what the user wants from limited instructions.



Increase in the performance by learning from experience.

AI problems Intelligence does not imply perfect understanding: every intelligent being has limited perception, memory, and computation. AI seeks to understand the computations required from intelligent behavior and to produce computer systems that exhibit intelligence. Aspects of intelligence studied by AI include perception, motor control, and communication using human languages, reasoning, planning, learning and memory. Various AI problems are as follows. Mundane Tasks 

Perception ---Machine vision ---Speech understanding



Natural language processing --- Natural language understanding ---Language generation ---Machine translation

 

Commonsense reasoning Robot control Formal tasks



Games ---Chess ---Backgammon

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

3

Artificial Intelligence

---Checkers 

Mathematics ---Geometry ---Logic ---Integral calculus ---Proving properties of programs. Expert tasks



Engineering ---Design ---Fault finding ---Manufacturing planning

  

Scientific analysis Medical diagnosis Financial analysis

Perception: Machine vision:Accurate machine vision opens up a new world of computer applications. These applications include mobile robot navigation, complex manufacturing tasks, analysis of satellite images, and medical image processing. Perception of the world around us is crucial to our survival. Animals with much less intelligence than people are capable of more sophisticated visual perception than are current machines. If it easy to interface a TV camera to a computer and an image into memory. The problem is understanding what the image represents vision takes lots of computation. Speech understanding: Spoken language is a more natural form of communication in many human computer interfaces. Speech understanding is available now on personal computers. These A.Rakesh Babu M.C.A., M.Tech Asst.Prof

4

Artificial Intelligence

systems must be trained for the individual user and require pauses between words. Understanding continuous speech with a larger vocabulary is harder. The ability to use language to communicate a wide variety of ideas is perhaps the most important thing that separates human from other animals.

Natural Language Processing: Natural Language understanding:Natural languages are human languages such as English. Making computers understand English allows non- program mess to use them with little training. Natural language generation:Making computers to generate human or natural languages can be called as natural language generation. It is much easier than natural language understanding Machine Translation:A text written in one language and then generate it in another language by means of computers can be called as machine Translation. It is important for organizations that operate in many countries.

Common Sense Reasoning:A computer program that interacts with real world must be able to reason about things like time, space and materials. As a fundamental and commonsensical as these concepts may be modeling them turns out to present some problems.

Robot Control:Robots can process visual and auditory information, and they can also be equipped with more special sensors, such as laser range finders, speedometers and radar. Although industrial robots to date have been expensive, robot hardware can be cheap. What is needed is perception and intelligence to tell robot effectors what to do; “bling” robots are limited to very well-structured tasks like spray painting car bodies.

Planning:Planning attempts to order the application of resources to achieve goals planning applications include logistics; manufacturing scheduling planning steps in manufacturing is to construct a desired product.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

5

Artificial Intelligence

Expert Systems:Expert systems attempt to capture the knowledge of human expert and make it available through a computer program.

Machine Learning:Learning has remained a challenging area of AI. Expert systems may perform costly computations to solve problem. Unlike human beings it can’t remember the solution, if it is given the same problem for second time one of the solutions for these problems for programs is to learn on their own either from experience examples or analogy.

AI Technique:There AI techniques are: 1. Search 2. Use of knowledge 3. Abstraction Search:Search programs find a solution for a problem by trying different sequences of actions/operators until a solution is found. The advantage of search is, to solve a program using search, it is only necessary to code the operators that can be used: search will find the sequence of actions that will provide the desired result. For example a program can be written to play chess using search if one knows the rules of chess if is not necessary to know how to play good chess. The disadvantage of search is, most problems have search so large that it is impossible to search the whole space. Chess has been estimated to have 1020 possible games. Use of Knowledge:Use of knowledge provides a way of solving complex problems by exploiting of the objects that are involved. Games can be good models of competitive situations, so principles discovered in games playing programs may be applicable to practical problems. Abstraction:Abstraction provides a way of separating important features and variations from the many unimportant ones that would otherwise overwhelm any process.

CHAPTER - 2 PROBLEMS, PROBLEM SPACES AND SEARCH A.Rakesh Babu M.C.A., M.Tech Asst.Prof

6

Artificial Intelligence

To build a system to solve a particular problem, for that we need to do four things 1) Define the problem exactly. The definition must include precise specification of what the initial situation will be as well as what final situations constitute acceptable solutions to the problem. 2) Analyze the problem a few very important features can have an immense impact on the appropriateness of various possible techniques for solving the problem. 3) Isolate and represent the task knowledge that is necessary to solve the problem. 4) Choose the best problem solving techniques and apply it to the particular problem.

Defining problem as a state space search A state space represents a problem in terms of states and operators that change states A state space consists of: 1) A representation of the states the system can be in. in a chess game, for example, any board position represents the current state of the game. 2) A set of operators that can change one state into another state. In chess game, the operators are the legal moves from any given state. Often the operators are representation to represent the new state. 3) An initial state. 4) A set of final states, some of these may be desirable others are undesirable this sets often represented implicitly by a program that deletes terminal states. Tic-tac-toe as a state space State space is good representations for board games such as tic-tac-toe the state of a game can be described by the contents of the board and the player whose turn is next. The board can be represented as an array of 9 cells, each of which may contain a X or O or be empty. State:  Play to move next X or O.  Board configuration.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

7

Artificial Intelligence

X

O O

X

X

Operators:

Change an empty cell to X or O.

Start state:

Board empty, X’s turn

Terminal states: Three X’s in arrow there O’s in arrow all the cells full. Search tree: The sequence of states formed by possible moves is called a search tree each level of the tree is called a play.

X X

X

O

X

X

X O

O

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

8

Artificial Intelligence

Since the same state may be reachable by different sequence of moves the state space may be in a general graph it may be as a tree for simplicity at the cost of duplicating states. Solving problems using search: Given an informal description of the problem construct a formal description as a state Space.  Define a data structure to represent the state.  Make a representation for the initial state from the given data.  Write programs to represent operators that change a given state representation to new state representations.  Write programs to delete terminal state.

Choose an appropriate search technique based on the following quires: 1) How large is the search space? 2) How well structured is the domain? 3) What knowledge about the domain can be used to guide the search?

Evaluating search strategies: Completeness: Guarantees finding a solution when ever one exits. 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. Big O notation used for measuring time complexity. Space Complexity: How much space is used by the algorithm? Usually measured in term of the maximum size that nodes list becomes during the search. Optimality: If a solution is found is it guaranteed to be an optimal one? That is the one with minimum cost?

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

9

Artificial Intelligence

Water jug problem: There are two jugs a 4-Gallon one and 3-Gallon one. Neither has any measuring marker on it. There is a pump that can be used to fill the jugs with water how can you get exactly 2- Gallon water into the 4- Gallon jug? The state space for this problem can be described as the set of ordered pairs of integers(x, y) such that x=0, 1, 2, 3, 4 and y=0, 1, 2, 3. X represents the number of gallons of water in the 4- Gallon jug. Y represents the number of gallons of water in the 3- Gallon jug. The state space is (0, 0). The goal state is (2, n) for any value of n. Operators: The operators to be used to solve the problem can be described as follows. 1. (x, y)

(4,y)

fill the 4-g jug

(x, 3)

fill the 3-g jug

(x-d, y)

pour some water out of the 4-g jug

(x, y-d)

pour some water out of the 3-g jug

(0, y)

empty the 4-g jug on the ground

(x,0)

empty the 3-g jug on the ground

(4,y-(4-x))

pour water from the 3-g jug into

If x0 5. (x, y) If x>0 6. (x, y) If y>0 7. (x, y) If x + y >= 4 and y>0 8. (x, y) A.Rakesh Babu M.C.A., M.Tech Asst.Prof

the 4-g jug until the 4-g jug is full (x,-3(3-y),3)

pour water from the 4-g jug into 10

Artificial Intelligence

If x + y>3 & x>0 9. (x, y)

the 3-g jug until the 3-g jug is full (x+y,0)

If x + y0 10. (x, y)

4-g jug (0,x+y)

If x + y0 11. (0, 2)

pour all the water from 3-g jug into

pour all the water from the 4-g jug into the 3-g jug

(2, 0)

pour the 2-g from 3-g jug into 4-g Jug

12. (2, y)

(0, y)

empty the 2-g in the 4-g jug on the ground.

Solution to the water jug problem: Gallon in the 4-g jug 0

Gallon in the 3-g jug

Rule Applied

0 2

0

3 9

3

0 2

3

3 7

4

2 5/12

0

2 9/11

1

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

0

11

Artificial Intelligence

Production Systems: The search forms the basic intelligent process it is useful to structure. A.I programs in a way that facilities describing and performing the search process. Production system provides such structures. A production system consist of 1) A set of rules, each consisting on the left side that determines the applicability of the rule and on a right side that describe the operation to be performed if the rule is applied. 2) One/more knowledge /database that contain what ever information is appropriate for the particular task. a production system has two memories a) A production memory or long-term memory contains the production rules. b) A working memory or short-term memory containing data about the current problem. 3) A control strategy that specifies the order in which the rules will be compared to the database and a way of resolving conflicts that arise when several rules match at once. 4) A rule applier. The production rules operate on the knowledge base/database. Each rule has a precondition that is either satisfied by the knowledge base. If the precondition is satisfied, the rule can be applied. Application of the rule changes knowledge base. The control system chooses which applicable rule should be applied and causes computation when a termination condition on the knowledge base.

8-Puzzle: Give an initial configuration of 8 numbered tiles on a 3X3 board, move the files in such a way so as to produce a desired goal configuration of the tiles. State: 3 X 3 array configuration of the file on the board. Operators: move blank square left, right, up or down. Initial state: a particular configuration of the board. Goal: a particular configuration of the board.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

12

Artificial Intelligence

2

1

3

1

2

3

7

8

9

4

5

6

4

7

7

8

Initial State

Goal State

The traveling sales man problem: Sales man has a list of cities, each of which he must visit exactly once. Three are direct roads b/w each pair of cities on the list. Find the route the salesman should follows for the shortest possible round trip that both starts and finishes at any of the cities.

Heuristic search: A heuristic search is a technique that improves the efficiency of search process. One example of a good general-purpose heuristic search that is useful for a variety of combinational problems is the nearest heuristic. Applying it to the traveling salesman problem. Then we produce the following procedure. 1) Arbitrarily select a starting city. 2) Select the next city, look at all cities not yet visited and select the one closet to the current city go to it next 3) Repeat step2 until all cities have been visited.

Problem characteristics: Heuristic search is very general method applicable to a large class of problems. It encompasses a variety of specific techniques, each of which is particularly effective for a small class of problems in order to choose the most appropriate method for a particular problem. It is necessary to analyze the problem along several key dimensions. The following characteristics are nothing but problem characteristics: 1) 2) 3) 4)

Is the problem decomposable into a set of smaller sub problems? Can solution steps be ignored or undone if they do not move towards a solution? Is the problem universe predictable? Can we find a good solution to the problem with out comparing to all other possible solution? 5) Is the desired solution is path/state? A.Rakesh Babu M.C.A., M.Tech Asst.Prof

13

Artificial Intelligence

6) Is a large amount of knowledge required to solve the problem to constrain the search? 7) Can a system return the solution/will the solution of the problem require interaction between the system and a person? Is the problem decomposable into subprograms? Suppose we want to solve a problem of computing the expression ∫(x3+x2+2x+3sinx) dx This problem can be solved by breaking it into 4 smaller problems, each of which we can solve by using a small collection of specific rules: ∫ (x3+x2+2x+3sinx) dx

∫ x3 dx

∫ x2dx

∫2x dx

x4/4

x3/3

2 ∫ x dx

2x2/2

∫ 3sinxdx

3 ∫ sin x dx

-3cosx

Fig: A Decomposable Problem Using the technique of problem decomposition, we can solve very large problems, very easily. This can be considered as one of the intelligent behaviors.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

14

Artificial Intelligence

Can solution steps to be ignored or undone? Suppose we are trying to prove a mathematical theorem. We may precede by first a lemma that will be useful. Later we may realize that the lemma is not at all useful. We may start with another one to prove the theorem here we can simply ignore the first method we have adopted to find the solution. Consider the 8-puzzel problem in attempting to solve the 8-puzzel, we might make a stupid move and realize that mistake and found we have done wrong step. But still mistakes can be recovered it may be as easy as in the theorem proving problem here the control strategy must keep track of all the moves. so that we can backtrack to the initial state and start with some new move. Consider the problem of playing chess. Here once we make move we can never recover from that step. These three problems, i.e. theorem proving, 8-puzzel, chess illustrate the differences b/w three important classes of problems. 1) Ignorable: In which solution steps can ignore. Ex: Theorem proving 2) Recoverable: In which solution step can be undone. Ex: 8-puzzle 3) Irrecoverable: In which solution steps can not be undone. Ex: chess Is the problem universe predictable? Consider 8-puzzle problem. Every time we make a move .we knows exactly what will happen. This means that it is possible to plan an entire sequence of moves and be confident what the resulting state will be. We can backtrack to undone moves if they prove unwise. Suppose we want to play bridge. Here we need to plan the entire hand before making the first play. But we can not play with certainty. The outcome in this game is very uncertain. In case of 8-puzzlethe outcome is very certain. To solve uncertain outcome problems we need to allow for a process of plan revision to tale place as the plan is carried out and the necessary feedback is provided. The disadvantage is that the planning in these cases is often very expensive. A.Rakesh Babu M.C.A., M.Tech Asst.Prof

15

Artificial Intelligence

Is a good solution absolute/relative? Consider the problem of answering questions based on a database of simple facts, such as the following: 1) Marcus was a man. 2) 3) 4) 5) 6) 7)

Marcus was a Pompeian. Marcus was born in 40 A.D. All means are mortal. All Pompeian’s died when the volcano erupted in 79 A.D. No mortal lives longer than 150yers. It is now 1991 A.D.

Suppose the question is “is Marcus alive”? By representing each of these facts in a formal language, such as predicate logic, and then using formal inference methods, we can easily derive an answer to the question. In fact we can use either of two methods to give answer to the question, which as shown below. 1) 2) 3) 4) 5) 6) 7) 8)

Marcus was a man. All men are mortal. Marcus is mortal. Marcus was born in 40 A.D. It is now 1991A.D. Marcus age is 1951 years. No mortal lives longer than 150 years. Marcus id dead. Or

1) It is now 1991 A.D. 2) All Pompeian’s died in 79 A.D. 3) All Pompeian’s are dead now. 4) Marcus was Pompeian. 5) Marcus is dead.

Since we are interested in the answer of the question it does not matter which path we follow. If we follow one path successfully, to the answer, there is no reason to go back and A.Rakesh Babu M.C.A., M.Tech Asst.Prof

16

Artificial Intelligence

see if some other path might also lead to a solution. Now, consider the traveling salesman problem our goal is to find the shortest route that visits each city exactly once. Suppose the cities to be visited and the distance b/w they are as shown below. Boston Boston

New York

Miami

Dallas

S.F

250

1450

1700

3000

1200

1500

2900

1600

3300

New York

250

Miami

1450

1200

Dallas

1700

1500

1600

S.F

3000

2900

3300

1700 1700

Fig: An instance of the traveling salesman problem Once place the sales person could start is Boston. In that case, one path might be followed as shown below. Boston

3000 San Francisco 1700 Dallas

1500 New York

1200 Miami

1450

Total=8850

Boston

Fig: One path among the cities Here the total distance is 8850kms.but this may not be a solution to the problem, may be other paths may give shortest route. A.Rakesh Babu M.C.A., M.Tech Asst.Prof

17

Artificial Intelligence

These toe examples illustrate the difference b/w any path problems and best-path problems. Any path problems can often be solved in a reasonable amount of time by using heuristic techniques that give good solution to explore. Is the desired solution a path /state? Different problem domains represent their goal in different ways such as states/paths. Consider water jug problem, whose solution is a desired state and traveling salesman problems solution is the shortest path. At one level the difference can be ignored and all can be formulated as ones in which only a state is required to be reported as a solution. The role of knowledge: The knowledge require to solve a particular problem is depending upon the problem it self. for example take playing chess, for this we need acknowledge of legal moves and some simple control mechanism that implements an appropriate search procedure on the other side, take a problem of design a robot have the knowledge about the source and destination, car driving rules, operating knowledge of car, weather knowledge and so on. These two problems illustrate the difference b/w problems for which a lot of knowledge is important only to constrain the search for a solution. Does the problem require interaction with a person? If the level of interaction b/w the computer and its human users is problem-in-solutionout then we can program computers to solve problems into the ways that majority of people additional input and additional reassurance then we need to go for progress that interacts with people. When computers move into the areas of human lives like medical diagnosis people will not blindly accept the systems solution. They need to interact with it. This we can distinguish two kinds of problems. 1) Solitary: Here computer is given a problem description and it produces the answer with out any intermediate interaction. 2) Conversational: Here intermediate interaction between the user and a computer is necessary either to provide additional assistance to the computer or to provide additional information to the user.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

18

Artificial Intelligence

Production system characteristics: Production system provide us with a good set of production rules, by using which we can solve the problems. Two questions may a raise at this point of time. 1) Can production systems, be described by a set of characteristics? 2) Can we draw any relationship between the problem types and the types of production systems suited to solve the problems? There are four categories of production systems: 1) A monotonic production system is a production system in which the application of a rule never prevents the later application of another rule that could have been applied at the time the first rule is selected. 2) A non monotonic production system is one in which the application of a rule prevents the later application of another rule that would have been applied at the time the first rule was selected. 3) A partially commutative production system is a production system with the property that if the application of a particular sequence of rules transforms state p into state q. then any permutation of those rules is allowable also transforms state p into state q. 4) A commutative production system is production system that is both monotonic and partially commutative.

Ex: Monotonic

Non monotonic

Theorem proving

Robot navigation

Chemical analysis

Bridge

Partially Commutative Commutative Production system/ Non partially Commutative

Fig: The 4-categories of Production Systems. A.Rakesh Babu M.C.A., M.Tech Asst.Prof

19

Artificial Intelligence

CHAPTER - 3 HEURISTIC SEARCH TECHNIQUES Generate and Test:The Generate and test strategy is the simplest of all approaches. Algorithm:i. ii. iii.

Generate a possible solution. Text to see if this is actually a solution by comparing with goal. If solution has been found quit otherwise return to step1.

The Generate and text algorithm is a DFS procedure since complete solution must be generated before they can be tested. In this form it is also known as British museum algorithm a reference to method for finding an object in British museum by wandering randomly. HILL CLIMBING:Hill Climbing is a variant of generate and test in which feedback from the test procedure is used to help the generator decide, which direction to move in the search space. Hill Climbing is often used when a good Heuristic Function is available for evaluating states but when no other useful knowledge is available. For example, suppose you are in an unfamiliar city without a map and you want to get down town you simply aim for the tall buildings. The Heuristic Function is just distance between the current locations of the tall buildings. Absolute solutions exist whenever it is possible to recognize a goal state by just examining it.

Simple Hill Climbing:Algorithm:i. ii.

Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise continue with the initial state as the current state. Loop until a solution is found (or) until there are no new operators left to be applied in the current state. a) Select an operator that has not yet been applied to the current static and apply it to produce a new state.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

20

Artificial Intelligence

b) Evaluate the new state  If it is a goal state, then return it and quit  If it is not a goal state but better than the current state, then make it the current state.  If it is not better than the current state, then continue in the loop.

A

4

3

5

2 A

A

A

Steepest-Ascent Hill Climbing:Algorithm:i.

Evaluate the initial state. If it is also goal state, then return it and quit otherwise continue with the initial state as the current state. ii. Loop until a solution is found(or) until a complete iteration produces no change to current state a) Let succ be a state such that any possible successor of the current state will be better than succ. b) For each operator that applies to the current state do: o Apply the operator and generate a new state. o Evaluate the new state. If it is a goal state, then return it and & quit. If not, compare it to succ. If it is better than set succ to this state. If it is not better leave succ alone. o If the succ is better than current state, then set current state to succ. Both basic and steepest-ascent Hill Climbing fail to find a solution.  Local maximum is a state that is better that all its neighbors but is not better than some other states further away.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

21

Artificial Intelligence

EX:5

8

6

2

 Plateau is a flat area of the search space in which a whole set of neighboring states has the same value. Ex:6 5

5

 Ridge is a special kind of local maximum. It is an area of the search space that is higher than the surrounding areas & itself has a slope. Ex:It means better but having slope.

There are some ways of dealing with these problems i. Back track to some earlier node and try going to different direction. ii. Make a big jump in some direction to try. To get a new section of the search space. iii. Apply two (or) more rules before doing the test suppose we use the following heuristic function operators:  Pick up one put it on the table  Pick up one it on the other

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

22

Artificial Intelligence

Simulated annealing:Simulated annealing is a variation of hill climbing and we describe it valley descending. Here we use the term objective function which aims at minimizing the value simulated annealing is patterned after the physical process of annealing in which physical substances such as metals are melted and then gradually cooled until some solid state is reached. The goal is to produce a minimal energy final state. There is some portability that a transition to a higher state will occur the probability is given by P=e-∆E/KT ∆E = Positive change in

the energy level.

T= temperature K=constant The rate at which the system is cooled is called the “Annealing schedule”. Algorithm:i. ii. iii. iv.

v.

Evaluate the initial state. If it is a goal state, then return it and quit. Otherwise continue with the initial state as the current state. Initialize BEST-SO-FAR to the current state. Initialize T according to the annealing schedule. Loop until a solution is found or until no new operators are left to be applied. a. Select an operator that has not yet been applied to the current state and apply it to get a new state. b. Evaluate this new state, compute ∆E = value of current state – value of new state. o If the new state is a goal state, then return it & quit o If it is not a goal state but is better than the current state, then make it the current state. Also set BEST-SO-FAR to this new state. o If the new state is not better than the current state, then make it the current state with probability P` o Revise T as necessary return BEST-SO-FAR as the answer:

Here we need to do enough exploration of the whole space early so that the final solution is relatively insensitive to the starting state. These lower the chances of getting caught at a local maximum, a plateau or a ridge.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

23

Artificial Intelligence

BEST- FIRST SEARCH: OR GRAPH Best first search combines the advantage of both depth-first and breadth first search methods. It selects the most promising node at each step by applying an approximate heuristic function the successors of this node are generated using applicable rules if one of them is a solution, we quit if not all these new nodes are added to the nodes. So far generated, and the process continues. Figure shows the beginning of a Best- First search procedure. 1

4

2

3

6

4

2

6 7

7

8

5

9

5

10

6

7

11

Best-first search tree

To implement such a graph-search procedure, we will need to use two lists of nodes. Open:Open is actually a priority queue in which the elements with the highest priority are those with the most promising value of the heuristic function. Closed:Nodes that have been already been examined. We need to keep these nodes in memory if we want to search a graph rather than a tree.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

24

Artificial Intelligence

Algorithm: Best-First search:1. State with open containing just the initial state 2. Until a goal is found or there are no nodes left on open do: a) Pick the best node on open b) Generate its successors c) For each success do:  If it has not been generated before, evaluate it add it to OPEN, and record its parent.  If it has been generated before, change the parent if this new path is better than the previous one.

A* ALGORITHM:The A* provides general guidelines with which to estimate goal distances for the search graphs. The A* algorithm generates all successor nodes and computes an estimate of the distance from the start node to the goal through each of the successors. It chooses the successor with the shortest estimated distances for further expansion. The successors or this node are then generated, their distances estimated and this process continues until a goal is found or the search ends in a failure. The form of heuristic function for A* is F*(n)-g*(n) +h*(n) Where g*(n) =h*(n) =estimates of the cost (or) distances from the start node to node n and the distances from node n a goal node Algorithm:1. Set SUCCESSOR to point back to BESTNODE.(Back links will help to recover the path). 2. Compute g(SUCCESSOR) = g( BESTNODE) cost of getting from BESTNODE to SUCCESSOR. 3. If SUCCESSOR is same as any node to OPEN, call that node OLD and add OLD to BESTNODE’S SUCCESSORS. Check g (OLD) AND g(SUCCESSOR).If g(SUCCESSOR) is cheaper then rest OLD’S parent link to point to BESTNODE. Update g (OLD) and f’ (OLD). 4. If SUCCESSOR was not on OPEN, see if it is on CLOSED. If so call the node CLOSED OLD, and better as earlier and set the parent link and g and f’ values approximately. 5. If SUCCESSOR was not already on earlier OPEN or CLOSED, then put it on OPEN and add it to the list of BESTNODE’S successors. Compute f’ (SUCCESSOR) = g (SUCCESSOR) +h’(SUCCESSOR) A.Rakesh Babu M.C.A., M.Tech Asst.Prof

25

Artificial Intelligence

PROBLEM REDUCTION: Problem reduction is a basic problem solving technique of AI. It involves reducing a problem to a set of easier sub problems whose solutions, if found, can be combined to form a solution, to the hard problem, the procedure is as follows. 1) If the given problem is a primitive sub problem return the solution to it. 2) Otherwise, try breaking the given problem into sets of simpler sub problems, and call the program recursively to try to solve the sub-problems. 3) If a set of sub problems is found such that all the sub problems. Can be solved, combine the sub problem solutions in an appropriate way to form the solution to the current problem. The given problem is reduced to a set of simpler sub problems, the solution of which will allow the original problem to be solved. This reduction applied recursively until permissive sub problems which are immediately solvable are reached. The resulting is called an AND/OR graph. AND node:All sub problems must be solved in order to solve the main problem. An arc is drawn across branches of an and node

OR node:Solution of any sub-problem will solve the main problem. A state space search graph consists entirely of OR nodes.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

26

Artificial Intelligence

AND / OR Graph Example: Go from JNTU, Hyderabad To JNU, New Delhi AND

Go to Hyderabad Airport

Fly to New Delhi

Go from New Delhi Airport to JNU

OR

Drive

Take a bus

Take a taxi Drive Take a subway

Call a taxi

Take a taxi

Get Money Steal a car Rent a car

Look UP number

Dial Phone

Ask for Taxi

Terminal nodes

Solution to an AND/OR Graph:1) A successful terminal node is a solved node 2) If a non terminal OR node has any solved successors, then it is a solved node. 3) If all of the successors of a non terminal AND node are solved, then it is a solved node. 4) The problem is solved if the start node is solved. 5) A solution graph is a sub graph of solved nodes that demonstrates that the start node is solved. Search of an AND/OR Graph:An AND|OR graph is searched recursively until the root node is solved, to solve a node, attempt to solve each successor of a non terminal node sequentially. i.

If any successor of an AND node fails, the AND node fails immediately.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

27

Artificial Intelligence

ii.

If any successor of an OR node succeeds, the OR node succeeds immediately. The search time may be improve by ordering consideration of the nodes:  To solve an AND node try first to solve those successors that are most likely to fail.  To solve an OR node try first to solve those successors that are most likely to succeed.

AO* ALGORITHM:I. II.

Let graph consists only one of the node representing the initial state compute h`(INIT) Until INIT is labeled solved or hi (INIT) and become greater than FUTILITY, repeat the following procedure. a. Trace the marked arcs from INIT and select an unbounded node NODE. b. Generate the successors of NODE if there are no successors then assign FUTILITY. As h` (NODE). This means that NODE is not solvable. If there are successors then for each one called successor, that is not also an ancestor of NODE do the following.  Add successor to graph G.  If successor is not a terminal node, mark it solved and assign zero to its h value.  Propagate the newly discovered information up the graph by doing the following. Let S be a set of nodes that have been marked SOLVED. Initialize S to NODE. Until S is empty repeat the following procedure. a) Select a node from S call if CURRENT and remove it from S. b) Compute h` of each of arcs emerging from CURRENT, assign minimum h` to CURRENT. c) Mark the minimum cost path a S the best out of CURRENT.

CONSTRAINT SATISFACTION:Many problems in AI can be considered as problems of constraint satisfaction, in which the goal satisfies a given set of constraint satisfaction problems can be solved by using any of the search strategies. Algorithm:1. Propagate available constraints. To do this, first see OPEN to the set of all objects that must have values assigned to then in a complete solution. Then do until an inconsistency is detected or until OPEN is empty.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

28

Artificial Intelligence

a) Select an object OB from OPEN. String then as possible the set of constraints that apply to OB. b) If this set is different from the set that was assigned. The last time OB was examined or if this is the first time OB has been examined, then adds to OPEN all objects that share any constraints with OB. c) Remove OB from OPEN. 2) If the union of the constraints discovered above defines a solution, they quit and report the solution. 3) If the union of the constraints discovered above defines a contradiction, they return failure. 4) If the union of the above occurs, there it is necessary to make a guess at something in order to proceed. To do this, loop until a solution is found or all possible solutions have been eliminated. a. Select an object whose value is not yet determined and select a way of strengthening the constraints on that object. b. Recursively invoke constraints satisfaction with the current set of constraints augmented by the strengthening constraint just selected. Consider The Crypt Arithmetic Problem:

Problem: SEND +MORE MONEY

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

29

Artificial Intelligence

Constraints: 

No two letters have the same value.



The sum of the digits must be as shown in the problem.



Any of search technique may be used.



Only single digit number can assign to a letter (0-9).

Initial state: M =?

O =?

R=?

E=?

S=?

N=?

D=?

Y=?

C1=? C2=?

C1, C2, C3 stands for the carry variables respectively. Goal State: The digits to the letters must be assigned in such a manner so that the sum is satisfied. Solution Process: 

Initially, rules for propagating constraints generate the following additional constraints.



M=1, since two single digit numbers plus a carry cannot total more than 19.



S=8 or 9.Since S+M+C3>9 and M=1, S+1+C3 >9, S+C3>8 and C3 is at most 1.



O=0, since S+M (1) +C3 (roman(x) Ruler (Caesar) x: Roman(x) ->loyal to(x, Caesar) V hate(x, Caesar) x: y: loyal to(x, y) x: y: Person(x) ^ruler(y) ^ try assassinate(x, y) Loyal to(x, y) Tryasssainate (Marcus, Caesar)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

45

Artificial Intelligence

Now suppose that we want to use these statements to answer the question. Was Marcus loyal to Caesar? Now let’s try to produce a formal proof, reasoning backward from the desired goal.

loyalto (Marcus, Caesar) ^ (7) Person (Marcus) ^ ruler (Caesar) ^ tryassasinate (Marcus, Caeser) ^ (4) Person (Marcus) Try assassinating (Marcus, Caesar) ^ (8) Person (Marcus)

REPRESENTING INSTANCE AND ISA RELATIONSHIP The specific attributes instance and is a plays an important role in a particularly useful form of reasoning, property inheritance. The predicate instance is a binary one, whose first argument is an object and whose second argument is a class to which the object belongs. But these representations don’t use an explicit is a predicate. The three ways of representing class membership is as follows. 1. Man (Marcus) 2. Pompeian (Marcus) 3. x: Pompeian(x) ->roman(x) 4. Ruler (Caesar) 5. x: Roman(x) ->loyal to(x, Caesar) V hate(x, Caesar) 1. Instance (Marcus, man) 2. Instance (Marcus, Pompeian) 3. x: instance(x, Pompeian) instance(x, Roman). 4. Instance (Caesar, ruler) 5. x: instance(x, Roman) loyalto(x, Caeser)V hate(x, Caeser)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

46

Artificial Intelligence

1. 2. 3. 4. 5.

Instance (Marcus, Man) Instance (Marcus, Pompeian) Isa (Pompeian, Roman) Instance (Caesar, ruler) x: instance(x, roman)loyalto(x, Caesar) V hate(x, Caesar).

The class and super class membership are important facts that need to be represented, those membership need not to be represented with predicates instance and Isa.

COMPUTABLE FUNCTIONS AND PREDICATES: In predicate calculus it is often useful to have computable a functions and computable predicates for this we want to express simple facts. Such as the following greater than and less than relationships: gt(1,0)

lt(0,1)

gt(2,1)

lt(1,2)

gt(3,2)

lt(2,3)

|

|

|

|

.

.

For example the simple fact (2+3)>1 might be represented as gt(2+3,1).to calculate the truth of gt(2+3,1) the value of the plus function is evaluated first and then the arguments 2+3(=5) and 1 are sent to the computable predicate gt.The use of computable functions and predicates is illustrated below. Consider the following set of facts and their representations. 1. Marcus was a man Man (Marcus) 2. Marcus was a Pompeian Pompeian (Marcus) 3. Marcus was born in 40 A.D Born (Marcus, 40 A.D) 4. All men are mortal x: Men(x) mortal(x)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

47

Artificial Intelligence

5. All Pompeian’s died when volcano erupted in 79 A.D Erupted (volcano, 79) ^ x :{ Pompeian(x) died(x, 79)} 6. No mortal lives longer than 150 years x: t1: t2: mortal(x) ^ born(x, t1) ^ gt (t2-t1, 150) ->dead(x, t2) 7. It is now 1991 Now=1991 8. Alive means not dead x: t: alive (x, t) ->&dead(x, t) ^ [

dead(x, t) ->alive(x,t)]

9. If someone dies then he is died at all later times. x: t1: t2:died(x,t1) ^gt(t2,t1)->dead(x,t2) The above predicates can be represented as set of facts as follows. 1. Man (Marcus) 2. Pompeian (Marcus) 3. Born (marcus,40) 4.

x: men(x)mortal(x)

5.

x: Pompeian(x)died(x,79)

6. Erupted (volcano, 79) 7.

x:

t1:

t2: mortal(x)^born(x, t1)^ gt(t2-t1,150)died(x,t2)

8. Now=1991 9.

x:

t:[alive(x, t)

10.

x:

t1:

dead(x,t)alive(x, t)]

t2:died(x,t1)^ gt(t2,t1)dead(x,t2)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

dead(x, t)]^[

48

Artificial Intelligence

Now let’s attempt to answer the question “Is Marcus alive?” By proving alive(Marcus, now) alive(Marcus, now) (9) Dead (Marcus, now) (10) Died (Marcus, t1) ^ (gt (now, t1) (5) Pompeian (Marcus) ^ gt(now,79) (2) gt (now, 79) (8) gt (1991, 79) (Compute gt) Nil From looking at the proof we have just shown, two things should be clear. -

Even a sample conclusion requires many steps to prove A variety of processes such as matching, substitution and application modus pones are involved in the production of proof.

(Modus ponenes is an important inference rule. it is the operation that produces the wff w2 from wff of the form w1 and w1->w2) The term nil at the end of the proof indicates that the list of conditions remaining to be proved to be approved is empty and so the proof has succeeded.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

49

Artificial Intelligence

RESOLUTION: Resolution is a procedure to prove a statement. It specifies the proof procedure by first converting the statements into a clause form (convenient standard form).Further it produces proofs by “refutation” i.e., it attempts to show that the negation of the statement produces a contradiction with the known statements.

Conversion to clause form: Resolution can be applied to certain class of wff’s called “clauses.” a clause is defined as a wff’s consisting of a disjunction of literals. The resolution process when it is applicable is applied to as pair of parent clauses to produce a derived clause. Suppose that there are two parent clauses in the system. Winter V summer ~Winter V cold In these two clauses either winter or ~winter is going to be true at any point. If winter is true then cold must be true to guarantee the truth of the second clause. If ~winter is true, then the summer must be true to guarantee the truth of the first clause. Thus from these two clauses we can deduce the resolve. Summer V cold Resolution procedure operates by taking two clauses that each contains the same literal. The literal must occur in positive from in one clause and in negative form in the order. The resolving is obtained by combining all of the literals of the two parent clauses except the ones that cancel. If the clause that is produced is An empty clause, then a contradiction has been found. Algorithm: 1. Eliminate , using the fact that ab is equivalent to

a v b. Perform this

transformation on the well formed formula, then the formula will becomes as, x:

[Roman(x) ^ know(x, Marcus)] v [ hate(x, Caesar) v ( y:

( y: hate(y, z)] v think crazy (x, y))]

2. Reduce the scope of search of each

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

(negation) to a single term, using facts,

50

Artificial Intelligence

(

p) = p

(a ^ b) =

av

b

(a v b) =

a^

b

x: a(x) = x: a(x) =

x: x:

a(x) a(x)

Perform these transformations on the well formed formula, then it becomes, x: [

roman(x) v

know(x ,Marcus)] v

[hate (x, Caesar) v ( y: z:

hate(y, z) v thinkcrazy(x, y))]

3. Standardize variable so that each quantifier binds a unique variable. for example, the formula x: P (a) v

a: Q (a) will be converted to

x: p (a) v b: Q(b) This step can be used in the next step. 4. Move all quantifiers to the left of the formula without changing their relative order. performing this operation on the formula of step 2, gives x:

y:

z: [

Roman(x) v

know(x, Marcus)] v

[hate (x, Caesar)v(

hate (y ,z)v think crazy(x, y))]

5. Eliminate existential qualifiers. for example the formula y: President(y) Can be transformed into the formula, President (S1) Where S1 is a function with no arguments that somehow produces a value that satisfies President. 6. Drop the prefix .the formula produced in step 4 will become as, [

Roman(x) v

know(x, Marcus)] v

[ hate(x, Caesar) v ( A.Rakesh Babu M.C.A., M.Tech Asst.Prof

hate(y,z) v thinkcrazy(x, y))] 51

Artificial Intelligence

7. Convert the matrix into a conjunction of disjoints the formula produced in step(6) will become as (here we can remove the brackets) Roman(x) v

know (x, Marcus) v

hate(x, Caesar) v

hate(y, z)v thinkcrazy(x, y).

( we applied [a v (b v c) = (a v b) v c] (associative property)) It is also frequently necessary to exploit the distributive property i.e. (a ^ b) v c = (a v c) ^ (b v c) [winter v (summer ^ wearing sandals) ] ^ [wearing boots v (summer ^ wearing sandals)] 8. Create a separate clause corresponding to each conjunct. 9. Standardize apart the variables in the set of clauses which are generated in step (8).

Resolution in proposition logic: In proposition logic, the procedure to produce a proof by resolution of preposition P with respect to a set of axioms f is the following: 1. Convert all the proposition of f to clause form 2. Negate p and convert the result to clause form add it to the set of clauses obtained in step1. 3. Repeat until either a contradiction is found or no progress can be made: a. Select two clauses. Call these the parent clauses, b. Resolve them together. The resulting clause, called the resolving, will be the disjunction of all the literals of both of the parent clauses. c. If the resolving is the empty clause, then a contradiction has been found. If it is not, then add it to the set of clauses available to the procedure.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

52

Artificial Intelligence

Example: Given axioms

Converted to clause form

P

P

(P ^ Q)->R

Pv

(S^ T)->Q

SVQ

(3)

TVQ

(4)

T

(1) Q^R

T

(2)

(5)

Fig: A few facts in proposition logic The following figure shows the generation of the sequence of resolvents.

Pv

qvR

R

PV Q

P

TvQ

Q

T

T

{

}

Fig: Resolution in propositional logic A.Rakesh Babu M.C.A., M.Tech Asst.Prof

53

Artificial Intelligence

UNIFIACTION ALGORITHM: In propositional logic, it is easy to determine that two literals cannot both be true at the same time. Simply look for L and L. In predicate logic, this matching process is more complicated since the arguments of the predicates must be considered. For example, man (john) and man (john) is a contradiction, while man (john) and man (spot) is not. To determine these contradictions, we need a matching procedure that compares two literals and discovers whether there exists a set of substitutions that makes them identical. There is a straight forward recursive procedure that does this matching. It is called unification algorithm. To unify two literals, we first check if their initial predicate symbols are the same. If same, we proceed. Otherwise there is no way they can be unified. For example two literals tryassasinate (Marcus, Caesar) hate (Marcus, Caesar) Cannot be unified. If the predicate symbols are match, then we check the arguments, one pair at a time. The matching rules are: 1. Different constants, functions or predicates cannot match, where as identical ones can. 2. A variable can match another variable, any constants or a function or predicate expression, subject to the condition that function must not contain any instance of variable being matched. 3. The substitution must be consisting. substitute y for x now and then z for x later is inconsistent(a substitution y for x written as y/x) The unification procedure UNIFY (L1, L2), which returns a list representing a composition of the substitutions that were performed that a match was found any substitutions .if the list unification procedure failed. Algorithm: UNIFY (L1, L2) 1. If L1 or L2 are both variables or constants, then: a) If L1 and L2 are identical, then return NIL

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

54

Artificial Intelligence

b) Else if L1 is a variable, then if L1 occurs in L2 then return {FAIL}, else return (L2/L1). c) Else if L2 is a variable, then if L2 occurs in L1 then return {FAIL}, else return (L1/L2). d) Else return {FAIL] 2. If the initial predicate symbols in L1 and L2 are not identical, then return {FAIL}. 3. If L1 and L2 have a different number of arguments, then return {FAIL}. 4. Set SUBST to NIL. (At the end of this procedure, SUBST will contain all the substitutions used to Unify L1 and L2. 5. For i 1 to number of arguments in L1: a) Call Unify with the i result in S.

th

argument of L1 and the i

th

argument of L2, putting

b) If S contains FAIL then return {FAIL}. c) If S is not equal to NIL then: 1. Apply s to the reminder of both L1 & L2. 2. SUBST:=APPEND(S,SUBST) 6. Return SUBST.

Resolution in Predicate Logic:

Two literals are contradictory if one can be unified with the negation of the other. for example man(x) and &man(spot) are contradictory, since man(x) and man(spot) can be unified .in predicate logic unification algorithm is used to locate pairs of literals that cancel out. if is important that of two instances of the same variable occur, they must be given identical substitutions. The resolution algorithm for predicate logic as follows. Let us assume a set of give statements F and a statement to be proved P.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

55

Artificial Intelligence

Algorithm: 1. Convert all the statements to F to clause form 2. Negate P and convert the result to clause form add it to the set of clauses obtained in step1. 3. Repeat until either a contradiction is found, no progress can be made. a) Select two clauses. Call these two parent clauses. b) Remove them together. The resulting clause, called the resolvent, will be the disjunction of all the literals of both of the parent clauses. If there is a pair of literals T1 and T2 such that one parent clauses contains T1 and other contains T2 and if T1 and T2 are unifable, then neither T1 nor T2 complementary literals. c) If the resolving is the empty clause, then a contradiction has been found. If it is not, then add it to the set of clauses available to the procedure. Using resolution to produce proof is illustrated in the following clause forms: 1. Man (Marcus) 2. Pompeian (Marcus) 3.

Pompeian(x1) ->roman(x1)

4. Ruler (Caesar) 5.

Roman(x2) V loyal to(x2, Caesar) hate(x2, Caesar)

6. loyalto(x3, f1(x3)) 7.

Man(x4) v

ruler (y1) v

try assassinate(x4, y1) V loyalto (x4, y1).

8. tryasssainate (Marcus, Caesar)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

56

Artificial Intelligence

Prove: hate (Marcus, Caesar)

hate (Marcus, Caesar)

5

Marcus/x2 3

Roman (Marcus) v loyalto (Marcus, Caesar)

Marcus/x1 Pompeian (Marcus) V loyalto (Marcus, Caesar)

Loyal to (Marcus, Caesar)

2

7 Marcus/x4, Caeser/y1

1

man (Marcus) V (ruler (Caesar) V tryassasiante (Marcus, Caesar)

ruler (Caesar) V

tryassasinate (Marcus, Caesar)

8

tryassasinate(marcus,Caeser)

{

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

4

}

57

Artificial Intelligence

Natural Deduction The disadvantage of Predicate logic is i.e., it is not having any inference programs. So we have to make use of a resolution outcome, but the resolution is in clause form. By using clause form, the original meaning be destroyed or changed. Ex: If we consider the statement ab means that b is depending only on existing of a. i.e., b is dependent on a. But as we convert the system into clause form we can has a v b. The symbol “v” (OR) is we have to prove either a as true. i.e., the statement is true. The whole statement is considered as b is not depends on a. So, this statement is reverse of the first statement (a b).Suppose we represent the statement into natural deduction the meaning of the sentence may not be changed.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

58

Artificial Intelligence

CHAPTER - 6 REPRESENTING KNOWLEDGE USING RULES We have to represent the knowledge in two ways. They are 1. Declarative knowledge 2. Procedural knowledge In the declarative knowledge, how to make use of knowledge is not to specify. In the procedural knowledge, how to make use of knowledge can be embedded in the representation itself. Procedural knowledge is PROLOG (programming logic) and it follows backward chaining method. Ex:

consider the following statements. 1. Man (Caesar) 2. Man (Marcus) 3. person (Cleopatra) 4.

x: man(x)  person(x)

The above statements converted into PROLOG programs are: 1. Man (Caesar) 2. Man (Marcus) 3. Person (Cleopatra) 4.

x: man(x)  person(x)

A predicate logic statement is always explicitly quantified and PROLOG programs are always implicitly quantified.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

59

Artificial Intelligence

Convert the following statements (Predicate logic) into PROLOG 1.

x: pet(x) ^ small(x) apartment(x)

2.

x: cat(x) ^ dog(x)  pet(x)

3.

x: poodle(x)  dog(x) ^ small(x)

4. Poodle (fluffy) The predicate logic forms can be converted into PROLOG programs as follows 1. Apartment (x): - pet (x), small (x) 2. a) pet(x):- cat(x) b)Pet(x):- dog(x) 3. a)dog(x) :- poodle(x) b)Small(x):- poodle(x) 4. Poodle (fluffy) The following constrains can be used to convert the predicate logic statements into PROLOG programs (i) (ii) (iii) (iv) (v)

ab = b: -a Implication before ^ => put, (comma) Implication after ^ => write as 2 stmts Implication before v => write as 2 stmts Implication after v => put , (comma)

Convert the following predicate logical stmts into PROLOG programs y : Cat(x) ^ Fish(y)  Likes(x, y)

1.

x:

2.

x: Calico(x)  Cat(x)

3.

x: Tuna (x)  Fish(x)

4. Tuna (Charley) 5. Tuna (Herb) 6. Calico (Pussy)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

60

Artificial Intelligence

PROLOG programs: 1. 2. 3. 4. 5. 6.

Likes (x, y): - cat (x), fish (y) Cat(x) :- calico (x) Fish (x): - tuna (x) Tuna (charley) Tuna (herb) Calico (pussy)

Using backward chaining find “what does pussy likes to eat?” for this consider likesto(x, y) Likesto (pussy, x)

(1)

Cat(x), fish(y)

(2)

Cat (pussy),

(6)

fish(x)

Calico (pussy), fish(x)

Fish(x)

(3)

Tuna(x)

{ --Pussy likes to charley A.Rakesh Babu M.C.A., M.Tech Asst.Prof

(4)

}

x= charley . 61

Artificial Intelligence

Consider the following stmts 1. 2. 3. 4. 5. 6.

John likes all kinds of food Apples are food Chicken is a food Anything anyone eats and is not killed by his food Bill eats peanuts and is still alive Sue eats everything bill eats

The stmt’s in predicate logic are as follows: 1. x: food (x)  likes (John, x) 2. food (Apples) 3. foods (Chicken) 4. x : y : eats (x, y) ^ killed (x, y) food(x) 5. a) eats (Bill, Peanuts) b) killed (bill, peanuts) 6. x : eats (Bill, x)  eats (Sue, x) PROLOG programs: 1. 2. 3. 4. 5.

likes (John, x) :- food(x) food (Apples) food (Chicken) food(x) :- eats (x, y), killed(x ,y) a) eats (Bill, Peanuts) b) killed (Bill, peanuts) 6. eats(Sue, x) :- eats (Bill, x)

Horn clause The logical assertion in the PROLOG language is the set of horn clauses. A positive literal is called horn. a v b,

a v b, a v

b, ab

=> horn clauses.

a v b => not horn clause In the PROLOG statements, there is no logical assertion. The only assertion is horn clause. In this stmts, the variables can be referred in capital letters and the constants are denoted to small letters. 1. 2.

x : pet (x) ^ small (x) apartment(x) x : cat(x) ^ dog(x) pet(x)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

62

Artificial Intelligence

x : poodle(x)  dog(x) ^ small(x) poodle (fluffy)

3. 4.

Find the variable x. Convert the above statements into horn clause Apartment(x)

2(a)

pet(x), small(x)

3(a)

(4)

dog(x),

cat(x)

Poodle(x)

{

(1)

}

x=fluffy

small(x)

it is dead end

3(b)

poodle(x)

x=fluffy

(4)

{

}

In the above example we get 2 alternatives pelf(x), small(x). First we start with the first sub goal pet(x). It again contains 2 sub goals dog(x), cat(x). If we go on proceeding with cat(x) we get a dead end. PROLOG programming starts with root node. It finds a fact (or) the left hands of the rules to match with the root node, if a rule is found the R.H.S will be the resolvent. In the above example three are 2 sub goals pet(x) and small(x) in the resolvent. If both of the sub goals are true then a value for a variable ‘y’ can be found. Consider a sub goal pet(y) with has 2 alternatives with Pet(x):- cat(x) and Pet(x); - dog(x)

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

63

Artificial Intelligence

A PROLOG tries with the first alternative until a dead end is reached or a solution is found. The first alternative leads to a dead end in the above example and ‘y’ is bounded to a value fluffy when second alternative is explores.

REASONING: The aim of search procedure is to discover a path through a problem space from an initial configuration to a goal state. There are actually 2 directions in which a search colud proceed. a) Forward Reasoning b) Backward Reasoning a). Forward Reasoning: When we have set of input to prove current situation. Those are applied on the initial state. The forward rules encode the knowledge when certain input conditions are true. Ex. Water jug problem b). Backward reasoning: These rules are used to sub goals-backward rules are the rules which encode the knowledge when sub goals are true. Eg. Whether Marcus is alive or not ? The following factors that influence the question of whether it is better to reason forward or backward. i) Are there more possible start states or goal state? We prefer to move from the smaller set of states to the largest set of states. ii) In which directions is the branching factor greater? (Branch Factor: - the average no of nodes that can be reached directly from a single node.) We refer to proceed in the direction with the lower process to a user. iii) Will be program be asked to justify its reasoning process to a user? It is important proceed in the direction that corresponds more closely with the way the user will think. iv) What kind of event is going to trigger a problem solving proceeds? The forward reason makes sense if it is a query to which a response is desired backward reasoning is more natural. A.Rakesh Babu M.C.A., M.Tech Asst.Prof

64

Artificial Intelligence

Backward chaining rule systems : They are good for goal directed problem solving. For example a query system would probably use backward chaining to reason about answer user questions. Examples of these systems are PROLOG and MYCIN. Forward-chaining rule systems: Forward chaining rule system left sides of rules are matched against the state description. Rules that match dump their right hand side assertion into the state, and process repeats. Matching is typically more complex chaining system that backward once .

Matching: Matching is a process of comparing two or more structures to discover their difference or similarities. Matching is used to the best of a no of alternatives or retrieves items from a database or knowledgebase. Different matching processes are,    

Indexing Matching with variables Complex and approximate matching Conflict resolution

Indexing: In indexing the correct state is used as an index into the rules in order to select the matching once. For example in chess, we assign a no to each board position. Then we use a hosting function to treat the no as an index into the rules. Matching with variables: In this case we will match many rules against many elements in the state description simultaneously. One efficient algorithm RETE, which gains efficiency from three major sources. I.

The temporal nature of data:

Whenever we apply a rule on the current state. Some properties will be added and some other properties are deleted and some times the rule will not be applicable. If no rule will not be applicable to the problem, the RETE process will tell which rule applicable to the pre-state is not applicable to the current state.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

65

Artificial Intelligence II.

Structural similarities in rules:

In the similarities of the rules, data can be considered as i) ii)

Tiger(x)  mammal(x) ^ stripes(x) ^ carnivorous(x) Jaguar(x) mammal(x) ^ sports (x) ^ carnivorous(x)

Eg. For this consider Frame-I

frameII

Similarities

similarities

Mammal(x)

stripes(x)

Carnivorous(x)

sports(x)

In RETE process , first we have to verify the dissimilarities rules and after that we verify the similar rules and also we have to identify which rule have less no of sub goals and which rule has more no of sub goals. III.

Persistence in binding up of variables:-

There may be variable binding conflicts that prevent the rule from firing. For example, consider the following facts. Son (john, David) Son (bill, Ellen)

and we can compare to son(x,y) and son(y,z)

The individual preconditions of the rule is x:

y : son(x, y) ^ son(y, z)grandparent(y, z).

Where x=John and y=David. For this first time, x, y has initial values after the completion of first predicate here x,y are binded variables. For the second time, if y=bill which is not accepted because ‘y’ has already a value is given. So, we can not give another value ‘y’. Therefore, ‘y’ is a binding up variable. The RETE takes the binding up of variables to the problem solving.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

66

Artificial Intelligence

Complex and Approximate Matching : An approximate matching is one which used, when the pre conditions approximately match the current situation. One of the complex problem, we can take as a speech understanding. It understand the word and proceedings the matching. If that time it takes appropriate words. The conversion between ELIZA, an A.I problem and the user. Here ELIZA will try to match the left side of the rule against the sentence and use the correct right side rule to generate a response. Let us considering the following ELIZA rules. (x me y)(X you y) (I remember x)(Why do remember x just now?) (My family –member is y)(Who else is your family is y?) Suppose the use say “I remember Mary”. How ELIZA will try to match the above response to the left hand side of the given rules. It finds that it matches to the first rule and now it take the right hand side ask, “Why do remember Mary just now?” This is the why how the conversion proceeds taking into consideration the approximate matching.

Conflict Resolution: The conflict resolution is a strategy in which we incorporate the decision making into the matching process. We have three basic approaches. a) Preference based on rules: Here we consider the rule in the order they are given or we given some priority to special case rules. b) Performance based on object: Here we use key words to match into the rules. Consider the example of ELIZA. c) Performance based on states: In this case we consider all rules that are waiting, which gives some states. Here a heuristic function we can decide which state is the best.

Control Knowledge: Knowledge about which paths are most likely to lead quickly to a goal state is often called, search control knowledge. It can take many forms.    

knowledge about which states are more preferable to others Knowledge about which rule to apply in given situation. Knowledge about the order in which to achieve sub goals Knowledge about useful sequence of0 rules to apply

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

67

Artificial Intelligence

Control knowledge is also called as Meta knowledge that is knowledge about knowledge. Two systems which represent control knowledge with rules are SOAR and PRODIGY. SOAR CONSIST OF, a) Long-term memory: It contains all the set of productions or rules. b) Short-term memory: It is also called as working memory. In this the facts are deducted by rules. c) All problems solving activity takes place as a state space traversal i.e. which rule to be applied. d) It keeps track of all the intermediate and the final result.

A.Rakesh Babu M.C.A., M.Tech Asst.Prof

68

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF