You are on page 1of 72

Knowledge Representation

 To solve a large problem in AI, one


need
 A large amount of knowledge
 Some mechanism to manipulating
these knowledge to create solution to
these problem.
Representations and Mappings
 Different models for representation
of knowledge
 Domain-specific knowledge most
important for designing efficient
problem solving methods
Two entities of knowledge
 Facts
 Truths in some relevant world.
 Eg. There is a queen in row 1, column 2
 Formalism
 Representation of facts in a generalized
form
 Eg. For each queen, create a variable
which takes the ordered pair (row, col)
as a value
Mapping between Facts and
Representation

Reasoning Programs

Facts Internal Representations

English English
generation understanding

English Representation
Representation using
Mathematical Logic
 Fact
 English : Spot is a dog.
 Logic : Dog(Spot) …… (1)
 English : All dogs have tails
 Logic : x Dog(x)  hastail(x) ….. (2)
Using (1) and (2), we can derive a
new knowledge
Logic : hastail(Spot)
English : Spot has a tail.
Propositional Logic Representation

 Can easily represent real world facts


as logical propositions written as
well-formed formulas (wff’s)
 Example
 Socrates is a man
 SOCRATESMAN
Building Blocks
 Logical constants: true, false
 Propositional symbols: P, Q, S, ... (atomic
sentences)
 Wrapping parentheses: ( … )
 Sentences are combined by connectives:
...and [conjunction]
 ...or [disjunction]
...implies [implication / conditional]
..is equivalent [biconditional]
 ...not [negation]
 Literal: atomic sentence or negated atomic
sentence
Propositional logic
 A simple language useful for showing key
ideas and definitions
 User defines a set of propositional
symbols, like P and Q.
 User defines the semantics of each
propositional symbol:
 P means “It is hot”
 Q means “It is humid”
 R means “It is raining”
Propositional logic
 A sentence (well formed formula) is defined as
follows:
 A symbol is a sentence

 If S is a sentence, then S is a sentence

 If S is a sentence, then (S) is a sentence

 If S and T are sentences, then (S  T), (S 


T), (S  T), and (S ↔ T) are sentences
 A sentence results from a finite number of
applications of the above rules
Some terms
 The meaning or semantics of a sentence
determines its interpretation.

 Given the truth values of all symbols in a


sentence, it can be “evaluated” to determine its
truth value (True or False).
More terms
 A valid sentence or tautology is a sentence that
is True under all interpretations, no matter what
the world is actually like or what the semantics is.
Example: “It’s raining or it’s not raining.”
 An inconsistent sentence or contradiction is a
sentence that is False under all interpretations.
The world is never like what it describes.
Example: “It’s raining and it’s not raining.”
 P entails Q, written P |= Q, means that
whenever P is True, so is Q. In other words, all
models of P are also models of Q.
Inference rules
 Logical inference is used to create new
sentences that logically follow from a given set
of predicate calculus sentences (KB).
 An inference rule is sound if every sentence X
produced by an inference rule operating on a
KB logically follows from the KB. (That is, the
inference rule does not create any
contradictions)
 An inference rule is complete if it is able to
produce every expression that logically follows
from (is entailed by) the KB. (Note the
analogy to complete search algorithms.)
Sound rules of inference
 Here are some examples of sound rules of inference
 A rule is sound if its conclusion is true whenever the
premise is true
 Each can be shown to be sound using a truth table
RULE PREMISE CONCLUSION
Modus Ponens A, A  B B
And Introduction A, B AB
And Elimination AB A
Double Negation A A
Unit Resolution A  B, B A
Resolution A  B, B  C AC
Soundness of the resolution inference
rule
Proving things
 A proof is a sequence of sentences, where each sentence is
either a premise or a sentence derived from earlier sentences in
the proof by one of the rules of inference.
 The last sentence is the theorem (also called goal or query) that
we want to prove.
 Example for the “weather problem” given above.
1 Hu Premise “It is humid”
2 HuHo Premise “If it is humid, it is hot”
3 Ho Modus Ponens(1,2) “It is hot”
4 (HoHu)R Premise “If it’s hot & humid, it’s
raining”
5 HoHu And Introduction(1,3) “It is hot and humid”
6R Modus Ponens(4,5) “It is raining”
Horn sentences

 A Horn sentence or Horn clause


has the form:
P1  P2  P3 ...  Pn  Q
or alternatively (P  Q) = (P  Q)
P1   P2   P3 ...   Pn  Q
where Ps and Q are non-negated atoms
 To get a proof for Horn sentences,
