0% found this document useful (0 votes)
23 views92 pages

11 Knowledge Representation 22-08-2024

Uploaded by

Parth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views92 pages

11 Knowledge Representation 22-08-2024

Uploaded by

Parth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 92

Knowledge

Representation Using
Rule-Based System
The importance of knowledge
representation

• Contrary to the beliefs of early workers in AI, experience


has shown that Intelligent Systems cannot achieve
anything useful unless they contain a large amount of
real-world - probably domain-specific - knowledge.
• Humans almost always tackle difficult real-world
problems by using their resources of knowledge -
"experience", "training" etc.
Introduction to Knowledge
Representation
• Knowledge Representation in AI:
Definition: Knowledge representation is a field in AI
that deals with how knowledge can be stored, structured,
and manipulated by a computer system to solve complex
problems. It’s about modeling the world in a way that a
machine can process.
• Importance in Decision-Making:
Reasoning Processes: Knowledge representation
is crucial for enabling machines to make decisions and
reason about the world. It allows AI systems to interpret
data, draw conclusions, and make predictions based on
the stored knowledge.
Methods of Knowledge
Representation:
• Semantic Networks: Graph-based structures
representing relationships between concepts.
• Frames: Data structures for dividing knowledge into
substructures by representing "stereotyped situations.“
• Logic: Mathematical approach using formal languages
to represent knowledge (e.g., propositional logic, first-
order logic).
• Rule-Based Systems: Use of rules to represent
knowledge in the form of If-Then statements, forming
the basis for inference engines.
Reasoning approach
• What is Forward Chaining?
Forward chaining is a reasoning approach used in rule-based
systems where the inference engine starts with known facts
and applies rules to infer new facts until a goal is reached or
no more inferences can be made. It is a data-driven approach,
as it begins with the available data and uses inference rules
to extract more data until a desired conclusion is reached.
Practical Example: Medical Diagnosis
• Scenario: A simple medical diagnosis system for
determining whether a patient has a cold, flu, or strep throat
based on symptoms.
Goal:
Determine if the patient has strep throat.
What is a Rule-Based System?
• Definition:
A rule-based system is a type of knowledge representation where
rules are used to encode expert knowledge in the form of
If-Then statements. These systems are particularly effective in
domains requiring decision-making, reasoning, and problem-solving.
• Components:
Rules: Fundamental units of knowledge, represented as condition-
action pairs. Example: "If the patient has a fever and a cough, then
consider flu."
Facts: Pieces of information that are known to be true. Example:
"Patient has a fever."
Inference Engine: The core component that processes the rules and
facts to derive new knowledge or reach conclusions.
Working Memory: Temporary storage for facts and intermediate
conclusions generated during the inference process.
• Role in AI:
Expert Systems: Rule-based systems are widely used in
expert systems to simulate the decision-making ability of
a human expert in fields like medicine, law, and finance.
Structure of a Rule-Based System
• Rules:
Definition: Statements that dictate actions based
on conditions. Example: "If the temperature is above
100°C, then turn off the heater.“
• Facts:
Definition: Information known to be true within the
system. Example: "The temperature is 105°C."
• Inference Engine:
Function: The component that applies rules to the
known facts to infer new facts or reach a decision. It
works by either forward chaining (starting from known
facts) or backward chaining (starting from a goal).
• Working Memory:
Purpose: Stores the facts and intermediate
conclusions. It acts as the system's temporary data
storage. Example: During the diagnosis process,
symptoms and possible conditions are stored in working
memory.
Software Solution
Knowledge Base Database

Rule: IF-THEN Fact

Inference Engine

Explanation Facilities

User Interface

User
23
■ The human mental process is internal, and it is too
complex to be represented as an algorithm.
However, most experts are capable of expressing
their knowledge in the form of rules for problem
solving.

IF the ‘traffic light’ is


green THENthe action is go

IF the ‘traffic light’ is


red THEN the action is stop
 Negnevitsky, Pearson Education, 2011

25
Rules as a knowledge representation technique

■ The term rule in AI, which is the most commonly


