PROSPEC Computer Systems This is the sixth README file for Expert86 6.1 Building a Expert86 Knowledge Base This section explains how to use Expert86 to construct a working expert system. The full Expert86 User Guide contains much more information than we can include here and is supplied to all registered users. We have taken pains to make Expert86 as easy to use as possible but to get the most from it you will need to understand how knowledge bases are built. Essentially an Expert86 knowledge base consists of two files kept on disk. One contains a list of examples of an expert at work. The other contains all the extra information which the system will need, such as the text of any questions it will have to put to the user. This document explains how to prepare these two files. For illustration we'll use a simple example since the task at hand is to explain how an expert system works, not to explain a complex field of expertise. The knowledge base presented below is discussed in greater detail in the full Expert86 User Guide, where it is extended to be more powerful. The User Guide contains a detailed tutorial on Expert86 and further examples, such as an expert system designed to advise which of the many programming languages available would be most suitable for a particular programming task. The expert system we will describe here is an advice system to help a car buyer identify which vehicle best fits his requirements. This subject has the great advantage that the expertise needed to make decisions is reasonably universal. To reduce the problem to a manageable size to begin with, we will limit the choice of cars quite severely, to the following: sports cars family saloons executive saloons cheap secondhand cars More cars can be added to this list later. Next we need an effective means of describing the customers requirements to the system. We might ask: - how large his income is - whether he has a family, and if so how large that is - where he lives, and how much parking space is available - what the car will be used for - how old he is, for reasons of insurance and so on. For the purposes of this introdction we will look at just two factors - size of income and size of family. Now, it is a simple matter to describe the merits of each car in these terms: income? family? car ------------------------------------------------------------------------ LARGE NONE PORSCHE LARGE WIFE PORSCHE LARGE CHILDREN JAG/BMW/MERC MODERATE NONE SALOON MODERATE WIFE SALOON MODERATE CHILDREN SALOON SMALL * CHEAP_SECONDHAND If you disagree with these classifications, that's fine. Later we will show you how to use your own instead. The column headings are known as 'attributes'. The different states that an attribute may take are called its 'values'. Therefore 'income?' is an attribute which can take the values 'LARGE', 'MODERATE' or 'SMALL'. Attributes may have any values you choose. The simplest attributes have just two values - 'YES' and 'NO'. We could have chosen to present the 'income?' attribute as: Is your income more than £10000 per annum? expecting the user to answer either YES or NO. An attribute could also be numeric, such as How many children do you have? which would expect 1, 2, 3, etc. as answers. Even as it stands the system here bears comparison with rather more serious expert systems - a medical diagnosis advisor for instance. The decisions (the cars, in this case) would be replaced by illnesses and the attribute names would be a little different (Does the patient smoke?, How old is he?, etc.) but the principle is very much the same. At this stage we have a very simple decision making system. We could ask both of the questions, collect the answers, and by comparing them with the table of examples, determine which car is most suitable. However, a system based on a look-up table has very limited intelligence. It would have to ask for the value of each and every attribute before it could begin to identify the object. That is not a particular problem in this case, where only 2 attributes are in use, but a full-size system, used for oil exploration, perhaps, might deal with 20 or even 50 attributes (each one requiring a complex test to be performed, costing a great deal of time and money) before its value could be determined. Expert86 takes things one stage further than a look-up table. It reduces the table of examples to one single rule, a distilled version of the information in the examples. By reducing the set of examples, which is called a 'training set', to a rule the expert system ensures that it can make a decision based on the minimum of information. It only needs to ask the absolute minimum number of questions necessary to find an answer. This property is particularly important for industrial expert systems, where very large savings can be made by an intelligent choice of tests. It is pointless to perform tests which yield little or no useful information. 6.2 The CAR and CAR.ATT Files A file on this disk called CAR contains a copy of the training set discussed above. If you have not already done so, it is a good idea to try it to see how the program works. Simply type: E86 CAR and then press the RETURN key. The computer will load and run the Expert86 shell with CAR as its knowledge base. You will see the expert system induce a rule from the examples in CAR and then you will be given an opportunity to try the resulting advice system out. That is virtually all there is to using an expert system with Expert86. There should be another file on the disk called CAR.ATT. CAR.ATT contains the definitions of the attributes and the values that each attribute can take. Both of these files are simple ASCII text files and may be displayed in the usual way with: TYPE CAR or TYPE CAR.ATT You can prepare your own knowledge bases for Expert86 using a text editor such as Locoscript. However, with Locoscript you will have to use the 'Make ASCII file' option to convert the file from Locoscript format to ASCII format. This process is explained in detail in the full Expert86 User Guide. Alternatively, ED.COM can be used to create and edit knowledge bases. ED is supplied on the system disks that came with your Amstrad. However, the documentation provided is rather sparse so we have produced a tutorial on ED which can be found in README.8 on this disk. A .ATT file must be laid out in a particular way. It is necessary to understand how the .ATT file is constructed before you can create expert systems of your own. Each attribute must be defined in a .ATT file before it can be used in a training set. The definition for the first attribute for CAR is: income? ASK "How would you describe your income?" EXPLAIN "Cars can be very expensive!" REPLIES: ( LARGE MODERATE SMALL ) income? serves as a means of identifying the question and need not concern us at the moment. It is used as a reminder when you look at a long-forgotten training set, and to identify which attributes have been used if you inspect a finished rule. ASK and the text that follows it are there to make the system appear friendly during consultation. The ASK text is used when the system puts questions to the user. Rather than employing ASK text, we could have allowed the system to say "What is the value of income?". However, the user is unlikely to know how to answer such an obscure question unless he is already familiar with the CAR knowledge base. The ASK text makes life a little easier. If he still does not know how to answer the user can press '?' which will list out every value the income? attribute can take. How would you describe your income? ? Acceptable answers are: LARGE MODERATE SMALL The EXPLAIN text is also provided to make the system user-friendly. At any time during consultation the user may type 'WHY' to demand an explanation of why the equestion he has just been asked is relevant to the problem. For instance, part of a consultation might be: ... How would you describe your income? WHY Cars can be very expensive! How would you describe your income? MODERATE ... REPLIES is used to define the values that the income? attribute may take. In this case there are three values: 'LARGE' 'MODERATE' and 'SMALL'. The values must be enclosed in brackets as shown above. As we said, it's very important that you understand how to write a .ATT file so re-read the paragraphs above if there's anything that puzzles you, and have a look at CAR.ATT for further guidance if necessary. The final entry in the .ATT file defines not an attribute but something called the 'class'. The class is the decision reached by an expert at the end of the consultation. An expert on CARS, when presented with the following problem: income? family? LARGE NONE would announce that the class is 'PORSCHE' (assuming that he thought along the same lines as our CAR system). The class is defined at the end of the .ATT file. The format is almost the same as for the other attributes but there are one or two differences. car EXPLAIN "I'd suggest you look for something like " REPLIES ( PORSCHE "a Porsche" SALOON "a Sierra or Cavalier maybe" JAG/BMW/MERC "a large executive saloon - a Jaguar,#BMW, or Mercedes" CHEAP_SECONDHAND "a cheap, popular secondhand car - a#Cortina, Escort or Mini perhaps" ) You do not need to include any ASK text, and if you do it will be ignored. Each value is followed by some optional value text. The text is used, together with the EXPLAIN text, to notify the user when a conclusion has been reached. The EXPLAIN text is printed first and then whatever text following the class that the system has chosen as its conclusion is added. For example, it might print: I'd suggest you look for something like a Porsche or I'd suggest you look for something like a cheap, popular secondhand car - a Cortina, Escort or Mini perhaps 6.3 Running Expert86 To run the CAR advice system with Expert86 type: E86 CAR You will see Expert86 read first the CAR.ATT file and then the CAR file. Finally it will build a decision tree and offer you the chance to question the expert system. From then on it is simply a matter of answering Expert86's queries or of typing '?' (to discover what the permissible answers to a question are), 'why' (to discover why Expert86 has asked you a particular question) or 'quit' (to get back to CP/M). The decision tree that Expert86 builds is stored on a file with a .TRE extension, so the tree for CAR can be found in CAR.TRE. It may be inspected with: LIST CAR.TRE LIST is our own utility. It behaves in a similar way to TYPE (supplied with your Amstrad) but does not have the annoying: Press RETURN to continue messages that TYPE usually produces. However TYPE CAR.TRE will work, since CAR.TRE is a simple ASCII file. 6.4 Conclusion That covers everything you need to know to use Expert86 at its most basic level. The best way to become familiar with Expert86 is to try out a few small systems like CAR of your own. By looking at the tree it should be easy to see the logic behind Expert86's decisions. There are many points about the program that we have not described here. We have not mentioned the Expert86 error messages at all since they are, as far as possible, self-explanatory. The Expert86 User Guide includes all the details we have omitted here including a chapter explaining how Expert86 produces decision trees and uses them during consultation. 6.5 Registration If you would like to register send £19.95 to PROSPEC Computer Systems Shareware PO BOX 28 Beeston Nottingham NG9 1PH Great Britain For an up to date copy of this disk send £3.50 + 50p postage. The fee covers the price of the disk only - the software is free. We do not even charge a copying fee. On this disk you should find the following files: HELP.COM - advice on getting started README.1 - introduction to Expert86 README.2 - details of our Expert86 competition README.3 - details of other PROSPEC shareware products README.4 - how to copy Expert86 README.5 - more information about Expert86 [README.6] - this file README.7 - a blank order form for you to print out README.8 - details of the ED.COM editor E86.COM - the Expert86 expert system generator CAR - a sample knowledge base for Expert86 - training set CAR.ATT - a sample knowledge base for Expert86 - definitions LIST.COM - a utility, similar to TYPE.COM