You are on page 1of 37

Nur Azzah Abu Bakar

2103, 2nd Floor, School of Computing


nurazzah@uum.edu.my
04 928 4606

Knowledge
Reasoning & Inference
Reasoning

A process of applying knowledge to arrive at


solution

Requires the ability to infer conclusions from the


available facts

It works through interaction of rules and data


Inference

A reasoning mechanism that is


used to relate between facts and
rules to derive a new conclusion or
fact
Reasoning Types
deduce new info
deduce new info from logically related
from heuristics known information

Analogi
Common
Deductive
Abductive
Inductive deduce new info
cal
sense
drawing conclusion from a set of
from the lessons observed cases
learned – look (generalization)
for similarities
& differences
deductive reasoning that
allows plausible inference
Important Concepts

Pattern Instantiatio
Unification
matching n

Substitute/
Matching Pattern
replace a
between matching
variable
symbols,
with +
and
another instantiatio
between
variable or n
predicates.
a constant.
Pattern Matching
2 symbols/predicates
are matched if they arePattern 2
identical

mi
sm
tweety  tweety ... match

atc
h
mismatch
Pattern3 tweaty ... not match
tweety

Pattern 1
fly  flies ... not match
a tch
man  men ... not match
m
Pattern 4
teach(X, math)  teach(she,
math) ... match
Pattern Matching
tweety  tweety exactly the same string of symbols

tweety  tweaty ‘e’ ≠ ‘a’

fly  flies ‘y’ ≠ ‘ies’

man  men ‘a’ ≠ ‘e’

teach(X, math)  •identical predicate name/functor


teach(she, math) •identical # of arguments
Instantiation
A variable
can be
E.g.:
instantiated
with
Another man(X), man(Y)
variable
X/Y or Y/X
e.g: X/Y;
X/Z man(X), man(adam)
X/adam
Constant,
e.g.: X/math; teach(X, math),
Y/adam teach(joe,Y) X/joe;
Y/math
Instantiation

The same variable in the same rule must


be instantiated with the same value
• Rule1: have(X, wings)  flies(X)  isa(X, Y)
• Axiom1: flies(tweety)

• Flies(X) match with flies(tweety) where X=tweety

Rule1 : have(tweety,wings)  flies(tweety) 


isa(tweety,Y)
Unification
E.g.:
isa(X,mammal) and isa(whale,mammal ) ..... X
X/whale; mammalmammal
isa(X,mammal) and isa(Y,Z) ..... X/Y or Y/X;
Z/mammal

Two predicates unify isa(X,Y) and isa(whale,mammal) ..... X/whale;


Y/mammal
when they pass pattern
matching and isa(X,Y) and isa(whale,fish) ..... X/whale; Y/fish
instantiation test.
isa(X,Y) and isa(P,Q) ..... X/P or P/X; Y/Q or Q/Y

isa(X,Mammal) and isa(Whale,mammal) .....


X/Whale or Whale/X; Mammal/mammal
isa(X,Y) and isa(whale,X) ..... X/whale; Y/X and
therefore Y/whale
Unification
E.g.:
isa(X,mammal) and isa(whale,fish ) .....
mammal  fish
Two predicates cannot
isa(X,mammal) and is(Y,Z) ..... isa  is
unify if they failed
pattern matching and/or
isa(X,Y) and isa(whale,mammal,animal) .....
instantiation test.
different # of arguments

isa(X,X) and isa(whale,mammal) ..... whale 


mammal

isa(X,mammal) and isa(whale,X) ..... X/whale;


X/mammal (2 different values for X)
Inference Technique

Modus Ponens
Hypothetical
Modus
Resolution
Tollens
Syllogism

Chaining Strategies:
• Forward
• Backward
Modus Ponens
Definition: Rule of logic that asserts IF A and (A 
B) are known to be true, then one can infer that B is
true.

1. It is sunny day (A)


2. If it is sunny day (A), then we will go to the beach (B)
3. We will go to the beach (B)

1. A
2. A B
3. B
Modus Ponens

