Unit 4
Unit 4
AND
EXPERT SYSTEMS (CSE209)
2
Introduction to Expert System:
• An expert system is a computer program that is designed to solve complex problems and to provide
• It performs this by extracting knowledge from its knowledge base using the reasoning and inference
• The expert system is a part of AI, and the first ES was developed in the year 1960, which was the first
successful approach of artificial intelligence. It solves the most complex issue as an expert by extracting
• The system helps in decision making for complex problems using both facts and heuristics like a human
expert. These systems are designed for a specific domain, such as medicine, science, etc.
Components of an Expert System
Expert systems typically consist of the following key components that work together to
simulate expert decision-making:
• Knowledge Base: This is the core of the expert system, where all domain-specific
knowledge is stored. It contains facts, rules, and heuristics (rules of thumb) that
represent the expert's knowledge.
• Inference Engine: This is the processing unit that applies the knowledge stored in the
knowledge base to specific problems. It reasons through the knowledge base to derive
conclusions or recommendations based on the inputs provided by the user.
• User Interface: This allows users to interact with the expert system. Users input
data related to the problem they are trying to solve, and the expert system
returns solutions or suggestions based on the knowledge base and inference
engine.
• Explanation Facility: This component explains the reasoning behind the
system’s conclusions. It helps users understand why certain decisions were
made.
• Knowledge Acquisition Module: This module helps collect and update
information in the knowledge base. It interacts with human experts to gather new
knowledge or refine existing knowledge.
Block diagram that represents the working of an expert system:
Working Process of an Expert System
The expert system operates in a step-by-step process to solve problems and
offer advice:
a. Problem Definition
The user presents a problem or question through the user interface by
providing relevant inputs or answering specific queries posed by the system.
b. Input Interpretation
The system interprets the input provided by the user and matches it with the
relevant facts and rules in the knowledge base. The input is transformed into a
format that can be processed by the system.
c. Knowledge Representation
The system organizes the expert's knowledge in a structured manner (e.g.,
rules, facts, or logical assertions). The knowledge base can be represented in
various formats, such as:
• Rule-based representation: Uses "if-then" rules to represent knowledge. For example,
"If the patient has a fever, then the diagnosis might be an infection."
• Frame-based representation: Organizes knowledge into objects or entities with
associated attributes and values.
• Logic-based representation: Uses formal logic to represent relationships between facts
d. Reasoning (Inference Engine)
The inference engine processes the input and applies the rules in the knowledge base to
draw conclusions. It uses two main reasoning strategies:
• Forward Chaining (Data-driven): Starts with known facts and applies rules to infer new
facts or conclusions. It proceeds by gathering more information and updating its
knowledge until a conclusion is reached. For example, "If X and Y are true, then Z must be
true."
• Backward Chaining (Goal-driven): Starts with a goal or hypothesis and works backward to
see if there is enough evidence to support it. It asks questions or looks for facts that can
confirm or refute the goal. For example, "To prove Z, I need to establish if X and Y are
true."
e. Generating Output
Once the inference engine processes the rules, the expert system presents the
results to the user in the form of recommendations, diagnoses, or solutions.
The system can either provide a single solution or a ranked list of potential
solutions.
f. Explanation
Many expert systems provide explanations for their decisions. The explanation
facility allows the system to explain the reasoning process, helping the user
understand how the conclusion was reached.
g. Learning and Updating (Optional)
Some expert systems include a learning component that allows the
system to learn from new cases and update its knowledge base.
However, traditional expert systems usually require manual
updating by knowledge engineers.
Example of How an Expert System Works
Let’s consider a medical expert system for diagnosing diseases:
• Input: The user inputs symptoms such as fever, cough, and sore throat into
the system.
• Knowledge Base: The system has a knowledge base with rules such as:
• "If a patient has a fever and a sore throat, they might have strep throat."
• "If a patient has a cough and a fever, they might have the flu."
• Inference Engine: The inference engine processes the symptoms and
applies the rules. Based on the input (fever, cough, sore throat), it
concludes that the patient might have the flu or strep throat.
• Output: The system suggests possible diagnoses (flu or strep throat)
and may recommend further tests or treatments.
• Explanation: The system explains its reasoning, stating that the flu is
suggested due to the combination of fever and cough, while strep
throat is considered because of the sore throat and fever.
Some popular examples of the Expert System:
• DENDRAL(Dendritic Algorithm)
It was an artificial intelligence project that was made as a chemical analysis expert system.
It was used in organic chemistry to detect unknown organic molecules with the help of
their mass spectra and knowledge base of chemistry.
• 1960s: Dendral was initiated by Professor Edward Feigenbaum, a computer scientist,
in collaboration with Bruce Buchanan (another computer scientist), and Joshua
Lederberg, a Nobel Prize-winning biochemist.
• The goal was to create a system that could assist chemists in determining the
structure of organic molecules, based on mass spectrometry data.
• Dendral was one of the first AI systems that demonstrated the value of knowledge-
based approaches. Unlike earlier AI efforts that focused on general problem-solving,
Dendral was tailored to a specific domain (chemistry), embedding expert knowledge
directly into the system.
MYCIN:
• It was one of the earliest backward chaining expert systems that was designed to find
the bacteria causing infections like bacteraemia and meningitis. It was also used for the
recommendation of antibiotics and the diagnosis of blood clotting diseases.
• 1970s: Mycin was developed during the early 1970s as a PhD research project by Dr.
Edward Shortliffe under the guidance of AI pioneer Bruce Buchanan at Stanford
University. Mycin was written in LISP.
• Domain: It was designed specifically for diagnosing bacterial infections in blood and
meningitis cases. The focus was on prescribing the right antibiotics based on bacterial
culture results.
PXDES(Pulmonary Expert System):
• It is a medical expert system developed to diagnose lung diseases based on a set of
symptoms and diagnostic tests. It was an evolution of early expert systems like
Mycin and Dendral, applying AI techniques to assist healthcare professionals in
diagnosing pulmonary conditions.
• PXDES was designed to assist doctors in diagnosing diseases related to the lungs,
such as pneumonia, bronchitis, tuberculosis, and other pulmonary infections and
conditions.
• It is an expert system that is used to determine the type and level of lung cancer.
• Like other expert systems, PXDES aimed to simulate the decision-making process of a
• To determine the disease, it takes a picture from the upper body, which looks like the
LISP (LISt Processing) is one of the earliest programming languages used to develop expert systems due to
its excellent support for symbolic reasoning and manipulation, which is essential for AI applications. Here’s
LISP’s primary strength lies in symbolic computation, which allows it to manipulate symbols and lists
effectively. In expert systems, knowledge can be represented as symbols and lists, making LISP a perfect fit
diagnosis(X, Treatment) :-
symptom(X),
treatment(X, Treatment).
Explanation:
The diagnosis rule states that if a person has a symptom X and there is a treatment for that symptom,
then Prolog can infer the appropriate treatment. The system can use this rule to diagnose and suggest a
treatment based on the provided symptoms.
Example query:
?- diagnosis(fever, Treatment). Treatment = 'Take antipyretics'.
3. Backtracking and Query Resolution
Prolog is based on backtracking, meaning that it tries to satisfy a query by attempting
different facts and rules, backtracking when a path fails until it finds a valid solution.
This feature is critical in expert systems, where the system needs to explore multiple
possibilities before arriving at a conclusion.
• Example: Prolog backtracking in action
symptom(fever).
symptom(cough).
symptom(headache).
treatment(fever, 'Take antipyretics').
treatment(cough, 'Take cough syrup').
# Example usage:
symptom = input("Enter the symptom: ")
result = expert_system(symptom)
print("Suggested treatment:", result)
Explanation:
• The system checks the symptom entered by the user and
applies a series of rules to determine the suggested
treatment.
• The logic is implemented using Python's if-else conditional
statements, making it straightforward to encode rules.
2. Knowledge Representation
Knowledge in expert systems can be represented using Python data structures such as
dictionaries, lists, or classes. This helps in organizing the system's knowledge base and
rules more effectively.
Example: Representing rules using dictionaries in Python
rules = {
"fever": "Take antipyretics",
"cough": "Take cough syrup",
"headache": "Take pain relievers"
}
• The decision tree model is trained on this data, and based on new
symptom combination.
4. Integration with Databases
Expert systems often use knowledge bases to store facts and rules.
dynamically.
if result:
print("Suggested treatment:", result[0])
else:
print("No treatment found in knowledge base")
conn.close()
CLIPS
• Overview: CLIPS (C Language Integrated Production System) is a
programming environment designed specifically for building expert
systems. It is a rule-based system written in C, and its focus is on
simplifying the creation and maintenance of expert systems.
• Features:
• Provides a complete environment for building expert systems, including
rule-based reasoning and knowledge representation.
• Efficient and scalable for handling large knowledge bases.
• Supports forward chaining, backward chaining, and object-oriented
programming.
• Usage: CLIPS is widely used in academia, research, and industry for
developing expert systems in fields like decision support and diagnostics.
Java
• Overview: Java is an object-oriented programming language that is often used in the
development of AI applications, including expert systems. Java’s platform independence
and rich ecosystem make it suitable for building cross-platform AI applications.
• Features:
• Libraries like Drools (a rule engine for Java) help in the development of rule-based
systems.
• Strong support for object-oriented design, which is useful for organizing knowledge in
expert systems.
• Cross-platform capability ensures scalability and maintainability of expert systems.
• Usage: Java is used to create expert systems for web-based and enterprise applications,
especially in business rule management systems.
Java is widely used in developing expert systems due to its object-oriented features,
platform independence, and availability of frameworks and libraries that support rule-
based systems and inference engines. Here’s how Java can be employed to develop
expert systems:
1. Object-Oriented Programming (OOP) and Knowledge Representation
In Java, you can represent knowledge using classes, objects, and attributes. These act as
the fundamental components of the expert system's knowledge base. The facts and
rules of the expert system are typically modeled as objects that store data and provide
methods for accessing and manipulating that data.
Example: Representing knowledge as objects
class Symptom {
String name;
public Symptom(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Explanation:
In this case, the Symptom class represents a fact (e.g., symptoms a patient might have). More complex
relationships, such as rules for diagnosis, can be created using additional classes.
2. Rule-Based Inference
In Java, inference engines and rule processing can be implemented using if-else
is a popular rule engine for Java, and it allows you to define and manage business
class Diagnosis {
if (symptom.getName().equals("fever")) {
} else if (symptom.getName().equals("cough")) {
} else {
}}}
Explanation:
Explanation:
This rule triggers if the symptom is identified as "fever" and suggests taking antipyretics.
Drools automatically processes rules and executes the appropriate action.
C/C++
• Overview: C and C++ are not specifically designed for AI but are sometimes used for
expert system development when performance is a critical factor. They provide low-level
control over memory and system resources, making them suitable for high-performance
expert systems.
• Features:
• High performance and control over memory management.
• Can be used for building custom expert system shells or inference engines.
• Extensive libraries for AI and rule-based systems.
• Usage: C/C++ is used for developing expert systems where performance and memory
management are crucial, such as real-time decision-making systems.
C and C++ are general-purpose programming languages widely used
for developing expert systems, especially when performance,
efficiency, and low-level control are required. While they are not
typically designed with built-in features for artificial intelligence (AI)
and expert systems (unlike languages such as LISP or Prolog), their
flexibility, speed, and control over system resources make them a
good choice for building complex expert systems. Here’s how C and
C++ can be used to develop expert systems:
1. Rule-Based Systems in C/C++:
Expert systems rely on rule-based logic to simulate
decision-making. Rules are defined in an "if-then" format,
and C/C++ can represent these rules using conditionals
(if-else statements) or switch-case structures.
Example of a simple rule-based system in C++:
#include <iostream>
using namespace std;
int main() {
string symptom;
cout << "Enter the symptom: ";
cin >> symptom;
expertSystem(symptom);
return 0;
}
2. Knowledge Representation:
In expert systems, knowledge (facts, rules, and logic) needs
to be represented in a way that can be efficiently accessed
and manipulated by the system. In C/C++, you can represent
knowledge using data structures like arrays, struct, classes,
or even more advanced data structures like trees or graphs.
3. Decision Trees in C++:
Decision trees are a common method of decision-making in expert
systems. C/C++ can represent decision trees using tree data structures
(with nodes and branches).
• Expert System GUIs: Many expert system shells (e.g., CLIPS, Jess)
expert systems.
Design of Expert System
Designing an expert system involves a structured process
where a system is built to replicate the decision-making
ability of a human expert in a specific domain. The design
phase includes identifying the problem, acquiring and
structuring knowledge, building and testing the system, and
finally deploying it. Below is a detailed breakdown of the
steps involved in the design of an expert system:
1. Introduction
• An expert system is an artificial intelligence (AI) program
that uses knowledge and reasoning techniques to solve
problems that typically require human expertise.
• The system aims to mimic the decision-making process of
a human expert in specific domains, providing solutions
or recommendations to users.
2. Selecting an Appropriate Problem
The success of an expert system depends on the nature of the problem it
aims to solve. Selecting an appropriate problem involves ensuring that the
problem is:
• Well-structured: It should be a problem with clear inputs, outputs, and
possible solutions.
• Domain-Specific: The problem should belong to a specific, well-defined
field, such as medical diagnosis, financial planning, or troubleshooting.
• Knowledge-Intensive: The problem should require significant expert
• Frequent and Repetitive: The problem should occur frequently so that the
• Goal: Ensure the expert system remains accurate and relevant over time.
• Tasks:
Errors during expert system development can occur at various stages, affecting the overall
performance and reliability of the system:
• Knowledge acquisition errors: Miscommunication between domain experts and
developers can result in incorrect or incomplete knowledge being incorporated into the
system.
• Knowledge representation errors: Inaccuracies in translating expert knowledge into a
machine-readable format may lead to flawed reasoning.
• Inference errors: Faulty inference mechanisms can produce incorrect conclusions if not
tested thoroughly.
• Interface design errors: Poorly designed user interfaces can reduce the usability of the
expert system, leading to low adoption rates.
5. Expert System Life Cycle
Similar to software engineering, expert systems follow a life cycle involving several phases,
including:
• Feasibility study: Evaluating whether the problem is suitable for an expert system solution.
• Knowledge acquisition: Gathering knowledge from experts and other sources.
• Design: Structuring the knowledge and system architecture.
• Development: Coding the system, integrating the knowledge base, and building the
inference engine.
• Testing and validation: Ensuring accuracy, consistency, and performance.
• Deployment: Implementing the system in a real-world setting.
• Maintenance and updating: Regularly updating the system to ensure it remains useful and
accurate.
6. Difficulties in the Development of an Expert System
Developing expert systems can present several challenges:
• Knowledge acquisition bottleneck: Extracting expert knowledge can be difficult
due to the implicit nature of much expert knowledge.
• Complex knowledge representation: Some domains require highly complex
knowledge structures that can be difficult to represent.
• Dynamic knowledge: In rapidly changing fields, maintaining an up-to-date
knowledge base can be a significant challenge.
• Reasoning complexity: Some systems require highly sophisticated reasoning
processes that are computationally intensive or difficult to implement.
7. Pitfalls in Expert Systems
Several pitfalls can hinder the success of expert systems:
• Over-reliance on system output: Users may become over-reliant
on the system’s decisions, leading to errors when the system is
wrong.
• Inflexibility: Expert systems are often rigid and cannot easily
adapt to new, unforeseen problems.
• Narrow scope: Many expert systems are designed for a very
specific domain, limiting their usefulness outside of that area.
• High development costs: Developing expert systems, especially
in knowledge-intensive fields, can be expensive and time-
consuming.