Date post: | 24-Dec-2015 |
Category: |
Documents |
Upload: | julius-floyd |
View: | 223 times |
Download: | 0 times |
Expert Systems
Expert systems are AI programs that solve a highly technical problem in some domain
Normally a human expert is used for solving such problems.
An expert system encodes a human expert’s knowledge. Common areas:
medicine science: chemistry, biology engineering agriculture military finance.
1COSC 2P93 Prolog: Expert Systems
Expert systems
Prolog is an excellent language for implementing expert systems
1. declarative Prolog can denote expert rules (knowledge base)
2. Prolog’s default execution is an “inference” strategy.
(called “backward chaining”)
3. Can write meta-interpreters for inference, which can implement things like explanation (knowledge traces), as well as new logic inference strategies.
4. Can use operators and grammars to make user-friendly knowledge languages.
2COSC 2P93 Prolog: Expert Systems
Expert Systems: terms Knowledge-based system (or expert system): a program which
exhibits, within a specific domain, a degree of expertise in problem solving that is comparable with a human expert
expert: person with superior knowledge in some particular field, usually only obtained through experience
knowledge base: repository of expert's rules and facts about a domain
inference engine: procedure for drawing conclusions from knowledge base
knowledge engineer: develops, implements, and maintains a model of an expert's knowledge base
expert system shell: software used to implement an expert system; usually generic (and commercialized)
3COSC 2P93 Prolog: Expert Systems
Expert System Architecture
4COSC 2P93 Prolog: Expert Systems
KnowledgeBase
InferenceEngine
Interface
"Real world"
( humans, robots, machines, ... )
WorkingStorage
Simple example: Bird Identification
Expert’s rule
IF family is albatross and
color is white
THEN
bird is laysan_albatross
In Prolog the same rule is:
bird(laysan_albatross) :-
family(albatross),
color(white).
5COSC 2P93 Prolog: Expert Systems
More Bird KB rules
bird(laysan_albatross):-
family(albatross),
color(white).
bird(black_footed_albatross):-
family(albatross),
color(dark).
bird(whistling_swan) :-
family(swan),
voice(muffled_musical_whistle).
bird(trumpeter_swan) :-
family(swan),
voice(loud_trumpeting).
6COSC 2P93 Prolog: Expert Systems
Running Bird KB
At some point, the user must indicate the family and colour of a bird. In Prolog, these facts would be added to KB...
family(albatross).
color(dark).
Then...
?- bird(X).
X = black_footed_albatross
7COSC 2P93 Prolog: Expert Systems
An expert system shell
Preferable to ask user to enter colour, or answer “yes” or “no” as necessary.
Also, don’t want to ask user same question repeatedly. Save answers (eg. colour).
But note that Prolog does not do this by default. Repeated calls to the same goal will be executed each time called. Need a “cache” of computed goals.
Improvements that a shell could offer:1. Add predicates to ask questions when required.
2. Save the answers to questions.
8COSC 2P93 Prolog: Expert Systems
Shell
color(X) :- ask(color, X). % put this in KB.
ask(A, V):-known(yes, A, V), % succeed if true!. % and don’t ask user
ask(A, V):-known(_, A, V), % was asked before, but not “yes”!, fail. % therefore fail
ask(A, V):-write(A:V), % ask userwrite('? : '), read(Y), % get the answerasserta(known(Y, A, V)), % remember itY == yes. % succeed or fail
9COSC 2P93 Prolog: Expert Systems
Bird ES
?- bird(X).
nostrils : external_tubular? yes.
live : at_sea? yes.
bill : hooked? yes.
size : large? yes.
wings : long_narrow? yes.
color : white? yes.
X = laysan_albatross
10COSC 2P93 Prolog: Expert Systems
Explanation
A valuable feature of expert systems is their ability to explain their line of reasoning.
Often users want to know WHY advice was given, in addition to the advice itself.
Explanation also a good way to debug KB.
eg.nostrils : external_tubular? why.
[nostrils(external_tubular), order(tubenose), family(albatross), bird(laysan_albatross)]
nostrils : external_tubular?
11COSC 2P93 Prolog: Expert Systems
Explanation
Why: explain the line of reasoning for this question Goes from node UP to the root of the tree.
How: How was some advice derived? Goes from node DOWN the branch.
Why not: Why was some other advice not given?
If Prolog’s inference is used, then the above can be implemented with a meta-interpreter. Very similar to the one that kept the proof tree for boolean logic. Also similar to grammars that keep the parse tree.
12COSC 2P93 Prolog: Expert Systems
Simple meta-interpreter
prove(true,_) :- !.
prove(menuask(X,Y,Z),Hist) :- menuask(X,Y,Z,Hist), !.
prove(ask(X,Y),Hist) :- ask(X,Y,Hist), !.
prove((Goal, Rest),Hist) :-
!,
prove(Goal, [Goal|Hist]),
prove(Rest, Hist).
prove(Goal,Hist) :-
clause(Goal,Body),
prove(Body,Hist).
13COSC 2P93 Prolog: Expert Systems
Meta-interpreter
2nd argument of prove is the “explanation” list.
Every time a goal is called, it is added to list. represents the goals from a node up the tree to the root.
Explanation list passed to ask, menuask utilities. If user asks “why”, then the list can be written out. Best to write it out in pieces, in “english” format.
14COSC 2P93 Prolog: Expert Systems
Improving the shell
Using “op”, can make nicer looking rules in KB.
rule 1
if nostrils is external_tubular and
live is at_sea and
bill is hooked
then order is tubenose cf 80.
rule 2
if feet is webbed and
bill is flat
then order is waterfowl cf 80.
15COSC 2P93 Prolog: Expert Systems
Explanation
With nicer looking rules, you can make explanation and queries more English-like...
Are the nostrils external_tubular? why.
The nostrils are external_tubular is necessary
To show that the order is tubenose
To show that the family is albatross
To show that the bird is a laysan_albatross
16COSC 2P93 Prolog: Expert Systems
Uncertainty
Previous rules had “CF 80” terms: Certainty Factor Expertise is often vague, rather than black and white.
eg. medical diagnoses: could be likelihoods of different diseases.
Doctors want to consider all possibilities. Expert systems with uncertainty will allow multiple
conclusions to be reached. an ordered list of conclusions (disease diagnoses) will be
generated at end of a session...Measles CF 80
Chicken Pox CF 75
Yellow Fever CF 45
17COSC 2P93 Prolog: Expert Systems
Forward-chaining
Backward chaining: Prolog’s default inference hierarchical, top-down strategy
However, some problems are not top-down in nature. eg. building complex machines: often start bottom-up
Forward chaining: bottom-up reasoning strategy You start with low-level facts (requirements), and “fire” rules until a high-
level conclusion reached. Prolog easily lets you make a forward-chaining meta-interpreter
This is a new “logic programming language” paradigm. However, no longer a top-down “tree” for inference (like regular
Prolog). Instead, forward-chaining uses a “working storage” of facts.
facts are asserted/retracted during inference.
18COSC 2P93 Prolog: Expert Systems
Forward-chaining rules
rule id1:
[1: has(X,hair)]
==>
[assert(isa(X,mammal)),
retract(all)].
rule id3:
[1: has(X,feathers)]
==>
[assert(isa(X,bird)),
retract(all)].
19COSC 2P93 Prolog: Expert Systems
Forward-chaining interpreter
% the main inference loop, find a rule and try it. if it fired, say so
% and repeat the process. if not go back and try the next rule. when
% no rules succeed, stop the inference
go :-
call(rule ID: LHS ==> RHS),
try(LHS,RHS),
write('Rule fired '),write(ID),nl,
!,go.
go.
20COSC 2P93 Prolog: Expert Systems
Conclusion
Expert systems: one of the major commercial success stories of AI (along with data mining, vision, object-oriented programming, ...)
tens of thousands of expert systems being used. If you qualify (or not) for a mortgage or credit card, an
expert system probably made the decision!
Prolog is commonly used as an expert system implementation language. Its ability to interface with databases, other languages, and the
WWW, makes it ideal for implementing ES software.
21COSC 2P93 Prolog: Expert Systems