Вы находитесь на странице: 1из 66

Topic 3- Knowledge

Representation

Prof. Asoka S Karunananda


Faculty of Computing
KDU

1
Overview

Introduction
Logical Representation
Propositional Logic
Predicate Logic
Procedural representation
Network representation
Structured representation
Frames
Scripts
Ontology

2
Introduction

Knowledge Representation (KR) is an


approach to Artificial Intelligence
The concept of KR is as old as AI
KR formalisms allows to represent and
reasoning on knowledge
There are so many types of knowledge
Requires different ways to represent
knowledge

3
Major KR Techniques

Logical Representation Schema


Procedural representation
Network representation
Structured representation

4
Logical representation

Oldest form of knowledge representation


Propositional and Predicate logic are so
popular in KR in Artificial Intelligence
Precise representation and effective
reasoning mechanism

5
Logic

A formal system for describing knowledge


Logic is a language
Logic deals with
Syntax
Semantics
Inference mechanism

6
Propositional logic

Proposition is a statement (sentence) which is either


true or false
Propositional symbols such as P, Q are used to
represent sentences
The following logical connectives are used to
combine propositions
(and), (or), (implies),
(equivalent), (negation)
Parentheses are also used to group sentences
E.g. (P Q) R

7
Semantics of Propositional Logic
Here is a truth value table for two propositions P and Q

P Q P PQ PQ PQ P Q
T T T T T T T
T F F F T F F
F T T F T T F
F F T F F T T

P Q = (P Q) ( Q P )
P Q = ~P Q is read as P implies Q
P Q is read as p if and only if q

8
Consider the connective P Q in detail
How can P Q be true for P=F and Q=T?
Suppose your friend asks whether you have an umbrella
and you respond if I had an umbrella, (then) I would not
have got wet
Here, P = I had an umbrella, Q = I would not
have got wet
Suppose P=F. That is I do not have an umbrella.
Is the proposition P Q true?
If we take Q as F, then not having an umbrella
could certainly make you wet. So P Q = T
If we take Q as T, then not having an umbrella
may not necessarily make you wet (e.g., you were
indoors at that time!), Then P Q = T
9
Example

e.g., Evaluate the truth value for


u = ~(p /\ q) (p V ~q)
P Q PQ ~(P Q) (P ~Q) U

0 0 0 1 1 1
0 1 0 1 0 0
1 0 0 1 1 1
1 1 1 0 1 1

10
Examples

If I work hard then I will pass the exam, and I


work hard, so I will pass the exam
This can be written in Propositional logic as

P- I work hard
Q I will pass the exam

(P Q)P Q

11
Propositional logic
Assignment: each raw of a truth table
Interpretation: what each assignment yields
Model: an assignment that makes a true interpretation
Counter example: an assignment that makes a false
interpretation
Tautology: an expression whose interpretation is always
true
Contradiction: an expression whose interpretation is
always false
Equivalence: Two expressions with same interpretations

12
Examples
P T and Q-F is a model for P Q

P T and Q-F is a counter example for P Q

((P Q) P) Q is a tautology

((P Q) (P Q)) contradiction

P Q and P Q are equivalent

13
Two statements X and Y are logically
equivalent if X Y is a tautology.
From a practical point of view, you can
replace a statement in a proof by any
logically equivalent statement.

Show that P Q and P Q are logically


equivalent.

14
Propositional Logic..

Argument
An argument consists of set of propositions
called premises and another proposition
called conclusion as in the following form

P1P2P3Pn C

If an argument is a tautology, then the


argument is called valid.

15
Inference Methods

Several basic methods for determining


whether a given set of premises
propositionally entails a given conclusion
exist;
Truth Table Method
Deductive (Proof) Systems
Resolution

16
Truth Table Method

One way of determining whether or not a set


of premises logically entails a possible
conclusion is to check the truth table for the
logical constants of the language

17
Truth Table Method (2)
The truth table method can be formalized as
follows:
Step 1: Starting with a complete truth table for the
propositional constants, iterate through all the premises
of the problem, for each premise eliminating any row that
does not satisfy the premise
Step 2: Do the same for the conclusion
Step 3: Finally, compare the two tables; If every row
that remains in the premise table, i.e. not eliminated,
also remains in the conclusion table, i.e. not eliminated,
then the premises logically entail the conclusion

18
Example
Simple sentences:
Amy loves Pat: P

Amy loves Quincy: Q

It is Monday: R

