What is Prolog? "How To Install Prolog on Ubuntu"?


Experiment No: AI-

TITLE:- Implementation of Expert System on Prolog Platform:Medical Diagnosis of 5-10 diseases based on adequate symptoms


Problem Statement: - Implement Expert system for Medical 
Diagnosis.


Objective:To study about Expert/Rule based system.To study 
about Prolog Platform

Requirements (Hw/Sw): 
PC, Windows OS & SWI-Prolog 
platform.


Theory:

What are Expert Systems?

The expert systems are the computer applications developed to solve complex problems in a particular domain, at the level of extra-ordinary human intelligence and expertise.
Characteristics of Expert Systems
  • High performance
  • Understandable
  • Reliable
  • Highly responsive
Capabilities of Expert Systems
The expert systems are capable of −
  • Advising
  • Instructing and assisting human in decision making
  • Demonstrating
  • Deriving a solution
  • Diagnosing
  • Explaining
  • Interpreting input
  • Predicting results
  • Justifying the conclusion
  • Suggesting alternative options to a problem
They are incapable of −
  • Substituting human decision makers
  • Possessing human capabilities
  • Producing accurate output for inadequate knowledge base
  • Refining their own knowledge
Components of Expert Systems
The components of ES include −
  • Knowledge Base
  • Inference Engine
  • User Interface
Let us see them one by one briefly −
Knowledge Base
It contains domain-specific and high-quality knowledge. Knowledge is required to exhibit intelligence. The success of any ES majorly depends upon the collection of highly accurate and precise knowledge.
What is Knowledge?


The data is collection of facts. The information is organized as data  and facts about the task domain. Data, information, and past  experience combined together are termed as knowledge.
Components of Knowledge Base
The knowledge base of an ES is a store of both, factual and heuristic knowledge.
    • Factual Knowledge − It is the information widely accepted bythe Knowledge Engineers and scholars in the task domain.
    • Heuristic Knowledge − It is about practice, accurate judgement, one’s ability of evaluation, and guessing.
Knowledge representation
It is the method used to organize and formalize the knowledge in the knowledge base. It is in the form of IF-THEN-ELSE rules.
Knowledge Acquisition
The success of any expert system majorly depends on the quality, completeness, and accuracy of the information stored in the knowledge base.
  • The knowledge base is formed by readings from various experts, scholars, and the Knowledge Engineers. The knowledge engineer is a person with the qualities of empathy, quick learning, and case analyzing skills.
He acquires information from subject expert by recording, interviewing, and observing him at work, etc. He then categorizes and organizes the information in a meaningful way, in the form of IF-THEN-ELSE rules, to be used by interference machine. The knowledge engineer also monitors the development of the ES.
Inference Engine
Use of efficient procedures and rules by the Inference Engine is essential in deducting a correct, flawless solution.
In case of knowledge-based ES, the Inference Engine acquires and manipulates the knowledge from the knowledge base to arrive at a particular solution.
In case of rule based ES, it −
  • Applies rules repeatedly to the facts, which are obtained from earlier rule application.
  • Adds new knowledge into the knowledge base if required.
  • Resolves rules conflict when multiple rules are applicable to a particular case.
To recommend a solution, the Inference Engine uses the following strategies
  • Forward Chaining
  • Backward Chaining

Applications of Expert System

  • The following table shows where ES can be applied.
Application
Description
Design Domain
Camera lens design, automobile design.
Medical Domain
Diagnosis Systems to deduce cause of disease from observed data, conduction medical operations on humans.
Monitoring Systems
Comparing data continuously with observed system or with prescribed behavior such as leakage monitoring in long petroleum pipeline.
Process Control Systems
Controlling a physical process based on monitoring.
Knowledge Domain
Finding out faults in vehicles, computers.
Finance/Commerce
Detection of possible fraud, suspicious transactions, stock market trading, Airline scheduling, cargo scheduling.

MYCIN (ES):
MYCIN was an early backward chaining expert system that used artificial intelligence to identify bacteria causing severe infections, such as bacteremia and meningitis, and to recommend antibiotics, with the dosage adjusted for patient's body weight — the name derived from the antibiotics themselves, as many antibiotics have the suffix "-mycin". The Mycin system was also used for the diagnosis of blood clotting diseases. MYCIN was developed over five or six years in the early 1970s at Stanford University. It was written in Lisp as the doctoral dissertation of Edward Shortliffe under the direction of Bruce G. Buchanan, Stanley N. Cohen and others.

What is Prolog? 
  • Prolog stands for programming in Logic.It is logical & declarative language that plays important role in Artificial intrelligence.
  • In prolog, logic is expressed as relations which is in the form of “Facts” and “Rules”.Main part in implementation of Prolog is logic being applied.
  • In prolog Computation is carried out by running a query over these wriyyen relations whereas  relation are formed with the help of Facts & Rules.
  • In Declarative language the programmer specifies a goal to be achieved & prolog system works on how to achieve it.
  • In prolog .pl extension is used for program.