A B
A
B

((A  B)  A)  B

..... a tautology
Modus Ponens

What if a rule have >1 propositions?

ABC
A
B
C

((((A  B)  C)  A)  B)  C
Forward & Backward
Chaining Strategy

Nur Azzah Abu Bakar


2103, 2nd Floor, School of Computing
nurazzah@uum.edu.my
04 928 4606
Chaining Strategy

Inference technique used


in rule-based expert
system
Some important concepts
 Goal rule
◦ A rule in which its conclusion is not a premise of any other
rules in the knowledge base
◦ E.g.
R1: (A  B)  C  D
R2: D  G  T
R3: P  Q  B

◦ R2 is the goal rule as its conclusion, T, is NOT one of the


premises of the other rule (i.e. R1 and R3)
Some important concepts
 Sub-goal rule
◦ A rule in which its conclusion is also a premise of the other
rules or in the goal rule.
◦ E.g.
R1: (A  B)  C  D
R2: D  G  T
R3: P  Q  B
◦ R1 and R3 are sub-goal rule as their conclusions are
premises of the other rules
 Conclusion of R1, i.e. D, is a premise of R2
 Conclusion of R3, i.e. B, is a premise of R1
Some important concepts
 Primitive premise
◦ A premise that is not a conclusion of any other rules
◦ E.g.
R1: (A  B)  C  D
R2: D  G  T
R3: P  Q  B

◦ A, C, G, P and Q are primitive premises. WHY? … Look


at the THEN part of R1, R2 and R3
 None of these rules has either A or C or G or P or Q as a conclusion.
Some important concepts
 Non-primitive premise
◦ A premise that is also a conclusion of the other rule(s)
◦ E.g.
R1: (A  B)  C  D
R2: D  G  T
R3: P  Q  B
◦ B and D are non-primitive premises. WHY? … Look at the
IF part of R1 and R3.
 R1 has D as a conclusion while R3 has B as a conclusion.
 Both B and D are premises, at the same time they also are
conclusions, thus they are non-primitive premises.
Some important concepts
 “Rule fire”
◦ A “rule fire” means “rule is concluded”. In other words, it
refers to a state where the conclusion of that rule is proved
as true, because its premise(s) is true”
◦ E.g.
R1: (A  B)  C  D
 If A and B are true, or if C is true, then we say “R1 fire” with a
conclusion D true.

 “Rule not fire”


◦ Is a vice versa of “rule fire” … due to its premise(s) not
true.
Forward Chaining
Inference strategy that
begins with a set of known
facts, derives new facts
using rules which premises
match the known facts,
continues until goal reached
or no more rules matches.

Begins with known data


and works forward to see if
any conclusions (new
information) can be drawn.
Forward Chaining Steps
Get initial If found
data and • fire the rule
place it in • add its
working conclusion to
working
memory. memory.

1 2 3 4

Scan the Repeat


rules Steps 2 &
searching 3 until no
for more
matched match or
premises. goal is
achieved.
Example 1
R1: (A and B) or C implies
D
R2: D or G implies T
 If A and B are true, or C is true, R1 fires and D is inserted into working
memory. D will cause R2 to fire when R2 is scanned. Process is then
terminated as all rules have been scanned, and no more match can be done.
 If none of A, B and C true, continue scan the next rule, i.e. R2. If G is
true, R2 fires and T is inserted into working memory. Process is then
terminated as all rules have been scanned, and no more match can be done.
What if T is in R1?
R1: (A and B) or T implies
D
R2: H or G implies T

 If none of A, B and T is true, scanning is continued with R2.


 If H or G is true, R2 fires and T is inserted into working memory. End of
1st cycle with conclusion T.
 The 2nd cycle of scanning and firing rules begins. T is now in working
memory, therefore R1 fires. D is concluded and inserted into working
memory. End of 2nd cycle with conclusions T and D. The most recent, i.e.
D, becomes the final conclusion.
Example 2
R1: Y  D  Z

R2: X  B  E  Y

