1 / 40

Knowledge Based Systems

Knowledge Based Systems. Expert Systems. WHAT DOES AN EXPERT SYSTEM LOOK LIKE?. A Dialog with MYCIN. 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?

waseem
Télécharger la présentation

Knowledge Based Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Knowledge Based Systems • Expert Systems

  2. WHAT DOES AN EXPERT SYSTEM LOOK LIKE? A Dialog with MYCIN

  3. The following is a sample interaction between a physician and anexpert 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? May 5, 2002.

  4. • Let's call the most recent positive culture CULTURE-1. From what site was CULTURE-1 taken? From the blood. • When? May 9, 2002. • Let's call the first significant organism from this blood culture ORGANISM-1. Do you know the identity of ORGANISM-1 ? No. • Is ORGANISM-1 a rod or a coccus or something else? Rod. • What is the gram stain of ORGANISM-1 ? Gramnegative. • Have there been positive cultures from sites which are not associated with infections about which you are seeking advice? No. • Did ORGANISM-1 grow aerobically? Yes.

  5. • Did ORGANISM-1 grow anaerobically? Yes. • What is the suspected portal of entry of ORGANISM-1? The gastrointestinal tract. • Does the patient have a clinically significant allergic reaction to any antimicrobial agent? No. • How much does the patient weigh? 70 kilograms. • My first recommendation is as follows: Give Gentamycin using a dose of 119 mg 1.7 mg/kg) q8h IV [or IM] for 10 days. Modify dose in renal failure. Give Clindamycin using a dose of 595 mg (8.5 mg/kg) q6h IV [or IM] for 14 days. If diarrhea or other gastrointestinal symptoms develop, check for pseudo membranous colitis. • Do you wish to see the second choice?

  6. It seems unlikely (and unsafe) that a professional would follow blindly the recommendations of a computer program unless it can explain its chain of reasoning. MYCIN: Is the patient's illness with ORGANISM-1 a hospital-acquired infection? USER: WHY ? TEIRESIAS: (i.e. WHY is it important to determine whether or not the infection with ORGANISM-1 was acquired while the patient was hospitalized?) [1.0] This will aid in determining the category of ORGANISM-1. It has already been established that [1.1] the gram stain of ORGANISM-1 is gramneg, and [1.2] the morphology of ORGANISM-1 is rod, and [1.3] the aerobicity of ORGANISM-1 is facultative Therefore, if [1.4] the infection with ORGANISM-1 was not acquired while the patient was hospitalized then there is strongly suggestive evidence (.8) that the category of ORGANISM-1 is enterobacteriaceae Also: there is weakly suggestive evidence (.1) that the identity of ORGANISM-I is pseudomonas-aeruginosa [RULE 37].

  7. 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? TEIRESIAS: The following rule could have been used to determine that the identity of ORGANISM-1 was streptococcus: RULE 33. But clause 2 ('the morphology of the organism is coccus') was already known to be false for ORGANISM-1, so the rule was never tried.

  8. Domain Expert(S) User Knowledge User Interface Knowledge Engineer Formalized Knowledeg Inference Engine Explanation Facility Knowledge Base Working Memory Agenda

  9. Summary: The main components of an expert system: • • The knowledge base - a declarative representation of the expertise(human knowledge),in the form of IF THEN rules, frames, semantic networks or other forms • • The working memory - the data which is specific to theproblem being solved • • The inference engine – a part of the expert system which derives conclusionsusing the knowledge base and the data in the working memory; • • The user interface - controls the dialog between the user and the system • The explanation facility- Expert systems must be able to explain and justify their solutions, this is the component that answer how and why type questions

  10. Production Rules IF Condition(s) THEN Action • An Example: • IFthe stain of the organism is gramneg • ANDthe morphology of the organism is rod • ANDthe aerobicity of the organism is aerobic • THENthere is strongly suggestive evidence (0.8) • that the class of the organism is enterobacteriaceae

  11. In Prolog +Condition -> +Action (yes(S) -> true ; (no(S) -> fail ; ask(S))). In CLIPS (defrule fire-emergency (emergency (type fire) => (assert (response (action activate-sprincler-system))))

  12. Simple expert systems in Prolog 1. Animal identification

  13. ?- go. 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. Does the animal have the following attribute: has_dark_spots? no. Does the animal have the following attribute: has_black_stripes? yes. I guess that the animal is: tiger Yes

  14. go :- hypothesize(Animal), write('I guess that the animal is: '), write(Animal), nl, undo. /* hypotheses to be tested */ hypothesize(cheetah) :- cheetah, !. hypothesize(tiger) :- tiger, !. hypothesize(giraffe) :- giraffe, !. hypothesize(zebra) :- zebra, !. hypothesize(ostrich) :- ostrich, !. hypothesize(penguin) :- penguin, !. hypothesize(albatross) :- albatross, !. hypothesize(unknown). /* no diagnosis */

  15. /* animal identification rules */ cheetah :- mammal, carnivore, 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).

  16. penguin :- bird, verify(does_not_fly), verify(swims), verify(is_black_and_white). albatross :- bird, verify(appears_in_story_Ancient_Mariner), verify(flys_well). /* classification rules */ mammal :- verify(has_hair), !. mammal :- verify(gives_milk). bird :- verify(has_feathers), !. bird :- verify(flys), verify(lays_eggs). carnivore :- verify(eats_meat), !.

  17. carnivore :- verify(has_pointed_teeth), verify(has_claws), verify(has_forward_eyes). ungulate :- mammal, verify(has_hooves), !. ungulate :- mammal, verify(chews_cud). /* how to ask questions */ ask(Question) :- 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).

  18. :- dynamic yes/1,no/1. /* How to verify something */ verify(S) :- (yes(S) -> true ; (no(S) -> fail ; ask(S))). /* undo all yes/no assertions */ undo :- retract(yes(_)),fail. undo :- retract(no(_)),fail. undo.

  19. 2. Farm management

  20. ?- go. 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 ?i. 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.

  21. 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 this stand. Yes ?-

  22. /* ESFM.PL*/ go :- clear_kb, give_advice. give_advice :- recommendation(X), 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.').

  23. 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)).

  24. 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).

  25. 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).

  26. 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), recommend('The best silvaculture method to use is clearcut.').

  27. 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), recommend('The best silvaculture method to use is the shlterwood method.').

  28. 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), recommend('The best silvaculture method to use is clearcut.').

  29. 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.'). fact(X,Y) :- kb(X,Y),! .

  30. 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.').

  31. 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.').

  32. recommendation(convert) :- fact(branch11,yes), fact('pine desired',yes), fact('pine suited',no), recommend('You should convert the area to some more desirable kind of tree.'). recommendation(convert) :- 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), fact('improved stock',yes), recommend('Since there is better stock available, you can plant using that stock.').

  33. 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),!.

  34. 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 ? '),nl,nl, write('If you are unsure of how to determine stocking,'),nl, write('see page 4 in the Managers Handbook for Jack Pine'), nl,ask('',Ans,[ yes , no ]).

  35. 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) :- ask('Do you want to manage the timber for large or small products ?', Ans,[large,small]).

  36. question('120+ basal area',Ans) :- ask('Is the basal area per acre at least 120 square feet ?', 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',Ans) :- ask('Is jack pine well suited to this site ?',Ans,[yes,no]).

  37. 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 area ?',Ans,[yes,no]).

  38. 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(X,Y), write(X),write(' is '),write(Y), nl, fail. display_kb.

  39. 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('type "display_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, ask(Ques,Ans,LegalResponses).

  40. 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('type "display_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, ask(Ques,Ans,LegalResponses).

More Related