Lesson 2: Adding Rules and Backward Chaining

The system built in Lesson 1 worked, but (to say the least) was limited in its ability to solve problems. For example, suppose the problem is not that the bulb is burned out, but the circuit breaker tripped, or there was a general power failure. If the power failed, this system would go around changing light bulbs both unproductive and difficult to do in the dark. So lets try to improve the system. Currently, you have one rule: IF A light suddenly goes out THEN Change the light bulb First you want to expand this rule to: IF A light suddenly goes out and Other lights in the room are still on

THEN Change the light bulb

1

First you need to go back to the system built in Lesson 1. This should have been named BULB and built exactly as described in 1.
If you did not save the system or you experimented while we were building the system (Who ME???) copy the files BULB.RUL and BULB.TXT from the TUTORIAL\BACKUP directory to your working directory. (DO NOT directly work on the copies in the TUTORIAL\BACKUP directory since these are the starting points for each lesson)

Start the EXSYS Professional Editor and under the File menu select Open and open the file BULB.RUL.

Getting Started with EXSYS® Professional

19

b.Lesson 2: Adding Rules and Backward Chaining 2 3 You should see the title screen for the system. Double clicking on the rule number. Under the Rule menu select Edit Rule. Clicking on the number to select it and clicking on OK. 20 Getting Started with EXSYS® Professional . 4 Select the rule to edit by either: a. First you will edit the rule in the system to add the condition that other lights are still on. This brings up the rule editing window with Rule 1 displayed.

