AI Module No 4
AI Module No 4
4
Wumpus PIT Breeze
3
Stench Breeze
2
Player Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
4
3
2
Player
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
4
3
Player has arrow and can be shoot once to kill Wumpus
2
Player
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Stench
4
Wumpus Stench
3
Stench
2
Player
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Breeze PIT
4
Breeze PIT Breeze
3
Breeze
2
Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
2
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
4
Gold
2
Player
1
1 2 3 4
By Mr. Sachin Balawant Takmare
• WUMPUS World
• Exploring a WUMPUS World
• The first percept is shown in diagram, from which the agent can
conclude that its neighbouring squares, [1,2] and [2,1], are free of
dangers—they are OK.
• Diagram(a) shows the agent’s state of knowledge at this point.
• Exploring a WUMPUS World
• A cautious agent will move only into a
square that it knows to be OK.
Let us suppose the agent decides to move
forward to [2,1].
• The agent perceives a breeze
(denoted by “B”) in [2,1], so there must be a
pit in a neighbouring square.
• The pit cannot be in [1,1], by the rules of the game, so there must be a
pit in [2,2] or [3,1] or both.
• The notation “P?” in Figure(b) indicates a possible pit in those squares.
• At this point, there is only one known square that is OK and that has not
yet been visited. So the prudent agent will turn around, go back to [1,1],
and then proceed to [1,2].
• Exploring a WUMPUS World
• The agent perceives a stench in [1,2], resulting in
the state of knowledge shown in Figure (c).
• The stench in [1,2] means that there must be a
Wumpus nearby.
• But the Wumpus cannot be in [1,1], by the
rules of the game, and it cannot be in [2,2]
(or the agent would have detected a stench
when it was in [2,1]).
• Therefore, the agent can infer that the
Wumpus is in [1,3].
• The agent has now proved to itself that
there is neither a pit nor a Wumpus in [2,2],
so it is OK to move there.
• Exploring a WUMPUS World
• Here in figure not shown the agent’s state of knowledge at [2,2]; we just
assume that the agent turns and moves to [2,3], giving us Figure (d).
• In [2,3], the agent detects a glitter, so it will grab the gold and then
return home.
Exploring a WUMPUS world
WUMPUS World
Stench Breeze PIT
4
Wumpus PIT Breeze
3
Stench Breeze
2
Player Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Stench Breeze PIT
4
Wumpus PIT Breeze
3
Stench Breeze
2
Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Stench Breeze PIT
4
Wumpus PIT Breeze
3
Stench Breeze
2
Player Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Stench Breeze PIT
4
Wumpus PIT Breeze
3
Stench Breeze
2
Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Stench Breeze PIT
4
Wumpus PIT Breeze
3
Stench Breeze
2
Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Stench Breeze PIT
4
Wumpus PIT Breeze
3
Stench Breeze
2
Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
WUMPUS World
Stench Breeze PIT
4
Wumpus PIT Breeze
3
Stench Breeze
2
Breeze PIT Breeze
1
1 2 3 4
By Mr. Sachin Balawant Takmare
• PEAS description of WUMPUS World
• We can play and feel this game by downloading it from Google
play on android devices
• PEAS description of WUMPUS World
Assume a robotic agent as a player
• Performance measure
• +1000 for grabbing the gold and coming back to the starting position
• -1000 if agent is killed(by falling into pit or eaten by Wumpus)
• - 1 for every move
• - 10 for using the arrow
• Environment
• Empty rooms
• Rooms with Wumpus
• Rooms with Pit
• Room with gold which is glittery
• Rooms with breeze and stench
• Arrow to shoot the Wumpus
• PEAS description of WUMPUS World
• Actuators (Effectors)
• Motor to move forward, Turn left by 900 and Turn right by 900
• Robotic arm to grab the gold
• Mechanism to shoot an arrow
• Sensors
• Camera to get the view
• Odour sensor to smell the stench
• PEAS description of WUMPUS World
• The Wumpus world environment has following characteristics
1. Fully observable
2. Deterministic
3. Episodic
4. Static
5. Discrete
6. Single agent
• Reasoning(Logic)
• Reasoning is associated with thinking, cognition, and intellect.
• The philosophical field of logical studies in which humans reason
formally through arguments
• Reasoning may be subdivided into many forms, we are going to
study only following
✔ Propositional Logic(PL)
✔ First Order Predicate Logic
• Propositional Logic(PL)
• PL is a simple knowledge representation language
• A proposition is the statement of a fact. We usually assign a
symbolic variable (Symbols are denoted by capital letters like A,B,C, etc.)
to represent a proposition, e.g.
• P = It is raining
• Q = I carry an umbrella
• A proposition is a sentence whose truth values may be
determined. So, each proposition has a truth value,(Constants have
truth values i.e. 0 is False and 1 is True) e.g.
• The proposition ‘A rectangle has four sides’ is true
• The proposition ‘The world is a cube’ is false.
• PL is the foundation for higher logics like First Order Logic(FOL)
• Propositional Logic(PL)
• Different propositions may be logically related and we can form
compound statements of propositions using logical connectives.
• Common logical connectives are:
1. ˄ AND (Conjunction)
2. ˅ OR (Disjunction)
3. ¬ NOT (Negation)
4. => If … then (Conditional)
5. <=> If and only if (bi-conditional)
• Propositional Logic(PL)
• Propositional Logic(PL)
• To define logical connectives truth tables are used
• Following Truth Table shows five connectives
T T
T F
F T
F F
• Propositional Logic(PL)
• To define logical connectives truth tables are used
• Following Truth Table shows five connectives
T T T
T F F
F T F
F F F
• Propositional Logic(PL)
• To define logical connectives truth tables are used
• Following Truth Table shows five connectives
T T T T
T F F T
F T F T
F F F F
• Propositional Logic(PL)
• To define logical connectives truth tables are used
• Following Truth Table shows five connectives
T T T T F
T F F T F
F T F T T
F F F F T
• Propositional Logic(PL)
• To define logical connectives truth tables are used
• A=>B equal to ¬A ˅ B
T T T T F T
T F F T F F
F T F T T T
F F F F T T
• Propositional Logic(PL)
• To define logical connectives truth tables are used
• A<=>B equal to (A=>B) ˄ (B=>A)
T T T T F T T
T F F T F F F
F T F T T T F
F F F F T T T
• Propositional Logic(PL)
Conversion of sentences into PL
1. It is hot and sunny
• A: it is hot
• B: it is sunny
✔ A˄B
8. If John brought an i-phone today then he either sold his old mobile
or took a bank loan
• A: John brought i-phone
• B: John sold his old mobile
• C: John took a bank loan
✔ A => (B ˅ C)
• Propositional Logic(PL)
Conversion of sentences into PL
9. If it is hot and humid then it is raining
• A: it is hot
• B: it is humid
• C: it is raining
✔ (A ˄ B) => C
Q2. (A 🡪 B) 🡪 C
Q.3 (A V B) 🡪(C 🡪 D)
Q.4 ¬ ((P V ¬ Q) 🡪 R) 🡪(P ˄ R))
• Propositional Logic(PL)
• Inference in PL:
• If knowledge base is having initial knowledge A=B and B=C
then inference is A=C
• Inference is a new sentence created logically according to
knowledge base
• First Order Logic(FOL)
• FOL is also called as First Order Predicate Logic
• It is much more expressive than PL to represent knowledge
• In FOL we can represent information using relations, variables and
quantifiers
• e.g. 1. “It is Sunday today” can be represented as : today(Sunday)
• e.g. 2. “Gorilla is Black” can be represented as : Gorilla(X)🡪Black(X)
• Rules has two parts predecessor and successor. If the predecessor is
evaluated to true successor will be true
• It uses the implication symbol🡪
• e.g. “if the bag is of Blue colour, I will buy it” will be represented as
• colour(bag, blue)🡪buy(bag)
• First Order Logic(FOL)
• Quantifiers:
• They quantify the number of variables taking part in the relation
• Universal Quantifier(∀):
• Pronounced as “for all” and it is applicable to all the variables in the
predicate
• “ ∀ x A” means A is true for every replacement of x
• 🡪 is the main connective with ∀
• E.g. “Every Gorilla is Black” can be represented by
• ∀ x (Gorilla(x) 🡪 Black(x) )
• E.g. “Everyone in TE Comps is smart” can be represented by
• ∀ x (x, TE Comps 🡪 smart(x) )
• First Order Logic(FOL)
• Existential Quantifier(∃):
• Pronounced as “there exists”
• “∃ x A” means A is true for at least one replacement of x
• ˄ is the main connective with ∃
• E.g. “There is a white Dog” can be represented by
• ∃ x (Dog(x) 🡪 White(x) )
• E.g. “Someone killed the cat and is guilty” can be represented by
• ∃ x Killed(x, Cat) ˄ guilty(x)
❑ Conversion of sentences into FOL
1. “It is Sunday today” can be represented as : today(Sunday)
2. “Gorilla is Black” can be represented as : Gorilla(X)🡪Black(X)
3. “if the bag is of Blue colour, I will buy it” will be represented as
colour(bag, blue)🡪buy(bag)
4. “Every Gorilla is Black” can be represented as
∀ x (Gorilla(x) 🡪 Black(x) )
5. “Everyone in BE Comps is smart” can be represented as
∀ x (x, BE Comps 🡪 smart(x) )
6. “There is a white Dog” can be represented as
∃ x (Dog(x) 🡪 White(x) )
7. “Someone killed the cat and is guilty” can be represented as
∃ x Killed(x, Cat) ˄ guilty(x)
❑ Convert the following sentences into FOL
1. Apple is a fruit
fruit(apple)
2. John is tall
tall(John)
3. Country China is an enemy of India
Enemy(China, India)
4. Anish only likes easy courses
∀ x : Courses(x) ˄ Easy(x) 🡪 Likes(Anish, x)
5. If it is Saturday and warm then Sam is in the Park
day(Saturday) ˄ whether(Warm) 🡪 in_the_park(Sam)
❑ Convert the following sentences into FOL
6. Ravi likes all kind of food
∀x : Food(x) 🡪 Likes(Ravi, x)
7. Ajay eats peanuts and still alive
Eats(Ajay, Peanuts) ˄ Alive(Ajay)
8. Anything anyone eats and not killed is food
∀x ∀y : Eats(x, y) ˄ ¬ Killed(x)
9. Every perfect square is divisible by some prime
∀x ∃y : Square(x) ˄ Divides(Prime, x)
10. All the missiles were sold to PAK by China
∀x Missile(x) ˄ Owns(PAK, x) 🡪 Sell (China, x, PAK)
❑ Convert the following sentences into FOL
After skolemization
1. Smile(A)
2. Graduating(B)
• Convert FOL(First Order Logic) to CNF (Conjunctive Normal Form)
5. Drop universal quantifiers:
Replace universal quantifiers(∀) with constants
e.g.
Before dropping universal quantifier
1. All are smiling ∀(X)Smile(X)
2. All are graduating ∀(X)Graduating(X)
∀ W (¬ Smile(W) ) ….remain as it is
• Convert to CNF
Step:4 Drop universal quantifier (Remove ∀ operator)
Answers:
A. All people who are graduating are happy
∀ X [¬ Graduating(X) ∨ Happy(X) ] … It will change to
¬ Graduating(X) ∨ Happy(X)……(Fact 1)
B. All happy people smile
∀ Y [¬ Happy (Y) ∨ Smile(Y) ] … It will change to
¬ Happy (Y) ∨ Smile(Y) …… (Fact 2)
C. Someone is graduating
Graduating(A)….. remain as it is….. (Fact 3)
¬ Smile(W)
Now search into the list of rules for smile (i.e. Fact 2) and draw it in front
of first box, like
¬ Graduating(W) Graduating(A)
Now contradict above two boxes,
positive Graduation and negative Graduation
get cancelled
NULL
• Final Resolution Tree
Hence “Someone is not smiling” is Wrong, so “Someone is smiling” is Proved
¬ Graduating(W) Graduating(A)
NULL
• FOL-CNF-Resolution
Exercise:
Q. Consider the following facts
1. Ravi likes all kind of food
2. Apple and Chicken are food
3. Anything anyone eats and is not killed is food
4. Ajay eats peanuts and still alive
5. Rita eats that Ajay eats
• Convert to FOL
• Convert FOL to CNF
• Prove that “Ravi likes Peanuts” using resolution
• Draw resolution Graph/Tree
• FOL-CNF-Resolution
Exercise:
Q. Consider the following facts
1. It is a crime for an America to sell weapons to the enemy nations
2. Country Nono is an enemy of America
3. Nono has some missiles
4. All the missiles were sold to Nono by Colonel
5. Missile is a weapon
6. Colonel is an American
• Convert to FOL
• Convert FOL to CNF
• Prove that “Colonel is a Criminal” using resolution
• Draw resolution Graph/Tree
• Inference in First Order Logic
Inference- (conclusion/decision)
Inference engine:
It is component of the system that applies logical rules to the
knowledge base to deduce new information
There are two modes of inference engine
1. Forward chaining: start with the known facts and asserts new
facts
2. Backward chaining: start with goal and work backward to
determine what facts must be asserted so that the goal can be
achieved
• Inference in First Order Logic
1. Forward chaining:
Conclude from A and A => B to B
It is raining(A); if it is raining the road is wet(A=>B)
Infer: the road is wet(B)
2. Backward chaining
Conclude from B and A => B to A
The road is wet(B); if it is raining the road is wet(A=>B)
Infer: It is raining(A)
• Inference in First Order Logic
Forward chaining
• Let’s look at how a doctor goes about diagnosing a patient.
• He asks the patient for symptoms and then infers diagnosis from
symptoms.
• When based on the available data a decision is taken then the
process is called as the forward chaining
• It works from an initial state and reaches to goal state
• Inference in First Order Logic
• Inference in First Order Logic
Backward chaining
• Backward chaining : start with goal and work backward to
determine what facts must be asserted so that the goal can be
achieved
• Backward chaining is an inference strategy that works backward
from a hypothesis to a proof.
• You begin with a hypothesis about what the situation might be.
Then you prove it using given facts,
• e.g. a doctor may suspect some disease and proceed by inspection
of symptoms.
• In backward chaining terminology, the hypothesis to prove is
called the goal.
• Inference in First Order Logic
• Inference in First Order Logic
Forward vs. backward chaining
• The exploration of knowledge has different mechanisms in
forward and backward chaining.
• Backward chaining is more focused and tries to avoid exploring
unnecessary paths of reasoning. Forward chaining, on the other
hand is like an exhaustive search.