apply Modus Ponens repeatedly until
nothing can be done
Propositional logic is a weak language

 Hard to identify “individuals” (e.g., Mary, 3)

 Can’t directly talk about properties of individuals or


relations between individuals (e.g., “Bill is tall”)

 Generalizations, patterns, regularities can’t easily be


represented (e.g., “all triangles have 3 sides”)

 First-Order Logic (abbreviated FOL or FOPC) is expressive


enough to concisely represent this kind of information
FOL adds relations, variables, and quantifiers, e.g.,
“Every elephant is gray”:  x (elephant(x) → gray(x))

“There is a white alligator”:  x (alligator(X) ^ white(X))


Example

 Consider the problem of representing


the following information:
 Every person is mortal.

 Confucius is a person.

 Confucius is mortal.

 How can these sentences be


represented so that we can infer the
third sentence from the first two?
Example
 In PL we have to create propositional symbols to stand for all
or part of each sentence. For example, we might have:
P = “person”; Q = “mortal”; R = “Confucius”

 The above 3 sentences are represented as:


P  Q; R  P; R  Q
 Although the third sentence is entailed by the first two, we
needed an explicit symbol, R, to represent an individual,
Confucius, who is a member of the classes “person” and
“mortal”
 To represent other individuals we must introduce separate
symbols for each one, with some way to represent the fact
that all individuals who are “people” are also “mortal”
First-order logic
 First-order logic (FOL) models the world in terms of
 Objects, which are things with individual identities
 Properties of objects that distinguish them from other
objects
 Relations that hold among sets of objects
 Functions, which are a subset of relations where there is
only one “value” for any given “input”

 Examples:
 Objects: Students, lectures, companies, cars ...
 Relations: Brother-of, bigger-than, outside, part-of, has-
color, occurs-after, owns, visits, precedes, ...
 Properties: blue, oval, even, large, ...
 Functions: father-of, best-friend, second-half, one-more-
than ...
User provides

 Constant symbols, which represent individuals in the


world
 Mary
 3
 Green

 Function symbols, which map individuals to individuals

 father-of(Mary) = John

 color-of(Sky) = Blue

 Predicate symbols, which map individuals to truth values

 greater(5,3)

 green(Grass)

 color(Grass, Green)
FOL Provides

 Variable symbols
 E.g., x, y, foo

 Connectives

 Same as in PL: not (), and (), or (),


implies (), if and only if (biconditional )
 Quantifiers

 Universal x or (Ax)

 Existential x or (Ex)
Quantifiers
 Universal quantification
 (x)P(x) means that P holds for all values of x in
the domain associated with that variable
 E.g., (x) dolphin(x)  mammal(x)

 Existential quantification
 ( x)P(x) means that P holds for some value of x in
the domain associated with that variable
 E.g., ( x) mammal(x)  lays-eggs(x)
 Permits one to make a statement about some
object without naming it
Sentences are built from terms and atoms

 A term (denoting a real-world individual) is a constant symbol, a


variable symbol, or an n-place function of n terms.
x and f(x1, ..., xn) are terms, where each xi is a term.
A term with no variables is a ground term

 An atomic sentence (which has value true or false) is an n-place


predicate of n terms

 A complex sentence is formed from atomic sentences connected


by the logical connectives:
P, PQ, PQ, PQ, PQ where P and Q are sentences

 A quantified sentence adds quantifiers  and 

 A well-formed formula (wff) is a sentence containing no “free”


variables. That is, all variables are “bound” by universal or
existential quantifiers.
(x)P(x,y) has x bound as a universally quantified variable, but y is free.
Quantifiers
 Universal quantifiers are often used with “implies” to form “rules”:
(x) student(x)  smart(x) means “All students are smart”

 Universal quantification is rarely used to make blanket statements


about every individual in the world:
(x)student(x)smart(x) means “Everyone in the world is a student and is
smart”

 Existential quantifiers are usually used with “and” to specify a list of


properties about an individual:
(x) student(x)  smart(x) means “There is a student who is smart”

 A common mistake is to represent this English sentence as the FOL


sentence:
(x) student(x)  smart(x)
 But what happens when there is a person who is not a student?
Quantifier Scope
 Switching the order of universal quantifiers does not
change the meaning:
 (x)(y)P(x,y) ↔ (y)(x) P(x,y)

 Similarly, you can switch the order of existential


quantifiers:
 (x)(y)P(x,y) ↔ (y)(x) P(x,y)

 Switching the order of universals and existentials does


change meaning:
 Everyone likes someone : (x)(y)
likes(x,y)
 Someone is liked by everyone : (y)(x)