Premises:
If Amy loves Pat, Amy loves Quincy: P Q

If it is Monday, Amy loves Pat or Quincy: R (P Q)

Question:
If it is Monday, does Amy love Quincy?

Is R Q entailed by the premises?

19
Example 2

If the band performs, then the hall will be full provided


that the tickets are not too costly. However, if the band
performs, the tickets will not be too costly.
Therefore, if the band performs, then can the hall will be
full?
- p: the band performs
- q: the hall is (will be) not empty
- r: tickets are not too costly
Write the premises.

20
Equivalencies
(P) P
PQ QP
PQ QP
P Q PQ
(PQ) PQ
(PQ) PQ
P(QR) (PQ) (PR)
P Q Q P

21
Inference Rules
Modus ponens P Q, P Q
Modus tolens P Q, Q P
And- elimination P1P2 ..Pn Pi
And introduction P1,P2,..Pn P1P2..Pn
Or introduction P1 P1P2 ...Pn
Double negation P P
Unit resolution PQ, Q P
Resolution PQ, Q R PR
22
Reasoning in Propositional Logic

We can use Equivalencies and Inference


rules to draw conclusions about propositional
logic statement
The Equivalencies and Inference can be
used to develop what is called Conjunctive
Normal Forms (CNF)
CNF with Modus Ponens can implement
method of contradiction

23
Reasoning Example

Show that ((P Q)QP R) R

LHS ((P Q)QP R) (using modus tolens)


P(P R)
(P R)P
(P R)P (using modus ponens)
R (i.e. RHS)

Note that this can also be shown by using truth tables

CNF is more powerful

24
Conjunctive Normal Forms
Procedure to convert propositional logic expression to CNF

Eliminate , replacing PQ with (P Q)(Q P)

Eliminate , replacing P Q with PQ

Push negation in using: (P) P,


(PQ) PQ,
(PQ) PQ

Distribute over (break at sign)

With the use of CNF proof can be done by using the method
of contradiction
25
Using CNF - Example
Consider the paragraph:
If Sarath works hard and or lucky he can pass the exam.
Sarath is curious but he is not lucky. If sarath is curious
then he works hard.

From this paragraph, check whether Sarath can


pass the exam.

We define propositions as follows


P- Sarath works hard
Q- Sarath is Lucky
S- Sarath is curious
R- Sarath can pass exam

26
Using CNF Example
Paragraph in propositional logic
(PQ) R ----(a)
SQ ----(b)
SP ----(c)
Converting to CNF
(a) Eliminate , we get (PQ)R
remove , then get (PQ)R
R(PQ)
(R P) (RQ)
break at sign
(R P) ----(a1)
(RQ) ----(a2)
(b) Only the last step apply
S ----(b1)
Q ----(b2)
(c) elimination
SP ----(c1)

27
Using CNF Example
In Propositional Logic In CNF

(PQ) R ----(a) (R P) ----(a1)


(RQ) ----(a2)

SQ ----(b) S ----(b1)
Q ----(b2)

SP ----(c) SP ----(c1)

28
Using CNF Example
In order to show Sarath can pass the exam.
We assume its negation is true add it as a new
CNF to the system
R ----(d1)

Then resolve a1 through d1 and try to get a


contradiction as follows

29
Using CNF Example
Elegant use of Modus ponens
P, PQx Q(a)
This is same as P, PQ Q

PQ P

Q
Now we resolve the above problem as follows

30
Using CNF Example

R P R

P SP

S S

{}

Therefore, we conclude that R is true

31
Limitations of Propositional logic

Inability to generalize
Inability to represent internal information

32
Predicate Logic
This Address the issues of propositional logic
Predicate Logic is also known as First Order Logic

Predicates are defined as objects with properties


E.g. fruit(mango).

fruit is name of the predicate and mango is a property

Using a variable for a property we can achieve


generalization
Predicate name tells us about what the predicate
represents so we know internal information

In Addition Quantifiers can define the scope of variables


33
Quantifiers in FOL

x universal quantifiers
Read as for all x
x existential quantifier
Read as for some, there exists

34
Examples

Everything is fine x fine(x)


Something is expensive x expensive(x)
All dogs are animal
x dog(x) animal(x)
Some dogs are friendly
x dog(x) friendly(x)
Nothing is fine x fine(x)
Not everything is fine x fine(x)

35
Order of quantifiers

