Knowledge
and
Reasoning
Knowledge-Based Agent in Artificial
intelligence
• An intelligent agent needs knowledge about the real world for taking
decisions and reasoning to act efficiently.
• Knowledge-based agents are those agents who have the capability
of maintaining an internal state of knowledge, reason over that
knowledge, update their knowledge after observations and take
actions.
• Knowledge-based agents are composed of two main parts:
• Knowledge-base
• Inference system.
• A knowledge-based agent must able to do the following:
• An agent should be able to represent states, actions, etc.
• An agent Should be able to incorporate new percepts
• An agent can update the internal representation of the world
• An agent can deduce the internal representation of the world
• An agent can deduce appropriate actions.
A Knowledge Based Agent
Levels of knowledge base
Architecture of a KB Agent
Knowledge-base
Knowledge-base is a central component of a knowledge-
based agent. It is a collection of sentences (here
'sentence' is a technical term and it is not identical to
sentence in English). These sentences are expressed in a
language which is called a knowledge representation
language. The Knowledge-base of KBA stores fact about
the world.
•Why use a knowledge base?
•Knowledge-base is required for updating knowledge for
an agent to learn with experiences and take action as per
the knowledge.
Operations Performed by KBA
• Following are three operations which are
performed by KBA in order to show the intelligent
behavior:
[Link]: This operation tells the knowledge base what it
perceives from the environment.
[Link]: This operation asks the knowledge base what
action it should perform.
[Link]: It performs the selected action.
Representation of Knowledge using
Rules
• Knowledge can be considered to be represented at generally two
levels
• (i) Knowledge level : This level describes the facts.
• (ii) Symbol level : This level deals with using the symbols for
representing the objects, which can be manipulated in programs.
• Knowledge can be represented using the following rules
• (a) Logical representations
• (b) Production rule representations
• (c) Semantic networks
Ways of logical representations
• 1. Propositional logic : These are restricted kinds that make use of propositions (sentences that are either
true or false but not both) which can be either true or false. Proposition logic is also known as propositional
calculus, sentential calculus or Boolean algebra.
• All propositions are either true or false, For example :
• (i) Leaves are green (ii) Violets are blue.
Ways of logical representations
• 2. First order predicate logic : These are much more expressive and
make use of variables, constants, predicates, functions and
quantifiers along with the connectives.
• 3. Higher order predicate logic: Higher order predicate logic is
distinguished from first order predicate logic by using additional
quantifiers and stronger semantics.
• 4. Fuzzy logic : These indicate the existence of in between TRUE and
FALSE or fuzziness in all logics.
(b) Production rule
representation
• One of the widest used methods to represent knowledge is to use production
rules, it is also known as IF-THEN rules.
• Syntax :
• IF condition THEN action
• IF premise THEN conclusion
• IF proposition p1 and proposition p2 are true THEN proposition p3
is true
• Example :
• IF pressure is high, THEN volume is small.
• IF the road is slippery, THEN driving is dangerous.
• Some of the benefits of IF-THEN rules are that they are modular, each defining
a relatively small and, at least in principle, independent piece of knowledge. New
rules may be added and old ones deleted usually independently of other rules.
(c) Semantic networks
• These represent knowledge in the form of graphical
networks, since graphs are easy to be stored inside programs
as they are concisely represented by nodes and edges.
• A semantic network basically comprises of nodes that are
named and represent concepts, and labelled links
representing relations between concepts. Nodes represent
both types and tokens.
Example
• For example, the semantic network in Fig. expresses the knowledge to
represent the following data :
• Tom is a cat.
• Tom caught a fish.
• Tom is grey in color.
• Tom is owned by Sam.
• Tom is a Mammal.
• Fish is an Animal.
• Cats love Milk.
• All mammals are animals
Propositional Logic (PL)
• Propositional Logic (PL) is simple but powerful for
some artificial intelligence problems.
• In case of artificial intelligence propositional logic is
not categorized as the study of truth values, but it is
based on relativity of truth values. (i.e. The
relationship between the truth value of one
statement to that of the truth value of other
statement)
• First-order logic statements can be divided into two parts:
• Subject: Subject is the main part of the statement.
• Predicate: A predicate can be defined as a relation, which binds two atoms
together in a statement.
• Consider the statement: "x is an integer.", it consists of two parts, the
first part x is the subject of the statement and second part "is an integer," is
known as a predicate.
•Every gardener likes the sun.
(Ax) gardener(x) => likes(x,Sun)
•All purple mushrooms are poisonous.
(Ax) (mushroom(x) ^ purple(x)) =>
poisonous(x)
•Deb is not tall.
~tall(Deb)
Inference engine:
• The inference engine is the component of the intelligent
system in artificial intelligence, which applies logical
rules to the knowledge base to infer new information
from known facts.
• Inference engine commonly proceeds in two modes,
which are:
[Link] chaining
[Link] chaining
A. Forward Chaining
• Forward chaining is a form of reasoning which start with atomic sentences in
the knowledge base and applies inference rules (Modus Ponens) in the forward
direction to extract more data until a goal is reached.
• The Forward-chaining algorithm starts from known facts, triggers all rules
whose premises are satisfied, and add their conclusion to the known facts.
This process repeats until the problem is solved.
• Properties of Forward-Chaining:
• It is a down-up approach, as it moves from bottom to top.
• It is a process of making a conclusion based on known facts or data, by
starting from the initial state and reaches the goal state.
• Forward-chaining approach is also called as data-driven as we reach to the
goal using available data.
Backward Chaining
If based on the decision the initial data is fetched, then it is called as backward chaining. Backward chaining or
goal-driven inference works towards a final state, and by looking at the working memory to see if goal already
there
For example, If while going out one has taken umbrella. Then based on this decision it can be guessed that it is
raining.
Here, “taking umbrella” is a decision based on which the data is generated that “it's raining”. This process is
backward chaining. “Backward chaining” is called as a decision-driven or goal-driven inference technique.
To better understand all the above steps, we
will take an example in which we will apply
resolution.
The WUMPUS World Environment
• WUMPUS is an early computer game also known as “Hunt the Wumpus”.
WUMPUS was developed by Gregory Yob in 1972/1973. It was originally written
in BASIC (Beginner's All-purpose Symbolic Instruction Code).
• WUMPUS is a map-based game. Let's understand the game :
• WUMPUS world is like a cave, which represents number of rooms, rooms,
which are connected by passageways.
• We will take a 4 4 grid to understand the game.
• WUMPUS is a monster who lives in one of the rooms of the cave. WUMPUS eats
the player (agent) if player
• (agent) comes in the same room. Fig. shows that room (3, 1) where WUMPUS is
staying.
• Player (agent) starts from any random position in cave and has to explore the
cave. We are starting from (1, 1) position.
• There are various sprites in the game like pit, stench, breeze, gold, and arrow.
Every sprite has some feature. Let’s understand this one-by-one :
The WUMPUS World
Environment
• Few rooms have bottomless pits which trap the player (agent) if he comes to that
room. You can see in the Fig. that room (1,3), (3,3) and (4,4) have bottomless pit.
Note that even WUMPUS can fall into a pit.
• Stench experienced in a room which has a WUMPUS in its neighbourhood room.
See the Fig, here room (2,1), (3,2) and (4,1) have Stench.
• Breeze is experienced in a room which has a pit in its neighbourhood room. Fig. 3
shows that room (1,2), (1,4), (2,3), (3,2), (3,4) and (4,3) consists of Breeze.
• Player (Agent) has arrows and he can shoot these arrows in straight line to kill
WUMPUS.
• One of the rooms consists of gold, this room glitters. Fig. shows that room (3, 2)
has Gold.
• Apart from above features player (agent) can accept two types of percepts which
are: Bump and scream. A bump is generated if player (agent) walks into a wall.
While a sad scream created everywhere in the cave when the WUMPUS is killed.
Description of the WUMPUS World
• An agent receives percepts while exploring the rooms of cave. Every percepts can
be represented with the help of five element list, which is [stench, breeze, glitter,
bump, scream]. Here, player (agent) cannot perceive its own location.
• If the player (agent) gets percept as [Stench, Breeze, None, None, None]. Then
it means that there is a stench and a breeze, but no glitter, no bump, and no
scream in the WUMPUS world at that position in the game.
• Let's take a look at the actions which can be performed by the player(agent) in
WUMPUS World :
• o Move : To move in forward direction,
• o Turn : To turn right by 90 degrees or left by 90 degrees,
• o Grab : To pick up gold if it is in the same room as the player(agent),
• o Shoot : To Shoot an arrow in a straight line in the direction faced by the player
(agent)
Description of the WUMPUS
World
• These actions are repeated till the player (agent) kills the WUMPUS or
if the player (agent) is killed. If the WUMPUS is killed then it is a
winning condition, else if the player (agent) is killed then it is a losing
condition and the game is over.
• Game developer can keep a restriction on the number of arrows
which can be used by the player (agent). So if we allow agent to have
only one arrow, then only the first shoot action will have some effect.
If this shoot action kills the WUMPUS then you win the game,
otherwise it reduces the probability of winning the game.
• Lastly there is a die action : It takes places automatically if the agent
enters in a room with a bottomless pit or in a room with WUMPUS.
Goal of the game
• Main aim of the game is that player (agent) should grab the gold and
return to starting room (here its (1,1)) without being killed by the
monster (WUMPUS).
• Award and punishment points are assigned to a player (Agent)
based on the actions it performs. Points can be given as follows :
• o 100 points are awarded if player (agent) comes out of the cave
with the gold.
• o 1 point is taken away for every action taken.
• o 10 points are taken away if the arrow is used.
• o 200 points are taken away if the player (agent) gets killed.
Give PEAS descriptors for WUMPUS world (May 13, Dec.
14)
• 1. Performance measure
• + 100 for grabbing the gold and coming back to the starting position,
• – 200 if the player (agent) is killed.
• – 1 per action,
• – 10 for using the arrow.
• 2. Environment
• Empty Rooms.
• Room with WUMPUS.
• Rooms neighbouring to WUMPUS which are smelly.
• Rooms with bottomless pits
• Rooms neighbouring to bottomless pits which are breezy.
• Room with gold which is glittery.
• Arrow to shoot the WUMPUS.
Give PEAS descriptors for WUMPUS
world
• Sensors (assuming a robotic agent)
• Camera to get the view
• Odour sensor to smell the stench
• Audio sensor to listen to the scream and bump
• 4. Effectors (assuming a robotic agent)
• Motor to move left, right
• Robot arm to grab the gold
• Robot mechanism to shoot the arrow
Exploring a WUMPUS World
Let’s try to understand the WUMPUS world problem in step by step manner.
WUMPUS world with player in room (1,1)
• Step 1 : Initially the player(agent) is in the room (1,1).
• The first percept received by the player is [none,
none, none, none, none]. (remember percept consists
of
• [stench, breeze, glitter, bump, scream])
• Player can move to room(1,2) or (2,1) as they are safe
cells.
• Step 2 : Let us move to room (1,2).
As room (1,1) is visited you can see “V” mark in that room. The player receives following
percept : [none, breeze, none, none, none].
As breeze percept is received room (1,2) is marked with “B” and it can be predicted
that there is a bottomless pit in the neighboring room.
You can see that room (1,3) and room (2,2) is marked with “P?”. So room (1,3) and
(2,2) is not safe to move in. Thus player should return to room (1,1) and try to find
Step 3
WUMPUS world with player moving back to room (1,1) and then moves to other
safe room (2,1).
• As seen in Fig. . Player in now in room (2,1), where it receives a
percept as follows : [stench, none, none, none,none] which means
that there is a WUMPUS in neighboring room (i.e. either room (2,2) or
(3,1) has WUMPUS).
• As we did not get breeze percept in this room, we can understand
that room (2,2) cannot have any pit and from step 2
• we can understand that room (2,2) cannot have WUMPUS because
room (1,2) did not show stench percept.
• Thus room(2,2) is safe to move in.
Step 4 :
• Player receives [none, none, none, none, none] percept when it comes to room (2,2). From Fig. you
• can understand that room (2,3) and room (3,2) are safe to move in.
Step 5
• : Let's move to room (3,2). Here, player receives [stench, breeze, glitter, none, none] percept.
• Field 1 of the percept shows that room (3,1), (3,3) and (4,2) can have WUMPUS. Field 2 of the
percept shows that room (3,1), (3,3), (2,2) and (4,2) can have bottomless pit. Field 3 of the
percept shows that room (3,2) has gold. So, the player grabs the gold first. As the aim of this
game is to grab the gold and go back to the starting position, without being killed by the
WUMPUS.
• Now, we have to go back to the starting position i.e. room (1,1)
without getting killed by WUMPUS. From steps 1, 2, 3 and 4 We know
that room (1,1), (1,2), (2,1) and (2,2) are safe rooms. so, we can go
back to room (1,1) by following any of the two paths : i.e. (2,2), (2,1),
(1,1) or (2,2), (1,2), (1,1).
Step 6
• As can be seen in Fig. . We will go from room (2,2) to room (2,1) and from room (2,1) to room (1,1).
• Thus we won the WUMPUS World game!!!
Important Questions
What is Knowledge Based Agent? Explain with Architecture
Describe WUMPUS WORLD Environment. Specify PEAS
properties and type of environment
What is propositional logic? Write syntax and semantics and
example sentences for propositional logic.
What is first order logic? Write syntax and semantics of FOL with
example.
What is unification
Explain inference process in FOL using Forward Chaining and
Backward Chaining.
Write a short note on: Resolution.