likes(x,y)
Connections between All and Exists

Relate  and  using De Morgan’s


laws:

(x) P(x) ↔ (x) P(x)


(x) P ↔ (x) P(x)
(x) P(x) ↔  (x) P(x)
(x) P(x) ↔ (x) P(x)
Translating English to FOL

Every gardener likes the sun.


x gardener(x)  likes(x,Sun)

You can fool some of the people all of the time.


x t person(x) time(t)  can-fool(x,t)

You can fool all of the people some of the time.


x t (person(x)  time(t) can-fool(x,t))
x (person(x)  t (time(t) can-fool(x,t))

All purple mushrooms are poisonous.


x (mushroom(x)  purple(x))  poisonous(x)
Translating English to FOL
No purple mushroom is poisonous.
x purple(x)  mushroom(x)  poisonous(x)
x (mushroom(x)  purple(x))  poisonous(x)

Clinton is not tall.


tall(Clinton)

X is above Y iff X is on directly on top of Y or there is


a pile of one or more other objects directly on top
of one another starting with X and ending with Y.
x y above(x,y) ↔ (on(x,y)  z (on(x,z) 
above(z,y)))
Axioms, definitions and theorems

Axioms are facts and rules that attempt to capture all


of the (important) facts and concepts about a domain;
axioms can be used to prove theorems

Adefinition of a predicate is of the form “p(X) ↔ …”


and can be decomposed into two parts
Necessary description: “p(x)  …”
Sufficient description “p(x)  …”
Some concepts don’t have complete definitions (e.g.,
person(x))
More on definitions

Define father(x, y) by parent(x, y) and male(x)

 parent(x, y) is a necessary (but not sufficient)


description of father(x, y)
 father(x, y)  parent(x, y)

 parent(x, y) ^ male(x) ^ age(x, 35) is a sufficient (but


not necessary) description of father(x, y):
father(x, y)  parent(x, y) ^ male(x) ^ age(x, 35)

 parent(x, y) ^ male(x) is a necessary and sufficient


description of father(x, y)
parent(x, y) ^ male(x) ↔ father(x, y)
More on definitions

S(x) is a P(x)
necessary (x) P(x) => S(x)
S(x)
condition of P(x)

S(x) is a S(x)
sufficient (x) P(x) <= S(x)
P(x)
condition of P(x)

S(x) is a P(x)
necessary and (x) P(x) <=> S(x)
sufficient S(x)
condition of P(x)
Example: A simple genealogy KB

Predicates:
 parent(x, y), child(x, y), father(x, y), daughter(x, y),
etc.
 spouse(x, y), husband(x, y), wife(x,y)
 ancestor(x, y), descendant(x, y)
 male(x), female(y)
 relative(x, y)

Facts:
 husband(Joe, Mary), son(Fred, Joe)
 spouse(John, Nancy), male(John), son(Mark, Nancy)
 father(Jack, Nancy), daughter(Linda, Jack)
 daughter(Liz, Linda)
 etc.
Example: A simple genealogy KB
 (x,y) parent(x, y) ↔ child (y, x)
(x,y) father(x, y) ↔ parent(x, y)  male(x) (similarly for mother(x, y))
(x,y) daughter(x, y) ↔ child(x, y)  female(x) (similarly for son(x, y))
 (x,y) husband(x, y) ↔ spouse(x, y)  male(x) (similarly for wife(x, y))
(x,y) spouse(x, y) ↔ spouse(y, x) (spouse relation is symmetric)
 (x,y) parent(x, y)  ancestor(x, y)
(x,y)(z) parent(x, z)  ancestor(z, y)  ancestor(x, y)
 (x,y) descendant(x, y) ↔ ancestor(y, x)
 (x,y)(z) ancestor(z, x)  ancestor(z, y)  relative(x, y)
(related by common ancestry)
(x,y) spouse(x, y)  relative(x, y) (related by marriage)
(x,y)(z) relative(z, x)  relative(z, y)  relative(x, y) (transitive)
(x,y) relative(x, y) ↔ relative(y, x) (symmetric)
Semantics of FOL

 Model: an interpretation of a set of sentences


such that every sentence is True
 A sentence is
 satisfiable if it is true under some interpretation
 valid if it is true under all possible interpretations
 inconsistent if there does not exist any
interpretation under which the sentence is true

 Logical consequence: S |= X if all models of S


are also models of X
Semantics of FOL

 Domain M: the set of all objects in the world (of interest)

 Interpretation I: includes
 Assign each constant to an object in M
 Define each function of n arguments as a mapping Mn => M
 Define each predicate of n arguments as a mapping Mn => {T,
F}
 Therefore, every ground predicate with any instantiation will
have a truth value
 In general there is an infinite number of interpretations because
|M| is infinite

 Define logical connectives: ~, ^, v, =>, <=> as in PL

 Define semantics of (x) and (x)


 (x) P(x) is true iff P(x) is true under all interpretations
 (x) P(x) is true iff P(x) is true under some interpretation
Quantified inference rules

 Universal instantiation
 x P(x)  P(A)

 Universal generalization
 P(A)  P(B) …  x P(x)

 Existential instantiation
 x P(x) P(F)  skolem constant F

 Existential generalization
 P(A)  x P(x)
Universal instantiation

If(x) P(x) is true, then P(C) is true, where


C is any constant in the domain of x

Example:

(x) eats(Ziggy, x)  eats(Ziggy,


IceCream)

The variable symbol can be replaced by any


ground term, i.e., any constant symbol or
function symbol applied to ground terms
only
Existential instantiation

 From (x) P(x) infer P(c)

 Example:
 (x) eats(Ziggy, x)  eats(Ziggy, Stuff)

 Note that the variable is replaced by a brand-new constant


not occurring in this or any other sentence in the KB

 Also known as skolemization; constant is a skolem constant

 In other words, we don’t want to accidentally draw other


inferences about it by introducing the constant

 Convenient to use this to reason about the unknown object,


rather than constantly manipulating the existential quantifier
Existential generalization

 If P(c) is true, then (x) P(x) is inferred.

 Example

eats(Ziggy, IceCream)  (x) eats(Ziggy, x)

 All
instances of the given constant symbol are
replaced by the new variable symbol

 Note that the variable symbol cannot already


exist anywhere in the expression
Unification
 Example
1. x [ W1(x)  W2(x)]
2. W1(A)

 To apply modus ponens and universal specialization to


produce W2(A) from 1 and 2 above; it is necessary to
find the substitution “A for x”.

 Finding substitutions of terms for variables to make


expressions identical is an extremely important process
and is called unification.

 Substitution is represented by a set of ordered pairs s =


{t1/v1; t2/v2; ….. tn/vn}. The pair ti/vi means that term
ti is substituted for variable vi.}
Clauses