xy P(x,y) yx P(x,y)
x y P(x,y) y x P(x,y)
xy P(x,y) yx P(x,y)

36
Reasoning in First-order logic
Most useful rule is the modus ponens
P(a), P(x) Q(x) Q(a)
This is same as P(a), P(x)Q(x) Q(a)

This happens through substitution for


variables and unification

P(x)Q(x) P(a)
X= a

Q(a)

37
CNF with FOL

FOL expressions can also be converted as a


conjunct of disjunct.

Recall, we could convert propositional logic


formulae also into CNF

However, conversion procedure here is little


complicated due to involvement of quantifiers

38
Procedure - FOL to CNF

S1 - Elimination of implication
S2- Move inwards
S3 - Standardize variables
S4- Remove existential quantifier (skolemize)
S5- Drop universal quantifiers
S6- Distribute over

39
Example FOL to CNF
Consider the sentence every one who loves all
animals is loved by someone
x [y animal(y)loves(x,y)] [y loves(y,x)]

Using S1 (note replacing P Q with PQ)


x [ y animal(y)loves(x,y)][y loves(y,x)]

Using S2 push inwards


x [y (animal(y)loves(x,y))][y loves(y,x)]
x [y animal(y)loves(x,y))][y loves(y,x)]
x [y animal(y)loves(x,y))][y loves(y,x)]

40
Example FOL to CNF
Using S3: rename variable not to appear twice
x [y animal(y)loves(x,y))][z loves(z,x)]

Using S4: introduce constants to existential quantifiers


x [animal(A)loves(x,A))]loves(B,x)
Note: A and B can be written as F(x) and G(x) as
they are functions of x

x [animal(F(x))loves(x,F(x)))]loves(G(x),x)

41
Example FOL to CNF

Using S5
[animal(F(x))loves(x,F(x)))]loves(G(x),x)

Using S6
[animal(F(x))loves(G(x),x)]
[loves(x,F(x)))loves(G(x),x)]

42
Resolution using CNF - Example

Consider the example


Every one who loves all animals is loved by someone.
Anyone who kills an animal is loved by no one
Jack loves all animals
Either Jack or Curiosity killed the cat, who is named Tuna
Did Curiosity kill the cat?

Write these sentence in predicate logic (FOL)


Covert them into corresponding CNF

43
Writing in FOL

A. x [y animal(y)loves(x,y)] [y loves(y,x)]
B. x [y animal(y) kills(x,y)] [z loves(z,x)]
C. x animal(x) loves(Jack,x)
D. kills(Jack,Tuna) kills(Curiosity, Tuna)
E. Cat(Tuna)
F. x cat(x) animal(x)
G. kills(Curiosity, Tuna)
Note that we have assumed that Curiosity did not kills Tuna, as
we prove this using method of contradiction

44
Corresponding CNF
A1 animal(F(x)) loves(G(x), x)
A2 loves(x,F(x)) loves(G(x), x)
B aniaml(y)kills(x,y) loves(z,x)
C aniaml(x)loves(Jack,x)
D kills(Jack, Tuna) kills(Curiosity, Tuna)
E cat(Tuna)
F cat(x) animal(x)
G kills(Curiosity, Tuna)
45
Proof by contradiction

cat(Tuna) cat(x) animal(x) kills(Jack, Tuna)kills(Curiosity, Tuna)

kills(Curiosity, Tuna)
kills(Jack, Tuna)
animal(Tuna)
aniaml(y)kills(x,y) loves(z,x) loves(x,F(x)) loves(G(x), x)
aniaml(x)loves(Jack,x)
kills(x,Tuna)loves(z,x)
loves(z,Jack)
aniaml(F(Jack)) loves(G(Jack), Jack)

loves(z, Jack) animal(F(x)) loves(G(x), x)

loves(G(Jack), Jack)

{}
46
Procedural Representation

This is the rule-based representation of


knowledge
In this approach knowledge is represented in
the form of

IF <Condition>
THEN <Conclusion-1/Action-1>
ELSE <Conclusion-2/Action-2>

47
Examples rule-based representation

IF you follow lectures and do assignment


THEN you will pass the examination.
IF you pass the exam THEN you will find a
job ELSE you should change the career path

48
Production Systems

Expert systems that use rule-based KR are


called production systems
Rules-based KR is the most widely use KR
technique for Expert systems

49
Inference in rule-based representation

