Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

JU Ch8

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 30

Introduction to Artificial Intelligence

(Comp551)
1

JIMMA UNIVERSITY
JIMMA INSTITUTE OF TECHNOLOGY
DEPARTMENT OF COMPUTING

CHAPTER EIGHT
INFERENCE IN FIRST-ORDER LOGIC
Topics we will cover
2

Reducing first-order inference to propositional


inference:
 Resolution
Unification & Generalized Modus Ponens:
 Forward chaining
 Backward chaining
Logic Programming
Converting FOL to Propositional Logic (1)
3

 First stage is to eliminate universal quantifiers (i.e. )


 The rule of Universal Instantiation (UI):
 Every instantiation of a universally quantified sentence is entailed by it.

 E.g., x (Fast(x)  Strong(x))  EthiopianRunner(x)

 For example, if the KB contains the symbols Kenenisa, Derartu and Haile,
then the sentence,
 Yields:
Fast(Kenenisa)  Strong (Kenenisa)  EthiopianRunner (Kenenisa)
Fast(Derartu)  Strong (Derartu)  EthiopianRunner (Derartu)
Fast(Haile)  Strong (Haile)  EthiopianRunner (Haile).
Converting FOL to Propositional Logic (2)
4

 Next stage is to eliminate existential quantifiers (i.e. )


 The rule of Existential Instantiation(EI):
 We must create a new sentence for each existential quantifier using a
new object name that does not already exist in the KB.

 E.g., x Runner(x)  TeammateOf(x,Kenenisa)


 Yields:
 For example, the sentence could be converted to:
Runner(C1)  TeammateOf(C1,Kenenisa)
 Note that this will only be a valid replacement if the symbol C1 does
not already exist in the KB.
provided C1 is a new constant symbol
(called a Skolem Constant)
Converting FOL to Propositional Logic (3)
5

 The process of eliminating both universal and existential


quantifiers is known as propositionalising the KB.

 Every FOL KB can be propositionalised so as to preserve


entailment.

 Idea: propositionalise KB, query it, apply resolution,


return result.
 Problem:
 Propositionalisation seems to generate lots of
irrelevant sentences.
Converting FOL to Propositional Logic (4)
6

 Idea: propositionalise KB, query it, apply resolution, return result.


 Problem:
 Propositionalisation seems to generate lots of irrelevant sentences.
 E.g., From:
x (Fast(x)  Strong(x))  EthiopianRunner(x)
Fast(Kenenisa)
y Strong (y)
SameNationality(TeddyAfro,Kenenisa)
 It seems obvious that EthiopianRunner(Kenenisa), but propositionalisation
produces lots of facts such as Strong(TeddyAfro) that are irrelevant,
 Yields:
 Fast(Kenenisa)
 Strong (Kenenisa)
 Strong (TeddyAfro)
 SameNationality(TeddyAfro,Kenenisa)
Fast(Kenenisa)  Strong (Kenenisa)  EthiopianRunner (Kenenisa)
Fast(TeddyAfro)  Strong (TeddyAfro)  EthiopianRunner (TeddyAfro).
Converting FOL to Propositional Logic (5)
7

 E.g. Suppose the KB contains just the following:


x (Fast(x)  Strong(x))  EthiopianRunner(x)
Fast(Kenenisa)
Strong(Kenenisa)
TeammateOf(Haile, Kenenisa)

 Instantiating the universal sentence in all possible ways, we have:


Fast(Kenenisa)  Strong (Kenenisa)  EthiopianRunner (Kenenisa)
Fast(Haile)  Strong (Haile)  EthiopianRunner (Haile)
Fast(Kenenisa)
Strong(Kenenisa)
TeammateOf(Haile, Kenenisa)

 The new KB is propositionalised.


Inference by Unification
8

 This algorithm works by comparing sentences in the


KB element by element, and gradually building up a
set of substitutions.
 We can get the inference immediately if we can find a
substitution θ such that Fast(x) and Strong(x) match
Fast(Kenenisa) and Strong(y)

 x (Fast(x)  Strong(x))  EthiopianRunner(x)

θ = {x/Kenenisa,y/Kenenisa} works

Therefore we can infer that EthiopianRunner(Kenenisa)


Unification Examples
9

p q θ
Likes(Andy,x) Likes(Andy,Injera) {x/Injera}

Likes(Andy,x) Likes(y,Injera) {x/Injera, y/Andy}

Knows(Rahel,x) Knows(y,Mother(y)) {x/Mother(Rahel), y/Rahel}

Knows(Rahel,x) Knows(x,Selam) Fails


Generalized Modus Ponens (GMP)
10

 Recall the Modus Ponens inference rule from chapter 6:

 Unification allows us to define a Generalised Modus Ponens that we


can use with FOL, e.g. x (Fast(x)  Strong(x))  EthiopianRunner(x)
p1', p2', … , pn', ( p1  p2  …  pn q)
where pi'θ = pi θ for all i