6 Now. You want the question for "Other lights" to be asked only after the user has indicated that a light has gone out. Getting Started with EXSYS® Professional 21 . EXSYS tests the conditions of a rule in ord e r.) The IF Part radio button should be already selected (if it is not. it may be due to this type of error. If you put the "Other lights in the room are still on" condition first. it would be asked first and would not make sense. (If a system you develop asks questions in the wrong order.Lesson 2: Adding Rules and Backward Chaining 5 Add a second IF condition "Other lights in the room are still on". The qualifier dialog window will be displayed. This should be added AFTER the condition "A light suddenly goes out" . add a new qualifier. select it) and click on the Qualifier button. Click the New Qual button.

The text of the value will move down to the lower list box and the Value edit box will become blank. The dialog should now look like the the window to the left. This returns to the list of qualifiers.Lesson 2: Adding Rules and Backward Chaining 7 In the new qualifier dialog window. Now enter the text: also went out 4 in the Value edit box and again click the Add button. Click the Add button. Then enter the text: are still on in the edit box labeled Value. 22 Getting Started with EXSYS® Professional . enter the text: Other lights in the room 1 2 3 in the edit box labeled Qualifier. Click the OK button.

so click Cancel to return to the rule. Click on the New Qual button and enter a qualifier: All of the lights in the house with values went out and did not ALL go out The dialog should look like the the window to the left.Lesson 2: Adding Rules and Backward Chaining 9 In the rules you will add. Getting Started with EXSYS® Professional 23 . This is a convenient place to add that qualifier for future use. you will also need a qualifier about whether all of the lights in the house went out. Click OK to return to the qualifier list. 10 At this point you may have forgotten exactly what you were trying to add to the rule.

What you want to do was add "Other lights in the room are still on" to the IF part. Click on "are still on" to highlight it. The values associated with that qualifier will be displayed in the lower list box. 24 Getting Started with EXSYS® Professional . 12 13 14 Click on "Other lights in the room" to highlight it.Lesson 2: Adding Rules and Backward Chaining 11 Rule 1 is displayed. Since we now have the qualifiers defined you can rapidly do this. Click the Qualifier button.

The change you just made restricted the action of the first rule. but now you need to add rules to cover other situations. First add a rule: Under the Rule menu select Add Rule. 16 Click OK in the rule window to return to the system title screen.Lesson 2: Adding Rules and Backward Chaining 15 Click on the OK in the qualifier dialog box and the new condition is added to the rule. 1 2 IF A light suddenly goes out and and THEN Check breaker / fuse Other lights in the room also went out All of the lights in the house did not ALL go out Getting Started with EXSYS® Professional 25 .

The condition is: "Other lights in the room also went out". Instead you must build the condition.Lesson 2: Adding Rules and Backward Chaining 17 You could easily build the first condition in the rule from the qualifier list. Click on the qualifier "Other lights in the room" to highlight it and then click on the value "also went out" to select it. This is often the case when building rules with multiple conditions. The second condition is not the same as the preceding rule. 26 Getting Started with EXSYS® Professional . The new condition will be added to the rule. 19 Click on the OK button in the Qualifier dialog. The new rule often repeats the first IF conditions and only has changes in the last conditions. so you can not use repeat again. but you know that it is the same as the preceding rule. 18 The condition "A light suddenly goes out" is immediately added as the first IF condition. click on the Repeat button. To repeat a condition from the numerically previous rule. Click on the Qualifier button to bring up the list of qualifiers.

Getting Started with EXSYS® Professional 27 .Lesson 2: Adding Rules and Backward Chaining 20 Now add the third condition "All of the lights in the house did not ALL go out". Click on the Choice button to bring up the Choice list. select the appropriate qualifier and value and click on the OK button. The rule should now look like this. Click on the Qualifier button. 21 22 You need to add a Choice about checking the breaker or fuse. so click on the Then Part radio button. You now need to add the THEN part.

button and enter the text of the new choice: Click OK. 24 The new choice is displayed in the Choice list. If it is not already highlighted. 28 Getting Started with EXSYS® Professional .Lesson 2: Adding Rules and Backward Chaining 23 You have not yet added any choice about “breakers” so click on the New Ch. click on the 'breakers" choice to select it. 25 You have now built the second rule. Then click on the 10 button.

Click on the THEN Part radio button. Click on the Choice button and add a new choice: Call the power company Add that choice to the rule with a confidence factor of 10. IF and THEN A light suddenly goes out All of the lights in the house went out Call the power company Under the Rule menu select Add Rule.Lesson 2: Adding Rules and Backward Chaining 26 Click OK in the rule window to return to the system title screen. Repeat the first IF condition. You will now add a rule to consider what to do if it is a general power failure. Click on the Qualifier button and build the second IF condition. Your new rule should look like: Getting Started with EXSYS® Professional 29 .

or single click on it and then click on the How button. "Call the power company". Double click on the following answers: A light suddenly goes out also went out did not ALL go out Other lights in the room All of the lights in the house The results screen displays the correct recommendation: 28 Click on the OK button in the Results window and select to run again. Now try the input: A light suddenly goes out Other lights in the room also went out All of the lights in the house went out The result is correct. Rule 3 is displayed. The system starts asking questions. 30 Getting Started with EXSYS® Professional . Now try running the rules you have produced. Under the Options menu select Run. To see what rule(s) lead to this conclusion.Lesson 2: Adding Rules and Backward Chaining 27 Click on the OK button to accept the rule. double click on the "Call the power company" text.

But now try the input: A light suddenly goes out are still on went out cont. In the Run Again dialog. Try running the system with the input data: A light suddenly goes out are still on did not ALL go ou t 30 Other lights in the room All of the lights in the house This input is logically consistent. computers do not have intuition or the ability to guess anything beyond exactly what they have been told. Click on the OK buttons in the rule window and choice window. The computer has no concept of "room" or "house".Lesson 2: Adding Rules and Backward Chaining 29 The system seems to be working well. Other lights in the room All of the lights in the house Getting Started with EXSYS® Professional 31 . This time answer the questions with: A light suddenly goes out are still on Other lights in the room This should be enough to tell the system that the problem is the bulb. select Yes. "Change the light bulb". but you will be asked one more question! Intuitively we know that if other lights in the room are still on. and leads to the correct recommendation. ALL of the lights in the house could not possible have gone out. Unfortunately.

there is a better and more global solution. This process of having EXSYS combine the knowledge in separate rules is what can make expert systems appear "intelligent". You do not need to specify "links" to other rules. Backward chaining is a process that EXSYS uses to derive data. if the rule is needed to add data. The system should be modified to "know" that if some lights are still on in the room. This enables us to simply add facts that the system may need. it is tried. However. then not all of the lights in the house have gone out.Lesson 2: Adding Rules and Backward Chaining This inconsistent input leads to the recommendation: While these actions could be followed. A light suddenly goes out Other lights in the room also went out All of the lights in the house went out 32 Getting Started with EXSYS® Professional . This separate fact is added as a rule that will be used whenever it is needed. the end user is asked for input. If a possible way is found. The problem in the system could be fixed by modifying rule 3 to: IF and and THEN Call the power company This would prevent the "house" question from being asked unless the other lights in the room were out. the power company will probably get tired of being notified of your changing light bulbs. it will be called. If there is no way to successfully derive the data. EXSYS first looks to see if there is any way to derive the data from other rules. When a piece of data is needed.

Getting Started with EXSYS® Professional 33 .Lesson: 2 Adding Rules and Backward Chaining 31 Note: EXSYS supports two chaining modes . Select to add a rule and build the IF part in the same way as the previous rules.backward and forward. These modes can also be combined in a single system using more advanced commands. all you need to do is add a rule that says: IF Other lights in the room are still on THEN All of the lights in the house did not ALL go out Return to the system title screen and add this rule. To correct the "house"/"room" problem. The key to adding a rule to derive data is to use the same qualifiers that we have already used in the system.

This displays all of the known facts in the system. Any rule that needs the fact will test this rule to see if the fact can be derived without asking the user for input. Click on the Qualifier button and select the qualifier "All of the lights in the house" and value "did not ALL go out". add a fact about a qualifier. under the Question menu select Known Data. 34 Getting Started with EXSYS® Professional . and run the rules again. The system was able to derive this data from the new rule. We are no longer asked if all the lights in the house went out. Under the Options menu select Run. Input the data that caused problems last time: A light suddenly goes out Other lights in the room are still on Now we are immediately brought to the results screen with "Change the bulb".Lesson 2: Adding Rules and Backward Chaining 32 Click on the THEN Part radio button. To see this. 33 Click the OK button to accept the rule. This time instead of adding a Choice in the THEN part. The rule should now look like this.

Getting Started with EXSYS® Professional 35 . As you may have already guessed. EXSYS Professional has ways to help you with that which will be covered in the next lesson. the difficult part is to make sure that the rules cover all possible cases. The inference engine pulls these together to form an over all system. To determine how the system determined that this fact is true.Lesson 2: Adding Rules and Backward Chaining 34 The third fact is "All of the lights in the house did not ALL go out". It enables you to build systems by writing rules about individual facts or relationships. even though it did not ask directly. The system knows this. double click on the text "All of the lights in the house did not ALL go out" (or click on the fact to highlight it and then click on the Source button. Backward chaining is a very powerful tool.) Rule 4 is displayed as the source of the fact.