Knowledge Representation: To Introduce and Compare The Main Knowledge Representation Methods Used in AI
Knowledge Representation: To Introduce and Compare The Main Knowledge Representation Methods Used in AI
KNOWLEDGE REPRESENTATION
Aims
To introduce and compare the main knowledge
representation methods used in AI.
Objective
You should be able to :
use the different methods to represent knowledge.
Show how new facts can be inferred.
Discuss advantages and disadvantages of different methods.
Introduction
Solution
Representation methods
Semantic networks and frames
Predicate calculus/ logic
Rule-based system/ production rule.
Semantic networks and frames
Both provide a simple and intuitively way of representing
facts about objects.
Both represent classes (or categories) of objects and
relations.
Simple inference can be drawn based on this
representation.
Both different in used of notation to represent
knowledge.
Example: Representing some knowledge about animals.
Animal
subclass subclass
Reptile Mammal head
has-part
subclass
Africa Elephant large
livesin size
instance instance
Advantages:
well defined formal sentences.
sound and complete inference rules.
Review of Propositional Calculus
Propositional Calculus and Predicate Logic are languages.
Using their words, phrases and sentences we can represent
and reason about properties and relationship –
inference/generate a new fact
The first step to describe a language is its set of symbols.
Symbols are used to represent facts about the world.
i.e., “Ali likes cakes” represented symbol P
P is known as atomic symbol.
Other symbols truth symbols: true, false
Complex statement is a combination of atomic proposition
with the following connectives :
(and), (or), (not), = (equivalent), (implications)
Examples
P Q where Q is another fact “Ali eats cakes”.
PQ
Q “Ali doesn’t eats cakes”.
PQ “if Ali likes cakes then
P=Q “if Ali likes cakes then …, and vice versa
The Predicate Logic(PreL)
• In Propositional, i.e., “it is rained on Tuesday” denoted by P.
In PreL, is denoted as weather(tuesday, rain)
where it contains predicate name and arguments.
• Other example: “Ali likes chocolate” is written as
likes(ali, chocolate).
• Expression can contain variables, example
weather(X, rain) X representing any day
It allows to create general assertions.
Syntax of PredL
uses symbols to denote objects, properties or relation.
Symbol is a string of letters followed by digits/underscore.
Symbols in i(g,k) and likes(john, kate) are equivalent but
the second is more readable.
Constant symbol begin with lower case, ali, chocolate, rain
Variable symbol - begin with capital letter, i.e., X
Function likes predicate yields value, i.e., sum(X,Y)
Truth values/constant: true and false are reserved.
An atomic sentence is a predicate name followed by n terms
enclosed in ( ) and separated by commas and delimited by a
period. Examples:
friends(ali, azhar).
friends(father(razak), father(jamal) ).
likes(X, azhar).
existentially quantification.
True for at least one substitution from the domain.
“There exist bird that doesn’t flies.”
X (bird(X) flies(X))
Examples :
“Ali eats everything that he likes.” X(likes(ali, X) eats(ali, X)).
“Every person has something that they love”.
X (person(X) Y loves(X, Y) )
“If it doesn’t rain tomorrow, ahmad will go fishing.”
weather(rain, tomorrow) go(ahmad, fishing).
Note: The last two rules or implication give general descriptions of other relationships,
i.e., parent and sibling.
Therefore we can infer such as:
? sibling(mas, abu)
How to prove: mas and abu are sibling?
Notes:
In the language, universally and existentially quantified
variables may refer to objects (constants) in the domain of
discourse. Predicate and function names may not be replaced
by quantified variables. This language is called the First-Order
Predicate Logic.
c b
a d
on(c,a)
on(b,d)
ontable(a)
ontable(d)
clear(b)
clear(c)
hand_empty
To design a control algorithm for a robot arm
We need to represent knowledge based on :
• Does a given block have a clear top surface ?
• Can we pick up block a ? etc.
We need to know : (operations of the system)
• location of each block and the arm.
• The initial knowledge are shown the figure.
The arm can move blocks, change the state, and clear.
For example: to pick-up block-a
• Is block-a clear ?
• remove block-c.
• delete the knowledge of on(c,a).
• pick-up block-a.
on(c,a).
on(b,d)
ontable(a).
ontable(d).
clear(b).
clear(c).
hand_empty.
X( Y on (Y, X) clear (X) ).
XY((hand_empty clear(X) clear(Y) pick_up(X) put_down(X, Y) )
stack(X,Y) ).
• Exercise?
(1) You can translate semantic network examples, eg.
Animal relations into Predicate Logic. (Refer pg
dirt dirt
(0,2) (1,2) (2,2)
2. Rules for investment strategies where the conclusions are stock, savings or
combination (investment should be split)
Savings_account(inadequate) investment(savings).
Savings_account(adequate) income(adequate) investment(stocks).
Savings_account(adequate) income(inadequate) investment(combination).
3. The advisor must determines when savings are adequate or inadequate:
X amount_saved(X) Y(dependents(Y) greater(X, minsavings(Y)))
savings_account(adequate).
X amount_saved(X) Y(dependents(Y) greater(X, minsavings(Y) ) )
savings_account(inadequate).
where minsavings(Y) is a function : minsavings(Y) = 5000*Y;
amount_saved(22000).
earnings(25000, steady).
dependents(3).
What is the advise?
This yield a logical system consisting:
1. savings_account(inadequate) investment(savings).
2. savings_account(adequate)income(adequate) investment(stocks).
3. savings_account(adequate) income(inadequate) investment(combination).
4. X amount_saved(X)Y(dependents(Y)greater(X,minsavings(Y)))
savings_account(adequate).
5. X amount_saved(X)Y(dependents(Y)greater(X,minsavings(Y)))
savings_account(inadequate).
6. X earnings(X,steady)Y(dependents(Y)greater(X, minincome(Y)))
income(adequate).
7. X earnings(X,steady)Y(dependents(Y)greater(X,minincome(Y)))
income(inadequate).
8. X earnings(X,unsteady) income(inadequate).
9. amount_saved(22000).
10. earnings(25000, steady).
11. dependents(3).
Unification process:
Unify sentence 10 and 11 with sentence 7 under substitution
{25000/X, 3/Y} yielding the new implication
Since premises are true by applying modus ponens, the conclusion is true.
This is added as:
13. savings_account(adequate).
Condition-Action Rules
Database of Facts
R1: IF hot AND smoky THEN ADD fire
alarm_beeps
R2: IF alarm_beeps THEN ADD smoky hot
R3 IF fire THEN ADD switch_on_sprinklers
IF-THEN is not similar constructs in Java/C++ – not as part of a
sequence of instructions but treats each rule as an
independent chunk of knowledge.
The rules are more like implications in logic, i.e.,
raining carry_umbrella
Interpreter :
forward chaining
backward chaining
Forward chaining systems – start with some initial facts, and keep using
the rules to draw new conclusions.
Backward chaining systems – start with some hyphotesis (or goal) you are
trying to prove.
Forward chaining systems are primarily data driven, while backward
chaining systems are goal-driven.
Forward chaining systems
Facts are held in working memory – continually updated as
rules are invoked.
Rules represent possible actions to take when specified facts
occur in the working memory – referred as condition-action
rules.
Actions involve – adding or deleting item from working
memory or printing a message.
The interpreter control the system’s activity – based on a
cycle of activity – known as – a recognize-act-cycle.
It selects the rule and performs the actions in the action part
of it - is refered as firing the rule.
Algorithm of the interpreter (forward chaining) :
Repeat :
1. Find all rules which have conditions satisfied.
2. Select one, using conflict resolution strategies.
3. Perform actions in conclusion – possibly modify current
working memory.
Until no rules can fire or halt is added in memory.
Simple fire fighting example – only switch the sprinklers on if
smoke alarm on and hot :
R1 : IF hot AND smoky THEN ADD fire
R2 : IF alarm_beeps THEN ADD smoky
R3 : IF fire THEN ADD switch_on_sprinklers
F1 : alarm_beeps
F2 : hot
Start ?
Notice that the order in which rules fires depends on what is
in working memory.
What happens if, in some cycle, more than one rule has its
condition satisfied, i.e.,
R1 : IF hot AND smoky THEN ADD fire
R2 : IF alarm_beeps THEN ADD smoky
R3 : IF fire THEN ADD switch_on_sprinklers
R4 : IF dry THEN ADD switch_on_humidifier
R5 : IF switch_on_sprinklers THEN DELETE dry
F1 : alarm_beeps
F2 : hot
F3 : dry
In the 1st. cycle – R2 and R4 – conflict ?
If R4 is chosen, the humidifier is switched on and then things proceed as before.
If R2 is chosen, followed by R1, R3 and R5, then dry is deleted from working
memory and the humidifier never switch on.
Common conflict resolution strategies:
Rules that involve facts have been recently added, i.e., if R2 fires, the
next rule to be fired will be R1.
Rules with more specific condition, i.e., R1, it contains, hot and
smoky.
Allow user to prioritize rules. Eg. R4 could have very low priority. Only
fire if nothing else can fire.
Fire all applicable rules at once.
A language may provide a range of different strategies.
The CLIPS Expert System tool is based on forward chaining.
Backward Chaining System
Forward allow draws new conclusion from existing data.
Useful - know all the initial facts but do not know ….
If we know conclusions/goals/hypothesis without knowing all
initial facts then use backward chaining.
Avoid irrelevant inferences and focus just on the hypothesis
in question.
It does not need to update the working memory.
Algorithm :
To prove goal G:
If G is in the initial facts it is proven.
Otherwise, find a rule which can be used to conclude G, and try to prove each of
that rule’s preconditions.
If all preconditions true then G is proven.
Example (Given rules and some initial facts) :
Start to prove :
G1 : switch_on_sprinklers
Conflict strategies :
If there is more than one rules for the same conclusions. Try them all. See
which one can be proved. Search techniques may be used to try all posibilities.
Prolog uses backward chaining system.
Forward vs Backward Reasoning
Suitable applications such as on expert systems.
Medical diagnosis, i.e., MYCIN, use backward chaining since
hypotheses of the diseases are known.
Computer configuration, i.e., XCON – since there are an
enormous number of possible configurations and it would not
be sensible to go through all. Forward chaining is a better
idea. It starts with the specifications and gradually building up
(in working memory) a possible configurations.