R3: A  X

R4: C  L

R5: L  M  N

Axioms A, B, C, D and E are true.


A B C D E A B C D E A B C D E
X L X L Y X L Y Z

YDZ YDZ YDZ


XBEY XBEY XBEY
AX AX AX
CL CL CL
LMN LMN LMN

Cycle 1 Cycle 2 Cycle 3


Backward Chaining

An Inference strategy that attempts to


prove a hypothesis by gathering
supporting information

Works from the goal by chaining


rules (i.e. looks for all relevant,
supporting premises) together to
achieve
Backward Chaining Steps

Finally, fire
Repeat Step 3 the goal rule.
by jumping
If found, and firing all
check its relevant sub-
premise(s). goal rules.
Search for • If premise is
the goal rule. primitive, check if
it is in the
working memory,
ask user a
Identify question if it is
not there.
the goal. • If premise is non-
primitive, jump
to the rule where
it belongs to as a
conclusion (sub-
goal rule).
Repeat Step 3.
Example
R1: (A and B) or C implies
D
R2: D and G implies T

◦ Goal …. T.
◦ Goal rule ….. R2.
◦ T is unknown, thus stack R2 and attempt to establish D and G.
 D becomes the sub-goal … search a rule with in THEN part, find
it at R1, stack R1. Attempt to establish both A and B or just C.
 If A and B true, fire R1 and add D into working memory.
 Return to sub-goal D. Next, check G.
R1: (A and B) or C implies
D
R2: D and G implies T

 If G true, fire R2 and add T into working memory (the original


goal is finally established).
A B C D E

? X Y Z
X
Y
Z
YDZ
XBEY
AX
CL
LMN
Backward vs Forward Chaining
Attribute Backward Chaining Forward Chaining
Also known as Goal-driven Data-driven
Starts from Possible conclusion New data
Processing Efficient Somewhat wasteful
Aims for Necessary data Any conclusion (s)
Approach Conservative/cautious Opportunistic
Practical if Number of possible final Combinatorial explosion
answers is reasonable or creates an infinite number of
a set of known possible right answers
alternatives is available
Appropriate for Diagnostic application Scheduling and monitoring
Example of Selecting a specific type Making changes to corporate
application of investment pension fund
Exercise 1
R1: cheerful(X)  happy(aunt_petunia)
R2: kicking(X, Y)  eating(X)  cheerful(X)
R3: wizard(X)  magical(X)
R4: magical(X)  scares(X,dudley)  hates(uncle_vernon, X)
A1: wizard(harry).
A2: muggle(aunt_petunia).
A3: muggle(uncle_vernon).
A4: scares(hagrid, dudley).
A5: chases(crookshanks, scabbars).
A6: eating(dudley).

(a) Apply Forward Chaining and list all the newly generated
facts.
(b) Use Backward Chaining to prove all aunt_petunia is happy is
true
Exercise 2
R1: caught_with(X1, Y1)  attempted_to_bring_in(X1, Y1, C1).
R2: foreign_visitor(X2)  drugs(Y2)  country(C2) 
attempted_to_bring_in(X2/casey,Y2/cocine,C2/malaysia) 
facing(X2, death_penalty).
A1: country(malaysia)
A2: foreign_visitor(casey)
A3: drugs(cocaine)
A4: caught_with(casey, cocaine)

(a) Use Backward Chaining to determine who is “facing death


penalty”.
(b) Use Forward Chaining to prove your answer in (a).
Exercise 3
Use Backward Chaining to prove that Colonel West is a criminal.
(1) american(X)  weapon(Y)  nation(Z)  hostile(Z) 
sells(X,Y,Z)  criminal(X).
(2) missile(Y)  owns(Z,Y)  sells(colonel_west,Y,Z).
(3) missile(Y)  weapon(Y)).
(4) enemy(Z, america)  hostile(Z).
(5) nation(nono).
(6) enemy(nono, america).
(7) american(colonel_west).
(8) owns(nono, m1).
(9) missile(m1).

You might also like