Forward Chaining

  • View
    62

  • Download
    0

Embed Size (px)

DESCRIPTION

Forward Chaining. - PowerPoint PPT Presentation

Text of Forward Chaining

Forward Chaining

Forward ChainingNow we are ready to design an actual expert system tool. Remember, a tool is used to help make a task easier. The tool we will create is used for solving a particular type of problem. There are many ways to solve a problem; some methods are better than other methods for solving certain types of problems. The tool we need must be applicable to the kinds of problems found in the expert domain being considered, or it won't be much help in solving problems within that domain. A saw can't help you fix a car, and a wrench can't help you cut down a tree. Let's consider this problem: What would you do if you were driving and the temperature in your engine started rising? Of course, you'd get nervous. Most of us have encountered this problem when stuck in heavy traffic on a hot day. Let's restate this problem in a more general way. We have a condition (overheating) and we want to know what the result or consequence of this condition will be (Will the car stall?). Stop a minute and consider what happened. We first stated that a condition occurred, which was the overheating of the engine. Then we thought about all the rules we knew that were related to that condition. Some of these rules are

Rule 1 IF the car overheats, THEN the car will stall. Rule 2 IF the car stalls, THEN it will cost me money, AND I will be late getting home.

How do you arrive at the conclusion that this situation will cost money and cause you to be late? Keep in mind, as we describe the course of events, these two words: forward and chaining. The condition that triggered a chain of events is the car overheating. This caused the first part of rule 1, the condition, or IF part, to be called upon. Rule 1 being true caused the THEN part of the rule to be invoked, which is that the car will stall. The chaining continues: The IF part of rule 2 is triggered by the car actually stalling or because rule 1 is invoked. Your conclusion that a stall will cost money and make you late getting home can result from the stall itself or the observation of an overheating engine.

Why do we use the word "forward" in describing this problem? When a condition such as overheating takes place, something is affected by it (the THEN part, or conclusion). Since the condition comes before the conclusion, and we begin with conditions, we are going forward. Thereby we use the term forward chaining. Now let's define what we mean by a forward chaining tool. The tool helps us find answers to questions by applying forward chaining principles to a knowledge base. In other words, the tool will ask you for conditions-engine overheating-and the name of the appropriate knowledge base-automobile mechanical problems-. Once you have supplied these answers to the tool's questions, the tool will refer to the information stored in the knowledge base and apply the forward chaining techniques we've just discussed. It will provide you with the conclusions or results you need, such as "the car will stall" or "a stall will cost you money, and you will be late getting home." In order to explain the design of the tool in the simplest way, we will first lead you through the process you might use to solve a problem if no computer was available. This part of making the tool is known as developing an "algorithm," which is a logical step-by-step organization of the problem and all its aspects. Since we know that computers do the same things people do, only faster, the second step is to transform this organized scheme of the problem into the tool itself-a computer program. This chapter will explain both steps clearly. The C version of the expert tool is simple and is written in fundamental C so that it can be entered and run on almost any personal computer, including yours. You will be able to construct a knowledge base that covers a field of interest to you, and you can try it out by yourself. The design is also open-ended, so you can expand it in the future to make the tool more powerful for solving even more difficult and complex problems. Sound simple? It is. In this chapter we'll diagram a problem carefully and then make an expert system tool out of it. If you follow our explanations carefully and then parallel them with a domain of interest to you, you will be on your way to being a knowledge engineer.Example Using Forward ChainingHere is a simple set of rules that might be part of a stock market expert system. 10 IF INTEREST RATES = FALL THEN STOCK MARKET = RISE 20 IF INTEREST RATES = RISE THEN STOCK MARKET = FALL 30 IF DOLLAR EXCHANGE RATE = FALL THEN INTEREST RATES = RISE 40 IF DOLLAR EXCHANGE RATE = RISE THEN INTEREST RATES = FALL Using these rules, we ambitiously set up a stock market consulting company. Our first customer comes to us and tells us that the dollar exchange rate is declining (falling) against the money values of the major industrial nations. What should he do in the stock market? Obviously, the goal is to do well in the stock market, but whether or not our customer will make a profit will be decided by as yet undetermined conditions. Remember that forward chaining systems make predictions by considering conditions defined in clauses of the IF part of the rule and come to conclusions that are defined in the THEN part. In this case, the condition is DOLLAR EXCHANGE RATE = FALL Scanning our rules, we find that rule 30 contained DOLLAR EXCHANGE RATE in its IF clause. That is 30 IF DOLLAR EXCHANGE RATE = FALL THEN INTEREST RATES = RISE From it we can conclude that interest rates will rise. Scanning the rest of the IF-THEN rules for DOLLAR EXCHANGE RATE, we find it again in rule 40. But the IF clause 40 IF DOLLAR EXCHANGE RATE = RISE does not match the known condition of falling exchange rates. So rule 40 is not true. We are not yet finished since rule 30 introduced a new condition: INTEREST RATES = RISE We must now scan the rules to see if this condition leads to other conclusions, and we see that rule 10 10 IF INTEREST RATES = FALL THEN STOCK MARKET = RISE is not true but that rule 20 is: 20 IF INTEREST RATES = RISE THEN STOCK MARKET = FALL The chain continues by the introduction of a new condition: STOCK MARKET = FALL Therefore, we are still not finished. We must check all the rules for this new condition. Scanning all the IF clauses, we see that none contains STOCK MARKET. We can go no further, and therefore the session is over. We hand our customer a report as follows: When the dollar exchange rate is falling, interest rates will rise and the stock market will fall. The report, in reality, may need more complex rules, but the forward chaining system, like any system, acts only upon what is in the knowledge base.

