صفحه 1:
Expert Systems
صفحه 2:
An expert system is “an intelligent computer
program that uses knowledge and inference
procedures to solve problems that are difficult enough
to require significant human expertise for their
solutions.” - Edward Feigenbaum
An expert system solves such problems as good as a
human expert or even better. An expert system can
explain its behavior by answering questions such as:
Why are you asking this question?
Why didn’t you try X?
How did you reach this conclusion?
INTERNIST II is an expert system which has been
tested against experienced physicians in the field of
internal medicine. It arrived at the correct diagnosis,
first time, 83% of the time whereas experienced human
ee rn
et ee
صفحه 3:
WHAT DOES AN EXPERT SYSTEM LOOK
LIKE?
The following is a sample interaction between a
physician and an expert system called MYCIN.
[MYCIN] ¢ What is the patient's name?
[Doc] John Doe
٠ Male or female?
Male.
- Age?
He is 55.
¢ Have you obtained positive cultures indicating
general type?
Yes.
¢ What type of infection is it?
Primary Bacteremia.
¢ When did symptoms first appear?
صفحه 4:
USER: HOW ?
TEIRESIAS: (i.e. HOW was it established that the
aerobicity of ORGANISM-1 is facultative?) The
following were used :
[3.1] RULE 27 indicated there is strongly suggestive
evidence (.8) that the aerobicity of ORGANISM- 1 is
facultative
[3.2] RULE 27 indicated there is weakly suggestive
evidence (.2) that the aerobicity of ORGANISM-1 is
anaerobic Since this gave a cumulative CF of (.8) for
facultative, and (.2) for anaerobic, it has been
established that the aerobicity of ORGANISM-1 is
facultative.
USER: WHY DIDN'T YOU CONSIDER
STREPTOCOCCUS AS A POSSIBILITY FOR
ORGANISM-1?
صفحه 5:
Production Rules
If Condition(s) Then Action
ua Cxacvple:
عمسن عا من اجه مه سا 49
090000 the worpholow of the موه ts rod
®OO the vervbiniy of the orxyemise ts uervbic
MLEO there is sirvady sugesive evidewer (D.O)
In Prolog
+Condition -> +Action
(yes(S) -> true ; (no(S) -> fail ; ask(S))).
If -> Then ; Else is actually a term of the form ; (-
>(If, Then), Else).
or EE ee ee
200
صفحه 6:
Explanation
Facility
Working
Memory
User Interface
Inference
Engine
۱ Knowledge
Base
domain Expert(S)
Knowledge
Knowledge
ngineer
Formalized
Knowledeg
صفحه 7:
Simple expert systems in Prolog
1. Animal identification
صفحه 8:
2- ۰
Does the animal have the following attribute:
has_hair? no.
Does the animal have the following attribute:
gives_milk? yes.
Does the animal have the following attribute:
eats_meat? no.
Does the animal have the following attribute:
has_pointed_teeth? yes.
Does the animal have the following attribute:
has_claws? yes.
Does the animal have the following attribute:
has_forward_eyes? yes.
Does the animal have the following attribute:
has_tawny_color? yes.
صفحه 9:
go :- hypothesize(Animal),
write('l guess that the animal is: '),
write(Animal), nl, undo.
/* hypotheses to be tested */
hypothesize(cheetah) :- cheetalB.
hypothesize(tiger) :- tiger, !.
hypothesize(giraffe) :- giraffe, !.
hypothesize(zebra) :- zebra, !.
hypothesize(ostrich) :- ostrich, !.
hypothesize(penguin) :- penguin, !.
hypothesize(albatross) :- albatross, !.
hypothesize(unknown). /* no diagnosis */
صفحه 10:
/* animal identification rules */
cheetah :- mammal, carnivdBt,
verify(has_tawny_color),
verify(has_dark_spots).
tiger :- mammal, carnivore,
verify(has_tawny_color),
verify(has_black_stripes).
giraffe :- ungulate,
verify(has_long_neck),
verify(has_long_legs).
zebra :- ungulate,
verify(has_black_stripes).
ostrich :- bird,
verify(does_not_fly),
verify(has long neck).
صفحه 11:
\guin :- bird,
verify(does_not_fly),
verify(swims),
verify(is_black_and_white).
atross :- bird,
verify(appears_in_story_Ancient_Mariner),
verify(flys_well).
lassification rules */
mmal :- verify(has_hair), !. ]<[
mmal :- verify(gives_milk).
| :- verify(has_ feathers), !.
| :- verify(flys),
verify(lays_eggs).
nivore :- verify(eats_meat), !.
صفحه 12:
nivore :- verify(has_pointed_teeth),
verify(has_claws),
verify(has_forward_eyes).
gulate :- mammal, verify(has_hooves), !.
gulate :- mammal, verify(chews_cud).
Now to ask questions */
<(Question) :- B]
write('Does the animal have the following attribute: '),
write(Question), write('? '),
read(Response), nl,
( (Response == yes ; Response == y)
-> assert(yes(Question)) ;
assert(no(Question)), fail).
صفحه 13:
ynamic yes/1,no/1.
ow to verify something */
fy(S) :- (yes(S) -> true ; (no(S) -> fail ; ask(S)))
ndo all yes/no assertions */
0 :- retract(yes(_)),fail.
lo :- retract(no(_)),fail.
0.
صفحه 14:
2. Farm management
صفحه 15:
2- ۰
Is the stocking of the jack pine stand currently
at least minimum ?
If you are unsure of how to determine stocking,
see page 4 in the Managers Handbook for Jack Pine
|: yes.
Is the average diameter of the trees less than 5
inches ?no.
Is the age of the stand mature or immature 7i.
Please respond with : [mature, immature]
Is the age of the stand mature or immature ?immature.
Is the site index greater than 60 ?yes.
Do you want to manage the timber for large or small
products ?large.
Is the basal area per acre at least 120 square feet ?jjj.
Please respond with : [yes, no]
Is the basal area per acre at least 120 square feet ?yes.
Is there a high risk of loss or injury ?no.
صفحه 16:
Based upon your responses, the following is
recommended :
It is important to thin the area
You should wait before doing anything else to this stand.
To see the complete set of derived facts, type
"display_kb."
Yes
?- display _kb.
stocking good is yes
avg <5 is no
age is immature
site index > 60 is yes
product size is large
120+ basal area is yes
advice is It is important to thin the area
high risk is no
advice is You should wait before doing anything else to
eae. ne
صفحه 17:
الب هنا
0 :-
clear_kb,
give_advice.
give_advice :-
recommendation Bj
fail.
give_advice :-
write_advice.
/* The rules */
fact(branch8,yes) :-
fact('stocking good',yes),
fact('‘avg < 5',yes),
fact('2000+ per acre',yes),
recommend('The stand of jack pine must be weeded
and cleaned.').
صفحه 18:
fact(branch8,yes) :-
fact('stocking good',yes),
fact('avg < 5',yes),
fact('2000+ per acre',no).
fact(branch9,no) :-
fact('stocking good',yes),
fact('‘avg < 5',no),
fact(age,mature),
assertz(fact(branch11,yes)).
fact(branch11,yes) :-
fact('stocking good',yes),
fact('‘avg < 5',no),
fact(age,mature),
assertz(fact(branch9,no)).
صفحه 19:
fact(branch9,yes) :-
fact('stocking good',yes),
fact(‘avg < 5',no),
fact(age,immature),
fact('site index > 60',yes),
fact(‘product size',large),
fact('120+ basal area',yes),
recommend(‘It is important to thin the area’).
fact(branch9,yes) :-
fact('stocking good',yes),
fact(‘avg < 5',no),
fact(age,immature),
fact(‘site index > 60',yes),
fact(‘product size',large),
fact('120+ basal area',no).
صفحه 20:
fact(branch9,yes) :-
fact('stocking good',yes),
fact(‘avg < 5',no),
fact(age,immature),
fact(‘site index > 60',yes),
fact(‘product size' large).
fact(branch9,yes) :-
fact('stocking good',yes),
fact(‘avg < 5',no),
fact(age,immature),
fact(‘site index > 60',yes).
fact(branch11,yes) :-
fact('stocking good',no),
fact(‘other resources',no).
صفحه 21:
fact(branch9,yes) :-
fact(branch8,yes),
fact('severe competition',yes),
recommend('Competing trees should be
eliminated.').
fact(branch9,yes) :-
fact(branch8,yes),
fact('severe competition',no).
fact(branch17,yes) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact('pine suited',yes),
fact('desirable seed',yes),
fact('serotinous cones',yes),
fact('10/acres adequate',yes),
fact(‘burning planned',no),
add _fact(silvaculture,clearcut),
صفحه 22:
fact(branch17,yes) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact(‘pine suited',yes),
fact('desirable seed',yes),
fact('serotinous cones',yes),
fact('10/acres adequate',no),
add_fact(silvaculture,clearcut),
recommend('The best silvaculture method to use is
clearcut.').
fact(branch17,yes) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact(‘pine suited',yes),
fact('desirable seed',yes),
fact('serotinous cones',no),
fact(‘two harvests wanted',yes),
fact('two harvests possible',yes),
add_fact(silvaculture,shelterwood),
صفحه 23:
fact(branch17,yes) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact(‘pine suited',yes),
fact('desirable seed',yes),
fact('serotinous cones',no),
fact('two harvests wanted',yes),
fact(‘two harvests possible',no),
add_fact(silvaculture,clearcut),
recommend('The best silvaculture method to use is
clearcut.').
fact(branch17,yes) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact(‘pine suited',yes),
fact('desirable seed',yes),
fact('serotinous cones',no),
fact('two harvests wanted',no),
add_fact(silvaculture,clearcut),
TARAMMMaNnAC'Ths hact cilwvannilhinrgs mathnan وات يان يتنه to
صفحه 24:
fact(branch17,yes) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact(‘pine suited',yes),
fact('desirable seed',no),
add_fact(silvaculture,clearcut),
recommend('The best silvaculture method to use is
clearcut.').
fact(branch18,yes) :-
fact(branch17,yes),
fact('adequate seedbed', yes).
fact(branch18,yes) :-
fact(branch17,yes),
fact('adequate seedbed',no),
recommend('The site should be prepared before
planting.').
ae.
صفحه 25:
fact(X,Y) :-
not(kb(X,Anything)),
question(X,Answer),
assertz(kb(X,Answer)),
Y = Answer.
recommendation(maintain) :-
fact('stocking good',no),
fact(‘other resources',yes),
recommend('You should maintain the stand in its
present condition’).
recommendation(control) :-
fact(branch9,yes),
fact(‘high risk',yes),
recommend('The current area should be controlled, if
at all feasible.').
صفحه 26:
recommendation(wait) :-
fact(branch9,yes),
fact(‘high risk',no),
recommend(‘You should wait before doing anything else to this
stand.').
recommendation(‘use seed tree’) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact(‘pine suited',yes),
fact('desirable seed',yes),
fact('serotinous cones',yes),
fact('10/acres adequate',yes),
fact(‘burning planned',yes),
recommend('You should use seed trees to seed the
area.').
صفحه 27:
recommendation(convert) :-
fact(branch11,yes),
fact(‘pine desired',yes),
fact(‘pine suited',no),
recommend('You should convert the area to some more
desisahinkindaisieeednvert) :-
fact(branch11,yes),
fact(‘pine desired',no),
recommend('You should convert the area to some more
desirable kind of tree.').
recommendation(‘natural seeding’) :-
fact(branch18,yes),
fact(silvaculture,shelterwood),
recommend('The natural seeding technique should
be used.').
recommendation(plant) :-
fact(branch18,yes),
fact(silvaculture, clearcut),
Pee SA
د
صفحه 28:
recommendation('scatter cones’) :-
fact(branch18,yes),
fact(silvaculture,clearcut),
fact(‘improved stock',no),
fact('‘good cone supply',yes),
recommend('You should scatter the serotinous cones
over the area.').
recommendation(‘direct seed’) :-
fact(branch18,yes),
fact(silvaculture,clearcut),
fact(‘improved stock',no),
fact('good cone supply',no),
recommend('You should directly seed the area.').
/* Add fact to KB if not already there. */
add_fact(X,Y) :-
kb(X,Y),!.
صفحه 29:
add_fact(X,Y) :-
assertz(kb(X,Y)).
recommend(X) :-
add_fact(advice,X).
/* Questions to ask the user */
question('stocking good',Ans) :-
write('Is the stocking of the jack pine stand
currently'),nl,
write(‘at least minimum ? '),n1nl,
write(‘If you are unsure of how to determine
stocking,'),nl,
write('see page 4 in the Managers Handbook for Jack
صفحه 30:
question(‘avg < 5',Ans) :-
ask(‘Is the average diameter of the trees less than 5
inches ?',
Ans,[yes,no]).
question('2000+ per acre',Ans) :-
ask('Are there 2000 or more trees per acre ?',Ans,
[yes,no]).
question(age,Ans) :-
ask(‘Is the age of the stand mature or immature ?',
Ans,[mature,immature]).
question('site index > 60',Ans) :-
ask(‘Is the site index greater than 60 ?',Ans,[yes,no]).
question(‘product size',Ans) :-
صفحه 31:
question('120+ basal area',Ans) :-
ask(‘Is the basal area per acre at least 120 square feet
7
Ans,[yes,no]).
question(‘other resources',Ans) :-
ask('Do you want to maintain this condition to support
other resources?',Ans,[yes,no]).
question('severe competition',Ans) :-
ask(‘Is there severe overstory competition ?',Ans,
[yes,no]).
question(‘high risk',Ans) :-
ask(‘Is there a high risk of loss or injury ?',Ans,
[yes,no]).
question(‘pine desired',Ans) :-
ask('Do you want to keep jack pine in this area ?',Ans,
[yes,no]).
question('pine suited
صفحه 32:
question(‘desirable seed',Ans) :-
ask('Is there a desirable jack pine seed source on the
area ?',
Ans,[yes,no]).
question('serotinous cones',Ans) :-
ask('Do the trees on the site have serotinous
cones ?',Ans,[yes,no]).
question('10/acres adequate',Ans) :-
ask('Are 10 trees per acre adequate to seed the
area ?',Ans,[yes,no]).
question(‘burning planned',Ans) :-
ask('Has a prescribed burning been planned ?',Ans,
[yes,no]).
question(‘two harvests wanted',Ans) :-
ask('Do you want two commercial harvests on this
area ?',Ans,[yes,no]).
question('two harvests possible',Ans) :-
ask(‘Is it possible to get two harvests from this
صفحه 33:
question('adequate seedbed',Ans) :-
ask(‘Is there an adequate seedbed for planting ?',Ans,
[yes,no]).
question(‘improved stock',Ans) :-
ask(‘Is there an improved planting stock
available ?',Ans,[yes,no]).
question('good cone supply',Ans) :-
ask(‘Is there a good supply of serotinous cones in the
area ?',
Ans,[yes,no]).
/* Utility Routines - to be useful, we should add some
routines to allow
the user to ask 'How' and 'Why' */
display_kb :-
kb(%Y),
write(X),write(' is '),write(Y),
ا
صفحه 34:
write_advice :-
nl,nl,write(‘Based upon your responses, the following is
recommended:'),nl, nl,
show_advice.
show_advice :-
kb(advice,X),
write(X),nl, fail.
show_advice :-
nl,write('To see the complete set of derived facts, '),
write(‘ty[@llisplay_kb."), nl.
clear_kb:-
retractall(kb(_, )).
ask(Ques,Ans,LegalResponses) :-
nl, write(Ques),read(Ans),
member(Ans,LegalResponses),!.
ask(Ques,Ans,LegalResponses) :-
nl, nl,write('Please respond with : '),
write(LegalResponses) nl, nl,