An Expert System Shell for the ST
BY RON SCHAEFER, M.D.
If you're ever wanted to experiment with Expert Systems, here's your chance. A.I. Doctor is an Expert System Shell that comes complete with a medical knowledge base to try out. And the best thing is that you don't need a medical degree to use A.I. Doctor! The program was written in GFA BASIC 2.0 and runs in medium or high resolution.
Artificial Intelligence on the ST in the file AIDOCTOR.ARC on Side 1 of your START disk.
Okay, let's get something straight. A.I.Doctor is a fun and interesting program, but it is not a substitute for an examination by a real, live, human doctor. START's Editors almost decided not to publish A.I. Doctor for fear that some readers would diagnose themselves with all manner of serious ailments and then call START or their doctors and demand that various organs be removed. As I say in the disclaimer at the beginning of the program, if you are really sick, see a real doctor--not an artificial one!
What A.I. is All About
Artificial Intelligence (A.I.) is the attempt to mimic the human thought process with a computer. A.I. has become a multimillion dollar industry with the proliferation of specialized languages such as LISP and SMALL TALK, as well as numerous expert systems. An expert system can be defined as the embodiment within a computer of a set of rules from an expert skill in such a form that the system can offer expert advice or make an intelligent decision about a processing function. In other words, it's a computer program that gives expert advice in a given field.
Medicine was one of the first areas to explore the use of expert systems. Dr. Shortliffe and his colleagues at Stanford University developed a trailblazing program called MYCIN which diagnosed infectious diseases. This program has subsequently inspired the development of numerous expert systems in fields as diverse as drilling for oil or repairing computers. There is also a class of programs called expert system shells. These provide you with a shell or environment, in which you can enter the data or knowledge base and have the program manipulate this data/knowledge in an intelligent--expert--way.
A.I. Doctor: the BASICs
A.I. Doctor is an expert system shell. In it, I've created a knowledge base related to medicine, but if you're ambitious, you could easily write a set of rules for fixing TV's or cars. A.I. Doctor was written in GFA BASIC 2.0. If you don't have the GFA BASIC 2.0 Interpreter, pick up a copy of the January 1989 issue of START with disk; it includes this awesome programming language. For those of you with GFA BASIC 3.0--sorry, this program won't work without some minor modifications in the way windows are opened.
How to Run A.I. Doctor
To run A.I. Doctor, first boot this month's START disk; the START Menu runs automatically. At the main screen, click on Prepare, then select "A.I. Doctor" The program will un-ARC directly onto the destination disk you specify. You should have the following files: AIDOCTOR.PRG (the main program), RX.DAT (the medical knowledge base), AIDOCTOR.PI2 and AIDOCTOR.PI3 (title screens for medium and high resolutions).
Now, double-click on the AIDOCTOR.PRG icon. Read the disclaimer and then click on OK. If you would like some simple instructions, select the drop down menu item HELP or press the Help key.
|A.I. Doctor is an example of an expert system. It includes a know-
ledge base of 69 symptoms and 89 diseases and conditions, but you
can design your own in any area of knowledge for use with A.I.
The knowledge base on the START disk, called RX.DAT, contains data on 69 symptoms and 89 diseases and conditions. Select Load File from the OPTIONS menu or press [Alternate]-[L] to bring up the file selector; select RX.DAT. An alert box will ask you if you want to see the data listed out on the screen as it is read into memory, either by pages or scrolled (FAST). This feature is useful when writing your own knowledge bases; to speed uploading, click on NO.
Now select Diagnosis from the OPTIONS menu or press [Alternate]-[D]. A.I. Doctor will sort through the data, calculate the four most statistically likely diagnoses and the question that will have the most effect on determining the correct diagnosis. By the way, before you answer any questions you'll see four diagnoses, but don't be alarmed. It doesn't mean that you're sick, it just expresses the general prevalence of an illness in the general population. For example, about 14 percent of the U.S. population has hypertension.
At the top of the Diagnosis dialog box is a Question number and below that is the current symptom question. There are two methods to input your answer; you can click on the appropriate answer or use the number keypad. The small numbers following the answers correspond to the appropriate keys. The answers are pretty self-explanatory: Yes, Sort Of, Don't Know, Not Really, No and Abort. If you select Abort, the program calculates the top 20 diagnoses based on what you've answered to that point. Once the probabilities of a given diagnosis exceed about 95 percent, it adds very little to ask more questions--just click on Abort. The questioning will continue until the probability of a disease or condition equals about 98 percent or until all the questions have been asked.
Remember, this knowledge base only considers 89 possible diseases and conditions, not all known diseases or conditions. Even if you try to answer all of the questions accurately, you'll only be able to rely on the resulting diagnosis within the limits of the knowledge base. Don't attempt to doctor yourself based on the answers from this program.
Write Your Own Expert Knowledge Base
For those intrepid few of you out there who might be interested in writing your own knowledge bases take a look at the file RX.DAT. The first half of the knowledge base consists of questions or symptoms as in Figure 1.
Questions should not exceed 60 characters per line and can be one or two lines long. If the question is only one line long, use a period (.) to indicate a blank line. At the end of the questions section put nine 9's (999999999 as in Figure 1.Figure 1
The second half of the knowledge base contains the illnesses or answers, their prior probabilities and the effects that yes and no answers will have on their probabilities. For example:
Brain Tumor .0000001,7,.9,.01,41,.9,.01,38,.8,.01,50,.8,.01,38,.8,.01,999
The first line contains the name of the illness. The second line has the following format: the first number is the probability of this illness in the general population. The next number refers to symptom (question) number 7, which is "Do you have a headache?". The next number is the probability of the person answering yes to the question if he has the illness (.9 or 9 times out of 10 a person who has a brain tumor will have a headache). The next number is the probability of the person answering yes to the question if he does not have the illness (0.01 or 1 time out of a hundred a person without a brain tumor will have a headache). The next three items then repeat the format of the previous three. The next symptom is 41 for "Are you vomiting?", followed by the probability of .9 for a yes answer if the condition is true and a probability of .01 for a yes answer if the condition is false. At the end of the line place the end-of-line code 999.
The hard part is coming up with data for a knowledge base that makes sense and is consistent. When creating a new knowledge base, it's best to experiment with it. Pretend to have a disease or other condition and answer the questions appropriately; if the results seem odd, play around with the probabilities until you get the results you think appropriate.
How It Works
Fuzzy logic--that's the term used to describe the ability of a program to deal with answers that are not clearcut, such as Don't Know or Sort of. This is realistic, since many things in the real world are probabilistic in nature. Fuzzy logic is handled through the use of Bayes' Theorem which states:
P(I:S) = (S:I)P(I) P(S:I)P(I)+P(S:not I)P(not I)
You begin with a given probability for an event or illness, P(I). Next, you ask a question "S" and depending upon how it is answered, the probability of that illness is modified using Bayes' Theorem. The actual code taken from the program is as shown in Figure 2.Figure 2
P(I%) is the probability of the illness and Pushed is the value of certainty of an answer. Pushed is weighted differently for Yes than Sort Of and is a negative value for No or Not Really. A Don't Know answer has a Pushed value equal to 0 so that it has no effect on the probability.
Before each question is asked, the program goes through all the questions that have not yet been asked, finding the one that has the most effect on changing the probability of the diagnosis.
Confused? That's OK, artificial intelligence is a very complex subject. However, for those of you who are really curious, take a look at the source code of A.I. Doctor, which I've commented heavily. You should also take a look at "A.I. Apprentice" in the Fall 1986 START. And there are public domain versions of LISP and XLISP available for the ST; check with your local users group or on online services, such as CompuServe, GEnie or BIX.
Good luck and may you never get any of the illnesses diagnosed by this program!
Ron Schaefer has been programming for 8 years, the last three on his ST. Ron is the president of Schaefer Supergraphics, which markets medical software for the ST, and vice-president of ACE-HI. He wrote the game ATTACK! in the December 1989 issue of START.