From this example, we can describe the workings of a typical forward chaining system: 1. The system is presented with one or more conditions. 2. For each condition the system searches the rules in the knowledge base for those rules that correspond to the condition in the IF part. 3. Each rule can in turn generate new conditions from the conclusions of the invoked THEN part. These new conditions are added to the ones already existing. 4. Any conditions that have been added to the system are processed. If there are any such conditions, the system goes back to step 2 and searches the rules in the knowledge base again. If there are no more new conditions, this session ends. The Knowledge Base In this example you, as the expert, enter rules directly into the knowledge base and use these rules to direct your stock market decisions. But first you must create a variable name table, as shown in Figure 5-1, to make it easier to deal with long, clumsy variable names and to help you write the rules. Using the variable name table you can write the following stock market rules:

10 IF INTEREST = FALL THEN STOCK = RISE 20 IF INTEREST =RISE THEN STOCK =FALL 30 IF DOLLAR = FALL THEN INTEREST = RISE 40 IF DOLLAR = RISE THEN INTEREST = FALL 50 IF FEDINT = FALL AND FEDMON : ADD THEN INTEREST = FALL

A word of caution: These rules are not a complete list of rules needed to do a proper stock market analysis but merely show the general principles involved. We must always remember that an expert system is only as good or as bad as the experts who formulate the rules. Keeping that in mind, let's continue to examine how the system uses the rules to arrive at answers.

Figure 5-1 Variable name table.

Variable nameMeaning

INTERESTInterest rate direction

DOLLARDollar exchange rate

FEDINTFederal reserve interest rate goals

FEDMONFederal reserve money circulation goals (i.e., add or remove reserves from the banking system)

STOCKStock market directionFigure 5-2 The knowledge base of the stock market expert system and its related data structure.

10 IF INTEREST = FALL THEN STOCK = RISE 20 IF INTEREST =RISE THEN STOCK =FALL 30 IF DOLLAR = FALL THEN INTEREST = RISE 40 IF DOLLAR = RISE THEN INTEREST = FALL 50 IF FEDINT = FALL AND FEDMON : ADD THEN INTEREST = FALL

Knowledge base INTEREST INTEREST DOLLAR3 FEDINT4 FEDMON5 INTEREST67 Variable list Clause variable pointer89 DOLLAR10111213 DOLLAR14151617 FEDINTFEDMON

Clause variable list Conclusion Variable queue

Processing the Knowledge Base Now that we have established the knowledge base using the variable name table, we are ready to begin processing that information using forward chaining principles. Our expert technique requires the construction of a number of useful tables that will aid in answering Questions and making decisions about the problem we are trying to solve. These tables, or data structures, therefore serve