used type of knowledge representation, can be
defined as an IF-THEN structure that relates given
information or facts in the IF part to some action in
the THEN part. A rule provides some
description of how to solve a problem. Rules are
relatively easy to create and understand.
■ Any rule consists of two parts: the IF part, called
the antecedent (premise or condition) and the
THEN part called the consequent (conclusion or
action).
26
IF antecedent
THEN consequent
■ A rulecan have multiple antecedents joined by the
keywords AND (conjunction), OR (disjunction) or
a combination of both.

IF IF antecedent
antecedent 1 AND 1 OR
ante.cedent 2
. .
ante.cedent 2
AND antecedent OR antecedent
n
THEN consequent THEN consequent
n

27
■ The antecedent of a rule incorporates two parts: an
object (linguistic object) and its value. The object and
its value are linked by an operator.
■ The operator identifies the object and assigns the
value. Operators such as is, are, is not, are not are
used to assign a symbolic value to a linguistic object.
■ Expert systems can also use mathematical operators
to define an object as numerical and assign it to the
numerical value.
IF ‘age of the customer’ <
18 AND ‘cash withdrawal’ >
1000
THEN ‘signature of the parent’
is required 28
Rules can represent relations, recommendations,
directives, strategies and heuristics:
■ Relation
IF the ‘fuel tank’ is
empty THEN the car is dead
■ Recommendation
IF the season is
autumn AND the sky is cloudy
AND the forecast is
drizzle
THEN the advice is ‘take
an umbrella’the car is dead
■ DirectivePearson
 Negnevitsky, the ‘fuel tank’
Education, is empty
2011
IF the action is ‘refuel the car’
AND 29
THEN
■ Str ategy
IF the car is dead
THEN the action is ‘check the fuel tank’;
step1 is complete
IF step1 is complete
AND the ‘fuel tank’ is full
THEN the action is ‘check the battery’;
step2 is complete
■ Heuristic
IF the spill is liquid
AND the ‘spill pH’ <
AND 6
THEN the ‘spill smell’
is vinegar
the ‘spill 30

material’ is
Forward chaining and backward chaining
■. The inference engine compares each rule stored
in the knowledge base with facts contained in the
database. When the IF
(condition) part of the rule matches a fact, the rule
is fired and its THEN (action) part is executed.
■ The matching of the rule IF parts to the facts
produces inference chains. The inference chain
indicates how an expert system applies the rules to
reach a conclusion.

 Negnevitsky, Pearson Education, 2011

31
Forward chaining
■ Forward chaining is the data-driven reasoning.
The reasoning starts from the known data and
proceeds forward with that data. Each time
only the topmost rule is executed. When fired,
the rule adds a new fact in the database. Any rule
can be executed only once. The match-fire cycle
stops when no further rules can be fired.

 Negnevitsky, Pearson Education, 2011

32
Types of Rule-Based Systems
• Forward Chaining:
Process: Starts with known facts and applies rules
to infer new facts until a goal is achieved. Example: In a
medical diagnosis system, starting with symptoms and
applying rules to infer the possible disease.
• Backward Chaining:
Process: Begins with a goal and works backward to
determine the facts needed to achieve that goal.
Example: In legal reasoning, starting with the conclusion
of guilt and determining what evidence is needed to
support this conclusion.
Forward Chaining

Forward chaining or data-driven inference works


