Date post: | 03-Jun-2018 |
Category: |
Documents |
Upload: | idharufaida |
View: | 226 times |
Download: | 0 times |
of 123
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
1/123
AN EXPERT SYSTEM FOR DIABETES DIAGNOSIS
Submitted in partial fulfillment of the requirements for the award of the degree of
Master of Philosophy
By
SMITHA V
(Roll No: 0935014)
Supervisor
Mrs. Rohini V
(Asst. Professor)
Department of Computer Science
CHRIST UNIVERSITY BANGALORE
2010
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
2/123
DECLARATION
I hereby declare that the dissertation entitled An Expert System for Diabetes
Diagnosissubmitted for the M.Phill Degree is my original work and the dissertation has not
formed the basis for the ward of any degree, associateship fellowship or any other similar
titles.
Place: Bangalore SMITHA V
Date: Roll No.: 0935014
Signature:
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
3/123
This is to certify that the dissertation work entitled An Expert System for Diabetes
Diagnosis is a bonafide research work carried out by SMITHA V, student of M.Phill
(Computer Science) Christ university, Bangalore, during the year 2009-2010, in partial
fulfillment of the requirements for the award of the Degree of Master of philosophy and that
the dissertation has not formed the basis for the award previously of any degree, diploma,
associateship, fellowship or any other similar title.
CERTIFICATE
Place: Bangalore Mrs. Rohini. V
Date: (Asst. Professor)
Signature
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
4/123
APPROVAL SHEET
Thesis entitledAn Expert System for Diabetes DiagnosisbySmitha V is approved for the
degree of Master of Philosophy in Computer Science.
Examiners:
1. ___________________ ___________________
2. ___________________ ___________________
3. ___________________ ___________________
Supervisor (s)
1. ___________________ ___________________
2. ___________________ ___________________
3. ___________________ ___________________
Chairman:
___________________(Seal)
Date: ___________
Place: __________
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
5/123
Abstract
Expert system is a computer system that emulates the decision making ability of a human
expert. That is it acts in all respects like a human expert. It uses human knowledge to solve
problems that would require human intelligence. The expert system represents expertise
knowledge as data or rules within the computer. These rules and data can be called upon
when needed to solve problems.
Diabetes is a knotty disease and very common in the modern world. Diabetes is a serious
disease that affects almost every organ in the body like heart, eyes, kidney, skin, nerves, blood
vassals, foot etc. If left the disease unchecked it will make serious complications including
death. Though the disease can not possible to cure completely, it can be well managed or
control and can lead a very healthy life. Early diabetes diagnosis plays a crucial role in
diabetic control, and can prevent further medical complications.
This paper presents the design and development of medical expert system for Diabetes
disease and it support diagnosis, give information about complications and act as diabetes
trainer. It used rule based approach to collect data and forward chaining inference technique.
This system provides a user interactive, menu driven environment. Symptoms and risk factors
associated with diabetes are taken as the basis of this study. In case of diagnosis the system
will ask a bunch of questions about the symptoms and risk factors to the expert system user
and user should give yes or no answer. According to the answer the system will make
judgment about the possibility of illness, how much severe it is like slight chance, moderate
chance, high chance, very high chance, diabetic or not. If the user wants to know the details of
diabetes complications he can select the complication option from the menu. It can also used
in teaching practice.
The system is drawn up with CLIPS expert system building tool version 6.3 and in
Windows/Dos environment.
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
6/123
List of Tables
Table.1: Relation between sugar level and HbA1C 10
Table.2: Diabetic Personal Detail 48
Table 3: Rules employed for ESDD 62
List of Figures
Figure 1: Main components of an expert system 15
Figure 2: Structure of a rule based expert system 16
Figure 3: Hierarchy of expert system development process 46
Figure 4: Decision Flow diagram for Diabetes Diagnosis Expert System. 56
Figure 5: Menu of an Expert System for Diabetes Diagnosis 63
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
7/123
Table of Contents
Abstract .................................................................................................................................... IVList of Tables ..............................................................................................................................VList of Figures .............................................................................................................................V1 INTRODUCTION AND MOTIVATION OF RESEARCH ................................................. 1
1.1. INTRODUCTION ........................................................................................................ 11.2. MOTIVATION OF RESEARCH .................................................................................. 2
2 DIABETES MELLITUS ..................................................................................................... 32.1. DIABETES DISEASE- AN OVERVIEW ..................................................................... 32.2. DIFFERENT TYPES OF DIABETES .......................................................................... 42.3. THE RISK FACTORS OF GETTING DIABETES ....................................................... 52.4. MAIN SYMPTOMS OF DIABETES ........................................................................... 62.5. THE MAIN COMPLICATIONS OF DIABETES ......................................................... 82.6. DIABETES DIAGNOSIS ............................................................................................. 82.7. DIABETES TREATMENT ........................................................................................ 10
3. ARTIFICIAL INTELLIGENCE AND EXPERT SYSTEM ................................................... 113.1. ARTIFICIAL INTELLIGENCE ................................................................................. 113.2. EXPERT SYSTEMS .................................................................................................. 113.3. IMPORTANCE OF EXPERT SYSTEM ..................................................................... 123.4. MAIN COMPONENTS OF AN EXPERT SYSTEM .................................................. 143.5. RULE BASED EXPERT SYSTEMS .......................................................................... 163.6. THE NEED FOR EXPERT SYSTEM ........................................................................ 183.7. LIMITATIONS OF EXPERT SYSTEMS ................................................................... 183.8. EXPERT SYSTEM AND MEDICAL FIELD ............................................................. 20
4. EXPERT SYSTEM BUILDING TOOLS ............................................................................. 214.1. PROGRAMMING LANGUAGES FOR EXPERT SYSTEM ..................................... 214.2. CLIPS- EXPERT SYSTEM TOOL ............................................................................. 22
4.2.1 HISTORY ........................................................................................................... 224.2.2 FEATURES OF CLIPS ....................................................................................... 224.2.3 WORKING WITH CLIPS ................................................................................... 234.2.4 CLIPS PROGRAMMING ELEMENTS .............................................................. 244.2.5 GARBAGE COLLECTION ................................................................................ 39
5. LITERATURE REVIEW ...................................................................................................... 40
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
8/123
5.1. REVIEWED PAPERS ................................................................................................ 40
6. METHODOLOGY................................................................................................................ 456.1. DESCRIPTION OF THE DEVELOPED SYSTEM .................................................... 456.2. EXPERT SYSTEM DEVELOPMENT PROCESS...................................................... 46
7. SUMMARY AND CONCLUSION....................................................................................... 657.1 FUTURE WORK........................................................................................................ 65
APPENDIX (I) ......................................................................................................................... 66PROGRAMMING OF EXPERT SYSTEM FOR DIABETES DIAGNOSIS ......................... 66
LITERATURE CITED ............................................................................................................105ACKNOWLEDGEMENT........................................................................................................107
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
9/123
INTRODUCTION AND MOTIVATION OF
RESEARCH
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
10/123
1 INTRODUCTION AND MOTIVATION OF RESEARCH
1.1. INTRODUCTION
This paper deals with designing and building an Expert System for Diabetes Mellitus
diagnosis which is a common health disorders in many people. This expert system interacts
with user with plain English language where user needs to answer only yes or no. Internally
the system classifies user input as primary symptoms, hereditary symptoms, complication
symptoms, other symptoms to analysis. The expert system uses a score accumulation method
to decide the level of impact of diabetes in individual. The different levels are classified as
slight chance, moderate chance, high chance, very high chance, or already diabetic or not.
Diabetes Mellitus (technical name of diabetes) is a metabolic disorder that affects morethan 100 million people in the world. In India 19.4 million people are suffering with this
chronic condition. Diabetes is a condition which associates with very high glucose level in
the blood. A hormone called insulin, secreted by pancreas helps to move the glucose from
the blood into liver, muscles and fat cells where it is used for fuel. The diabetic person does
not produce enough insulin or the body could not use the insulin properly as it should. It
causes to increase the blood sugar level. This not only harms the cells that need the glucose
for fuel but also harm certain organs and tissues. Diabetes is a serious disease that affects
almost every organ in the body like heart, eyes, kidney, skin, nerves, blood vassals, foot etc.
If left the disease unchecked it will make serious complications including death. Some of
these long-term complications of diabetes could be the damage of blood vessels and nerves,
loss of functioning of the kidneys, blindness, heart disease and strokes, and loss of
sensation. Most of the people, who have diabetes, do not know that they have it and hence
do not treat it till it become very late. There are several symptoms of diabetes. Most of the
people will get some of these symptoms before they know that they are diabetic. But some
people not get any symptoms initially and they come to know that they are diabetic only
after they get some complications. Some of the classical symptoms are excessive thirst,
frequent urination, extreme hunger, feeling tired or fatigue, unexplained weight loss,
sudden vision changes, tingling or numbness in hands or feet, slow healing and infections
than usual, nausea, vomiting, abdominal pain etc. Though the disease can not possible to
cure completely, it can be well managed or control and can lead a very healthy life. Early
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
11/123
Diabetes diagnosis plays a crucial role in diabetic control, and can prevent further medical
complications.
1.2. MOTIVATION OF RESEARCHThe main reason of this research was to introduce the design and development of an expert
system which is able to fully diagnose the very knotty disease diabetes. The system An
Expert system for Diabetes Diagnosis is a medical expert system for diagnosis of the disease
Diabetes using rule based approach and it support diagnosis, give information about
complications and act as diabetes trainer. This system, on the basis of particular knowledge or
rules basis, draws conclusions, takes decisions, and its activity is similar to the human activity
in that sphere. It uses the inference mechanism of forward chaining-reasoning from facts to
the conclusion, resulting from those facts using CLIPS as the programming language. The
expert system provides an interactive way to the user, ask questions about personnel details
and symptoms, to answer whether the diabetes symptom is experienced by the individual or
not. According to the answer given by the person, the system will make judgment about the
possibility of illness, how much severe it is moderate chance or higher chance etc.
This expert system is use to diagnosis for all types of diabetes because nowadays diabetes is a
very common disease in children, youngsters, adults and old people due to a lot of factors like
life style, obesity etc which may be type 1 diabetes or type 2 diabetes .The symptoms of both
types of diabetes are almost similar. If a patient diagnosed as diabetic even the doctors cant
predict from the very beginning that it is type 1 or type 2.They need to examine the patient for
2 to 3 months.(In some cases they can predict from the beginning stage whether type 1 or type
2). So this expert system is a general tool for diagnosis of all type of diabetes.
Since, diabetes diseases are widely spreads in India, the expert system is not meant to replace
the human endocrinologist but users those who are diabetic or under risk will get a thorough
knowledge about diabetes that will help them to take proper treatment against this disease.
This system can be used to help the physician in their work. This expert system initially
evaluated with existing classical test cases. The result of the evaluation was accurate and
promising.
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
12/123
DIABETES MELLITUS
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
13/123
2 DIABETES MELLITUS
2.1. DIABETES DISEASE- AN OVERVIEW
Definition of disease Diabetes Mellitus:
Diabetes Mellitus is a clinical syndrome characterizes by hyperglycemia due to absolute or
relative deficiency of insulin. The lack of insulin affects the metabolism of the body. It causes
to increase the blood sugar level. That is there is not enough insulin to reduce the percentage
of glucose to its normal level.
All the people with diabetes have one thing common. They have too much sugar or glucose in
their blood. This is because a person who intake food is converted into glucose and the body
is unable to remove glucose from the blood and deliver it to the cells as a source of energy in
order to stay alive. A hormone called Insulin, secreted by the pancreas helps to convert
glucose to energy. When a person has diabetes, the body either does not generate enough
insulin or cannot use its own insulin as it should. This will cause sugar to rise in the blood. So
insulin is a key regulator of the body's metabolism. It works in the following way:
During and immediately after a meal the process of digestion breaks down
carbohydrates into sugar molecules (including glucose) and proteins into amino
acids.
Right after the meal, glucose and amino acids are absorbed directly into the
bloodstream, and blood glucose levels rise sharply.
The rise in blood glucose levels signals important cells in the pancreas, called beta
cells, to secrete insulin, which pours into the bloodstream. Within 10 minutes after
a meal, insulin rises to its peak level.
Insulin enables glucose and amino acids to enter cells in the body, particularly
muscle and liver cells. Here, insulin and other hormones direct whether these
nutrients will be burned for energy or stored for future use. As blood glucose levels
reach their peak, the pancreas reduces the production of insulin.
About 2 to 4 hours after a meal, both blood glucose and insulin are at low levels,
with insulin being slightly higher. The blood glucose levels are then referred to as
fasting blood glucose concentrations.
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
14/123
2.2. DIFFERENT TYPES OF DIABETES
There are three types of Diabetes.
Type-1diabetes (Juvenile Diabetes or Insulin dependent diabetes):-In Type I diabetes, the
immune system attacks insulin-producing beta cells in the pancreas and destroys them. With
little or no insulin, the cells are prevented from taking up sugar from the blood. Patients with
type 1 do not make enough insulin and they are treated with insulin to sustain life. Genetic
and environment factors are involved in the development of type 1 diabetes such as
unidentified virus, stimulating an immune attack against the beta cells of pancreas in some
genetically predisposed people. This occurs in youngsters (below 18 years) and older people.
This occurs in older people due to destruction of pancreas by alcohol, disease or removal by
surgery or progressive failure of pancreatic beta cells which produce insulin.
Type 2 diabetes: :( Adult onset Diabetes or Insulin independent diabetes):- Patients with
type 2 do make insulin, but for some reason, the cells in their bodies are resistant to insulins
action or they do not make enough insulin. 90% of all types of diabetes are type 2. It may
involve the following three stages in most patients.
The first stage in type 2 diabetes is the condition called insulin resistance. Certain
mechanisms prevent insulin from moving glucose (blood sugar) into the cells where it can be
used. Thus lowering the rate in which glucose is utilized. Most patients with type 2 diabetes
produce variable, even normal or high, amounts of insulin. In the beginning, this amount is
usually sufficient to overcome such resistance.
Over time, the pancreas becomes unable to produce enough insulin to overcome resistance
and in turn increasing the glucose in the blood leading topre diabetes.It is the condition in
which the blood sugar level is more than the normal level but not reach to the diabetic level.
In type 2 diabetes, the initial effect of this stage is usually an abnormal rise in blood sugar
right after a meal (called postprandial hyperglycemia). This effect is now believed to be
particularly damaging to the body.
Eventually, the cycle of elevated glucose further impairs and possibly destroys beta cells,
thereby stopping insulin production completely and causing full-blown diabetes. This is made
evident by fasting hyperglycemia, in which elevated glucose levels are present most of the
time.
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
15/123
Gestational diabetes:This appears during pregnancy in some women with no previous type-1
or type-2 diabetes and usually goes away after pregnancy. But after pregnancy 5 to 10
percentage of women with gestational diabetes are diagnosed with type 2 diabetes within 10
years. Pregnant women have enough insulin, but the effect of insulin is partially blocked by
other hormones produced in the placentas during pregnancy period. Around 13% of pregnant
women were diagnosed with this form of diabetes, including many who did not have any risk
factors. All pregnant women are tested for gestational diabetes between their 24th and 28th
week.
2.3. THE RISK FACTORS OF GETTING DIABETES
The main causes of diabetes are-
Hereditary and genetics factors
Infections caused by viruses
Stress
Obesity(A weight that is 20% more than ideal body weight)
Increased cholesterol level (HDL (good) cholesterol less than 35 mg/dL or
triglyceride level 250 mg/dL or higher)
High carbohydrate diet
Nutritional deficiency
Excess intake of oil and sugar
No physical exercise
Overeating
Tension and worries
High blood pressure(140/90 mm/Hg or higher)
Insulin deficiency
Insulin resistance
Age 45 or older
African American, Hispanic/Latin American, American Indian and Alaska Native,
Asian American, or Pacific Islander ethnicity
Polycystic ovary syndrome (metabolic disorder that affects female reproductive
system
If you are on high levels of prednisone for asthma or allergies or other autoimmune
diseases, you are very much at risk for diabetes.
A pregnant woman's risk factors include-:
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
16/123
Family history of diabetes
African American, Hispanic, Asian, or Pacific Islander ethnicity
Overweight
Older than 25 years
Gestational diabetes with past pregnancy
Having given birth to a child weighing over 9 pounds
Diagnosis of pre-diabetes
The Risk factors that cannot control
The risk factors that cannot control include:
Family history: If you have a parent, brother, or sister who has type 2 diabetes, you
have a greater chance of developing the disease.
Age. The risk for getting pre diabetes and type 2 diabetes increases with age and the
number of children being diagnosed with type 2 diabetes is increasing. Usually,
children who get type 2 diabetes have a family history of the disease, are overweight,
and are physically inactive.
Race and ethnicity. African Americans, Hispanics, Native Americans, Asian
Americans, and Pacific Islanders are at higher risk than whites for type 2 diabetes.
History of gestational diabetes or having a baby weighing more than 9 lb (4 kg).
Women who have had gestational diabetes or who have had a large baby are at higher
risk for developing type 2 diabetes later in life.
Low birth weight. People who weighed less than 5.5 lb (2.5 kg) at birth are more
likely to develop type 2 diabetes later in life.
Polycystic ovary syndrome (PCOS), a hormone imbalance that interferes with normal
ovulation.
Metabolic syndrome, a group of abnormal physical findings related to the body's
metabolism.
2.4. MAIN SYMPTOMS OF DIABETES
The common symptoms are-
Classic Symptoms
Frequent urination with large volume of urine (poly urea)
Excessive thirst (polydipsia)
Extreme Hunger (polyphagia)
Unusual sudden unexplained weight loss
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
17/123
Increased fatigue
Feeling very tired
Feeling ill
Sudden vision changes or Blurry vision
Nausea
Vomiting
Stomach pain
Other Symptoms
Hair loss or thinning of hair
Leg pain
Sugar in urine
Dry mouth
Irritability
Sleep disorder
Dry or itchy skin
Gestational diabetes
Bladder, Skin, or vaginal infection (in female)
Impotence (in male)Swollen red gums and loosing teeth
Lethargy
Over eating and rapid weight gain
Taking steroid medicine for Asthma
Loss of consciousness
Complication Symptoms
Delayed wound healingBruises that wont go away
Sores that wont heal
Tingling or numbness in hands or legs
A feeling of pins and needles in feet
Unexplained aches and pains
Burning pain in legs, feet, arms
Fruity smell of breath and sweat
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
18/123
2.5. THE MAIN COMPLICATIONS OF DIABETES
Uncontrolled diabetes can harm the nerves in your body causing diabetic neuropathy.
Heart disease, stroke, heart attack are all caused by blockage of blood vessels causing
lack of oxygen in extreme case breakage of blood vessels may happen.
Diabetic retinopathy caused due to blood vessel damage in retina causing lack of
blood circulation thus lack of oxygen to nourish retina and in extreme cause leakage of
blood in retina.
Diabetic Gastroparesis is disorder of stomach that takes too long to empty its contents
it is caused by vagus nerve damage.
Diabetes kidney disease are caused due to small blood vessel of kidney get damaged
due to long run of high blood glucose. Erectile dysfunction or impotence is due to over all nerve damage, and also may be
nerves in penis.
Urinary incontinence, over active bladder, bladder problems are all caused by nerve
damage due to prolonged high blood glucose.
Urinary tract infection is also caused by nerve damage, but it is not directly related
with nerve cause. Due to Diabetic Gastroparesis the food emptying is delayed, thus
bacteria start growing and on it way it causes urinary tract infection. Also due to longterm diabetes immune system loss it capacity thus not able to fight the infection.
Diabetic ketoacidosis is a serious condition in which uncontrolled hyperglycemia
overtime creates a buildup in the blood of acidic waste products called ketones. High
level of ketones is very harmful. This is particularly happens in people with type 1
diabetes who do not have good blood glucose control. Diabetic ketoacidosis is caused
by infections, stress, trauma, missing medications like insulin or medical emergencies
like stroke and heart attack.
2.6. DIABETES DIAGNOSIS
Some diabetic patients will not get any warning sign or symptoms. The only way to be sure is
to have blood test for glucose. The diabetics diagnosis tests include-
Fasting Plasma Glucose: The fasting plasma glucose (FPG) test is the standard test for
diabetes. It is a simple blood test taken after 8 hours of fasting. Results indicate:
FPG levels are considered normal up to 100 mg/dL
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
19/123
Levels between 100 and 125 mg/dL are referred to as impaired fasting glucose or
pre-diabetes. These levels are considered to be risk factors for type 2 diabetes and
its complications.
Diabetes is diagnosed when FPG levels are 126 mg/dL or higher on two or more
tests on different days.
Postprandial blood glucose test (PPB):This test is followed by Fasting plasma glucose test.
Take good amount of food after FPG wait 2 hours, and do the blood test again. Postprandial
glucose level should be under 140 mg/dL. The value between 140 and 199mg/dL indicate pre-
diabetes.200 and above value may indicate diabetes.
Random blood glucose test: A random blood glucose test can also be used to diagnose
diabetes.
A blood glucose level of 200 mg/dl or higher indicates diabetes
The Oral glucose tolerance test:This test is used for diagnosis of type 2. It is still commonly
used for diagnosing gestational diabetes and in conditions of pre-diabetes. With an oral
glucose tolerance test, the person fasts overnight (at least eight but not more than 16 hours).
Then first, the fasting plasma glucose is tested. After this test, the person receives 75 grams of
glucose (100 grams for pregnant women). Blood samples are taken at specific intervals to
measure the blood glucose over a period of three hours. In a person without diabetes, theglucose levels rise and then fall quickly. In someone with diabetes, glucose levels rise higher
than normal and fail to come back down as fast. People with glucose levels between normal
and diabetic have impaired glucose tolerance (IGT). People with impaired glucose tolerance
do not have diabetes, but are at high risk for progressing to diabetes.
Glucose tolerance tests may lead to one of the following diagnoses:
Normal response:A person is said to have a normal response when the 2-hour glucose
level is less than 140 mg/dl, and all values between 0 and 2 hours are less than 200mg/dl.
Impaired glucose tolerance:A person is said to have impaired glucose tolerance when
the fasting plasma glucose is less than 126 mg/dl and the 2-hour glucose level is
between 140 and 199 mg/dl.
Diabetes: A person has diabetes when two diagnostic tests done on different days
show that the blood glucose level is high.
Gestational diabetes: A woman has gestational diabetes when she has any two of the
following: a 100g OGTT, a fasting plasma glucose of more than 95 mg/dl, a 1-hour
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
20/123
glucose level of more than 180 mg/dl, a 2-hour glucose level of more than 155 mg/dl,
or a 3-hour glucose level of more than 140 mg/dl.
Hemoglobin A1C
In the body, sugar sticks with proteins. The red blood cells are a protein that circulates in the
body live for about three months before they die off. When sugar st icks to these cells, it gives
us an idea of how much sugar is around for the preceding three months. In most labs, the
normal range is 4%-5.9 %. In poorly controlled diabetes, its 8.0% or above, and in well
controlled patients it's less than 7.0% (optimal is
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
21/123
ARTIFICIAL INTELLIGENCE AND
EXPERT SYSTEM
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
22/123
3.ARTIFICIAL INTELLIGENCE AND EXPERT SYSTEM
3.1. ARTIFICIAL INTELLIGENCE
Definition of Artificial Intelligence (AI):AI is concerned with the design of intelligence in an artificial device or it is a branch of
computer Science concerned with the automation of intelligent behavior. The term is coined
by Mc. Carthy in 1956.
Artificial intelligence has several areas of interest such as robotics, vision, natural language
understanding and semantic modeling, speech, artificial neural system and parallel
processing, automated reasoning and theorem proving, expert systems, game playing and
human performance modeling.
The term intelligence covers many cognitive skills, including the ability to solve problems,
learn, and understand language; AI addresses all of those. But most progress to date in AI has
been made in the area of problem solving -- concepts and methods for building programs that
reason about problems rather than calculate a solution.
The root of expert system lies in many disciplines. One of the major roots of expert systems is
the area of human informational processing called cognitive science. Cognition is the study of
how human process information or how people think especially when solving problems.
3.2. EXPERT SYSTEMS
Expert system is a branch of Artificial intelligence.
Definition of Expert System:
It is an intelligent computer program that uses knowledge and inference procedures to solve
problems at the level of a human expert. It emulates the decision making ability of a human
expert. That is the expert system is intended to act in all respects like a human expert in a
particular field.
Building an expert system is known as knowledge engineering and its practitioners are called
knowledge engineers. The knowledge engineer must make sure that the computer has all the
knowledge needed to solve a problem. The knowledge engineer must choose a knowledge
representation. He must also ensure that the computer can use the knowledge efficiently byselecting from a handful of reasoning methods.
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
23/123
Typically such a system contains a knowledge base containing accumulated experience and a
set of rules for applying the knowledge base to each particular situation that is described to
the program. The knowledge in expert system may be either expertise or knowledge that is
available from books, journals conferences, magazines, knowledge persons, internet etc.
Expert systems can be classified from different points of view. It can be the advisory systems,
the ones that suggest the direction; systems taking decisions without the help and human
interference; criticizing systems the ones which on the basis of a particular problem and the
predicted solution by a man, analyze and comment the particular reasoning and action way.
A human experts knowledge is specific to one problem domain. A problem domain is the
special problem area such as medicine, finance, science, or engineering. The problem domain
consist many problems. The experts knowledge about solving specific problems is called the
knowledge domain of the expert. In the same way expert systems are designed to address
specific problem in the problem domain, called knowledge domain.
It is important that there is a close cooperation between a system engineer and experts on
those interest fields when constructing the appropriate expert system. Nothing can replace the
knowledge and experts experience.
3.3. IMPORTANCE OF EXPERT SYSTEM
Expert systems have experienced tremendous growth and popularity in all fields like business,
science, engineering, manufacturing, medicine and many other fields. Conventional computer
programs make use of well structured algorithms, data structures for problem solving and use
crisp reasoning strategies to find solutions. The implementation of algorithm in a program is
called procedural program. So the terms algorithmic programming, procedural programmingand conventional programming are often use interchangeably. Problems that cannot solve by
conventional methods, use non conventional or AI method. Expert systems are designed for
problems those have no efficient algorithmic solution and rely on inferences to achieve a
reasonable solution. Such cases are called ill-structured problems that are difficult or
impossible to do by using conventional or procedural or programming. The reasoning may
offer the only hope of a good solution because there may so many possibilities or several
possible inferences. Explanation facility is an integral part of an expert system. The expert
system reasons or makes inferences in the same way that a human expert would infer the
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
24/123
solution of a problem. That is, given some facts, a conclusion that follows is inferred. It must
be able to explain its reasoning to the user so that its reasoning can be checked.
The process of developing an expert system has an indirect benefit also since the knowledge
of human experts must be put into an explicit form for entering into the computer. Because
the knowledge is then explicitly known instead of being implicit in the experts mind, it can
be examined for correctness, consistency and completeness. The knowledge may then have to
be adjusted or re-examined, which improve the quality of the knowledge.
Expert systems have appropriate and inappropriate applications. Most applications of expert
systems will fall into one of the following categories.
Interpreting and identifying
Predicting
Diagnosing
Designing
Planning
Monitoring
Debugging and testing
Instructing and training
Controlling
Conventional computer programs perform job using a decision making logic containing very
little knowledge other than the basic algorithm for solving that specific problem. The basic
knowledge is embedded as part of the programming code, so that as the knowledge changes
the program has to be rebuilt. Knowledge based expert system collect small fragments of
human knowledge into knowledge base, which is used to reason through the problem usingthe knowledge that is appropriate. An important advantage here is that within the domain of
knowledge base, a different problem can be solved using the same program without
reprogramming efforts. Moreover expert systems could explain the reasoning process and
handle level of confidence and uncertainty which conventional algorithms do not handle.
The expert system, having a written expert knowledge from a chosen field, can use many
times in an economic and effective way because it does not need the presence of the expert.
The special advantage of such systems is the possibility of solving the particular tasks without
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
25/123
the direct expert's participation, and also the possibility of knowledge aggregation in one
system of the numerous experts team.
3.4. MAIN COMPONENTS OF AN EXPERT SYSTEM
Figure 1 shows the concept of a knowledge based expert system. The expert system receives
facts from the user and provides expertise in return. The two main components of an expert
system (invisible from outside) are the knowledge base and inference engine.
The knowledge base: It contains the domain knowledge coded in the form of knowledge. It
stores all relevant information, data, rules, cases and relationships used by the expert system.
The knowledge base can combine the knowledge of multiple human experts. A knowledge
base is the nucleus of an expert system structure. A knowledge base is not a data base. Theknowledge base is created by the knowledge engineers who translate the knowledge of real
human experts into rules. In a rule based expert system a knowledge base is usually stored in
terms of if-then rules.
The knowledge baseof expert systems contains both factual and heuristic knowledge.
Factual knowledge is that knowledge of the task domain that is widely shared,
typically found in textbooks or journals, and commonly agreed upon by those
knowledgeable in the particular field.
Heuristic knowledge is the less rigorous, more experiential, more judgmental
knowledge of performance. In contrast to factual knowledge, heuristic knowledge is
rarely discussed, and is largely individualistic. It is the knowledge of good practice,
good judgment, and plausible reasoning in the field. It is the knowledge that underlies
the "art of good guessing." For the difficult problems with which expert system are
concerned it uses heuristics: Strategies that often lead to correct solution, but that also
sometime fail.
The inference engine: The Inference engine may infer solutions or conclusions from the
knowledge base, based on the facts supplied by the user. The inference engine acts as an
interpreter or scheduler that interprets which rules matches with the facts. The word inference
or reasoning is very important in expert system; because reasoning is the standard technique
by which expert system solve problems. It makes inferences by deciding which rules are
satisfied by facts, prioritizes the satisfied rules, and execute the rule with the highest priority.
These conclusions are the expert systems response to the user queries, as the user supplies
facts or other information to the expert system for getting the expertise or expert advice or
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
26/123
response. So the purpose of inference engine to seek information and relationship from the
knowledge base and to provide answers, predictions and suggestions in the way a human
expert would. The inference engine must find the right facts, interpretations and rules and
assemble them correctly. Two types of inference methods are commonly used. Forward
Chaining and backward chaining.
Figure 1: Main components of an expert system
The other components are-
User interface: The mechanism by which the user and the expert system communicate. There
is specialized user interface software available, that can be use to designing, updating and
using expert system. The purpose of user interface is to ease use of expert system for
developers, users and administrators.Explanation facility: The explanation facility allows the user to understand how the expert
system arrived at certain results. That is it explains the reasoning of the system to the user.
Working memory: It is a global database of facts used by the rules. This data is supplied by
the end user.
Agenda: A prioritized list of rules created by the inference engine, whose patterns are satisfied
by facts in working memory.
Knowledge acquisition facility: The overall purpose of knowledge acquisition facility is to
provide a convenient and efficient means for capturing and storing all components of a
knowledge base. It also provides an automatic way for the user to enter knowledge in the
system instead of having the knowledge engineer explicitly code the knowledge. The
knowledge acquisition facility is an optional feature on many systems. Some expert system
tools like KEE (Knowledge engineering Expert) can learn by rule induction through examples
and can automatically generate rules. The examples are generally from tabular or spreadsheet
type data better suited to decision trees. General rules constructed by knowledge engineer can
be much more complex than the simple rules from rule induction. Figure 2 shows the
structure of an expert system
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
27/123
Figure 2 Structure of a rule based expert system
3.5. RULE BASED EXPERT SYSTEMS
The main differences between the expert systems are how they capture and store knowledge
in the knowledge base or knowledge representation in the knowledge base. Knowledge
representation is of major importance in expert system for two reasons. First expert system
shells are designed for certain type of knowledge representation. Second the way in which
expert system represents knowledge affects the development, efficiency, speed andmaintenance of the system.
One of the most popular types of expert system today is the rule based or production rule
system. A rule is conditional statement that links given conditions to actions or outcomes.
Expert systems making use of rules to store knowledge are called rule based expert systems. It
is based on an efficient algorithm called rete pattern matching algorithm for matching facts
against the patterns in rules to determine which rules have had their conditions satisfied. Rete
algorithm performance is theoretically independent of the number of rules in the system and
requires less memory.Rule based expert system use human expert knowledge to solve real
world problems that normally would require human intelligence. Experts knowledge is
represented in the form of rules or as data within the computer. Depending upon the problem
requirement these rules and data can be recalled to solve problems. Knowledge can easily
grow incrementally in a rule based system. That is the knowledge base can grow little by little
as rules are added so that the performance and correctness of the system can be continuously
checked. The incremental growth of knowledge facilitates rapid prototyping so that the
knowledge engineer can quickly show the expert a working prototype of the expert system
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
28/123
This is an important feature because it maintains both the experts and managements interest
in the project rapid prototyping also quickly exposes any gaps, inconsistencies or errors in the
experts knowledge or the system so that corrections can be made immediately. Rule based
expert system have played an important role in modern intelligent system and their
applications in design, planning, scheduling, fault monitoring, diagnosis etc.
A rule based expert system consists of if-then rules, a bunch of facts and an interpreter
controlling the application of rules, given facts. A single if-then rule assumes the form if X is
A then Y is B; if part of the rule X is A is called antecedent or premise and then part of the
rule Y is B is called consequent or conclusion.
Rule based expert systems are popular for a number of reasons.
Modular nature: This makes it easy to encapsulate knowledge and expand the expert
system by incremental development
Explanation facilities: It is easy to build explanation facilities with rules because the
antecedents of a rule specify exactly what is necessary to activate the rule. By keeping
track of which rules have fired, an explanation facility can present the chain of
reasoning that led to a certain conclusion.
Similarity to the human cognitive process: Rules appear to be the natural way of
modeling how humans solve problems. The simple IF.THEN representation of rules
makes it easy to explain to experts the structure of knowledge the knowledge engineer
trying to elicit from them and the process is called knowledge engineering.
Inference Engines in Rule Based Systems
The two broad kinds of inference engines used in rule based expert systems are forward
chining and backward chaining system.
Forward chaining: It starts with the facts and works forward to reach the conclusion. It
involves checking the condition part of the rule to determine whether it is true or false.
If the condition is true then the action part of the rule is also true. This procedure
continues until the solution is found or a dead end is reached. Forward chaining is
commonly referred to as data driven reasoning.
Backward chaining: It is the process of starting with the conclusion and working back-
ward to the supporting facts. It is the reverse of forward chaining. Backward chaining
is very good when all the outcomes are known and the number of possible outcome is
not large. In this case a goal is specified, and the expert system tries to determine what
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
29/123
conditions are needed to arrive at the specified goal. Thus backward chaining is also
called goal-driven reasoning.
3.6. THE NEED FOR EXPERT SYSTEMExpert systems are necessitated by the limitations associated with conventional human
decision-making processes, including:
1. Human expertise is very scarce.
2. Humans get tired from physical or mental workload.
3. Humans forget crucial details of a problem.
4. Humans are inconsistent in their day-to-day decisions.
5. Humans have limited working memory.
6. Humans are unable to comprehend large amounts of data quickly.
7. Humans are unable to retain large amounts of data in memory.
8. Humans are slow in recalling information stored in memory.
9. Humans are subject to deliberate or inadvertent bias in their actions.
10.Humans can deliberately avoid decision responsibilities.
11.Humans lie, hide, and die.
Coupled with these human limitations are the weaknesses inherent in conventional
programming and traditional decision-support tools. Despite the mechanistic power of
computers, they have certain limitations that impair their effectiveness in implementing
human-like decision processes.
Conventional programs:
1. Are algorithmic in nature and depend only on raw machine power
2. Depend on facts that may be difficult to obtain
3. Do not make use of the effective heuristic approaches used by human experts
4. Are not easily adaptable to changing problem environments
5. Seek explicit and factual solutions that may not be possible
3.7. LIMITATIONS OF EXPERT SYSTEMS
Lack of Causal Knowledge
A practical limitation of many expert systems today is lack of causal knowledge. That is, the
expert systems do not really have an understanding of the underlying causes and effects in a
system. The programming using causal knowledge would be an enormous task and even if
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
30/123
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
31/123
recommendations with the same confidence even if the data they are dealing with are
inaccurate or incomplete.
3.8. EXPERT SYSTEM AND MEDICAL FIELDThere already some expert systems are in medical field. Some of them are-
MYCIN: It was the first well known medical expert system developed by Shortliffe at
Stanford University (Buchanan and Shortliffe, 1984) used for diagnosis and remedy bacterial
infections. It uses backward chaining inference procedure. It helps doctors, not expert in
antimicrobial drugs; prescribe such drugs for blood infections. The limitation of MYCIN was
its knowledge base is incomplete since, it does not cover anything like the full spectrum of
infectious diseases. Running it would have required more computing power than most
hospitals could afford at that time (1976). Doctors do not relish typing at the terminal and
require a much better user interface than that provided one.
PERFEX: It is a medical expert system that support solving problems clinicians currently
have in evaluating perfusion studies (Ezquerra et al., 1992). The heart of the PERFEX system
is the knowledge base, containing over 250 rules. They were formulated using the expertise of
clinicians and researchers at Emory University Hospital. PERFEX limitation resides in its
output. It is mostly numerical.
INTERNIST-I: It is a rule-based expert system designed at the University of Pittsburgh in
1974 (Kumar et al., 2009) for the diagnosis of complex problems in general internal
medicine.
ONCOCIN: It is a rule-based medical expert system for oncology protocol management
(Wiederhold et al., 2001) developed at Stanford University. ONCOCIN was designed to assist
physicians with the treatment of cancer patients receiving chemotherapy.
Dxplain: It is a decision support system which uses a set of clinical findings (signs,
symptoms, laboratory data) to produce a ranked list of diagnoses which might explain (or be
associated with) the clinical manifestations (Elhanan et al., 1996). The Dxplain provides
justification for why each of these diseases might be considered, suggests what further clinical
information would be useful to collect for each disease and lists what clinical manifestations,
if any, would be unusual or a typical for each of the specific diseases.
PUFF: It is an expert system for the interpretation of pulmonary function tests for patients
with lung disease. PUFF was probably the first AI system to have been used in clinical
practice.
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
32/123
EXPERT SYSTEM BUILDING TOOLS
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
33/123
4. EXPERT SYSTEM BUILDING TOOLS
4.1. PROGRAMMING LANGUAGES FOR EXPERT SYSTEMExpert systems are typically written in special programming languages. An expert system
language is higher order language than other languages like C or artificial languages like LISP
(List Processing), PROLOG (Program logic) because it is easier to do certain things. Artificial
intelligence languages are mainly used for symbolic processing, but also used for developing
expert system. The specialized nature of expert system languages make them suitable for
writing expert systems but not for general purpose programming.
The major advantage of these languages, as compared to conventional programming
languages, is the simplicity of the addition, elimination, or substitution of new rules and
memory management capabilities. The primary functional difference between expert system
language and procedural languages is the focus of representation. Procedural languages focus
on providing flexible and robust techniques to represent data such as arrays, records, linked
list, stack, queue etc that are easily create and manipulate. In contrast, expert system
languages are providing flexible and robust ways to represent data. It allows two levels of
abstraction-data abstraction and knowledge abstraction. Expert system languages specifically
separate the data from the methods of manipulating the data. An example of this separation is
that of facts (data abstraction) and rules (knowledge abstraction) in a rule based expert system
language. So the expert system language requires less rigid control of the execution sequence.
The inference engine is used to apply the knowledge to the data. But in procedural language
there is a tight interleaving of data and knowledge and programmers must carefully describe
the sequence of execution. In expert system the separation of knowledge and data allows a
higher degree of parallelism and modularity.
Some of the distinguishing characteristics of programming languages needed for expert
systems work are:
Efficient mix of integer and real variables
Good memory-management procedures
Extensive data-manipulation routines
Incremental compilation
Tagged memory architecture
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
34/123
Optimization of the systems environment
Efficient search procedures.
4.2. CLIPS- EXPERT SYSTEM TOOL
4.2.1 HISTORY
CLIPS, an acronym for C Language Integrated Production System, are a computer language
developed by NASAs Johnson Space Center for developing application in expert system.
The origin of the CLIPS(C language integrated production system) was in 1984 and is
designed using C programming language. CLIPS is a productive development and delivery
expert system tool which provides a complete environment for the construction of rule and/or
object based expert systems which includes features such as an integrated editor and adebugging tool. Because of its portability, extensibility, capabilities and low cost it accepted
widely in all fields like government, academia, industry etc. The development of CLIPS has
helped to improve the ability to deliver expert system technology throughout the public and
private sections for a wide range of applications. CLIPS have being used by numerous users
both in public and private sections include military, numerous federal bureaus, government
contractors, universities and many private companies. Originally CLIPS support only rule
based programming.
4.2.2 FEATURES OF CLIPS
Knowledge Representation:CLIPS provides a cohesive tool for handling a wide variety of
knowledge with support for three different programming paradigms: rule-based, object-
oriented and procedural. Rule-based programming allows knowledge to be represented as
heuristics, or "rules of thumb," which specify a set of actions to be performed for a given
situation. Object-oriented programming allows complex systems to be modeled as modular
components (which can be easily reused to model other systems or to create newcomponents). The procedural programming capabilities provided by CLIPS are similar to
capabilities found in languages such as C, Java, Ada, and LISP. So the different ways to
represent in CLIPS are:
Rules: Primarily intended for heuristic knowledge based on experience.
Deffunctions and generic functions: for procedural knowledge.
Object-oriented programming: Primarily for procedural knowledge.
Portability:CLIPS is written in C for portability and speed and has been installed on many
different operating systems without code changes. Operating systems on which CLIPS has
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
35/123
been tested include Windows 95/98/NT, MacOS X, and UNIX. CLIPS can be ported to any
system which has an ANSI compliant C or C++ compiler. CLIPS come with all source code
which can be modified or tailored to meet a users specific needs.
Integration/Extensibility: CLIPS can be embedded within procedural code, called as a
subroutine, and integrated with languages such as C, Java, FORTRAN and ADA. CLIPS can
be easily extended by a user through the use of several well-defined protocols.
Interactive Development:The standard version of CLIPS provides an interactive, text oriented
development environment, including debugging aids, on-line help, and an integrated editor.
Interfaces providing features such as pull down menus, integrated editors, and multiple
windows have been developed for the MacOS, Windows 95/98/NT, and X Window
environments.
Verification/Validation: CLIPS includes a number of features to support the verification and
validation of expert systems including support for modular design and partitioning of a
knowledge base, static and dynamic constraint checking of slot values and function
arguments, and semantic analysis of rule patterns to determine if inconsistencies could
prevent a rule from firing or generate an error.
Fully Documented: CLIPS comes with extensive documentation including a Reference
Manual and a User's Guide.Low Cost:CLIPS is maintained as public domain software.
4.2.3 WORKING WITH CLIPS
The CLIPS interface is a simple, interactive, text oriented, command prompt interface for
high portability. The standard usage is to create or edit a knowledge base using any standard
text editor, exit the editor and execute CLIPS, then load the knowledge base into the CLIPS.
The primitive way of interacting with CLIPS is through CLIPS command prompt. The
interface provides commands for viewing the current state of the system, tracing execution,
adding or removing information, and clearing CLIPS. Comments can be included in CLIPS
code using semicolon. Everything from the semicolon until the next return character will be
ignored by CLIPS.
To start CLIPS, double-click on the CLIPSWin.exe file. Then get a window with nothing in
it but the command prompt CLIPS> comes. This mode is called top level. This is where type
commands and programs. To exit CLIPS, type (exit) or shut down the program like any other
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
36/123
windows application. CLIPS commands are always encased in brackets. Here is a list of some
important commands:
(exit) Shuts down CLIPS
(clear)Removes all rules and facts from memory or all constructs currently contained in
CLIPS. Equivalent to shutting down and restarting CLIPS.
(reset) Removes facts information from memory (but not rules) and resets the agenda.
(run) Starts executing a CLIPS program.
The above commands can also be executed from the CLIPS menu bar.
The primary method for interacting with CLIPS is through the CLIPS command prompt on
top level. When CLIPS> prompt comes, commands can be entered in brackets. Whenever
the user wants to exit from CLIPS type (exit) from the command prompt.
4.2.4 CLIPS PROGRAMMING ELEMENTS
The basic components of CLIPS programming languages are different data types, functions
for manipulating data, and constructs for adding to knowledge base.
Data Types
The different data types available in are float, integer, symbol, string, external-address, fact-
address, instance-name and instance-address.
Floats & Integer: A number consist only of digits (0-9), a decimal point (.), a sign (+ or -)
and an e for exponential notation A number having only digits and its sign (optional) is
called integer and all other numbers are called floats.
Example: integers 123 +98 -135
Floats 1.378 +1.09 33e7
Symbol:A symbol in CLIPS is a sequence of characters that starts with any printable ASCII
character and is followed by zero or more characters. The end of the symbol is reached when
a delimiter is encountered. That is non printable ASCII characters like space, line feed, tabs,
carriage return etc
Example: fire, a81Ad @-+= 2xyz
CLIPS are a case sensitive language. So the symbols fire, Fire, FIRE are considered different
symbols by CLIPS.
String:String is a set of characters that starts and ends with double quotes
Example: a and b number 8
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
37/123
External Address: An external address is an address of an external data structure returned by
a user defined function. That is a function written in language such as C and linked with
CLIPS to add additional functionality.
Fact-address: The fact in CLIPS as referred by facts index; facts index are called fact-
address
Example: where xxx is called index
Instance-name:An object is an instance of a class; an instance-name refers to an object of
the Specified name which is an instance of a user-defined class, instance name is represented
by a symbol enclosed within left and right brackets
Example: [abc] [value-03]
Instance-address: An object is an instance of a class; the address of an instance of user
defined class is called instance-address. It is obtained as the return value from a function.
Example: The instance-address is represented by
Function:Function in CLIPS is a piece of executable codes with specific name which return
useful value or perform useful actions.
Different types of function are user defined functions and system defined functions. System
defined functions are functions internally defined in CLIPS and user defined functions are
functions externally defined to CLIPS environment in C, FORTRAN or Ada etc. and linkedwith CLIPS environment. Using deffunction constructs user can create new functions in
CLIPS; these user function acts like any other functions.
Example: CLIPS> (+3 4)
CLIPS> 7
Constructs: Constructs are defined in CLIPS to change CLIPS environment adding to
CLIPS language base. Constructs form the core of CLIPS program by adding the
programmers knowledge to the CLIPS environment and are different from functions andcommands. Function calls return value but commands never have a return value.
Different constructs available in CLIPS are defmodule, defrule, deffacts, deftemplate,
defglobal, deffunction, defclass, definstances, defmessage-handler, defgeneric, and
defmethod.
Facts: Facts are the first component of a CLIPS system and are made up of fields, which are
symbols, strings, integers or floats. Facts are one of the basic high-level forms for
representing information in CLIPS. The number of facts in the fact list and the amount of
information that can be included in the fact is limited by the memory of computer. CLIPS
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
38/123
operate by maintaining a list of facts and a set of rules which operate on them. A fact is a
piece of information such as (risk_factor smoking) or (risk_factor alcoholic) Facts are
created by asserting them onto the fact database using the assert command .The assert
command return a value called fact index. Example:
CLIPS> (assert (risk_factor smoking))
CLIPS> (assert (risk_factor alcoholic))
The facts command can be used to display the facts in the fact list.
CLIPS> (facts)
f-0 risk_factor smoking
f-1 risk_factor alcoholic
For a total of 2 facts
The term f-0 and f-1 are called fact identifiers assigned to the facts by CLIPS and the
integers following the letter f is called fact index.
The facts command can be used to display the facts in the fact list.
Facts can be retracted from fact data base by using retract CLIPS command
Example:
CLIPS> (retract 0)
CLIPS>(facts)
f-1 (risk_factor alcoholic)
for a total of 1 facts
A single retract command can be used to retract multiple facts at once.
(retract 0 1)
Will retract facts 0 and 1.The symbol * with the retract command would remove all facts
CLIPS>(retract *)
Facts are used to store a chunk of information in CLIPS. In that case facts consist of a relation
name, the first field of fact, is normally used to indicate the type of information stored in the
fact. The relation name (symbolic field) followed by zero or more slots (symbolic fields) and
their associated values. The following is an example of a fact.
(Person (name George)
(age 45)
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
39/123
(gender M)
(height 175)
(weight 80))
Deftemplate construct:It is analogous to the record structure in languages like C or Pascal.
Deftemplate construct is used to assign slot names to specific fields of a fact beginning with a
specified relation name. Before facts can be created, CLIPS must be informed of the list of
valid slots for a given relation name. Group of facts that share the same relation name and
contain common information can be described using the deftemplate construct. So the person
fact can be described with the following deftemplate.
(deftemplate person
(multislot name)
(slot age)
(slot gender)
(slot height)
(slot weight)
)
Slots of a fact that have been specified with the slot keyword in their corresponding
deftemplates are allowed to contain only one value. These are referred to as single field slots.Slots of a fact that have been specified with the multislot keyword in their corresponding
deftemplates are allowed to contain zero or more values and are referred to as multislot fields.
Ordered facts: Facts with a relation name that has a corresponding deftemplate are called
deftemplate facts. Facts with a relation name that does not have a corresponding deftemplate
are called ordered facts. Ordered facts have a single implied multifield slot that is used to
store all values following the relation name. That is whenever CLIPS encounters an ordered
fact it automatically creates an implied deftemplate for that fact. Since an ordered fact hasonly one slot, the slot name is not required when defining the fact.
(number-list 7 9 4 5 6)
It is equivalent in defining the following deftemplate
(deftemplate number-list (multislot values))
And then adding the fact as follos
(number-list (values 7 9 4 5 6))
Normally deftemplate facts use more because the slot name makes the facts more readable
and easier to work with. There are two cases in which ordered facts are useful. First facts
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
40/123
consist of just relation name and used as flags, second for facts containing a single slot, the
slot name is usually synonymous with the relation name.
Slot values of a deftemplate facts can be modified using modify command.
(modify+)
Where is ( )
Eg: CLIPS>(modify 0 (age 24))
The modify commandworks by retracting the original fact and then asserting a new fact
with the specified slot values modified. A new fact index is generated for a modified fact. The
facts in the fact list would be deleted, inserted or modified frequently; some fact indexes
would be missing in the fact list. So the fact identifiers may not be strictly sequential as a
CLIPS program executes.
The duplicate commandworks in the same way as modify command with the exception that
it does not retract the original fact.
(duplicate +)
The deffacts construct:
It is used to assert a set of facts instead of typing in the same assertions from the top level.
This is true for facts that are known to be true before running the program that is initial
knowledge. Groups of facts that represent initial knowledge can be defined using the deffactsconstruct. The general format of deffacts construct is
(deffacts )
The deffacts name is any valid symbol. The facts in the deffacts statement are asserted using
the CLIPS reset command. The reset command removes all facts from the fact list and then
asserts the facts from existing deffacts statement. The syntax is
(reset)
It also create a new fact called initial-fact. Upon startup CLIPS automatically defines twoconstructs.
(deftemplate initial-fact)
(deffacts initial-fact
(initial-fact)
So if not define any deffacts statement, a reset will assert the fact initial-fact. The fact
identifier of initial-fact is always f-0. The utility of initial-fact is to start the execution of a
program.
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
41/123
Components of a Rule: An expert system consists of rules as well as facts. Rules can be type
directly into CLIPS or loaded in from a file of rules created by an editor. Before rules created
the deftemplate for the type of facts referred to by the rules must be defined. Rules can be
entered by typing it after the CLIPS prompt.If the rule entered correctly, the CLIPS prompt
will reappears; otherwise an error message will come. Comments can be including with rules
but it should begin with a semicolon. The general format of the rule is
(defrule []
;LHS of the rule
=>
); RHS of the rule
A rule may have multiple patterns and actions. The entire rule must be surrounded by
parentheses and each of the pattern and actions also must be surrounded by parentheses.
The header of the rule consists of three parts. The rule must start with a defrule keyword,
followed by the name of the rule. If the rule name already exist the new rule replace the old
rule. The third part is an optional comment string. A comment is normally used to describe
the purpose of the rule of any other information.
After the rule header are zero or more conditional elements (CEs).One is the pattern CE orsimply pattern. Each pattern consists of one or more constraints intended to match the fields
of a deftemplate fact. CLIPS attempted to match the pattern of the rule against the facts in the
fact list. If all the pattern of the rule matches facts, the rule is activated and put on the agenda,
the collection of activated rules. There may be zero or more rule in the agenda. The pattern of
the rule follows an arrow indicating the THEN part of the IF. THEN rule.
The last part of rule actions will be executed when the rule fires. A program stops executionwhen there are no rules in agenda. When there are multiple rules on agenda CLIPS
automatically determines which is the appropriate rule to fire. CLIPS orders the rules in
agenda according to priority and execute the rule with highest priority. The priority of the rule
is an integer attribute called salience.
The list of rules on the agenda can be displayed with the agenda command. The syntax of the
agenda command is
CLIPS> (agenda)
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
42/123
Salience:
CLIPS provide salience techniques for controlling the execution of the program. Salience
allows the priority of rules to be explicitly specified. Normally the agenda acts like a stack.
The most recent activation placed on the agenda is the first one to fire. Salience allows most
important rules to be placed on the top of agenda regardless of when the rules were added.
Lower salience rules pushed below the higher salience rules on the agenda. Salience is set
using a numerical value ranging from the smallest value of -10,000 to the highest of
10,000.One of the use of salience is to force rules to fire in sequential fashion. Overuse of
salience results poorly coded program. A well coded expert system needs not more than three
or four salience values.
Halt function:
The halt function can be used on the RHS of the rule to stop the execution of rules on the
agenda. It requires no arguments. When called control will return on the top level prompt. The
halt function is particularly useful for halting execution when the user intends to restart
execution later using the run command.
BIND function:
For storing value in temporary variable to avoid recalculation, the bind function can be used
to bind the value of a variable to the value of an expression. The syntax is(bind )
The bind variable, , uses the syntax of a single field variable. The new value,
should be an expression that evaluates to either a single or a multi field value.
In addition to creating new variables for use on the RHS of the rule, the bind function can also
be used to rebind the value of a variable use in the LHS of the rule.
Printout command: The RHS of the rule can use to print out information using the printout
command. The syntax of printout command is(printout )
Where indicates the output destination of printout command and are zero or more items to be printed by this command.
The letter t after the printout command indicates the destination of the output. This destination
is also referred to as logical name. Normally the logical name t tells CLIPS to send the output
to the standard output device of the computer, usually the terminal. So the default standard
output device can be specified with the logical name t. The standard output device may
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
43/123
something else such as a modem or a printer. In that case other logical names can be used
with the printout command to send the output to other destination other than screen.
Eg:
( defrule smoki ng( decl ar e ( salience 80))?p ( pri nt out t "Do you smoke? N=No Y=Yes" cr l f )( bi nd ?smoke ( r ead) )( whi l e ( and ( neq ?smoke Y) ( neq ?smoke y) ( neq ?smoke N) ( neq ?smoke n) ( neq?smoke Q) ( neq ?smoke q) )( pr i nt out t "You have ent er ed wr ong answer" cr l f
"Pl ease ent er yes or no ( y/ n) . . . " cr l f" i f you need t o qui t ent er q. . . . " cr l f )
(bind ?smoke ( r ead)))
( i f ( or ( eq ?smoke y) ( eq ?smoke Y) ( eq ?smoke N) ( eq ?smoke n) )t hen( - - - - - do requi red thi ng- - - - - )
)( i f ( or ( eq ?smoke y) ( eq ?smoke Y) )t hen ( - - - - - do requi red t hi ng- - - - - ) ) )( i f ( or ( eq ?smoke Q) ( eq ?smoke q) )t hen( halt) )(retract p))
Refraction:
Rules in CLIPS exhibit a property called refraction. It means CLIPS will not permit fire morethan once for a specific set of facts. Without refraction expert system would always caught in
trivial loops. That is as soon as the rule fired, it would keep on firing on that same fact over
and over again. So refraction prevents rules from being constantly activated by old facts. A
rule can be made to fire again by retracting the fact by using reset command and asserting it
again. Suppose two rules are there in agenda for ready to execute. If run command issued the
two rules would be executed and agenda would become empty. After enter agenda command
no rules or activations would be there in the agenda.
A refresh command can be used to make the rule fire again. The refresh command places all
activations that have already fired for a rule back on the agenda with the restrictions that the
facts that triggered the activations are still present in the fact list. The syntax is
(refresh )
Watch Command:
Watch command is useful for debugging programs. The syntax is
(watch )
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
44/123
Where watch is one of the symbols facts, rules, activations, statistics, compilations, focus or
all. By default, when CLIPS is first started, compilations are watched and the remaining
watch items are not watched. The word all can be used to enable all of the watch features.
CLI PS>( f act s)
f - 0 ( person ( name Geor ge)
( age 45)
( gender M)
( hei ght 175)
( wei ght 80) )
For a t ot al of 1 f act.
CLI PS> ( watch f act s)
CLI PS> ( modi f y 0 ( age 35) )
f-1 ( person ( name George)
( age 35)
( gender M)
( hei ght 175)( wei ght 80) )
CLI PS>
The character sequences indicates that the fact is being retracted, the fact is
being created.
CLI PS>( r eset )
CLI PS>( watch act i vat i ons)
CLI PS>( asser t ( r i sk_f act or ( smoki ng) ) )
== >Act i vat i on 0 smoki ng: f - 1
CLI PS>( agenda)
0 smoki ng : f - 1
For a t ot al of 1 acti vat i on.
CLI PS> ( r et r act 1)
< ==Act i vat i on 0 smoki ng: f - 1
CLI PS> ( agenda)
CLI PS>
If rules are being watched, CLIPS will print a message FIRE whenever a rule is fired.CLI PS> ( r eset )CLI PS> ( watch r ul es)
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
45/123
CLI PS> ( asser t ( r i sk_f act or ( smoki ng) ) )== > Act i vat i on 0 smoki ng : f - 1CLI PS> ( r un)FI RE 1 smoki ng: f - 1
CLI PS> ( agenda)CLI PS>
The effects of a watch command can be turned off by using corresponding unwatch command
( unwat ch )
Loading Constructs from a file:
A file of constructs made with a text editor can be loaded into CLIPS using the load
command. The syntax is
( l oad )
Where is a string or symbol containing the name of file to be loaded. While
loading the file the path name also should be specified. Normally the path is represented by
backslash character. But CLIPS consider backslash as an escape character, two backslash are
used to represent one backslash in a string. A file with name example.clp can be loaded as
( l oad c: \ \ user\ \ cl i ps\ \ exampl e. cl p)
If no error occurs during loading the file, the load command will return the symbol TRUE
otherwise return FALSE.
Watching Compilations:
When compilations are watched by default without using watch command, an informational
message including the construct name is printed for each construct loaded by the load
command.
Eg:
CLI PS> ( l oad t hesi s. cl p)Def i ni ng def gl obal : wei ghtDef i ni ng def gl obal : hei ghtDef i ni ng def r ul e: mai n_menu +j +jDef i ni ng def r ul e: per sonal _r ul e +j +jDef i ni ng def r ul e: smoki ng +j +jDef i ni ng def r ul e: al cohol i c +j +jDef i ni ng def r ul e: di agnosi sr ul e +j +jTRUECLI PS>
The message indicates that the above deftemplates and defrules were loaded. The +j string
at the end of the Defining defrule message is information from CLIPS about the internal
structure of the compiled rules.
If compilations are not being watched, then CLIPS prints a single character for each construct
loaded: * for defrule, % for deftemplates and $ for deffacts.
CLI PS> ( cl ear )CLI PS> ( unwatch compi l at i ons)CLI PS> ( l oad "dupl i cat e cl p")
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
46/123
: : : : : : : : %$*****************************************TRUECLI PS>
Saving Constructs to a File:
The save command allows the set of constructs directly entered at the CLIPS prompt to besaved to a disk file. The syntax of the save command is
( save )
( save C: \ dupl i cat e. cl p)
The save command will save all the constructs in CLIPS to the specified file. It is not possible
to save specified files constructs to a file. But if an editor is used to create and modify the
constructs, no need to use the save command.
Commands for manipulating constructs:
Displaying the list of members of a specified construct:
(list-defrules): displays the current list of rules maintained by CLIPS.
(list-deftemplates): displays current list of deftemplates
(list-deffacts): displays the current list of deffacts
CLI PS> ( r eset )
CLI PS> ( l i st- def f acts)
i ni t i al - f act
For a t ot al of 1 def f acts.
CLI PS> ( l i st- def rul es)
CLI PS> ( l i st - def t empl at es)
i ni t i al - f act
For a t ot al of 1 def t empl at e.
CLIPS>
The ppdefrule (pretty print defrule), ppdeftemplate(pretty print deftemplate), ppdeffacts(pretty
print deffacts) commands can be used to display the text representation of a defrule,
deftemplate and deffacts respectively.
( ppdef r ul e )( ppdef t empl at e )( ppdef f act s )CLI PS> ( ppdef r ul e smoki ng)( def r ul e MAI N: : smoki ng
( decl ar e ( salience 80))?p ( pri nt out t "Do you smoke? N=No Y=Yes" cr l f )( bi nd ?smoke ( r ead) )( whi l e ( and ( neq ?smoke Y) ( neq ?smoke y) ( neq ?smoke N) ( neq ?smoke n) ( neq
?smoke Q) ( neq ?smoke q) )( pr i nt out t "You have ent er ed wr ong answer" cr l f"Pl ease ent er yes or no ( y/ n) . . . " cr l f
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
47/123
" i f you need t o qui t ent er q. . . . " cr l f )(bind ?smoke ( r ead)))( i f ( or ( eq ?smoke y) ( eq ?smoke Y) ( eq ?smoke N) ( eq ?smoke n) )
t hen
( - - - - - do requi red thi ng- - - - - ))( i f ( or ( eq ?smoke y) ( eq ?smoke Y) )t hen ( - - - - - do requi red t hi ng- - - - - ) ) )( i f ( or ( eq ?smoke Q) ( eq ?smoke q) )t hen( halt) )(retract p))
The symbol MAIN:: preceeding each of the construct names indicate the module in which the
constructs have been placed. (ppdefacts ) has no text representation since it is
automatically created by CLIPS.Deleting a specified Construct member
The undefrule, undeftemplate and undeffacts commands are used to delete a defrule,
deftemplate and deffacts respectively. The syntaxes are
(undefrule )
(undeftemplate )
(undeffacts )
The initial-facts deffacts and initial-facts deftemplates can also be deleted using the above
commands. If a reset command performed after that, the (initial-fact) would not be added to
the fact list. If a symbol * is given as an argument to any of the construct deletion commands
then all constructs of the appropriate type are deleted.
(undefrule *) would delete all defrule constructs.
Variables:
CLIPS use variables to store values. Variables in CLIPs are written in the syntax of question
mark followed by a symbolic field name. There should be no space between the question
mark and symbolic field name. Variables are used on the LHS of the rule to contain slot
values that can later be compared to other values on the LHS of the rule or accessed on the
RHS of the rule. One common use of variable is to bind a variable on the LHS of the rule and
then use that value on the RHS of the rule. .
?speed
?sensor
?value
I/O functions:
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
48/123
Functions are entered at the CLIPS top level command loop or are used on the LHS or RHS
of the rule. CLIPS provide several I/O functions. The open and close functions can be used to
open and closing files. Opened files are associated with logical names. Logical names can be
used in most functions that perform input and output to more than one type of physical
devices. The printout and read function use logical names. The printout function can output to
the terminal and files. The read function can input from the keyboard and files. The format
function allows more control over the appearance of the output. The readline function can be
used to read an entire line of data.
Read function: This function is used to read information from the keyboard. The read
function is used to input a single field at a time. To read more than one field as input it should
enter in double quotes and treated as strings.
CLI PS>( r ead)
Sout h Af r i ca
Sout h Af r i ca
CLI PS>
Open Function: CLIPS can read from and write to files. Before a file can be accessed for
reading or writing, it must be opened using the open function.
( open [ ] )
is a string representing the name of the file on the computer, is the
logical name CLIPS associates with the file. This is a global name by which CLIPS can
access the file from any rule or the top level prompt. Mostly the logical name would be the
same as file name. It is better to use another name to avoid confusion. argument
represent the access mode. It may be read access only (r),write access only(w), read and
write access(r+), append access only(a). If file access not included as an argument the
default value of r will be used. It return the symbol TRUE if a file successfully opened
otherwise FALSE is returned.Close function: If the file is no need to access for a long time it should be closed.
( cl ose [ ] )
The optional argument is the logical name of the file to be closed. If no
closed all open files will be closed. All open files will be closed when an exit command is
issued.
Reading and Writing to a file:For writing to a file, first the file opened with write access
using open function. Then the values are written to the file using the or logical
name as the first argument of the printout command, follows the values that need to write to
8/12/2019 An Expert System for Diabetes Diagnosis by Smitha V
49/123
the file. Once the value has been written to the file, the file is closed using the close
command.