Ai Unit 3 Notess
Ai Unit 3 Notess
UNIT – III
KNOWLEDGE REPRESENTATION
Knowledge-Based agents
• 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. These agents can represent the world with some formal
representation and act intelligently.
• Knowledge-base and
• Inference system.
A knowledge-based agent must able to do the following:
1
Unit 3
• Inference means deriving new sentences from old. Inference system allows us to add a
new sentence to the knowledge base. A sentence is a proposition about the world.
Inference system applies logical rules to the KB to deduce new information.
TELL: This operation tells the knowledge base what it perceives from the environment.
ASK: This operation asks the knowledge base what action it should perform.
1. function KB-AGENT(percept):
2. persistent: KB - a knowledge base, t - a counter initially 0, indicating time
3. TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
4. Action = ASK(KB, MAKE-ACTION-QUERY(t))
5. TELL(KB, MAKE-ACTION-SENTENCE(action, t))
6. t=t+1
7. return action
Each time when the function is called, it performs its three operations:
• Firstly it TELLs the KB what it perceives.
• Secondly, it ASKS KB what action it should take
• Third agent program TELLS the KB that which action was chosen.
• The MAKE-PERCEPT-SENTENCE generates a sentence as setting that the agent
perceived the given percept at the given time.
• The MAKE-ACTION-QUERY generates a sentence to ask which action should be
done at the current time.
• MAKE-ACTION-SENTENCE generates a sentence which asserts that the chosen
action was executed.
2
Unit 3
Problem definition: The Wumpus world is a cave which has 4/4 rooms connected with
passageways. So there are total 16 rooms which are connected with each other. We have a
knowledge-based agent who will go forward in this world. The cave has a room with a beast
which is called Wumpus, who eats anyone who enters the room. The Wumpus can be shot by
the agent, but the agent has a single arrow. In the Wumpus world, there are some Pits rooms
which are bottomless, and if agent falls in Pits, then he will be stuck there forever. The exciting
thing with this cave is that in one room there is a possibility of finding a heap of gold. So the
agent goal is to find the gold and climb out the cave without fallen into Pits or eaten by
Wumpus. The agent will get a reward if he comes out with gold, and he will get a penalty if
eaten by Wumpus or falls in the pit.
There are also some components which can help the agent to navigate the cave. These
components are given as follows:
The rooms adjacent to the Wumpus room are smelly, so that it would have some
stench.
The room adjacent to PITs has a breeze, so if the agent reaches near to PIT, then he
will perceive the breeze.
There will be glitter in the room if and only if the room has gold.
The Wumpus can be killed by the agent if the agent is facing to it.
3
Unit 3
-1000 points penalty for being eaten by the Wumpus or falling into the pit.
-1 for each action, and -10 for using an arrow.
The game ends if either agent dies or came out of the cave.
Environment:
Actuators:
Left turn,
Right turn
Move forward
Grab
Release Shoot.
Sensors:
The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not
diagonally).
The agent will perceive breeze if he is in the room directly adjacent to the Pit. The
agent will perceive the glitter in the room where the gold is present.
4
Unit 3
Initially, the agent is in the first room or on the square [1,1], and we already know that
this room is safe for the agent, so to represent on the below diagram (a) that room is
safe we will add symbol OK. Symbol A is used to represent agent, symbol B for the
breeze, G for Glitter or gold, V for the visited room, P for pits, W for Wumpus.
At Room [1,1] agent does not feel any breeze or any Stench which means the adjacent
squares are also OK.
5
Unit 3
Propositional Logic
• Propositional logic (PL) is the simplest form of logic where all the statements are made
by propositions.
• A proposition is a declarative statement which is either true or false. It is a technique of
knowledge representation in logical and mathematical form.
Example:
a) It is Sunday.
6
Unit 3
• Statements which are questions, commands, or opinions are not propositions such as
"Where is Rohini", "How are you", "What is your name", are not propositions.
1) Atomic Propositions
2) Compound propositions
Atomic Proposition: Atomic propositions are the simple propositions. It consists of a single
proposition symbol. These are the sentences which must be either true or false.
Example:
Example:
P= Rohan is intelligent,
Q= Rohan is hardworking. → P∧ Q.
7
Unit 3
Truth Table:
8
Unit 3
9
Unit 3
• A square is breezy if and only if there is a pit in a neighbouring square. This has to be
stated for each square; for now, we include just the relevant squares:
• Now we include the breeze percept for the first two squares visited in the specific world
the agent is in
• The knowledge base, then, consists of sentences R1 through R5.It can also be
considered as a single sentence-the conjunction R1 A Rz A R3 A R4 A R5-because it
asserts that all the individual sentences are true.
Inference
For propositional logic, models are assignments of true or false to every proposition symbol.
Returning to our wumpus-world example, the relevant proposition symbols are B1,1, B2,1, P1,1,
P1,2,P2,1, P2,2 and P3,1.With seven symbols, there are 27=128 possible models; in three of these,
KB is true.
10
Unit 3
Inference:
In artificial intelligence, we need intelligent computers which can create new logic from old
logic or by evidence, so generating the conclusions from evidence and facts is termed as
Inference.
Inference rules:
Inference rules are the templates for generating valid arguments. Inference rules are applied to
derive proofs in artificial intelligence, and the proof is a sequence of the conclusion that leads
to the desired goal.
Modus Ponens:
Example:
11
Unit 3
Hence, we can say that, if P→ Q is true and P is true then Q will be true.
Modus Tollens:
by Truth table:
And elimination:
12
Unit 3
By applying inference rules, we have to prove any from the above condition.
From the above proof it is proved that there is no pit in [2,1], [2,3], [1,2] and [3,2] square.
13
Unit 3
First-Order Logic
• In propositional logic, we can only represent the facts, which are either true or false. PL
is not sufficient to represent the complex sentences or natural language statements. The
propositional logic has very limited expressive power.
First-Order logic:
Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus, ......
Relations: It can be unary relation such as: red, round, is adjacent, or n-any relation such
as: the sister of, brother of, has color, comes between
Function: Father of, best friend, third inning of, end of, ......
Variables x, y, z, a, b,....
14
Unit 3
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
The objects in the model may be related in various ways. In the figure, Richard and John are
brothers.
Thus, the brotherhood relation in this model is the set { (Richard the Lionheart, King John),
(King John, Richard the Lionheart) ).
Person Richard
Crown
15
Unit 3
sentences:
Atomic sentences are the most basic sentences of first-order logic. These sentences are formed
from a predicate symbol followed by a parenthesis with a sequence of terms.
We can represent atomic sentences as Predicate (term1, term2, ......, term n).
Complex Sentences:
Complex sentences are made by combining atomic sentences using connectives.
Sisters(geeta,seta)˄sisters(geeta,leela)
Universal Quantifier:
• Universal quantifier is a symbol of logical representation, which specifies that the
statement within its range is true for everything or every instance of a particular thing.
• The Universal quantifier is represented by a symbol ∀, which resembles an inverted A.
• If x is a variable, then ∀x is read as:
o For every x.
16
Unit 3
Existential Quantifier:
Existential quantifiers are the type of quantifiers, which express that the statement within its
scope is true for at least one instance of something. It is denoted by the logical operator ∃. If x
is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
o There exists a 'x.'
o For some
'x.' o For at least
one 'x.'
Let us take a variable x which can take the value of “student”. Let us take a predicate student(x)
which is true if x is a student. Similarly let us take another predicate likes(x,y) which is true if
x likes y.
Properties of Quantifiers:
o In universal
quantifier, ∀x∀y is
similar to ∀y∀x. o
In
Existential
quantifier, ∃x∃y is
similar to ∃y∃x.
17
Unit 3
Equality
We can use the equality symbol to make statements to the effect that two terms refer to the
same object. For example, Father(John) = Henry says that the object referred to by Father(John)
and the object referred to by Henry are the same.
Using FOL
Sentences are added to a knowledge base using TELL, exactly as in propositional logic. Such
sentences are called assertions. For example, we can assert that John is a king and that kings
are persons:
We can ask questions of the knowledge base using ASK. For example,
In this example, we need to make both above statements identical to each other. For this, we
will perform the substitution.
• 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.
18
Unit 3
• 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].
Algorithm
i. Check for Identical expression match. ii. If one expression is a variable vi, and the other is
a term ti which does not contain variable vi, then:
I. Substitute ti / vi in the existing substitutions II.
Add ti /vi to the substitution setlist.
III. If both the expressions are functions, then function name must be similar, and the
number of arguments must be the same in both the expression.
Example:
is inferred that Ram knows Shyam and Akash Conditions for Unification:
• Predicate symbol must be same, atoms or expression with different predicate symbol
can never be unified.
Example: UNIFY Knows (Ram,X) with Brother (Laxman, Ram)
Fails because predicate is different • Number of Arguments in both
expressions must be identical.
Example: UNIFY hate (Marcus) with hate (Marcus, john)
Fails because number of arguments are different • Unification will fail if there are
two similar variables present in the same expression. Example: UNIFY Knows (Ram,
X) with Knows (X, Raman)
Inference Engine
• The inference engine is the component of the expert system in AI, which applies logical
rules to the knowledge base to infer new information from known facts.
19
Unit 3
• Forward and Backward chaining is the strategies used by the inference engine in
making the deductions.
Rule 1: IF X is true
THEN A is true
Rule 2: IF A is true
AND B is true
AND C is true
THEN Y is true
Rule 3: IF Y is true
AND D is true
THEN Z is true
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.
Properties of Forward-Chaining:
Example:
20
Unit 3
• In forward chaining we need to check the given facts in the IF statement, the first given
fact is present in the Rule 2 (i.e Student gets marks > 80).
• In the Rule 2 along with the first given fact, third given fact is also present (i.e, He is
good in general knowledge).
• From the Rule 2, it is inferred that he is excellent in academics (the subgoal).
• Now remaining fact should be checked (i.e, student is making centuries)
• This fact is present in the Rule 3. From that it is inferred that he is good in sports
(subgoal).
• The two inferred subgoals are given in the Rule 1 IF, AND statement.
• From this it is inferred that he is all rounder, which is the final goal.
Backward Chaining
A backward chaining algorithm is a form of reasoning, which starts with the goal and works
backward, chaining through rules to find known facts that support the goal.
Example:
21
Unit 3
following facts:
• In Backward chaining from the goal we need to reach the given facts. Here the goal is
he is all rounder.
• First we need to check whether goal is present in given facts, if not the statements in IF,
AND condition should be treated as subgoals. In the given example IF student is
excellent in academics and AND he is good in sports are the subgoals.
• Next check the subgoals in IF statement, student is excellent in academics is present
in Rule 2 inferred part, so from that we got two given facts i.e student gets marks >
80 and he is good in genera knowledge.
• Next remaining subgoal (i.e he is good in sports) is checked in inferred part; it is
present in Rule 3. From this we got one more fact i.e, student is making centuries.
• Finally we got all the given facts from the inferred statements.
22