Chapter: 5
Knowledge Representation
knowledge representation 1
Knowledge:
Knowledge is a theoretical or practical understanding of a subject or a domain.
Knowledge is also the sum of what is currently known.
Knowledge is “the sum of what is known: the body of truth, information, and principles
acquired by mankind.” Or, "Knowledge is what I know, Information is what we know.“
Knowledge consists of information that has been:
interpreted,
categorised,
applied, experienced and revised.
In general, knowledge is more than just data, it consist of: facts, ideas, beliefs,
heuristics, associations, rules, abstractions, relationships, customs.
knowledge representation 2
Research literature classifies knowledge as follows:
Classification-based Knowledge - Ability to classify information
Decision-oriented Knowledge - Choosing the best option
Descriptive knowledge - State of some world (heuristic)
Procedural knowledge - How to do something?
Reasoning knowledge - What conclusion is valid in what situation?
Assimilative knowledge - What its impact is?
knowledge representation 3
Knowledge Representation
Knowledge representation (KR) is the study of how knowledge about the world can
be represented and what kinds of reasoning can be done with that knowledge.
Knowledge Representation is the method used to encode knowledge in Intelligent
Systems.
Since knowledge is used to achieve intelligent behavior, the fundamental goal of
knowledge representation is to represent knowledge in a manner as to facilitate
inferencing (i.e. drawing conclusions) from knowledge.
A successful representation of some knowledge must, then, be in a form that is
understandable by humans, and must cause the system using the knowledge to
behave as if it knows it.
knowledge representation 4
Some issues that arise in knowledge representation from an AI perspective are:
How do people represent knowledge?
What is the nature of knowledge and how do we represent it?
Should a representation scheme deal with a particular domain or should it be general
purpose?
How expressive is a representation scheme or formal language?
Should the scheme be declarative or procedural?
knowledge representation 5
Knowledge-Based Agent
•A knowledge based agent consists of a knowledge base (KB) and an inference
engine(IE).
Knowledge-base is a set of sentences of what one knows about the world.
Inference engine derives new sentences from the input and KB.
The agent operates as follows:
1. It receives percepts from environment
2. It computes what action it should perform (by IE and KB)
3. It performs the chosen action.
knowledge representation 6
Properties for Knowledge Representation Systems
The following properties should be possessed by a knowledge representation
system.
Representational Adequacy
the ability to represent the required knowledge;
Inferential Adequacy
the ability to manipulate the knowledge represented to produce new
knowledge corresponding to that inferred from the original.
Inferential Efficiency
the ability to direct the inferential mechanisms into the most productive
directions by storing appropriate guides.
Acquisitional Efficiency
the ability to acquire new knowledge using automatic methods wherever
possible rather than reliance on human intervention.
knowledge representation 7
Knowledge Representation schemes can be classified as below:
•Logical representation Scheme
• Procedural representation Scheme
• Network representation Scheme
• Structured representation Scheme
Logical representation Scheme
It uses expression in the form of formal notation to represent the knowledge base.
Propositional logic and predicate logic are examples of the logical representation
Scheme.
Procedural representation Scheme
These representation schemes constitute rule based expert systems.
If type of light is sunlight then light is bright
If type of light is bulb then light is dim
If location is outdoor then light is sunlight
If location is indoor then light is bulb
knowledge representation 8
Network representation Scheme
Network representation schemes represents knowledge in the form of a graph in which
the nodes represent objects, situations, or events, and the arcs represent the relationships
between them.
Semantic networks, conceptual dependencies and conceptual graphs are examples of
network representation.
Structured representation Scheme
This is the extension of network representation schemes where nodes are complex data
structures consisting of named slots with attached values.
Scripts, frames and objects are examples of structured representation scheme.
knowledge representation 9
Logic Based Knowledge Representation
Propositional Logic:
Propositional logic represents knowledge/ information in terms of propositions.
Propositions are facts and non-facts that can be true or false.
Propositions are expressed using ordinary declarative sentences.
Propositional logic is the simplest logic.
Syntax:
The syntax of propositional logic defines the allowable sentences.
The atomic sentences- the indivisible syntactic elements- consist of single
proposition symbol.
Each such symbol stands for a proposition that can be true or false.
We use the symbols like P1, P2 to represent sentences.
knowledge representation 10
The complex sentences are constructed from simpler sentences using logical
connectives.
There are five connectives in common use:
(negation), ^ (conjunction), (disjunction), (implication), (biconditional)
The order of precedence in propositional logic is from (highest to lowest): , ^ , ,
, .
Propositional logic is defined as:
If S is a sentence, S is a sentence (negation)
If S1 and S2 are sentences, S1 ^ S2 is a sentence (conjunction)
If S1 and S2 are sentences, S1 S2 is a sentence (disjunction)
If S1 and S2 are sentences, S1 S2 is a sentence (implication)
If S1 and S2 are sentences, S1 S2 is a sentence (biconditional)
knowledge representation 11
Formal grammar for propositional logic can be given as below:
Sentence Atomic Sentence | Complex Sentence
Atomic Sentence True | False | Symbol
Symbol P | Q | R …………
Complex Sentence Sentence
| (Sentence ^ Sentence)
| (Sentence Sentence)
| (Sentence Sentence)
| (Sentence Sentence)
Semantics:
Each model specifies true/false for each proposition symbol
Rules for evaluating truth with respect to a model:
S is true if, S is false
knowledge representation 12
S1 ^ S2 is true if, S1 is true and S2 is true
S1 S2 is true if, S1 is true or S2 is true
S1 S2 is true if, S1 is false or S2 is true
S1 S2 is true if, S1 S2 is true and S2 S1 is true
Truth Table showing the evaluation of semantics of complex sentences:
P Q P PQ PQ PQ PQ
false false true false false true true
false true true false true true false
true false false false true false false
true true false true true true true
knowledge representation 13
Examples of PL sentences
P means "It is hot“
Q means "It is humid"
R means "It is raining"
P^Q=>R
"If it is hot and humid, then it is raining"
Q=>P
"If It is humid, then it is hot"
Q
"It is humid."
knowledge representation 14
Properties
• Validity(Tautology)
• Satisfiability (contingency)
• Un-Satisfiability (Contradictory)
• Equivalent
• Entailment
• Completeness
• Soundness
knowledge representation 15
Validity
–A sentence is valid if it is true in all models,
-Valid sentences are also known as tautologies. Every valid sentence is logically
equivalent to True.
Example: Prove[(A→B)∧A]→B is a tautology.
Solution : The truth table is as follows
As we can see every value of [(A→B)∧A]→B is "True", it is a tautology.
knowledge representation 16
Satisfiability
–A sentence is satisfiable if it is true in some model
•E.g., A V A
–Satisfiable sentences are also known as Contingency.
•Example: Prove (A∨B)∧(¬A) a contingency
Solution: The truth table is as follows
As we can see every value of (A∨B)∧(¬A) has both “True” and “False", it is a
contingency
knowledge representation 17
Un-Satisfiability(Contradictory)
–A sentence is un-satisfiable if it is true in no models.
•E.g., A∧¬A
–Un-Satisfiable sentences are also known as contradictory sentences.
•Example: Prove (A∨B)∧[(¬A)∧(¬B)] is a contradiction
Solution: The truth table is as follows:
As we can see every value of (A∨B)∧[(¬A)∧(¬B)] is False, it is a contradiction.
knowledge representation 18
Propositional Equivalences
•Two statements X and Y are logically equivalent if any of the following two conditions
hold :
–The truth tables of each statement have the same truth values.
–The bi-conditional statement X⇔Y is a tautology.
•Example: Prove ¬(A∨B) and [(¬A)∧(¬B)] are equivalent.
Testing by 1st method (Matching truth table)
Here, we can see the truth values of ¬(A∨B) and [(¬A)∧(¬B)] are same, hence the
statements are equivalent.
knowledge representation 19
Testing by 2nd method (Bi-conditionality)
As [¬(A∨B)]⇔[(¬A)∧(¬B)] is a tautology, the statements are equivalent.
knowledge representation 20
Entailment:
–Entailment means that one thing follows from another:
•E.g., x + y = 4 entails 4 = x + y
–Entailment is a relationship between sentences that is based on semantics.
Knowledge base KB entails sentence α if and only if α is true in all worlds where KB
is true.: KB|=α
Soundness:
–An inference algorithm that derives only entailed sentences is called sound or truth
preserving.
Soundness is a highly desirable property.
Completeness:
–An inference algorithm is complete if it can definitely derive any sentence that is
entailed.
knowledge representation 21
Logical equivalence:
Two sentences and ß are logically equivalent ( ß) iff true they are true in
same set of models or Two sentences and ß are logically equivalent ( ß) iff
|= ß and ß |= .
knowledge representation 22
And-elimination
Inference rules in Propositional Logic
Inference rules are the standard patterns of inference that can be applied to derive
conclusions from given facts.
Modus Ponens
And-elimination
Monotonicity: the set of entailed sentences can only increase as information is added
to the knowledge base.
For any sentence and if KB |= then KB |= .
Resolution
Unit resolution rule:
Unit resolution rule takes a clause – a disjunction of literals – and a literal and
produces a new clause. Single literal is also called unit clause.
knowledge representation 23
Where li and m are complementary literals
Generalized resolution rule:
Generalized resolution rule takes two clauses of any length and produces a new clause
as below.
For example:
Resolution Uses CNF (Conjunctive normal form)
Conjunction of disjunctions of literals (clauses)
knowledge representation 24
The resolution rule is sound:
Only entailed sentences are derived
Resolution is complete in the sense that it can always be used to either confirm or
refute a sentence (it can not be used to enumerate true sentences.)
Conversion to CNF:
A sentence that is expressed as a conjunction of disjunctions of literals is said to
be in conjunctive normal form (CNF).
A sentence in CNF that contains only k literals per clause is said to be in k-CNF.
knowledge representation 25
Algorithm:
Eliminate ↔rewriting P↔Q as (P→Q) (Q→P)
Eliminate →rewriting P→Q as PQ
Use De Morgan’s laws to push ¬ inwards:
- rewrite (PQ) as PQ
- rewrite (PQ) as PQ
Eliminate double negations: rewrite P as P
Use the distributive laws to get CNF:
- rewrite (PQ) R as (PR) (QR)
Flatten nested clauses:
- (PQ) R as PQ R
- (PQ) R as PQR
knowledge representation 26
Example: Let’s illustrate the conversion to CNF by using an example.
B (A C)
Eliminate , replacing ß with ( ß)(ß ).
(B (A C)) ((A C) B)
Eliminate , replacing ß with ß.
(B A C) ((A C) B)
Move inwards using de Morgan's rules and double-negation:
(B A C) ((A C) B)
Apply distributivity law ( over ) and flatten:
(B A C) (A B) (C B)
knowledge representation 27
Resolution algorithm
Convert KB into CNF.
Add negation of sentence to be entailed into KB i.e. (KB ).
Then apply resolution rule to resulting clauses.
The process continues until:
There are no new clauses that can be added.
Hence KB does not entail
Two clauses resolve to entail the empty clause.
Hence KB does entail
knowledge representation 28
Example: Consider the knowledge base given as: KB = (B (A C))
B
Prove that A can be inferred from above KB by using resolution.
Solution:
At first, convert KB into CNF
B (A C)) ((A C) B) B
(B A C) ((A C) B) B
(B A C) ((A C) B) B
(B A C) (A B) (C B) B
knowledge representation 29
Add negation of sentence to be inferred from KB into KB
Now KB contains following sentences all in CNF
(B A C)
(A B)
(C B)
B
A (negation of conclusion to be proved)
Now use Resolution algorithm
knowledge representation 30
(B A C) (A B) (C B) B A
(BCB) (ACA) (BAB) (ACC) A
knowledge representation 31
Pros and cons of propositional logic
Propositional logic is declarative
Propositional logic allows partial/disjunctive/negated information
(unlike most data structures and databases)
Propositional logic is compositional:
meaning of B P is derived from meaning of B and of P
Meaning in propositional logic is context-independent
(unlike natural language, where meaning depends on context)
Propositional logic has very limited expressive power
(unlike natural language)
knowledge representation 32
Propositional logic assumes the world contains facts, whereas first-order logic (like
natural language) assumes the world contains:
Objects: people, houses, numbers, colors, baseball games, wars, …
Relations: red, round, prime, brother of, bigger than, part of, comes between,…
Functions: father of, best friend, one more than, plus, …
knowledge representation 33
knowledge representation 34
Representing knowledge in first-order logic
The objects from the real world are represented by constant symbols (a,b,c,...). For
instance, the symbol “Tom” may represent a certain individual called Tom.
Properties of objects may be represented by predicates applied to those objects (P(a),
...): e.g "male(Tom)" represents that Tom is a male.
Relationships between objects are represented by predicates with more arguments:
"father(Tom, Bob)" represents the fact that Tom is the father of Bob.
The value of a predicate is one of the boolean constants T (i.e. true) or F (i.e.
false)."father(Tom, Bob) = T" means that the sentence "Tom is the father of Bob" is
true. "father(Tom, Bob) = F" means that the sentence "Tom is the father of Bob" is
false.
Besides constants, the arguments of the predicates may be functions (f,g,...) or variables
(x,y,...).
knowledge representation 35
Function symbols denote mappings from elements of a domain (or tuples of elements
of domains) to elements of a domain. For instance, weight is a function that maps
objects to their weight: weight (Tom) = 150.Therefore the predicate greater-than
(weight (Bob), 100) means that the weight of Bob is greater than 100. The arguments
of a function may themselves be functions.
Variable symbols represent potentially any element of a domain and allow the
formulation of general statements about the elements of the domain.
The quantifier’s " and $ are used to build new formulas from old ones.
"$x P(x)" expresses that there is at least one element of the domain that makes P(x)
true.
"$x mother(x, Bob)” means that there is x such that x is mother of Bob or, otherwise
stated, Bob has a mother.
" " x P(x)" expresses that for all elements of the domain P(x) is true.
knowledge representation 36
Quantifiers
Allows us to express properties of collections of objects instead of enumerating objects
by name. Two quantifiers are:
Universal: “for all” "
Existential: “there exists” $
Universal quantification:
"<Variables> <sentence>
Eg: Everyone at UAB is smart:
"x At(x,UAB) Smart(x)
"x P is true in a model m iff P is true for all x in the model
knowledge representation 37
Roughly speaking, equivalent to the conjunction of instantiations of P
At(KingJohn,UAB) Smart(KingJohn) At(Richard,UAB)
Smart(Richard)At(UAB,UAB) Smart(UAB) ...
Typically, is the main connective with "
– A universally quantifier is also equivalent to a set of implications over all
objects
Common mistake: using as the main connective with ":
"x At(x, UAB) Smart(x)
Means “Everyone is at UAB and everyone is smart”
knowledge representation 38
Existential quantification
$<variables> <sentence>
Someone at UAB is smart:
$x At(x, UAB) Smart(x)
$x P is true in a model m iff P is true for at least one x in the model
Roughly speaking, equivalent to the disjunction of instantiations of P
At(KingJohn,UAB) Smart(KingJohn)At(Richard,UAB) Smart(Richard)
At(UAB, UAB) Smart(UAB) ...
Typically, is the main connective with $
Common mistake: using as the main connective with $:
$x At(x, UAB) Smart(x) is true even if there is anyone who is not at UAB!
knowledge representation 39
FOPL: Semantic
An interpretation is required to give semantics to first-order logic. The interpretation
is a non-empty “domain of discourse” (set of objects). The truth of any formula
depends on the interpretation.
The interpretation provides, for each:
constant symbol an object in the domain
function symbols a function from domain tuples to the domain
predicate symbol a relation over the domain (a set of tuples)
Then we define:
universal quantifier ∀xP(x) is True iff P(a) is True for all assignments of domain
elements a to x
existential quantifier ∃xP(x) is True iff P(a) is True for at least one assignment
of domain element a to x
knowledge representation 40
FOPL: Inference (Inference in first-order logic)
First order inference can be done by converting the knowledge base to PL and using
propositional inference.
– How to convert universal quantifiers?
– Replace variable by ground term.
– How to convert existential quantifiers?
– Skolemization.
Universal instantiation (UI)
Substitute ground term (term without variables) for the variables.
For example consider the following KB
" x King (x) Greedy (x) Evil(x)
King (John)
Greedy (John)
Brother (Richard, John)
knowledge representation 41
It’s UI is:
King (John) Greedy (John) Evil(John)
King (Richard) Greedy (Richard) Evil(Richard)
King (John)
Greedy (John)
Brother (Richard, John)
Note: Remove universally quantified sentences after universal instantiation.
Existential instantiation (EI)
For any sentence and variable v in that, introduce a constant that is not in the KB (called
skolem constant) and substitute that constant for v.
E.g.: Consider the sentence, $ x Crown(x) OnHead(x, John)
After EI,
Crown(C1) OnHead(C1, John) where C1 is Skolem Constant.
knowledge representation 42
Unification
A unifier of two atomic formulae is a substitution of terms for variables that makes
them identical.
- Each variable has at most one associated term
- Substitutions are applied simultaneously
Unifier of P(x, f (a), z) and P(z, z, u) : {x/ f (a), z/ f (a), u/ f (a)}
We can get the inference immediately if we can find a substitution such that
King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
Unify( ,) = if =
p q
Knows(John,x) Knows(John,Jane) {x/Jane}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}
Knows(John,x) Knows(x,OJ) {fail}
Last unification is failed due to overlap of variables. x can not take the values of John
and OJ at the same time.
We can avoid this problem by renaming to avoid the name clashes (standardizing
apart)
E.g.
Unify{Knows(John,x) Knows(z,OJ) } = {x/OJ, z/John}
Another complication:
To unify Knows(John,x) and Knows(y,z),
Unification of Knows(John,x) and Knows(y,z) gives ={y/John, x/z } or ={y/John,
x/John, z/John}
knowledge representation 44
First unifier gives the result Knows(John,z) and second unifier gives the result
Knows(John, John).
Second can be achieved from first by substituting john in place of z. The first unifier is
more general than the second.
There is a single most general unifier (MGU) that is unique up to renaming of variables.
MGU = { y/John, x/z }
knowledge representation 45
Applying Resolution Refutation
•Negate query to be proven (resolution is a refutation system)
•Convert knowledge base and negated query into CNF and extract clauses
•Repeatedly apply resolution to clauses or copies of clauses until either the empty
clause (contradiction) is derived or no more clauses can be derived (a copy of a clause
is the clause with all variables renamed)
•If the empty clause is derived, answer ‘yes’ (query follows from knowledge base),
otherwise answer ‘no’ (query does not follow from knowledge base)
Conversion to CNF:
1. Eliminate implications and bi-implications as in propositional case
2. Move negations inward using De Morgan’s laws
plus rewriting ¬∀xP as ∃x¬P and ¬∃xP as ∀x¬P
3. Eliminate double negations
4. Rename bound variables if necessary so each only occurs once
e.g. ∀xP(x)∨∃xQ(x) becomes ∀xP(x)∨∃yQ(y)
5. Use equivalences to move quantifiers to the left
e.g. ∀xP(x)∧Q becomes ∀x (P(x)∧Q) where x is not in Q
e.g. ∀xP(x)∧∃yQ(y) becomes ∀x∃y(P(x)∧Q(y))
6. Skolemise (replace each existentially quantified variable by a new term)
∃xP(x) becomes P(a0) using a Skolem constant a0 since ∃x occurs at the
outermost level
∀x∃y P(x, y) becomes P(x, f0(x)) using a Skolem function f0 since ∃y occurs
within ∀x
knowledge representation 47
7. The formula now has only universal quantifiers and all are at the left of the formula:
drop them
8. Use distribution laws to get CNF and then clausal form
knowledge representation 48
Resolution: Examples
1.) ⊢ ∃x (P(x)→∀xP(x))
Solution:
Add negation of the conclusion and convert the predicate in to CNF:
(¬∃x(P(x)→∀xP(x)))
1, 2. ∀x¬(¬P(x)∨∀xP(x))
2. ∀x (¬¬P(x)∧¬∀xP(x))
2, 3. ∀x (P(x)∧∃x¬P(x))
4. ∀x (P(x)∧∃y ¬P(y))
5. ∀x∃y(P(x)∧¬P(y))
6. ∀x (P(x)∧¬P( f (x)))
8. P(x), ¬P( f (x))
_______________________
Now, we can use resolution as;
1. P(x) [¬ Conclusion]
2. ¬P( f (y)) [Copy of ¬ Conclusion]
3. _ [1, 2 Resolution {x/ f (y)}]
Example of resolution refutation
KB:
1. Anyone passing his history exams and winning the lottery is happy.
2. Anyone who studies or is lucky can pass all his exams.
3. John did not study but John is lucky.
4. Anyone who is lucky wins the lottery.
query: ―Is John happy?
Use the resolution refutation algorithm to answer the given query.
knowledge representation 52
Translate the following four English sentences to first order logic (FOL).
1. Anyone passing his history exams and winning the lottery is happy.
2. Anyone who studies or is lucky can pass all his exams.
3. John did not study but John is lucky.
4. Anyone who is lucky wins the lottery.
knowledge representation 53
Convert them to conjunctive normal form (CNF).
Then: drop the “for all” quantifiers
knowledge representation 54
Then: move the negation inwards
knowledge representation 55
Then: distribute the “ors”
knowledge representation 56
Then: separate the “and” sentences into
individual sentences
Q. (Query to be proved)
knowledge representation 57
Now resolution of 1 and Q gives
5.
Now resolution of 2 b and 5 gives
6.
Now resolution of 4 and 6 gives
7.
Now resolution of 7 and 3 b gives
Hence John is happy.
knowledge representation 58
Semantic Network
• A semantic net (or semantic network) is a knowledge representation technique used for
propositional information. So it is also called a propositional net.
• Mathematically a semantic net can be defined as a labeled directed graph.
• Consist of:
–nodes,
–links (edges) and
–link labels.
Nodes:
In the semantic network diagram, nodes appear as circles or ellipses or rectangles to
represent objects such as physical objects, concepts or situations.
Links:
–appear as arrows to express the relationships between objects.
Link labels:
–specify particular relations. Relationships provide the basic structure for organizing
knowledge.
knowledge representation 59
Represent the following fact in semantic network
–Tom is a cat.
–Tom caught a bird.
–Tom is owned by John.
–Tom is ginger in color.
–Cats like cream.
–The cat sat on the mat.
–A cat is a mammal.
–A bird is an animal.
–All mammals are animals.
–Mammals have fur.
knowledge representation 60
knowledge representation 61
Object-based Approach: Frames
With this approach, knowledge may be represented in a data structure called a frame.
A frame is a data structure containing typical knowledge about a concept or object.
A frame represents knowledge about real world things (or entities).
Each frame has a name and slots.
Slots are the properties of the entity that has the name, and they have values or pointer to
other frames ( a table like data structure).
A particular value may be:
- a default value
- an inherited value from a higher frame
- a procedure to find a value
- a specific value, which might represent an exception.
62
When the slots of a frame are all filled, the frame is said to be instantiated, it now represents
a specific entity of the type defined by the unfilled frame.
Empty frames are sometimes called object prototypes.
The idea of frame hierarchies is very similar to the idea of class hierarchies found in object-
orientated programming.
Frames are an application of the object-oriented approach to knowledge-based systems.
Disadvantages
- complex
- reasoning (inference) is difficult
-explanation is difficult, expressive limitation
Advantages
- knowledge domain can be naturally structured (a similar motivation as for the O-O
approach).
- easy to include the idea of default values, detect missing values, include specialized
procedures and to add further slots to the frames
63
64