from an initial state, and by looking at the
premises of the rules (IF-part), perform the actions
(THEN-part), possibly updating the knowledge base
or working memory.
This continues until no more rules can be applied
Backward Chaining (Cont'd)

Backward chaining or goal-driven inference works towards a final state, and by looking at the
working memory to see if goal already there. If not look at the actions (THEN-parts) of rules that will
establish goal, and set up subgoals for achieving premises of the rules (IF-part).
This continues until some rule can be applied, apply to achieve goal state.
Advantage of backward chaining:search is directed Disadvantage of backward chaining:goal has to
be known
Example of Rule-Based System
• Example: Medical Diagnosis System
Scenario: A system that helps diagnose diseases based on
patient symptoms.
Rules:
• "If a patient has a sore throat and a fever, then suspect a throat
infection."
• "If a patient has a rash and a fever, then suspect measles."
Process:
• The system starts with known symptoms (facts) and applies the rules to
diagnose the disease.
Outcome: The system concludes that the patient may have a
throat infection based on the symptoms provided.
Advantages of Rule-Based Systems
• Easy to Understand and Implement:Rule-based
systems are straightforward to design and implement.
Rules are intuitive and can be easily updated or
modified.
• Transparent Reasoning Process:The decision-
making process is transparent, making it easier to trace
how a particular conclusion was reached. This is
especially important in fields like medicine or law,
where decisions must be explainable.
• Flexibility in Modifying Rules:Rules can be added,
removed, or modified without restructuring the entire
system, allowing for easy maintenance and updates as
Disadvantages of Rule-Based
Systems
• Scalability Issues: As the number of rules increases, the
system can become complex and slow, leading to
performance issues.
• Handling Uncertainty and Conflicting Rules: Rule-based
systems struggle with uncertainty and may have difficulty
resolving conflicts between rules. For example, if two rules
suggest different actions under the same conditions, the
system may not know which to follow.
• Limited Learning Capability: These systems do not learn or
adapt on their own. They rely entirely on predefined rules,
which limits their ability to handle new or evolving situations
without manual updates.
Applications of Rule-Based Systems
• Expert Systems:Medical Diagnosis: Systems like
MYCIN, which assists doctors in diagnosing infections
and recommending treatments based on patient
symptoms.
• Decision Support Systems:Financial Decision-
Making: Systems that assist in making investment
decisions by applying rules to financial data.
• Game AI:Strategic Games: Rule-based logic is used
in games like chess to determine the best possible
moves based on the current game state.
Enhancing Rule-Based Systems
• Incorporation of Fuzzy Logic:Purpose: Handle
uncertainty by allowing rules to operate with degrees of
truth rather than binary true/false values.Example: "If
the temperature is high, then increase the cooling" can
be handled more flexibly with fuzzy logic to account for
varying levels of "high" temperature.
• Integration with Machine Learning:Purpose: Enable
the system to adapt and evolve by learning from data,
allowing for the automatic generation or refinement of
rules.Example: A fraud detection system that learns
new fraud patterns over time and updates its rules
accordingly.
• Use of Meta-Rules:
Purpose: Introduce rules about the rules themselves,
allowing for more sophisticated reasoning and decision-
making processes.
Example: Meta-rules could determine which rule to
apply when multiple conflicting rules are triggered.
Facts (Family Information):

Parent Relationships: Parent Relationships:

•John is a parent of Mary.


•John is male.
•John is a parent of Michael.
•Michael is male.
•Susan is a parent of Mary.
•Peter is male.
•Susan is a parent of Michael.
•David is male.
•Mary is a parent of Jessica.
•Susan is female.
•Mary is a parent of David.
•Mary is female.
•Peter is a parent of Jessica.
•Jessica is female.
•Peter is a parent of David.
•Sibling Rule:
Two people are siblings if they have the same parent and are not
the same individual.
•Father Rule:
A person is the father of someone if they are a parent and are male.
•Mother Rule:
A person is the mother of someone if they are a parent and are
female.
•Grandparent Rule:
A person is a grandparent if they are a parent of someone who is
also a parent.
•Uncle or Aunt Rule:
A person is an uncle or aunt if they are a sibling of a parent of
someone.
•Cousin Rule:
Two people are cousins if their parents are siblings.
Step 1: Starting with Facts
Step 2: Apply Rules
• Rule 1: Father Rule
Apply the father rule: father(X, Y) :- parent(X, Y), male(X).
• Rule 2: Mother Rule
Apply the mother rule: mother(X, Y) :- parent(X, Y), female(X).
• Rule 3: Sibling Rule
Apply the sibling rule: sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y.
• Rule 4: Grandparent Rule
Apply the grandparent rule: grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
• Rule 5: Uncle or Aunt Rule
Apply the uncle or aunt rule: uncle_or_aunt(X, Y) :- sibling(X, Z), parent(Z, Y).
• Rule 6: Cousin Rule
Apply the cousin rule: cousin(X, Y) :- parent(A, X), parent(B, Y), sibling(A, B).
Scenario: Family Relationships

Grandparent Rule: Someone is a


Father Rule: Someone is the Mother Rule: Someone is grandparent if they are the parent
father if they are a parent and the mother if they are a of a parent.
male. parent and female.
Uncle/Aunt Rule: An uncle or Cousin Rule: Two people are cousins
aunt is the sibling of a parent. if their parents are siblings.
Step 3: Inferred Facts
Let’s apply backward chaining to
the same family facts and rules.
• Step 1: Define a Goal
Goal:Find out if Jessica has a grandparent.
grandparent(X, jessica).
• Step 2: Apply the Grandparent Rule
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
grandparent(X, jessica)
parent(X, Z) (X is the parent of Z),
parent(Z, jessica) (Z is the parent of Jessica).
• Step 3: Backtrack through the Parent Facts
Subgoal 1: Find who are the parents of Jessica:
From the facts:parent(mary, jessica) (Mary is Jessica’s
mother).
parent(peter, jessica) (Peter is
• Subgoal 2: Find who are the parents of Mary and Peter (since they
are candidates for Z):
• First, let’s check for Z = mary:
From the facts:parent(john, mary) (John is Mary’s father).
parent(susan, mary) (Susan is Mary’s mother).
Thus, we can infer:
grandparent(john, jessica) (since John is Mary’s parent and Mary is Jessica’s parent).
grandparent(susan, jessica) (since Susan is Mary’s parent and Mary is Jessica’s
parent).

Now, let’s check for Z = peter:


However, there are no facts about Peter’s parents in
the knowledge base, so we cannot infer any more
grandparents through Peter.
• Step 4: ConclusionFrom backward chaining, we infer the
following grandparents of Jessica:
• grandparent(john, jessica) (John is Jessica's grandparent
via Mary).
• grandparent(susan, jessica) (Susan is Jessica's
grandparent via Mary).
Difference between Forward Chaining & Backward Chaining :
S. No. Forward Chaining Backward Chaining
1. Forward chaining starts from known facts and applies Backward chaining starts from the goal and works
inference rule to extract more data unit it reaches to the backward through inference rules to find the required
goal. facts that support the goal.
2. It is a bottom-up approach It is a top-down approach
3. Forward chaining is known as data-driven inference Backward chaining is known as goal-driven technique
technique as we reach to the goal using the available as we start from the goal and divide into sub-goal to
data. extract the facts.
4. Forward chaining reasoning applies a breadth-first Backward chaining reasoning applies a depth-first
search strategy. search strategy.
5. Forward chaining tests for all the available rules Backward chaining only tests for few required rules.
6. Forward chaining is suitable for the planning, Backward chaining is suitable for diagnostic,
monitoring, control, and interpretation application. prescription, and debugging application.
7. Forward chaining can generate an infinite number of Backward chaining generates a finite number of
possible conclusions. possible conclusions.
8. It operates in the forward direction. It operates in the backward direction.
9. Forward chaining is aimed for any conclusion. Backward chaining is only aimed for the required data.

03/12/2024 55
Semantic Net - Reasoning in
Semantic Net
Reasoning in semantic networks allows us to draw
inferences from structured knowledge through:
1.Inheritance Reasoning: Where concepts inherit
properties from parent concepts.
2.Deductive Reasoning: Where we derive conclusions
based on relationships and known rules.
3.Analogical Reasoning: Where we infer properties
based on similarity between concepts.
• These reasoning mechanisms make semantic networks
a powerful tool for knowledge representation and
inference in AI systems.
Inheritance Reasoning

• Inheritance reasoning in a semantic network allows objects or concepts to inherit properties or relationships
from other objects or concepts higher in the hierarchy.

Example:Consider a simple semantic network representing animals:

 Animal has the property can_breathe.

 Mammal is a subclass of Animal and inherits the property can_breathe.

• Dog is a subclass of Mammal and also inherits the property can_breathe.

Reasoning Example:If we query, "Can a dog breathe?", we use inheritance


reasoning to conclude that because a Dog is a Mammal, and Mammal is
an Animal, it inherits the property can_breathe from the Animal node.
Deductive Reasoning
• Deductive reasoning in semantic networks refers to drawing
conclusions based on known rules or relationships between
entities in the network.
Example:Consider the following relationships in a semantic network:
• All birds can fly.
• Penguin is a Bird.
• But Penguin cannot fly.
Reasoning Example:If we query, "Can a penguin fly?",
deductive reasoning shows that although Birds can fly, the
specific property attached to Penguin overrides this general
rule.
Analogical Reasoning
• Analogical reasoning in semantic networks uses
similarity between different nodes to infer properties or
relationships.
Example:Assume the network includes:
• Car has the property has_wheels.
• Bicycle is similar to Car.
Reasoning Example:
• If we query, "Does a bicycle have wheels?", we can
infer this from the fact that a bicycle is similar to a
car and a car has wheels.
Limitations of Semantic Networks
1.Ambiguity:
The simplicity of semantic
networks can lead to ambiguity
when relationships are not clearly
defined.
2.Scalability:
Large semantic networks can
become complex and difficult to
manage as the number of nodes
and relationships increases.
3.Inconsistent Representations:
Relationships can sometimes be
oversimplified, and networks may
not handle complex reasoning,
exceptions, or contradictions well.
Semantic networks have many
advantages, including:
Simplicity: Semantic networks are easy to understand and represent data well.
Space efficiency: Semantic networks can optimize storage requirements.
Good organization: Semantic networks structure related data in a way that's
human and machine-readable.
Understandable meanings: Semantic networks easily represent related words
and concepts to humans.
Knowledge representation: Semantic networks allow knowledge to be
structured to reflect the structure of the world being represented.
Cognitive simulation: Semantic networks model human memory and
reasoning processes, which helps develop AI systems with more human-like
cognitive capabilities.
Natural language processing: Semantic technologies can enhance natural
language processing applications, allowing machines to better understand and
interpret human language.
Applications of Semantic Networks
1.Expert Systems:
Represent knowledge in medical or legal expert systems for
reasoning about diagnoses or legal cases.
2.Natural Language Processing (NLP):
Used to represent meanings of sentences and help in tasks
like word sense disambiguation and semantic analysis.
3.Artificial Intelligence (AI):
Widely used in AI for knowledge representation and
reasoning tasks, particularly for hierarchical categorization
and inheritance.
4.Cognitive Models:
Used in cognitive science to model human memory and
reasoning processes.
Frames and frame systems
• Frames are another form of knowledge representation,
designed to model stereotypical situations. They are
structured data representations containing slots
(attributes) and fillers (values).
Key Components:
• Frames: Represent an object or a situation (e.g., "Car,"
"Person").
• Slots: Represent attributes or features (e.g., "Color,"
"Speed").
• Fillers: Provide values for the slots (e.g., "Color: Red,"
"Speed: 100 km/h").
Description of
Frames
● Each frame represents a class or
either instance. an
● Class frame represents a general concept
whereas instance frame represents a
specific occurrence of the class instance.
● Class frame generally have default values
which can be redefined at lower levels.
● If class frame has actual value facet then
decedent frames can not modify that value.
● Value remains unchanged for subclasses
and instances.
Knowledge Representation
using Frames
● Frames are more structured form of
packaging knowledge,
– used for representing objects, concepts etc.
● Frames are organized into
hierarchies or network of
frames.level frames can inherit
● Lower uppe
information from level frames in network. r
● Nodes are connected using links viz.,
– ako / subc (links two class frames, one of which is
subclass of other e.g., science_faculty class is ako of
faculty class),
– is_a / inst ( connects a particular instance of a class
frame e.g., Renuka is_a science_faculty)
– a_part_of (connects two class frames one of which is
contained in other e.g., faculty class is_part_of
department class).
– Property link of semantic net is replaced by SLOT
● A frame may have any number of slots
needed for describing object. e.g.,
– faculty frame may have name, age, address,
qualification etc
as slot names.
● Each frame includes two basic
elements : slots
– Each slot may contain one or and
facetsfacets.
(called
more fillers)
which may take many forms such
as:
 range (indicates
value (value the
of the range of integer or enumerated
slot),
 values, a slot can
default (default have),
value of the
 demons (procedural attachments such as
slot),
if_needed, if_deleted, if_added etc.) and
 other (may contain rules, other frames, semantic net
or any type of other information).
1. Slots and Values
Slots define specific attributes or characteristics of a
frame.
For example, in a frame representing a "car,"
you might have slots for color, engine type, number of wheels,
etc.
Values within a slot represent the actual data or property for that
attribute. A value can be a constant, a variable, or even
computed dynamically.

frame(car, [
color: red,
wheels: 4,
engine_type: combustion
• 2 Linking to Other Frames
Slots can be used to link one frame to another.
This helps in organizing knowledge hierarchically, modeling
relationships between objects, or inheriting properties.
frame(car, [
wheels: 4,
engine: frame(combustion_engine, [
fuel_type: petrol,
horsepower: 200
])
]).
In this example, the engine slot in the car frame links to
another frame called combustion_engine, which has its
own set of attributes (fuel_type, horsepower).
• Example Use of Slots, Values, and Links
frame(vehicle, [
type: nil, % Slot initially unfilled
wheels: 4, % Default value
engine: nil, % Slot linking to another frame
color: unknown % Value unfilled, could be filled later
]).

frame(car, [
type: sedan,
engine: frame(combustion_engine, [
fuel_type: petrol,
horsepower: 180
])
]).
frame(hotel_room, [
room_number: 101,
room_type: double,
price_per_night: 150,
bed: frame(hotel_bed, [
bed_type: queen,
mattress: frame(mattress, [
size: queen,
firmness: medium,
material: memory_foam
])
]),
chair: frame(hotel_chair, [
chair_type: armchair,
material: leather,
comfort_level: high
]),
phone: frame(hotel_phone, [
phone_type: landline,
service_options: [room_service,
front_desk],
model: 'HotelPro-1000'
])
]).
• Frames can also support inferencing through slot-
filling and default reasoning.
Types of Inferencing in Frames:
1.Default Reasoning: If a slot has a default value, that
value is assumed unless explicitly changed.
1.Example: If the slot "Sound" in a Dog frame defaults to "Bark,"
all dogs can be assumed to bark unless specified otherwise.
2.Slot-Based Inference: Relationships can be inferred
from slot values.
1.Example: If a "Car" frame has a slot "Fuel Type" filled with
"Gasoline," we can infer that the car runs on gasoline.
Frame Network -
Example
university

a_part_of

d e p a rtm e n t h o stel

a _ p a rt_ o f is_a

faculty nilgiri hostel

ako

science_faculty

is_a

renuka
Detailed Representation of Frame
Network fra m e 0

f_name: university
pho ne : (default: - 0 11 6 8 6 9 7 1 )
address : (default - IIT Delhi)

fra m e 1 fra m e 2

f _ n a me : department f _ n a me : hostel
a_part_of : frame0 a_part_of : frame0
p r o g r a m m e : [Btech, Mtech, Ph.D] r o o m : (default - 100)

frame11 frame21

f_name: faculty f _ n a m e : nilgiri


a_part_of : frame1 is_a : frame2
age : range (25 - p h o n e : 0116862345
60)
nationality: (default -
Indian)
qual: (default - Post
graduate)
fra m e 1 2 fra m e 1 3

f _ n a m e : science faculty f _ n a m e : renuka


a ko : frame11 is_a : frame12
qual : (default - M.Sc ) qual :
Ph.D age: 45
adrres s: Janak
Puri
Inheritance in
Frames
● Suppose we want to know nationality or phone
of an instance-frame frame13 of renuka.
● These informations are not given in this frame.
● Search will start from frame13 in upward
direction till we get our answer or have
reached root frame.
● The frames can be easily represented in prolog
by choosing predicate name as frame with two
arguments.
● First argument is the name of the frame and
second argument is a list of slot - facet pair.
Advantages of Frames in Knowledge
Representation
Disadvantages of Frames in
Knowledge Representation

You might also like