Budditha Hettige
Department of Computer Engineering
Faculty of Computing
General Sir John Kotelawala Defence University
SOURCE : Building Expert Systems in Prolog, Dennis Merritt
Expert Systems
Overview
• What is an Expert System?
• What are the Expert system features?
• Steps to Expert System development
– Knowledgebase
– User Interface
– Shell
• Prolog Java Interface (JPL)
• Prolog Web Interface
• Examples
27/11/2015 Budditha Hettige ([email protected])
7/11/2015 Budditha Hettige ([email protected]) 3
Expert System
• Computer applications which embody some non-
algorithmic expertise for solving certain types of
problems
7/11/2015 Budditha Hettige ([email protected]) 4
{Dennis Merritt}
Advantages
• Easy to develop and modify
• The use of satisficing (accepting satisfactory solution rather than the optimal one)
• The use of heuristics
• Development by knowledge engineers and users
• Goal driven reasoning or backward chaining
• Coping with uncertainty
• Data driven reasoning or forward chaining
• Data representation
• User interface
• Explanations
7/11/2015 Budditha Hettige ([email protected]) 5
Limitations of Expert Systems
• Limited to relatively narrow problems
• Cannot readily deal with “mixed” knowledge
• Possibility of error
• Cannot refine own knowledge base
• Difficult to maintain
• May have high development costs
• Raise legal and ethical concerns
7/11/2015 Budditha Hettige ([email protected]) 6
Applications of Expert Systems• Credit granting
• Information management and retrieval
• AI and expert systems embedded in products
• Plant layout
• Hospitals and medical facilities
• Help desks and assistance
• Employee performance evaluation
• Loan analysis
• Virus detection
• Repair and maintenance
• Shipping
• Marketing
• Warehouse optimization
7/11/2015 Budditha Hettige ([email protected]) 8
Participants in Expert Systems
Development and Use
• Domain expert– The individual or group whose expertise and knowledge is
captured for use in an expert system
• Knowledge user– The individual or group who uses and benefits from the
expert system
• Knowledge engineer– Someone trained or experienced in the design,
development, implementation, and maintenance of an expert system
7/11/2015 Budditha Hettige ([email protected]) 9
Evolution of Expert Systems Software
• Expert system shell
– Collection of software packages & tools to design,
develop, implement, and maintain expert systems
7/11/2015 Budditha Hettige ([email protected]) 10
Popular Expert Systems
• PXDES
– Is a expert system that uses an inference engine to determine the type and degree of pneumoconiosis, or lung cancer
– Uses X-rays to look at shadows on the lungs
• MyCIN
– MYCIN was an early backward chaining expert system
– Operated using fairly simple inference engine, and a knowledge base of ~600 rules
7/11/2015 Budditha Hettige ([email protected]) 12
Steps to
Expert System Development
• Identify the problem
• Build up Knowledge base
– Fats
– Rules
– Expirations
• Build up Inference Engine
– Way to sole problem
• Design a user Interface
7/11/2015 Budditha Hettige ([email protected]) 13
Identify the problem
• Input
– What are the Questions?
– What is the order of the Questions?
• Output
– What is the final result(s)?
• Facts
– What are the fats requires to collect the answers?
• Explanations
– In case, what are the explanations?
7/11/2015 Budditha Hettige ([email protected]) 14
Build up Knowledgebase
• What are the facts?
• What are the rules?
• How they represents?
• Example
family(duck):-
order(waterfowl), feed(on_water_surface), flight(agile).
bird(mallard):- family(duck), voice(quack), head(green).
bird(mallard):- family(duck), voice(quack), color(mottled_brown).
bird(pintail):- family(duck), voice(short_whistle).
7/11/2015 Budditha Hettige ([email protected]) 15
Build up Inference Engine
• Prolog has a built-in backward chaining inference engine that can be used to partially implement some expert systems
• The rules for expert systems are usually written in the form:
– bird(pintail):- family(duck), voice(short_whistle).
7/11/2015 Budditha Hettige ([email protected]) 16
User Interface
• The system can be dramatically improved by
providing a user interface
• Identify Attribute and values for the each case
7/11/2015 Budditha Hettige ([email protected]) 17
Ask Questions
7/11/2015 Budditha Hettige ([email protected]) 18
Expert System Shell
• Architecture of the Native shell.
7/11/2015 Budditha Hettige ([email protected]) 21
The Shell
• The shell will seek to solve a generic predicate called
top_goal.
top_goal(X) :- bird(X).
• The shell has a predicate called solve, which does some
housekeeping and then solves for the top_goal.
• Example
7/11/2015 Budditha Hettige ([email protected]) 22
Explanation
• Expert systems have ability to explain theirbehavior.
• This means the user can ask the system for justification of conclusions or questions at any point in a consultation with an expert system
• Types of Explanation
– A rule trace, which reports on the progress of a consultation;
– Explanation of how the system reached a given conclusion;
– Explanation of why the system is asking a question;
– Explanation of why not a given conclusion.
7/11/2015 Budditha Hettige ([email protected]) 23
Explanation (Questions)
The why questions occur at the bottom of an inference
chain, and the how questions occur at the top
7/11/2015 Budditha Hettige ([email protected]) 24
Java Prolog Interface
• SET PATH for the swipl.exe
– C:\Program Files (x86)\swipl\bin
• Add jpl.jar to your project
• Create suitable prolog source file
• Add prolog source file into your java project folder
• Import jpl and complete your development
7/11/2015 Budditha Hettige ([email protected]) 25
Java Codes for Prolog connection
• Import JPL libraryimport org.jpl7.JPL;
import org.jpl7.Query;
import org.jpl7.Term;
• Collect JPL information
7/11/2015 Budditha Hettige ([email protected]) 26
JPL Code
• Consult prolog sourceString t1 = "consult('family.pl')";System.out.println(t1 + " " + (Query.hasSolution(t1) ? "succ" : "failed"));
• Run Prolog predicate String t2 = "child_of(joe, ralf)";
System.out.println(t2 + " is " + (Query.hasSolution(t2) ? "pro" : "not"));
• Get one solutionString t4 = "descendent_of(X, ralf)";
System.out.println("first solution of " + t4 + ": X = " +
Query.oneSolution(t4).get("X"));
7/11/2015 Budditha Hettige ([email protected]) 27
JPL Code (2)
String t4 = "descendent_of(X, ralf)";
Map<String,Term>[] ss4 =
Query.allSolutions(t4);
System.out.println("all solutions of " + t4);
for (int i = 0; i < ss4.length; i++)
{
System.out.println("X = " + ss4[i].get("X"));
}
7/11/2015 Budditha Hettige ([email protected]) 28
JPL Code (3)
String t5 = "descendent_of(X,Y)";
Query q5 = new Query(t5);
System.out.println("each solution of " + t5);
while (q5.hasMoreSolutions())
{
Map<String, Term> s5 = q5.nextSolution();
System.out.println("X = " + s5.get("X") + ",
Y = " + s5.get("Y"));
}
7/11/2015 Budditha Hettige ([email protected]) 29
Example (relation.pl)
male(somapala).
male(gunapala).
male(rathnapala).
female(seela).
female(susila).
female(neetha).
parent(seela,kamal).
parent(seela,nayana).
parent(seela,saman).
parent(somapala,kamal).
parent(somapala,nayana).
parent(somapala,saman).
parent(kamal,sanjaya).
parent(ruvani,sanjaya).
parent(saman,susi).
parent(saman,yasith).
parent(saman,oshan).
parent(kumari,susi).
parent(kumari,yasith).
parent(kumari,oshan).
print:-write('how are you').
print(X):- write('Anwer is '),write(X),nl.
print(X,Y):- write('Anwer is '),write(X), write(Y),nl.
mother(X,Y):-female(X),parent(X,Y).
father(X,Y):-male(X),parent(X,Y).
son(X,Y):- male(X),parent(Y,X).
whois(X, Y) :- mother(X,Y), write(X), write(' is mother of'), write(Y).
whois(X, Y) :- father(X,Y), write(X), write(' is father of'), write(Y).
whois(X, Y) :-
son(X,Y), write(X), write(' is son of'), write(Y).
7/11/2015 Budditha Hettige ([email protected]) 30
Example:
7/11/2015 Budditha Hettige ([email protected]) 31
Activity
• Create an expert system to select a suitable A/L
stream
– What should be the output
– Questions
– Order of the questions
– Input methods
7/11/2015 Budditha Hettige ([email protected]) 32
Top Related