INSTALLATION STEPS FOR PROLOG ON UBUNTU
1) sudo add-apt-repository ppa:swi-prolog/stable
2) sudo apt-get update
3) sudo apt-get install swi-prolog

How to RUN Prolog program on Terminal in UBUNTU
Write a prolog program as a text file with a .pl ending. For example, program.pl.
1. Open a terminal (Ctrl+Alt+T) and navigate to the directory where you stored your program.
2. Open SWI-Prolog by invoking swipl.
3. In order to query the loaded program, type goals and watch the output.
4. Alternatively, you can also load the program by passing its name as a parameter to SWI-Prolog: swipl -s program.pl.
5. After this infront of ?(querry) symbol type your querry....
6. To exit SWI-Prolog, type halt..

STEPS TO RUN PROGRAM USING TERMINAL
  • type following command along with program name .pl(medicalExpert.pl)  and predicate with .(go.) To run the program

  • sndcoe@sndcoe-ThinkCentre-M72e:~$ swipl -s medicalExpert.pl -t  go.

Comparing Prolog with Traditional Language
  • Traditional PL are said to be procedure oriented programming language where programmer specifies in details how to solve peoblems.In case of purely declarative language programmer only specifies what problem is & leaves rest of the part to language system(prolog).
  • Prolog is considered to be Nonprocedural language syetem.
  • It is pattern matching language consist of series of Rules & Facts.

Important Features of Prolog

English
Calculus
Prolog
and
^
,
or
V
;
if
--->
:-
not
~
not

  • . Indicates Prolog statement are termination.
  • \= Indicates Non equality operators.
  • ? Indicates querry start point
  • Facts & predicates always start with alphabet.

Terminologies used in Prolog 
1) Facts
  • Fact is explicit relationship between object and properties of object
  • In prolog, We declare some facts. These facts constitute the Knowledge Base of the system. We can query against the Knowledge Base. We get output as affirmative if our query is already in the knowledge Base or it is implied by Knowledge Base, otherwise we get output as negative. 
  • So, Knowledge Base can be considered similar to database, against which we can query. Prolog facts are expressed in definite pattern. 
  • Facts contain entities and their relation. Entities are written within the parenthesis separated by comma (, ). Their relation is expressed at the start and outside the parenthesis.
  •  Every fact/rule ends with a dot (.). 

So, a typical prolog fact goes as follows :Format : relation(entity1, entity2, ....k'th entity).
Example :
1.friends(raju, mahesh).
2.singer(sonu).
3.odd_number(5).
Explanation :
These facts can be interpreted as :
1.raju and mahesh are friends.
2.sonu is a singer.
3.5 is an odd number.
2) Rules
Rule is implicit relationship between object and properties of object\
Ex:-’A’ is child of ‘B’ if ‘B’ is parent of ‘A’
3) Querries
Asking question about relationship between object and object properties
Ex:-’B’ is parent of whom?

Running queries :A typical prolog query can be asked as :
Query 1 : ?- singer(sonu).
Output : Yes.
Explanation : As our knowledge base contains the above fact, so output was 'Yes', otherwise it would have been 'No'. 
Query 2 : ?- odd_number(7).
Output : No.
Explanation : As our knowledge base does not  contain the above fact, so output was 'No'.
4) Predicates-A predicate is defined by a collection of clauses. A clause is either a rule or a fact.Predicate is formed with the help of facts.

Sample Tutorials On Prolog :
Tutorial:-01(Applying Rules on Facts)
Facts are mentioned below-
Ram is male
Shyam is male
Ravi is male         
Savita is female
Sonia is female
From above facts Predicstes are formed.
  male(ram).
male(shyam).
male(ravi).
female(priyanka).
female(sonia).
Running above program on Ubuntu Terminal
Sample-01
vnd@vnd-Lenovo-H520e:~$ swipl -s fact.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- male(ram).
true ;
true.
?- female(sonia).
true.
?- female(ravi).
False.
Running above program on Ubuntu Terminal
Sample-02
vnd@vnd-Lenovo-H520e:~$ swipl -s fact.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- male(X).
true ;
X = shyam ;
true.
?- male(X).
true .
?- male(X).
true ;
X = shyam ;
true.
?- female(X).
X = priyanka ;
X = sonia.
Advantages :
1. Easy to build databse. Doesn’t need a lot of programming effort.
2. Pattern matching is easy. Search is recursion based.
3. It has built in list handling. Makes it easier to play with any algorithm involving lists.
Disadvantages :
1.LISP (another logic programming language) dominates over prolog with respect to I/O features.
2.Sometimes input and output is not easy.
Applications :
Prolog is highly used in artificial intelligence(AI). Prolog is also used for pattern matching over natural language parse trees.



 Download Prolog Programs From Here!!!!
Click Here to Download PROLOG  Programs


Flowchart:

Conclusion:




Comments

Popular Posts

Vivo Z1 Pro will be the first smartphone that comes with 712 chipset, Learn the specialty of this processor.