A clause is defined as a wff consisting of a


disjunction of literals.
Example
1. P1 V P2 V P3 …. V PN
2.  Q1(x1) V  Q2 (fn(x2))

Any predicate calculus well formed


formulae can be converted to a set of
clauses.
Converting to Clausal form
Step – I : Eliminate Implication Symbols
Example x [ W1(x)  [y [W2(y)  W3(f(x,y))]]]
x [W1(x) V [y [W2(y) V W3(f(x,y))]]]

Step – II : Reduce scopes of Negation Symbols


Example y [Q(x,y)  P(y)]
 y [Q(x,y)  P(y)]

Step – III : Standardize variables


Example x [ W1(x)  x W2(x)]
x [ W1(x)  y W2(y)]
Converting to Clausal form
Step – IV : Eliminate Existential Quantifiers
Example 1. y [ x P(x,y)]
y [P(g(y),y)]
2.  x P(x)
P(A)

Step – V : Convert to Prenex Form


Example No remaining existential quantifiers & Each
Universal quantifier has its own variable
Move all universal quantifiers to front of wff

Step – VI : Put in Conjunctive Normal Form


Example P V (Q  R)
Conjunction of a finite set of disjunctions of
literals
(P V Q)  (P V R)
Converting to Clausal form
Step – VII : Eliminate Universal Quantifiers
Example All variables remaining at this stage are universally
quantified
Left with a matrix in Conjunctive Normal Form.

Step – VIII : Eliminate Symbols


Example P Q V R )
1. P
2. Q V R

Step – IX : Rename variables


Example Variables symbols may be renamed so that no variable
symbol appears in more than one clause
Resolution for Ground Clauses
 Example
1. P1 V P2 V P3 …. V PN
2.  P1 V Q1 V Q2 V Q3 ….. V QM

 Assume that in above ground clauses all of Pi and Qj are


distinct.

 Note that one of these clauses contains a literal that is the


exact negation of one of the literals in the other clause.

 From the two above parent clauses we can infer a new


clause, called the resolvent of the two.

 The resolvent is computed by taking the disjunction of the


two clauses after eliminating the complementary pair P1 and
 P1.
Clauses and Resolvents
Parent Clause Resolvents Comments

