Escolar Documentos
Profissional Documentos
Cultura Documentos
Prior to beginning the design of the rules, you should study a sample expert sys
tem for diagnosing car problems in order to define rules for diagnosing the appl
iance described by the user manual you have been given in class.
Here are some instructions for running the sample expert system:
Download the expert shell (see also below): exshell.pl
Download the knowledge base containing the rules, and save it in the same folder
as the expert shell (see also below): cars.pl
To run SWI-Prolog in Windows, start 'plwin.exe' or double-click the Prolog file
in Explorer. Load the expert system shell and the cars knowledge base by typing:
?- consult(exshell).
?- consult(cars).
Ignore warnings about 'Singleton variables'. For further information go to Prolo
g Resources).
Start the program:
?- solve.
The program will ask you questions. Eventually the program succeeds (it comes up
with a recommendation, prints a justification for this recommendation, and then
prints 'Yes') or fails (cannot make a recommendation). If the program cannot ma
ke a recommendation, that means either the car is not broken, or the knowledge b
ase does not have the information needed to diagnose the problem.
The Cars Database
% This is the sample automotive diagnostic knowledge base for use
% with the EXSHELL expert system shell.
% When running it, be sure to load it with the file containing
% EXSHELL.
% To start it, give PROLOG the goal:
% solve.
% Knowledge Base for simple automotive diagnostic expert system.
% Top level goal, starts search.
rule((fix(Advice) :(bad_component(X),fix(X, Advice))), 100).
% rules to infer bad component of the failed system:
rule((bad_component(starter) :(bad_system(starter_system),lights(come_on))),50).
rule((bad_component(battery) :(bad_system(starter_system),not(lights(come_on)))),90).
rule((bad_component(timing) :(bad_system(ignition_system), not(tuned_recently))),80).
rule((bad_component(plugs) :(bad_system(ignition_system),plugs(dirty))),90).
rule((bad_component(ignition_wires) :(bad_system(ignition_system),
not(plugs(dirty)), tuned_recently)),80).
% Rules to infer system that failed.
rule((bad_system(starter_system) :(not(car_starts), not(turns_over))),90).
rule((bad_system(ignition_system) :(not(car_starts), turns_over,gas_in_carb)),80).
rule((bad_system(ignition_system) :(runs(rough),gas_in_carb)),80).
rule((bad_system(ignition_system) :(car_starts, runs(dies),gas_in_carb)),60).
% Rules to make reccommendation for repairs.
rule(fix(starter, 'replace starter'),100).
invert_threshold(Threshold, New_threshold),
solve(Goal, CF_goal, Rules, New_threshold),
negate_cf(CF_goal, CF).
% Case 3: conjunctive goals
solve((Goal_1,Goal_2), CF, Rules, Threshold) :- !,
solve(Goal_1, CF_1, Rules, Threshold),
above_threshold(CF_1, Threshold),
solve(Goal_2, CF_2, Rules, Threshold),
above_threshold(CF_2, Threshold),
and_cf(CF_1, CF_2, CF).
%Case 4: backchain on a rule in knowledge base
solve(Goal, CF, Rules, Threshold) :rule((Goal :- (Premise)), CF_rule),
solve(Premise, CF_premise,
[rule((Goal :- Premise), CF_rule)|Rules], Threshold),
rule_cf(CF_rule, CF_premise, CF),
above_threshold(CF, Threshold).
%Case 5: fact assertion in knowledge base
solve(Goal, CF, _, Threshold) :rule(Goal, CF),
above_threshold(CF, Threshold).
% Case 6: ask user
solve(Goal, CF, Rules, Threshold) :askable(Goal),
askuser(Goal, CF, Rules),!,
assert(known(Goal, CF)),
above_threshold(CF, Threshold).
% Case 7A: All else fails, see if goal can be solved in prolog.
% solve(Goal, 100, _, _) :% call(Goal).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Certainty factor predicates. Currently, these implement a variation of
% the MYCIN certainty factor algebra.
% The certainty algebra may be changed by modifying these predicates.
% negate_cf/2
% argument 1 is a certainty factor
% argument 2 is the negation of that certainty factor
negate_cf(CF, Negated_CF) :Negated_CF is -1 * CF.
% and_cf/3
% arguments 1 & 2 are certainty factors of conjoined predicates
% argument 3 is the certainty factor of the conjunction
and_cf(A, B, A) :- A =< B.
and_cf(A, B, B) :- B < A.
%rule_cf/3
% argument 1 is the confidence factor given with a rule
% argument 2 is the confidence inferred for the premise
% argument 3 is the confidence inferred for the conclusion
rule_cf(CF_rule, CF_premise, CF) :CF is CF_rule * CF_premise/100.
%above_threshold/2
% argument 1 is a certainty factor
% argument 2 is a threshold for pruning
%
% If the threshold, T, is positive, assume we are trying to prove the goal
% true. Succeed if CF >= T.
% If T is negative, assume we are trying to prove the goal
% false. Succeed if CF <= T.
above_threshold(CF, T) :T >= 0, CF >= T.
Parameter properties
EXPECT range of possible values
PROMPT English sentence to elicit reponse
LABDATA can be known for certain from Lab data
LOOKAHEAD lists rules mentioning the parameter in their premise (e.g. a rule mig
ht need to know whether or not a patient is febrile)
UPDATED-BY lists rules mentioning the parameter in their action (i.e. they may d
raw a conclusion about the value of the parameter, such as the IDENTITY paramete
r)
Dynamic data structures store information about the evolving case - the patient
details, possible diagnoses, rules consulted:
Example piece of dynamic data:
To evaluate the premise of the rule mentioned above:
($AND (SAME ORGANISM-1 GRAM GRAMNEG)
(SAME ORGANISM-1 MORPH ROD)
(SAME ORGANISM-1 AIR AEROBIC))
from following data
ORGANISM-1
GRAM = (GRAMNEG 1.0)
MORPH = (ROD 0.8) (COCCUS 0.2)
AIR = (AEROBIC 0.6) (FACUL 0.4)
Total value of whole expression is lowest certainty value = 0.6
Conclusion is therefore:
(CONCLUDE ORGANISM-1 is enterobacteriaceae 0.48 ( = 0.6 (CF of premise) x 0.8 (C
F of rule))
(In disjunctive premise, total value of whole expression is highest certainty va
lue)
Control structure
MYCIN first attempts to create a "patient context" containing information about
the case, then tries to compile a list of therapies for the context.
It uses a backward chaining mechanism, reasoning back friom the goals it want st
o prove to the data it has, rather than vice versa. The overall goal is "compile
a list of therapies".
Questions can be prompted by the invocation of rules, to find out necessary data
, to avoid unnecessary questions.
2. The Explanation System
MYCIN can answer questions about HOW a conclusion was reached and WHY a question
obtained specimens?
No
15) Has PT538 recently had objective evidence of abnormal neurologic signs (e.g.
seizures, coma) documented by physician?
Yes
The CSF culture will be considered to be associated with meningitis.
Cause
17) Does PT538 have an abnormal chest x-ray?
No
18) Has PT538 been exposed to any contagious diseases recently?
No
27) Please enter CSF findings in table:
WBC %PMN Protein CSFglucose Periph-glucose
100 99 280 5 UNKNOWN
35) Is meningitis a hospital-acquired infection?
Yes
39) is PT538 a burns patient?
Yes
I have found evidence (RULE545 RULE557)that treatment should cover for e-coli ca
using meningitis
I have found evidence (RULE545 RULE557 RULE578)that treatment should cover for p
seudomaonas aeruginosa causing meningitis
I have found evidence (RULE545 RULE557 RULE578)that treatment should cover for K
lebsiella pneumoniae causing meningitis
I have found evidence (RULE507)that treatment should cover for Diplococcus-pneum
oniae causing meningitis
Treatment
It is important to cover for the following infection(s) and associated organism(
s):
Meningitis
<item 1>e-coli
<item 2>pseudomaonas aeruginosa
<item 3>Klebsiella pneumoniae
<item 4>Diplococcus-pneumoniae
41) Does PT538 have a clinically significant allergic reaction to any antimicrob
ial agent?
No
43) PT538 s weight in kilograms:
70
Recommendation 1
My preferred therapy is as follows:
In order to cover for items <1 2 3 4>
give the following in combination:
1) AMPICILLIN
Dose 3.5g q4h IV
2) GENTAMYCIN
Dose 119 mg q8h IV
Since high concentration of penicilllins can inactivate aminoglycosides do not m
ix these two antibiotics in the same IV bottle.
To CS237 AI Applications Page
To CS237 Home Page
To Lyn Pemberton's Home Page