MI - Unit 2
MI - Unit 2
Unit –II
Prabhu K, AP(SS)/CSE
Unit I : Logical Agents
Logical Agents
Logical agents – Propositional logic – First order logic – syntax and semantics
of FOL–Using first order logic – knowledge engineering in FOL– Inference in
FOL– Unification and Lifting – Forward and backward chaining – Resolution.
• Apply Inference rules to the given
CO knowledge base for theorem proving
• An agent can represent knowledge of its world, its goals and the current
situation
• The Wumpus hiding somewhere in the cave, and that eats anyone who enters its room.
• The Wumpus can be shot by an agent, but the agent has only one arrow.
• Some rooms contain bottomless pits that will trap anyone who enters into these rooms.
• The only goal in this environment is the possibility of finding a bundle of gold
Wumpus World PEAS description
• Environment: 4 x 4 grid of rooms
• Squares adjacent to wumpus are smelly
• Squares adjacent to pit are breezy
• Glitter iff gold is in the same square
• Shooting kills wumpus if you are facing it
• Shooting uses up the only arrow
• Grabbing picks up gold if in same square
• Releasing drops the gold in same square
• Performance measure
• gold +1000, death -1000
• -1 per step, -10 for using the arrow
• Sensors: Stench, Breeze, Glitter, Bump, Scream (shot Wumpus)
• Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
Wumpus world characterization
• Discrete :Yes
P?
1,3 W? 2,3 3,3 4,3 1,3 W? 2,3 3,3 4,3
G A
S P?
B
1,2 2,2 3,2 4,2
OK A 1,2 S 2,2 3,2 4,2
OK OK
S OK
V V
V
1,1 2,1 3,1 4,1
1,1 2,1 3,1 P? 4,1
V OK OK
OK V P?
V
OK B
B
• Syntax defines how symbols can be put together to form the sentences in the
language Ex: x+4=6 is correct but 4x=6+ is wrong
• x+2 ≥ y is true iff the number x+2 is no less than the number y
• Ex: the sentence (A) The president was assassinated entails (B )The
president is dead A ╞ B
KB ╞ α
• (x=0) ╞(xy=0)
• (p=True) ╞(p∨q)
• (p∧q) ╞ (p∨q)
• ((p⇔q) ∨r) ╞(q⇒p))
• (q ⇒p) ╞(p⇔q) ∨r)?
Models
• Logicians typically think in terms of models, which are formally structured
worlds with respect to which truth can be evaluated
E.g.
α = Phillies won
Entailment in the wumpus world
• α as the needle
c) 3+3=7
• A-It is hot
• B-It is humid
• C-It is raining
• Conditions:
• If it is humid,then it is hot
• B->A
• If it is hot and humid then it is not raining
• A∧B->⏋C
A simple KB Rules :Wumpus world
sentences
Px,y is true if there is a pit in [x,y]
KB= R1∧R2 ∧ R3 ∧ R4 ∧ R5
Inference Goal
• Does KB ╞ P1,2?
• 27 = 128 models.
• For each model check that : if it is true in α it has to be true in KB
Inference :All possible models
Does KB ╞ P1,2?
Only three are true
First order logic
Drawbacks of propositional logic
• Propositional logic is very simple and declarative
• Propositional logic is not sufficient for complex or natural language sentences. ie.
We cannot represent relations like ALL,Some or none
• First order logic is also known as predicate logic or first order predicate
logic
• First-order logic, like natural language has well defined syntax and
semantics.
• First order logic (like natural language) assumes the world contains
• Relations: red, round, prime, brother of, bigger than ,part of, comes
between…
• Functions: father of, best friend, one more than, plus, …
Properties of FOL
• It has ability to represent facts about some or all of the objects and
relations in the universe
• For example, in English we might use the expression "King John's left leg"
rather than giving a name to his leg.
• This is what function symbols are for: instead of using a constant symbol,
we use LeftLeg(John).
Atomic sentences
• E.g.,
• Brother(KingJohn,RichardTheLionheart)
• > (Length(LeftLegOf(Richard)), Length(LeftLegOf(KingJohn)))
• Model contains objects (domain elements) and then relations among them
and functions
• Intended interpretation
• There are five objects in the model so there are 25 possible interpretations
for the constant symbols Richard and John
Models for FOL: Example
• In this way FOL provides meaning to the terms , the predicates and
formulas of the language
Quantifiers
• These are the symbols that permit to determine or identify the range
and scope of the variable in the logic expression
• ∀ x At(x,MCET) ∧ Smart(x)
• ∃x ∃ y is the same as ∃ y ∃ x
• ∃ x ∀ y Loves(x,y)
• ∀ y ∃ x Loves(x,y)
• Equality symbol signifies that two terms refer to the same object
• Predicate is fly(bird)
• ∀x bird(x)->fly
• Predicate is respect(x,y)
where
x=man
y=parent
• ∀y man(x)->respects(x,parent)
• ∃ x boy(x) ∧intelligent(x)
Nested Quantifiers
• AskVars(∃a BestAction(a,5))
• The agent program can then return grab as the action to take
The wumpus world
• Can encode raw percept
• Adjacent( square1,2,square1,1)
• Adjacent(square3,4,square4,4)
• Encode
• Knowledge engineer must describe the range of question that the KB will
support
• Find the facts that available for each specific problem instance
Logical Agents
Logical agents – Propositional logic – First order logic – syntax and semantics
of FOL–Using first order logic – knowledge engineering in FOL– Inference in
FOL– Unification and Lifting – Forward and backward chaining – Resolution.
Inference in FOL
Inference in FOL
• Definition
v α
SUBST({v/g}, α)
• SUBST(x/John)
• SUBST(x/Richard)
• SUBST(x/Father(John))
v α
SUBST({v/k}, α)
• Crown(C1) OnHead(C1,John)
• Skolem constant
• provided C1 is a new constant symbol which is not in KB but satisfy
all properties of ‘x’ called a Skolem constant
• Skolemization-replacing variables with ground terms
Reduction to propositional inference
Suppose the KB contains just the following:
King(John)
Greedy(John)
Brother(Richard,John)
• Instantiating the universal sentence in all possible ways, we have:
King(John)
Greedy(John)
Brother(Richard,John)
• The new KB is propositionalized: proposition symbols are
King(John), Greedy(John), Evil(John), King(Richard), etc.
Problem with propositionalization
• Father(Father(Father(John)))
Unit II
Logical Agents
Logical agents – Propositional logic – First order logic – syntax and semantics
of FOL–Using first order logic – knowledge engineering in FOL– Inference in
FOL– Unification and Lifting – Forward and backward chaining – Resolution.
Unification and Lifting
Unification
• Unification is a kind of binding logic between two or more variables
• In propositional logic it is easy to determine that two literals can not both be
true at the same time
UNIFY(p,q)=Θ where
SUBST(Θ,p)=SUBST(Θ,q)
• We ask ASKVARS(knows(john,x)) whom does John know?
• UNIFY(knows(John,x),Knows(John,Jane))={x/Jane}
• UNIFY(Knows(john,x),Knows(y,Bill))={y/John,x/Bill}
• UNIFY(Knows(John,x),Knows(y,Mother(y)))={y/
John,x/Mother(John))}
Example
• Lets say there are two different expressions
• Perform substitution
• P(x,y)---- ( i)
• P(a,f(z))….. (ii)
• Substitute x with ‘a’ and y with ‘f(z)’ in the first expression and it will be
represented as a/x and f(z)/y
• With both the substitutions the first expression will be identical to the
second expression and the substitution set will be [a/x, f(z)/y].
Example 1
• The UNIFY algorithm will search all the related sentences in the knowledge base which
• UNIFY(Knows(Ram,x),Knows(y,Aakash))={x/Aakash,y/Ram}
• UNIFY(Knows(Ram,x),Knows(x,Raman)=fails
• The last one failed because we have used the same variable for two persons or the two
P q θ
Knows(John,x) Knows(John,Jane) {x/Jane}
• Hate(Marcus,Caesar)
• Hate(Marcus)
• Hate(Marcus,Caesar)
• Unification will fail if there are two similar variables present in the same
expression
• UNIFY(Knows(Ram,x),Knows(x,Ram)=fails
Unification algorithm
Unification algorithm
A first order inference rule
• Suppose KB
• King( John)
• Greedy (John)
• For atomic sentences pi, pi', and q, where there is a substitution Θ such
that SUBST(Θ,p') = SUBST(Θ,pi), for all i,
SUBST(Θ,q)
p1' is King( John) p1 is King(x)
Logical Agents
Logical agents – Propositional logic – First order logic – syntax and semantics
of FOL–Using first order logic – knowledge engineering in FOL– Inference in
FOL– Unification and Lifting – Forward and backward chaining – Resolution.
Forward chaining
Inference Engine
• Horn clause and definite clause are the forms of sentences, which enables
knowledge base to use a more restricted and efficient inference algorithm.
• Horn clause: A clause which is a disjunction of literals with at most one positive
literal is known as horn clause. Hence all the definite clauses are horn clauses.
• It is equivalent to p ∧ q → k.
Forward chaining
• It is also known as a forward deduction or forward reasoning method
when using an inference engine.
• It starts with the available data and uses inference rules to extract more
data until a goal is reached
• Example
• It is raining --A
• If it is raining, the street is wet --A⇒B
• The street is wet ---B
• Conclude from “A” and “A implies B” to “B”
A
A⇒ B
B
What do you mean by forward chaining algorithm?
• The process repeats until the query is answered or no new facts are called.
Example
• Ǝx Owns(Nono, x) ∧ Missile(x)
• Missile(M1)---- 3
Facts Conversion into FOL
All of the missiles were sold to country Nono by Colonel West
• ∀x Missiles(x) ∧ Owns (Nono , x) ⇒Sells (West, x, Nono)
• Can be written as
Missiles(M1) ∧ Owns (Nono , M1) ⇒Sells (West, M1, Nono) .......(4)
• {x/West, y/M1, z/Nono}, so we can add Criminal(West) which infers all the available facts.
And hence we reached our goal statement 1. American (x) ∧ weapon(y) ∧ sells (x, y, z) ∧
hostile(z) ⇒ Criminal(x)
2. Owns(Nono, M1)
3. Missile(M1)
4. Missiles(x) ∧ Owns (Nono , x) ⇒ Sells (West, x,
Nono)
5. Missile(x) ⇒ Weapons (x)
6. Enemy(x, America) ⇒ Hostile(x)
7. Enemy (Nono, America)
8. American(West)
Backward chaining
Backward chaining
Logical Agents
Logical agents – Propositional logic – First order logic – syntax and semantics
of FOL–Using first order logic – knowledge engineering in FOL– Inference in
FOL– Unification and Lifting – Forward and backward chaining – Resolution.
Resolution
Resolution
• It is used ,if there are various statements are given and we need to prove
a conclusion of those statements
• Negate the statement which need to be proved and add the result to the
knowledge base
• If empty clause is produced ,stop and report that original theorem is true
Example1
1. Sunny ∨ warm ∨
enjoy
2. raining ∨ wet
3. warm
4. raining
5. sunny
Example 2:Step1 Conversion to FOL
• The humidity is high or the sky is • The humidity is high or the sky is cloudy
cloudy Let P:The humidity is high
Q: sky is cloudy
• If the sky is cloudy, then it will rain P∨Q
• If the humidity is high then it is hot • If the sky is cloudy, then it will rain
• P∨Q • P∨Q
• Q ⇒R • Q∨R
• P ⇒S • P∨S
• S • S
• P∨Q
• Q∨R
• P∨S
• S
• ( R) -Goal
Example 3 :Step 1:conversion of facts in to FOL
1. ∀x food(x)⇒likes(Sunil)
1. ∀x food(x) ∨ likes(Sunil,x)
2. Food (apple)
2. Food (apple) ∧Food(Vegetable)
∧Food(Vegetable)
3. ∀x∀y [eats(x,y) ∧ killed(x)] ∨
3. ∀x∀y eats(x,y) ∧ killed(x)
Food(y)
⇒Food(y)
4. Eats(Anil,peanuts) ∧alive(Anil)
4. Eats(Anil,peanuts) ∧alive(Anil)
5. ∀x eats(Anil,x) ∨ eats(Harry,x)
5. ∀x eats(Anil,x) ⇒eats(Harry,x)
6. Likes(Sunil,peanuts)
6. Likes(Sunil,peanuts)
7. ∀x [ killed(x) ] ∨ alive(x)
7. ∀x killed(x) ⇒ alive(x)
8. ∀x alive(x) ∨ killed(x)
8. ∀x alive(x) ⇒ killed(x)
Step 2:Move negation() inwards
1. ∀x food(x) ∨ likes(Sunil,x)
1. ∀x food(x) ∨ likes(Sunil,x)
2. Food (apple) ∧Food(Vegetable)
2. Food (apple) ∧Food(Vegetable)
3. ∀x∀y [eats(x,y) ∧ killed(x)] ∨
3. ∀x∀y eats(x,y) ∨ killed(x)] ∨
Food(y)
Food(y)
4. Eats(Anil,peanuts) ∧alive(Anil)
4. Eats(Anil,peanuts) ∧alive(Anil)
5. ∀x eats(Anil,x) ∨ eats(Harry,x)
5. ∀x eats(Anil,x) ∨ eats(Harry,x)
6. Likes(Sunil,peanuts)
6. Likes(Sunil,peanuts)
7. ∀x [ killed(x) ] ∨ alive(x)
7. ∀x killed(x) ∨ alive(x)
8. ∀x alive(x) ∨ killed(x)
8. ∀x alive(x) ∨ killed(x)
Step2: Rename Variables or standardize
variables
• ¬Enemy(x,America) ∨ Hostile(x)
• ¬Missile(x) ∨ Weapon(x)
• Owns(Nono,M1)
• American(West)
• Missile(M1)
• Enemy(Nono, America)
Resolution: brief summary
• Algorithm works using proof by contradiction
(l1 ··· li-1 li+1 ··· lk m1 ··· mj-1 mj+1 ··· mn)