Knowledge Representation Techniques
Knowledge Representation Techniques
11/15/2021 1
In order to solve complex AI problems, a large amount of knowledge and some
mechanisms for manipulating that knowledge both are required
forward representation
English
Representations
11/15/2021 2
Fact represented by English sentence: Tommy is a dog
From these above two facts the following can be inferred: hastail(Tommy)
11/15/2021 3
The meaning of knowledge is closely related to the meaning of intelligence .
Characteristic of intelligent people is that they possess much knowledge.
Knowledge may be declarative or procedural.
Heuristic, that is another special type of knowledge, used by humans to solve complex
problems.
knowledge is defined as a set of rules & facts
A fact is always unconditionally true.
rule is true if some condition is satisfied. Rules have:
a) a condition part (right hand side)
b) a conclusion part (left hand side)
c) : - means if
d) a rule is read as if right hand side is true then left hand side is true, or
left hand side is true if right hand side is true.
Example pam tom
ann
11/15/2021 4
A good knowledge representation system should possess the following properties:
11/15/2021 5
One of the most useful forms of inference is property inference, where elements of
specific classes inherit attributes & values from more general classes in which they
are included
11/15/2021 6
handed
Person Right
Isa
Adult-
5-10
Male height
Isa
height 6-1
Baseball
-Player Bat avg.
Isa Isa
.252
Bat Avg. Bat Avg.
.106 Pitcher Fielder .262
instance
instance
team team
Team 1 A B Team 2
11/15/2021 7
Apart from property inheritance, all the power of traditional logic is necessary for
inference
11/15/2021 8
All the knowledge so far discussed have concentrated on relatively static facts
The most common way is simply as code (in PROLOG/ LISP) for doing something
11/15/2021 9
One particular way of representing knowledge – principles of logic
A logic involves
▪ a language
▪ Inference rules for manipulating sentences
▪ Semantics for associating elements of the language with elements of some subject matter
Propositional calculus and First Order Predicate Calculus are said to be played an
important role for representing knowledge
11/15/2021 10
Propositions are elementary atomic sentences that may be either true or false, but
may take on no other values
This syntax governs the combination of the basic building blocks of propositional
calculus, such as propositions and logical connectives
11/15/2021 11
Elements of the Propositional calculus are as follows:
❑ Atoms: countably infinite set of those strings of characters that begin with a
capital letter, e.g. P, Q, R, ….., P1 and so on, including two special atoms T & F
❑ Connectives: ∨, ∧, ¬, →, ↔
11/15/2021 12
Meaning of a sentence is just the value true/ false, i.e. it’s an assignment of a
truth value to the sentence
Example: for sentence like (P & ¬Q), one interpretation (I1) assigns T to P and F to
Q, whereas another interpretation (I2) assigns T to P and T to Q.
Once an interpretation has been given to a sentence, its truth value can be
determined
11/15/2021 13
Rule no. True Sentences False Sentences
1. T F
2. ¬f ¬t
3. t ∧ t’ f∧a
4. t∨a a∧f
5. a→t t→f
6. f→a t↔f
7. t↔t’ f↔t
Here, t and t’ denote any two true sentences, f and f’ denote any two false
sentences, a is any sentence
11/15/2021 14
Find the meaning of the sentence ((P∧¬Q) →R) ∨Q for some instance I
11/15/2021 15
Satisfiable: if there is some interpretation for which the sentence is true
e.g. P is satisfiable
Valid: if is true for every interpretation. Valid sentences are also called tautologies
e.g. P ∨ ¬P is a valid sentence
Equivalence: two sentences are equivalent if they have the same truth value under
every interpretation
e.g. P → Q and ¬P ∨ Q are equivalent with each other
11/15/2021 16
Inference rules provide the means for logical proofs or deductions
The problem is to prove the truth of S ( the conclusion) from a given set of
sentences S’ = {s1, s2, …., sn} ( Premises).
11/15/2021 17
A literal is an atom in either positive form or negative form
The atom λ is the atom resolved upon and the said process is called resolution
11/15/2021 18
Resolving R ∨ P and ¬P ∨ Q yields R ∨ Q . This can also be proved by rule of
chaining. So it can be said that chaining is a special case of resolution
11/15/2021 19
An arbitrary wff ω can be inferred from a set of clauses ∆ by resolution as
follows:
❑ Convert the wffs in ∆ to CNF
❑ Iteratively apply resolution to the clauses in Γand add the results to Γ either
until there are no more resolvents that can be added or until the empty clause
is produced
11/15/2021 20
A wff written as a conjunction of disjunction of literals is said to be in CNF
Let’s convert a wff ¬(P→Q) ∨ (R → P) to CNF as follows:
11/15/2021 21
Consider a robot that is able to lift a block, if the block is liftable, i.e. not too
heavy, and if the robot’s battery power source is adequate. If both of these
conditions are satisfied, then when the robot tries to lift a block it is holding, its
arm moves.
Given set of wffs are as follows:
1. BAT_OK, 2. ¬MOVES, 3. (BAT_OK ∧LIFTABLE)→MOVES
11/15/2021 22
It does not permit to make generalized statements about classes of similar objects
It lacks the structure to express relations that exist among 2 or more entities
e.g. In propositions about toy blocks, ON_A_B and ON_B_C are completely different
with absolutely nothing in common
A new language is required that has names for the objects about which we want to
state propositions and names for the propositions we want to state
11/15/2021 23
The predicate calculus has symbols like object constants, relation constants and
function constants
11/15/2021 24
An object constant is a term, also called as individuals
11/15/2021 25
A relation constant of arity n, followed by n terms in parentheses and separated
by commas is an atom.
An atom is a wff
If P & Q are two wffs, then ¬P, P ∧ Q, P V Q, P→Q, ∀x P(x), ∃x P(x) are also wffs
11/15/2021 26
Consider the blocks world where there exist objects A, B, C, and Floor
Let’s consider two relations ON & CLEAR among these objects
ON is a binary relation, whereas CLEAR is unary
Let’s assume that the following configuration of blocks hold:
B
A
C
11/15/2021 27
When an assignment of values is given to each term and to each predicate symbol
in a wff, then it is called an interpretation
The set of objects to which assignments are made is called the domain of the
interpretation
If the truth values for 2 different wffs are same under every interpretation, then
they are said to be equivalent
11/15/2021 28
Let’s suppose it is needed to mention that every object in the domain has a
certain property/ participated in a certain relation
Let’s again suppose that we want to mention that at least one object in the
domain has a certain property
New syntactic entities for this purpose is required, like variable symbols and
quantifier symbols
11/15/2021 29
Variable symbols: infinite set consisting of strings beginning with lowercase
letters. Variable symbol is also a term
If ω is a wff and ξ is a variable symbol, then both (∀ξ)ω and (∃ξ)ω are also wffs
Universal quantifier: (∀ξ)ω(ξ) has the value true just in case ω(ξ) has the value
true for all assignments of the variable symbol ξ to objects in the domain
Existential quantifier: (∃ξ)ω(ξ) has the value true just in case ω(ξ) has the value
true for at least one assignment of the variable symbol ξ to objects in the domain
In the version of the predicate calculus, which is called FOPL, use quantification
over variable symbols
2nd or higher order predicate calculus allow quantification over relation and
function symbols
11/15/2021 30
Evaluate the truth value of the following expression:
11/15/2021 31
Represent the following English sentences in FOPL form:
E1: all employees earning $1400/ more per year pay taxes
11/15/2021 32
Let’s define the following relations & functions:
11/15/2021 33
Marcus was a man.
Marcus was a Pompeian.
All Pompeian were Roman.
Caesar was a ruler.
All Romans were either loyal to Caesar or hated him.
11/15/2021 34
Man (Marcus).
Pompeian (Marcus).
∀x: Pompeian (x) → Roman (x).
Ruler (Caesar).
∀x:Roman (x) → loyalto (x, Caesar) ∨ hated (x, Caesar).
∀x:∃y:loyalto (x, y).
∀x: ∀y: Person (x) ∧ Ruler (y) ∧ tryassassinate (x, y) → ¬loyalto (x, y)
tryassassinate (Marcus, Caesar).
11/15/2021 35
Eliminate implication signs like propositional calculus
❑ If existential quantifiers occur within the scope of universal quantifier, then the
value that satisfies the predicate may depend on the values of universally
quantified variable
❑ e.g. (∀x)[(∃y)Height (x, y)] means” every person, x, has a height y”. It can be
written as by eliminating existential var, (∀x) Height (x, h(x)), where h(x) is a
skolem function that maps each value of x into the y that exists.
11/15/2021 36
Convert to prenex form
❑ The resulting wff is said to be in prenex form, where a wff consists of a string
of quantifiers called a prefix, followed by quantifier free formula, called a
matrix.
❑ e.g. (∀x)(∀y){¬P(x) ∨{[¬P(y) ∨P(f(x, y))] ∧[Q(x, h(x)) ∧¬P(h(x))]}}
Put the matrix in CNF by repeatedly using one of the distributive rules, namely, by
replacing expressions of the form ω1 ∨ (ω2 ∧ ω5) by (ω1 ∨ ω2) ∧(ω1 ∨ ω5)
❑ When the matrix of the preceding example put in CNF, we have the following:
(∀x)(∀y){[¬P(x) ∨¬P(y) ∨P(f(x, y))] ∧[¬P(x) ∨ Q(x, h(x))] ∧[¬P(x) ∨¬P(h(x))]}
11/15/2021 37
Eliminate universal quantifiers.
Eliminate ∧ symbols.
❑ It is now possible to eliminate the explicit occurrence of ∧ symbols by replacing
expressions of the form (ω1 ∧ ω2) with the set of wffs {ω1, ω2}.
11/15/2021 38
In propositional logic, it’s easy to determine that two literals can’t be true both at
the same time
But in FOPL, this matching process is more complicated since the args of the
predicates must be considered
e.g. man (John) & ¬man (John) is a contradiction, whereas man (John) & ¬man (Spot) is not
If the predicate symbols match, then the args are checked one pair at a time
1. 2 instances of P match
2. Now x & y are compared, required substitution is y/x, i.e. substitute y for x
and the result is P(y, y), P(y, z)
3. Now y & z are compared, and the substitution required is z/y and the result is
P(z, z), P(z, z)
4. Therefore, the unification process has succeeded with the composition of the
following 2 substitutions: (z/y) (y/x)
11/15/2021 40
Resolve the following clauses:
1. Man (Marcus)
2. ¬Man (x1) ∨Mortal (x1)
11/15/2021 41
Let’s consider the following wffs in FOPL:
Man (Marcus).
Pompeian (Marcus).
∀x: Pompeian (x) → Roman (x).
Ruler (Caesar).
∀x:Roman (x) → loyalto (x, Caesar) ∨ hated (x, Caesar).
∀x:∃y:loyalto (x, y).
∀x: ∀y: Man (x) ∧ Ruler (y) ∧ tryassassinate (x, y) → ¬loyalto (x, y)
tryassassinate (Marcus, Caesar).
With this set of wffs as knowledge base prove the sentence “Did Marcus hate
Caesar?”
So the goal can be written in FOPL as hate(Marcus, Caesar)
11/15/2021 42
Converting above wffs in CNF we have the following clauses:
1.Man (Marcus).
2. Pompeian (Marcus).
3. ¬Pompeian(x1) ∨ Roman(x1)
4. Ruler (Caesar).
5. ¬Roman(x2) ∨Loyalto(x2, Caesar) ∨Hate(x2, Caesar)
6. Loyalto (x3, f(x3))
7. ¬Man(x4) ∨ ¬Ruler(y1) ∨ ¬Tryassassinate(x4, y1) ∨ ¬Loyalto (x4, y1)
8. Tryassassinate(Marcus, Caesar)
Since the goal is also needed to be converted in FOPL and as well as in negation
form, so the revised formation of the goal will be as follows:
9. ¬ hate(Marcus, Caesar)
11/15/2021 43
Clause 9 Clause 5
Marcus/x2
Clause 3 ¬Roman(Marcus) ∨Loyalto(Marcus, Caesar)
Marcus/x1
¬Pompeian(Marcus) ∨Loyalto(Marcus, Caesar) Clause 2
Nil
11/15/2021 44
Let’s consider the following axioms in FOPL:
1. in_room (bananas)
2. in_room (chair)
3. in_room (monkey)
4. tall (chair)
5. ¬close (bananas, floor)
6. can_move(monkey, chair, bananas)
7. can_climb (monkey, chair)
8. ∀xy close(x, y)→can_reach(x, y)
9. ∀xy ((get_on(x, y)∧under(y, bananas) ∧tall(y))→ close(x, bananas))
10. ∀xy ((in_room(x) ∧ in_room (y) ∧in_room(z) ∧ can_move (x, y, z)) →
close(z, floor) ∨ under(y, z))
11. ∀xy can_climb(x, y) → get_on (x, y)
12. Goal: can_reach(monkey, bananas)
11/15/2021 45
CNF representation of FOPL sentences:
1. in_room (bananas)
2. in_room (chair)
3. in_room (monkey)
4. tall (chair)
5. ¬close (bananas, floor)
6. can_move(monkey, chair, bananas)
7. can_climb (monkey, chair)
8. ¬close (x1, y1) ∨can_reach(x1, y1)
9. ¬ get_on(x2, y2) ∨ ¬ under(y2, bananas) ∨ ¬ tall(y2) ∨close(x2, bananas)
10. ¬ in_room(x3) ∨ ¬ in_room (y3) ∨ ¬ in_room(z1) ∨ ¬ can_move (x3, y3, z1) ∨
close(z1, floor) ∨under(y3, z1)
11. ¬ can_climb(x4, y4) ∨ get_on (x4, y4)
11/15/2021 46
Clause 1, 2, 3 Clause 10
monkey/x3, chair/y3, bananas/z1
Clause 7 ¬ can_move (monkey, chair, bananas) ∨ close(bananas, floor) ∨under(chair, bananas)
Chair/y4, x4/x2
clause 7 ¬ can_climb(x4, chair) ∨ close(x4, bananas)
Monkey/ x4
close(monkey, bananas) clause 8
monkey/x1, bananas/y1
clause 12 can_reach (monkey, bananas)
NIL
11/15/2021 47
Given the following text “Everyone who enters in a theatre has bought a ticket.
Person who does not have money can’t buy ticket. Vinod enters a theatre.” Prove by
resolution that “Vinod buys a ticket”
11/15/2021 48
FOPL representation of the given sentences is as follows:
1. ∀x: Enters(x, theatre)→Buyticket(x)
2. ∀x: Person(x) ∧¬Havemoney(x) → ¬Buyticket(x)
3. Enters(Vinod, theatre)
CNF representation of the above FOPL sentences:
1. ¬ Enters(x1, theatre) ∨Buyticket(x1)
2. ¬ Person(x2) ∨ Havemoney(x2) ∨¬Buyticket(x2)
3. Enters(Vinod, theatre)
Clause 4 Clause 1
Vinod/ x1
Clause 3 ¬ Enters(Vinod, theatre)
Nil
11/15/2021 49
An agent often has only uncertain information about its task & about its environment
Techniques discussed so far had limited abilities for representing & reasoning about
uncertain knowledge
11/15/2021 50
Let’s consider a collection of random variables V1, V2,…., Vk
Joint probability that the values of V1, V2,…., Vk are v1, v2,…, vk, respectively can be
represented by the expression p(V1= v1, V2= v2, …, Vk= vk).
If a fair coin is flipped five times, then we might have p(H, T, T, H, T) = 1/32
11/15/2021 51
Let’s consider 4 binary valued variables, B, M, L & G, there are 16 joint
probabilities over these variables, each of the form p(B=b, M=m, L=l, G=g)
B M L G Joint
Prob.
T T T T 0.5686
T T T F 0.0299
T T F T 0.0135
T T F F 0.0007
…. …. …. …. ….
11/15/2021 52
When we know the values of all of the joint prob. for a set of random
variables, then we can compute what is called the marginal prob. of one of
these random var.
Thus, given the full joint prob. function for a collection of random var., it’s
possible to compute all of the marginal & lower order joint prob.
However, when the no of random vars. are too large, then the task of
specifying all of the joint prob becomes intractable.
11/15/2021 53
For any values of the variables Vi & Vj, the conditional prob function is given
by:
p (Vi , V j )
p (Vi | V j ) =
p (V j )
Where p(Vi , Vj) is the joint prob. of Vi & Vj, and p(Vj) is the marginal prob. Of
Vj.
p ( B , M )
E.g. p ( B | M ) =
p ( M )
Conditional prob. is thus a normalized version of a joint prob.
11/15/2021 54
Joint prob. can be expressed in terms of a chain of conditional prob as follows:
k
p(V1 ,V2 ,...,Vk ) = p(Vi | Vi −1 ,.....,V1 )
i =1
p(Vi , Vj) = p(Vi| Vj) p(Vj) = p(Vj| Vi) p(Vi) = p(Vj , Vi)
p(V j | Vi ) p(Vi )
Then, p(Vi | V j ) =
p(V j )
11/15/2021 55
Consider the following joint probabilities:
p(P, Q, R) = 0.3, p(P, Q, ¬R) = 0.2, p(P, ¬Q, R) = 0.2, p(P, ¬Q, ¬R) = 0.1,
p(¬P, Q, R) = 0.05, p(¬P, Q, ¬R) = 0.1, p(¬P, ¬Q, R) = 0.05, p(¬P, ¬Q, ¬R) = 0.0
11/15/2021 56
Consider the following joint probabilities:
p(P, Q, R) = 0.3, p(P, Q, ¬R) = 0.2, p(P, ¬Q, R) = 0.2, p(P, ¬Q, ¬R) = 0.1,
p(¬P, Q, R) = 0.05, p(¬P, Q, ¬R) = 0.1, p(¬P, ¬Q, R) = 0.05, p(¬P, ¬Q, ¬R) = 0.0
11/15/2021 57
A variable V is conditionally independent of a set of variables Vi, given a set Vj, if
p (V | Vi , V j ) = p (V | V j )
This fact is represented by the notation I (V , Vi | V j )
The intuition is that if I (V , Vi | V j ) , then Vi tells us nothing more about V than we
already knew by knowing Vj
11/15/2021 58
Conditional independencies can be conveniently represented by Bayes Networks,
also called belief networks
A Bayes network is a DAG, where nodes are labeled by random variables
The intuitive meaning of an arrow from a parent to a child is that the parent
directly influences the child.
These influences are quantified by conditional probabilities
BNs are graphical representations of joint distributions.
In a Bayes network, each node Vi , in the graph is conditionally independent of any
subset of the nodes that are not descendants of Vi, given the parents of Vi.
Let’s consider A(Vi) – any set of nodes that are not descendants of Vi,
P(Vi) – immediate parents of Vi
With the above assumptions, we can say I(Vi, A(Vi)| P(Vi)), ∀ Vi in the graph
In turn the above expression is as equivalent as p(Vi| A(Vi), P(Vi)) = p(Vi| P(Vi))
11/15/2021 59
Let’s assume that V1, V2, …, Vk be the nodes in a Bayes network
L p(L) = 0.7
B p(B) = 0.95
p(M|B, L) = 0.9
p(M|B, ¬L) = 0.05
p(M| ¬B, L) = 0.0
p(M| ¬B, ¬L) = 0.0
P(G|B) = 0.95G M
P(G| ¬B) = 0.1
p( G, B, M, L) = p(G|B)p(M|B, L)p(B)p(L)
11/15/2021 60
Considering the Bayes network of last slide, calculate
p(M|L)
11/15/2021 61
Considering the Bayes network of last slide, calculate p(M|L)
11/15/2021 62
Q p(Q) = 0.05
p(R) = 0.01 R
p(P|R, Q) = 0.95
p(P|R, ¬Q) = 0.90 p(S|Q) = 0.95
p(P| ¬R, Q) = 0.80 P S p(S| ¬Q) = 0.05
p(P| ¬R, ¬Q) = 0.01
Calculate p(Q|U).
11/15/2021 63
From Bayes rule we have p(Q|U) = kp(U|Q)p(Q), where k=1/p(U)
Now, p(U | Q) = p(U | P) p( P | Q)
p
So p (P | Q) = 0.20
p(U|Q)=p(U|P)p(P|Q)+p(U|¬P)p(¬P|Q)=0.60
p(Q|U)=k*0.60*0.05=k*0.03------------------(1)
11/15/2021 64
bird(tweety).
fly(X) :- bird(X).
?- fly(tweety).
Yes
11/15/2021 65
Let’s consider the following situation:
11/15/2021 66
11/15/2021 67
A generic entry in the joint probability distribution
P(X1, …, Xn) is given by:
n
P ( X 1 , X 2 ,..., X n ) = P ( X i | Parents( X i ))
i =1
11/15/2021 68
Probability of the event that the alarm has
sounded but neither a burglary nor an
earthquake has occurred, and both Mary and
John calls:
11/15/2021 69
Probability of the event that the alarm has sounded
but neither a burglary nor an earthquake has
occurred, and both Mary and John calls:
P(J ∧ M ∧ A ∧ ¬B ∧ ¬E)
= P(J | A) P(M | A) P(A | ¬B ∧ ¬E) P(¬B) P(¬E)
=0.9 X 0.7 X 0.001 X 0.999 X 0.998
=0.00062
11/15/2021 70
Let A, B, C, D be Boolean random variables. Given that: A and B are
(absolutely) independent. C is independent of B given A. D is independent of
C given A and B.
Prob(A=T) = 0.3, Prob(B=T) = 0.6, Prob(C=T|A=T) = 0.8,
Prob(C=T|A=F) = 0.4, Prob(D=T|A=T,B=T) = 0.7, Prob(D=T|A=T,B=F) = 0.8,
Prob(D=T|A=F,B=T) = 0.1, Prob(D=T|A=F,B=F) = 0.2
11/15/2021 71
1. P(D=T) = P(D=T,A=T,B=T) + P(D=T,A=T,B=F) + P(D=T,A=F,B=T) +
P(D=T,A=F,B=F)
= P(D=T|A=T,B=T) P(A=T,B=T) + P(D=T|A=T,B=F) P(A=T,B=F) +
P(D=T|A=F,B=T) P(A=F,B=T) + P(D=T|A=F,B=F) P(A=F,B=F)
(since A and B are independent absolutely)
=P(D=T|A=T,B=T) P(A=T) P(B=T) + P(D=T|A=T,B=F) P(A=T) P(B=F) +
P(D=T|A=F,B=T) P(A=F) P(B=T) + P(D=T|A=F,B=F) P(A=F) P(B=F)
= 0.7*0.3*0.6 + 0.8*0.3*0.4 + 0.1*0.7*0.6 + 0.2*0.7*0.4 = 0.32
11/15/2021 72
Consider the following Bayesian Network
containing 3 Boolean random variables:
11/15/2021 73
(i) P (~B,C | A) = P (~B | A) P (C | A) = (0.15)(0.75) = 0.1125
(ii)
11/15/2021 74