| Home
| download
| source
| AI Book
| Ruby
|
Mycin Expert System
A Ruby Implementation
What is Mycin
Mycin is an expert system that can be programmed with knowledge database for different domains (e.g. medical diagnosis). It asks questions, reasons, gives explanations on why it asked the question, and deals with uncertainties. See the example below.
This is a Ruby rewrite of the Lisp code given in the book:
Peter Norvig: "Paradigms of Artificial Intelligence Programming.
Case Studies in Common Lisp"
Morgan Kaufmann Publishers, San Francisco. 1992
ISBN 1-55860-191-0
Original LISP source code is available HERE
Excerpts from the book:
MYCIN lead to the development of the EMYCIN expert-system shell... EMYCIN is a backward-chaining rule interpreter that has much in common with Prolog. However, there are four important differences. First, and most importantly, EMYCIN deals with uncertainty. Instead of insisting that all predications be true or false, EMYCIN associates *certainty factor* with each predication. Second, EMYCIN caches the results of its computation so that they not be duplicated. Third, EMYCIN provides an easy way for the system to ask the user for information. Fourth, it provides explanations of its behavior. This can be summed up in the equation:EMYCIN = Prolog + uncertainty + caching + questions + explanationsThe MYCIN expert system was one of the earliest and remain one of the best known. It was written by Dr. Edward Shortliffe in 1974 as an experiment in medical diagnosis.
A typical rule:
param context operation value
----- ------- --------- -----
(defrule 52 <--- rule number
if (site culture is blood )
(gram organism is neg ) <--- premise/condition
(morphl organism is rod )
(burn patient is serious)
then 0.4 <--- confidence factor (cf)
(identity organism is pseudomonas ) <--- conclusion
)
There is nothing to install really. Install Ruby first, then
This is a result of a test run, user's entries are in bold. The example is from the book, although some questions are out of order (probably due to random order when reading a Hash).
>test_mycin.rb
------- patient-1 -------
Patient's name: HELP
Type one of the following:
? - to see possible answers for this parameter
rule - to show current rule
why - to see why this question is asked
help - to see this list
xxx - (for some specific xxx) if there is a definite answer
xxx .5 yyy .4 - if there are several answers with
different certainty factors
Patient's name: SYLVIA_FISHER
Sex: FEMALE
Age: 27
------- culture-1 -------
From what site was specimen CULTURE-1 taken? BLOOD
How many days ago was this culture (CULTURE-1) obtained? 3
------- organism-1 -------
Enter the identity (genus) of ORGANISM-1? UNKNOWN
The gram strain of ORGANISM-1? ?
Must be one of: acid-fast, pos, neg
The gram strain of ORGANISM-1? NEG
Is ORGANISM-1 a rod or coccus? ROD
Is PATIENT-1 a burn patient? If so, mild or serious? WHY
[Why is the value of burn being asked for?]
It is known that:
The site of the culture is blood
The gram of the organism is neg
The morphology of the organism is rod
Therefore,
Rule 52:
If The burn of the patient is serious
Then with certainty of 0.4
The identity of the organism is pseudomonas
Is PATIENT-1 a burn patient? If so, mild or serious? SERIOUS
What is the aerobicity of ORGANISM-1? AEROBIC
Is PATIENT-1 a compromised host? YES
Findings for ORGANISM-1
for these goals: identity
IDENTITY: ENTERO 0.8, PSEUDOMONAS 0.76
Is there another organism?YES
------- organism-2 -------
Enter the identity (genus) of ORGANISM-2? UNKNOWN
The gram strain of ORGANISM-2? NEG 0.8 POS 0.2
Is ORGANISM-2 a rod or coccus? ROD
What is the aerobicity of ORGANISM-2? ANAEROBIC
Findings for ORGANISM-2
for these goals: identity
IDENTITY: BACTEROIDES 0.72, PSEUDOMONAS 0.6464
Is there another organism?NO
Is there another culture?NO
Is there another patient?NO