Backward chaining
Begins with a hypothesis, matches with the head
of a rule and tries to satisfy its body by matching
with head of another rule
By default Prolog operates in this manner
Forward chaining
Begins with facts, and tries to derive moving
towards conclusion.

50
Example Rule-based KB
leak_in_bathroom :- hall_wet, kitechn_dry
problem_in-kitechen :- hall_wer,bathroom_dry
kitchen
no_water_fron_out_side :- window_closed
; no_rain br hall
leak_in_kichen :- problem_in_kitchen,
no_water_from out_side
Some Observations as facts
hall_wet.
bathroom_dry.
window_closed.
Query ?- leak_in_kitchen.
yes
51
Inference network

kitechn_dry
leak_in_bathroom
hall_wet
problem_in_kitchen
bathroom_dry
leak_in_kitchen
window_closed
no_water_from_outside
no_rain

52
Backward chaining example

Begin with the hypothesis say, leak_in_kitchen


Moving backward, to confirm this we need problem_in_kitchen and
no_water_from_outside to be true
The former is confirmed with hall_wet and bathroom_dry
Latter is confirmed, say by knowing window_is_closed
Thus our hypothesis is proved.
Note: BC begins with the goal in mind. So, good for problems when
the goal is known.
E.g. diagnosis

53
Forward chaining example
Start with some known facts (but not from a hypothesis)
For example, having noticed the hall_wet and bathroom_dry
concludes that problem_in_kitchen
Having noticed, window_closed the concludes
no_water_from_outside
From the above two, we conclude leak_in_kitchen
Note: if we begin with facts, kitchen_dry and hall_wet we get
unnecessary conclusion, leak_in_bath_room
As such FC can go ahead with unnecessary derivations, without
an idea about a goal
Good for configuration, planning, design problems

54
Advantages of rules

Easy to implement
Easy to drive process reasoning
Easy to modify and maintain
Can extend incorporating concepts such as
uncertainty

55
Network Representation

A graphical representation of knowledge


It comprises of nodes and links
The nodes represent objects/entities, while
links represent relationships
Semantic Network is the well-known network
representation of knowledge

56
Example 1 - Semantic networks

lecturer

Is_a
Is_a
AI asoka
Human
teaches
being

enjoys
needs
writing

Semantic net represents inheritance


For example, asoka is_a lecturer, lecturer is_a food
human being, human being needs food infer that
Asoka needs food
57
Example 2 Semantic network
has_feature
Can move animal

subset
has_feature
bird can fly
is_a
Due to inheritance from superior
Ostrich cannot fly
nodes we can conclude that
has_feature
(i) Ostrich can move
(ii) Ostrich can fly

However, local assigned attribute can override inherited attributes


Therefore, we can conclude that Ostrich cannot fly

58
Comments on Semantic networks

Easy to understand
Large domains may need very complex
semantic networks
Cannot represent negations, disjunction,
variables and quantifiers
Yet, we can include logic and rules with
semantic networks to overcome the above
issue

59
Structured Representation

There are two major types of structured


representations of knowledge
Frames
Scripts

60
Frames

A frame is a collective description


As such, frames are more comprehensive
than nodes in a semantics network
The concept of frames has been influential to
develop the modern object-oriented
representation too
A frame comprises of its name, slots
(attribute) and filers (values)

61
Example - Frame
Consider the following frame describing about a car

Vehicle: car Name of the frame


Make: Toyota
Model: 1002
Fuel: diesel value

slots

Note: we can define new frames by referring to values of slots of a given frame

For example, we define new frame as vehicle:Toyota and link the new
frame with the above frame through the slot called Make
So we can have a network of frames

62
Comments on Frames

Frames are more comprehensive than


semantics networks
Frames can also be manipulated through
concepts such as inheritance
However, Frames can represent only the
Static descriptions, but not dynamic
scenarios.

63
Scripts

Scripts can represent dynamic scenarios


Its inspired by the concept of script in film and
drama
As such scripts are modeled in terms of
props, actors, acts, scene, etc.

64
Components of a script

Entry conditions
Assumption about the world for a script to begin (e.g. fight)
Results
Condition to meet once the script terminate
Props
Things that are involved in the scene (tables, etc.)
Roles
People and actions
Scenes
Temporal sequence of the sub-event in a script

65
Ontology

Ontology has many definitions


Its a specification something showing related
entities
Its about categories of objects
More comprehensive than objects in isolation
Next paradigm for KR and computing
Many tools are available for ontological
modelling (OntoWeb)

66

Вам также может понравиться