1. P Q Modus Ponens
2. P V Q
1. P VQ Q Merge
2. P V Q
1. P VQ Q V Q Tautologies
2. P V Q P V P
1. P  Empty Clause
2. P
1. P V Q P V R Chaining
2. Q V R
Rule based System
 This system represent knowledge in
terms of a brunch of rules.
 This rules tells us what to do in
different situations.
 Consists of brunch of IF-Then rules, a
brunch of facts and some interpreter
controlling the application of the rules.
Two Types…
 Forward chaining system: Starts
with the initial facts, keeps using the
rules to draw new conclusions.
 It is data driven
 Backward chaining system: starts
with some goal and then keeps
looking for rules that allow to
conclude the goal.
 It is goal driven.
For example,
“If sun shines then weather is fine”
Knowledge representation in first-order
logic:
 A - ”sun shines”
 B - ”weather is fine”
 AB
• Knowledge representation as
IF...THEN... rule:
IF sun shines THEN weather is
fine
Semantic NET
 Semantic net or semantic network
is used as a form of knowledge
representation.
 It is a directed graph consisting of
vertices represents concepts and
edges represents semantic relations
between concepts.
animal
Is_a Is_a
Has part

reptile mammal head

Is_a

elephant

Is_instance_of

Clyde

56
Nodes and Arcs
 Arcs define binary relations which hold between
objects denoted by the nodes.

mother age
Sue John 5
w age (john, 5)
ife
hu father father (John, max)
age s ba
nd age (max, 34)

34 Max
Non-binary relations

 We can represent the generic give event as a


relation involving three things:
 A giver
 A recipient
 An object
recipient giver
Mary GIVE John

object

book
Advantages
 Easy to visualize
 Formal definitions of semantic networks
have been developed.
 Efficient in space requirements
 Objects represented only once
 Relationships handled by pointers
Conceptual Graph
Fi Conceptual relations of different types.
Graph of “Mary gave John the book.”
Conceptual graph indicating that the dog named Emma is brown.

Conceptual graph indicating that a particular (but unnamed) dog is


brown.

Conceptual graph indicating that a dog named Emma is brown.

62
Conceptual graph of a person with three names.
Conceptual graph of the proposition “There are no pink dogs.”
Frames
 Frames are record like structures that
have slots and slot values for an
entity.
 A slot in a frame specify a character
of the entity and it contains
information as attribute-value pair,
default value etc.
 Using frames the knowledge about an
object/event can be stored as a unit.
Example
 (Parrot
(Species (value Bird))
(Color (value Yellow))
(Activity (value Fly)))
 Employee Details

(Richa
(professon (value teacher))
(EmpID (value t0015))
(Subject (value Computer)))
Advantages…
 Makes programming easier by
grouping related knowledge
 Easily understood by non-developers
 Expressive power
 Easy to set up slots for new
properties and relations
 Easy to include default information
and detect missing values
Unification in predicate logic
 In order to determine contradiction, the unification
procedure is used.
 It compares two literals and discovers whether
there exists a set of substitution that makes them
identical.
 A recursive procedure, called the unification
algorithm is used.
 Man(John) and ¬Man(John) is contradiction
 Man(John) and ¬Man(spot) is not.

 In order to determine contradiction, we need a


matching procedure that compares two literals and
discovers whether there exists a set of substitution
that make them identical.
 To unify two symbols , their predicate symbol
should be same. Otherwise they cannot be unified.
Tryassassinate (Marcus,Caesar)
Hate (Marcus,Caesar)
 If the predicate symbol match, we try check the
arguments one pair at a time.
 If the first matches, we continue with the second
one and so on.
Matching rule
1. Different constants or predicates cannot match,
identical ones can
2. A variable can match another variable, any
constant, or a predicate expression, with the
restriction that the predicate expression must not
contain any instances of the variable being
matched.
We must find a single, consistent substitution for the
entire literal, not separate ones for each piece of it.
Example
P(x,x)
P(y,z)
Predicates match..
Next, compare x and y.
Suppose , we decide to substitute y for x, written as
y/x.
So far we have p(y,x)
p(y,z) using y/x
If we continue and attempt to match x and z, we
produce the substitution z/x.
 We cannot substitute both y and z for x.
 Therefore after finding the first substitution y/x,we make the
substitution throughout the literals producing
p(y,y)
P(y,z)
Next we would attempt to unify the literals y and z by z/y
p(y,z)
p(y,z)
They are identical.
The entire substitution process has succeeded with a
substitution that is composition of two substitution (z/y) and
(y/x)
Resolution
 It describes a way of finding contradiction with
minimum use of substitution.

You might also like