p1' is Fast(Kenenisa) p1 is Fast(x)
p2' is Strong(y) p2 is Strong(x)
θ is {x/Kenenisa,y/Kenenisa} q is EthiopianRunner(x)
q θ is EthiopianRunner (Kenenisa)

 Can use this inference rule with forward/backward chaining


 Must first convert KB into definite clauses:
 “either atomic, or an implication with a single consequent (right-hand side) and
 left-hand side is a conjunction of literals”
Example knowledge base
11

 For Example:
 “The law says that it is a crime for all American to sell
weapons to hostile nations. The country Nono, an enemy
of America, has some missiles, and all of its missiles were
sold to it by Colonel West, who is American.”
 Show that Colonel West is a criminal.
 Prove that Nono, an enemy/hostile of America.

FOL:
Example knowledge base
12

 It is a crime for all American to sell weapons to hostile nations, we omit


the universal quantifier but keep the variables.
R1: ( American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z) ) Criminal(x)
 Nono … has owns some missiles, i.e., y Owns(Nono,y)  Missile(y):
 Using existential quantifier elimination we can replace this with the
sentence: R2: Owns(Nono,M1) and Missile(M1)
 Next we need to state that all of Nono’s missiles were sold to it by
Colonel West. (In short West)
R3: Missile(y)  Owns(Nono,y)  Sells(West,y,Nono)
 We also need to state that missiles are weapons.
R4: Missile(y)  Weapon(y)
 An enemy of America counts as "hostile“:
R5: Enemy(z,America)  Hostile(z)
 Colonel West(In short West) is an American:
R6: American(West)
 Finally, we say that the country Nono is an enemy of America.
R7: Enemy(Nono,America)
Forward chaining example (1)
13
Forward chaining example (2)
14

Missile(y)  Weapon(y) {y/M1}

Missile(y)  Owns(Nono,y)  Sells(West,y,Nono) {y/M1}


Enemy(z,America)  Hostile(z) {z/Nono}
Forward chaining example (3)
15

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


{x/West, y/M1, z/Nono}
Properties of forward chaining(FC)
16

Sound and complete for first-order definite


clauses.

Datalog = first-order definite clauses + no


functions.
FC terminates for Datalog in finite number of
iterations.

May not terminate in general if query sentence α is


not entailed.
Backward chaining example (1)
17
Backward chaining example (2)
18

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Backward chaining example (3)
19
Backward chaining example (4)
20

Missile(y)  Weapon(y)
Backward chaining example (5)
21

Missile(M1)
Backward chaining example (6)
22

Missile(y)  Owns(Nono,y)  Sells(West,y,Nono)


Backward chaining example (7)
23

Owns(Nono,M1) and Missile(M1)


Enemy(z,America)  Hostile(z) Enemy(Nono,America)
Properties of backward chaining
24

Depth-first recursive proof search: space is linear in


size of proof.

Widely used for logic programming.


Exercises
25
The following is a KB expressed in FOL definite
clauses.
Q1. Draw an AND-OR graph
that illustrates this KB?

Q2. State what steps will be involved in applying the forward chaining
algorithm to this KB?
Q3. State what steps will be involved in applying the backward chaining
algorithm to this KB to infer the goal Winner(Kenenisa)?
Logic Programming: Prolog (1)
26

Prolog – a First-Order Logic inference engine.


Knowledge expressed as FOL definite clauses.
 Performs inference using backward chaining.

 Widely used in universities, some application in expert


systems.
Program = set of clauses, e.g. “The law says that it is a
crime for all American to sell weapons to hostile nations.”
FOL:
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)

Prolog:
criminal(X) :- american(X),weapon(Y),sells(X,Y,Z),hostile(Z).
Logic Programming: Prolog (2)
27

Objects:
 Like variables in FOL, represented by identifiers starting
with lower-case letter, e.g. american, west
Variables:
 Identifiers starting with upper-case letters, e.g. X,Y,Z…
 Prolog will try to instantiate the variable to an object.
 Anonymous variables: we don’t care what the value is
 Represented by underscore symbol( _ )
For Example.
 The simplest way of describing the world is by stating facts
and rules, like this one:
Logic Programming: Prolog Program Examples (3)
28

Knowledge Base:
likes(tsega,Food) :- ethiopian(Food).
ethiopian(injera).
ethiopian(firfir).

Ask questions of the KB: ? likes(X,firfir).


X=tsega.
? likes(tsega,injera). ? likes(_,firfir).
True. ? likes(tsega,X).
?likes(bisrat,firfir). True. X=injera;
False. X=firfir.
Logic Programming: Prolog (4)
29

Conjunctions (AND) - use comma:


american(X), weapon(Y).
Disjunctions (OR) – use semi-colon:
american(X) ; weapon(Y).
Negation (NOT) – use not predicate:
not(likes(rahel, injera)).
Comments:
% single line comment
/* multi-line comment */
Summary
30

FOL Inference:
 Reduce FOL to Propositional Logic, then apply resolution.
 Use Unification & Generalised Modus Ponens, then apply
backward/forward chaining.
Logic Programming
 Prolog (& others) are FOL inference engines.

You might also like