Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 34

UNIT-IV

Logical Agents: Knowledge-based Agents


Logical Agents: Knowledge-based Agents
• Humans claim that how intelligence is achieved-not by purely reflect
mechanisms but by process of reasoning that operate on internal
representation of knowledge.
• In AI this techniques for intelligence are present in Knowledge Based
Agents.
• Knowledge-based agents have explicit representation of knowledge
that can be reasoned.
• They maintain internal state of knowledge, reason over it, update it
and perform actions accordingly. These agents act intelligently
according to requirements.
• Knowledge based agents give the current situation in the form of sentences.
They have complete knowledge of current situation of mini-world and its
surroundings. These agents manipulate knowledge to infer new things at
“Knowledge level”.
• A knowledge-based system has following features :
• Knowledge base (KB): It is the key component of a knowledge-based agent.
These deal with real facts of world. It is a mixture of sentences which are
explained in knowledge representation language.
• Inference Engine(IE): It is knowledge-based system engine used to infer new
knowledge in the system.
• Actions performed by an agent:
Inference System is used when we want to update some information
(sentences) in Knowledge-Based System and to know the already present
information. This mechanism is done by TELL and ASK operations. They include
inference i.e. producing new sentences from old.
Actions done by KB Agent:
• It TELLS what it recognized from the environment and what it needs
to know to the knowledge base.
• It ASKS what actions to do? and gets answers from the knowledge
base.
• It TELLS the which action is selected , then agent will execute that
action.
Algorithm :
function KB_AGENT (percept) returns an action
KB : knowledge base
t : time ( counter initially 0)
TELL(KB, MAKE_PERCEPT_SENTENCE (percept,t) )
action = ASK(KB, MAKE_ACTION_QUERY (t) )
TELL(KB, MAKE_ACTION_SENTENCE (action,t) )
t=t+1
return action
• If a percept is given, agent adds it to KB, then it will ask KB for the
best action and then tells KB that it has in fact taken that action.
• A Knowledge based system behavior can be designed in following approaches:-
• Declarative Approach: In this beginning from an empty knowledge base, the agent
can TELL sentences one after another till the agent has knowledge of how to work
with its environment. This is known as the declarative approach. It stores required
information in empty knowledge-based system.
• Procedural Approach: This converts required behaviors directly into program code in
empty knowledge-based system. It is a contrast approach when compared to
Declarative approach. In this by coding behavior of system is designed .
The Wumpus World
• The Wumpus World’s agent is an example of a knowledge-based agent that represents
Knowledge representation, reasoning and planning.
• Knowledge-Based agent links general knowledge with current percepts to infer hidden
characters of current state before selecting actions.

Problem Statement:
• The Wumpus world is a cave with 16 rooms (4×4). Each room is connected to others
through walkways (no rooms are connected diagonally).
• The knowledge-based agent starts from Room[1, 1]. The cave has – some pits, a treasure and
a beast named Wumpus. The Wumpus can not move but eats the one who enters its room.
• If the agent enters the pit, it gets stuck there. The goal of the agent is to take the
treasure and come out of the cave. The agent is rewarded, when the goal conditions
are met.
• Some elements support the agent to explore the cave, like -The wumpus’s adjacent
rooms are stenchy. -The agent is given one arrow which it can use to kill the
wumpus when facing it (Wumpus screams when it is killed). – The adjacent rooms
of the room with pits are filled with breeze. -The treasure room is always glittery.
• PEAS represents Performance Measures, Environment, Actuators, and Sensors. The PEAS
description helps in grouping the agents.

PEAS Description for the Wumpus World problem:


• Performance measures:
• Agent gets the gold and return back safe = +1000 points
• Agent dies = -1000 points
• Each move of the agent = -1 point
• Agent uses the arrow = -10 points
• Environment:
• A cave with 16(4×4) rooms
• Rooms adjacent (not diagonally) to the Wumpus are stinking
• Rooms adjacent (not diagonally) to the pit are breezy
• The room with the gold glitters
• Agent’s initial position – Room[1, 1] and facing right side
• Location of Wumpus, gold and 3 pits can be anywhere, except in Room[1, 1].
• Actuators:
Devices that allow the agent to perform the following actions in the environment.
• Move forward
• Turn right
• Turn left
• Shoot
• Grab
• Release
• Sensors:
Devices which helps the agent in sensing the following from the environment.
• Breeze
• Stench
• Glitter
• Scream (When the Wumpus is killed)
• Bump (when the agent hits a wall)
Propositional logic

• The simplest kind of logic is propositional logic (PL), in which all statements are
made up of propositions. The term "Proposition“ refers to a declarative
statement that can be true or false. It's a method of expressing knowledge in
logical and mathematical terms.
Example:
• It is Sunday.
• The Sun rises from West (False proposition)
• 3 + 3 = 7 (False proposition)
• 5 is a prime number.
• Because it operates with 0 and 1, propositional logic is also known as Boolean logic.
• In propositional logic, symbolic variables are used to express the logic, and any symbol can be
used to represent a proposition, such as A, B, C, P, Q, R, and so on.
• Propositions can be true or untrue, but not both at the same time.
• An object, relations or functions, and logical connectives make up propositional logic.
• Logical operators are another name for these connectives.
• The essential parts of propositional logic are propositions and connectives.
• Connectives are logical operators that link two sentences together.
• Tautology, commonly known as a legitimate sentence, is a proposition formula that is always
true.
• Contradiction is a proposition formula that is always false.
• Statements that are inquiries, demands, or opinions are not propositions, such as "Where is
Rohini","How are you", and "What is your name" are not propositions.
Syntax of propositional logic :
 The allowed sentences for knowledge representation are defined by the syntax of propositional
logic. Propositions are divided into two categories:
• Atomic Propositions.
• Compound propositions.
 Atomic propositions: Simple assertions are referred to as atomic propositions. It is made up of
only one proposition sign. These are the sentences that must be true or untrue in order to pass.
• Example:
• 2+2 is 4, it is an atomic proposition as it is a true fact.
• "The Sun is cold" is also a proposition as it is a false fact.
 Compound proposition: Simpler or atomic statements are combined with parenthesis and logical
connectives to form compound propositions.

Example:
• "It is raining today, and street is wet."
• "Ankit is a doctor, and his clinic is in Mumbai."
Logical Connectives:
Logical connectives are used to link two simpler ideas or to logically represent a statement. With the use
of logical connectives, we can form compound assertions. There are five primary connectives, which are
listed below:
• Negation: A statement like ¬P is referred to as a negation of P. There are two types of literals: positive
and negative literals.
Example: Rohan is intelligent and hardworking. It can be written as,
P = Rohan is intelligent,
Q = Rohan is hardworking. →P ∧ Q.
• Conjunction:A conjunction is a sentence that contains ∧ connective such as, P ∧ Q.
Example: "Ritika is a doctor or Engineer",
Here P = Ritika is Doctor. Q = Ritika is Doctor, so we can write it as P ∨ Q.
• Disjunction: A disjunction is a sentence with a connective ∨ , such as P ∨ Q, where P and Q are the
propositions.
• Implication: An implication is a statement such as P → Q. If-then rules are another name for
implications. It can be expressed as follows: If it rains, the street is flooded.
Because P denotes rain and Q denotes a wet street, the situation is written as P and Q
• Biconditional: A sentence like P Q, for example, is a biconditional sentence. I am alive if I am breathing.
P= I am breathing, Q = I am alive, it can be represented as P ⇔ Q.
Propositional Logic Connectives

Connective Technical Term Word Example


Symbol

∧ Conjunction AND P∧Q

V Disjunction OR PVQ

→ Implication Implies P→Q

⇔ Biconditional If and only If P⇔Q

¬ or ~ Negation Not ¬P or ¬Q
Truth Table:
• We need to know the truth values of propositions in all feasible contexts in
propositional logic. With logical connectives, we can combine all possible
combinations, and the representation of these combinations in a tabular manner is
known as a truth table. The truth table for all logical connectives is as follows:
For Negation : For Conjunction: For Disjunction: For Implication:
P ¬P P Q P∧Q
P Q PVQ P Q P→Q
true false true true true
true true true true true true
false true true false false
true false true true false false
false true false
false true true false true true
For Biconditional: false false false
false false false false false true
P Q P⇔Q
true true true
true false false
false true false
false false true
Precedence of connectives:
• Propositional connectors or logical operators, like arithmetic operators, have a
precedence order. When evaluating a propositional problem, this order should be
followed. The following is a list of the operator precedence order:

Precedence Operators
First Precedence Parenthesis
Second Precedence Negation
Third Precedence Conjunction(AND)
Forth Precedence Disjunction(OR)
Fifth Precedence Implication
Sixth Precedence Biconditional
Logical equivalence:
• One of the characteristics of propositional logic is logical equivalence. If and only if the
truth table's columns are equal, two assertions are said to be logically comparable. Let's
take two propositions P and Q, so for logical equivalence, we can write it as P ⇔Q. In
below truth table we can see that column for ¬P ∨ Q and P→Q, are identical hence P is
Equivalent to P
P Q ¬P ¬P V Q P→Q
T T F T T
T F F F F
F T T T T
F F T T T
Properties of Operators
• Commutativity:
• P ∧ Q= Q ∧ P, or
• P ∨ Q = Q ∨ P.
• Associativity:
• (P ∧ Q) ∧ R = P ∧ (Q ∧ R),
• (P ∨ Q) ∨ R= P ∨ (Q ∨ R).
• Identity element:
• P ∧ True = P,
• P ∨ True= True.
• Distributive:
• P ∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
• P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
• DE Morgan's Law:
• ¬(P ∧ Q) = (¬P) ∨ (¬Q),
• ¬(P ∨ Q) = (¬ P) ∧ (¬Q).
• Double-negation elimination:
• ¬(¬P) = P.
Reasoning Patterns in Propositional Logic
• The reasoning is the mental process of deriving logical conclusion and making predictions
from available knowledge, facts, and beliefs. Or we can say, "Reasoning is a way to infer facts
from existing data." It is a general process of thinking rationally, to find valid conclusions.
• In artificial intelligence, the reasoning is essential so that the machine can also think
rationally as a human brain, and can perform like a human.

Types of Reasoning
• In artificial intelligence, reasoning can be divided into the following categories:
1) Deductive reasoning
2) Inductive reasoning
3) Abductive reasoning
4) Common Sense Reasoning
5) Monotonic Reasoning
6) Non-monotonic Reasoning
Deductive reasoning
• Deductive reasoning is deducing new information from logically related known information. It is the
form of valid reasoning, which means the argument's conclusion must be true when the premises are
true.
• Deductive reasoning is a type of propositional logic in AI, and it requires various rules and facts. It is
sometimes referred to as top-down reasoning, and contradictory to inductive reasoning.
• In deductive reasoning, the truth of the premises guarantees the truth of the conclusion.
• Deductive reasoning mostly starts from the general premises to the specific conclusion, which can be
explained as below example.

Example:
• Premise-1: All the human eats veggies
• Premise-2: Suresh is human.
• Conclusion: Suresh eats veggies.
Inductive reasoning

• Inductive reasoning is a form of reasoning to arrive at a conclusion using limited sets of facts by
the process of generalization. It starts with the series of specific facts or data and reaches to a
general statement or conclusion.
• Inductive reasoning is a type of propositional logic, which is also known as cause-effect reasoning
or bottom-up reasoning.
• In inductive reasoning, we use historical data or various premises to generate a generic rule, for
which premises support the conclusion.
• In inductive reasoning, premises provide probable supports to the conclusion, so the truth of
premises does not guarantee the truth of the conclusion.
 Example:
• Premise: All of the pigeons we have seen in the zoo are white.
• Conclusion: Therefore, we can expect all the pigeons to be white.
Abductive reasoning
• Abductive reasoning is a form of logical reasoning which starts with single or
multiple observations then seeks to find the most likely explanation or conclusion
for the observation.
• Abductive reasoning is an extension of deductive reasoning, but in abductive
reasoning, the premises do not guarantee the conclusion.
• Example:
• Implication: Cricket ground is wet if it is raining
• Axiom: Cricket ground is wet.
• Conclusion It is raining.
Common Sense Reasoning

• Common sense reasoning is an informal form of reasoning, which can be gained


through experiences.
• Common Sense reasoning simulates the human ability to make presumptions
about events which occurs on every day.
• It relies on good judgment rather than exact logic and operates on heuristic
knowledge and heuristic rules.
Example:
• One person can be at one place at a time.
• If I put my hand in a fire, then it will burn.
The above two statements are the examples of common sense reasoning which a
human mind can easily understand and assume.
Monotonic Reasoning

• In monotonic reasoning, once the conclusion is taken, then it will remain the same even if
we add some other information to existing information in our knowledge base. In monotonic
reasoning, adding knowledge does not decrease the set of prepositions that can be derived.
• To solve monotonic problems, we can derive the valid conclusion from the available facts
only, and it will not be affected by new facts.
• Monotonic reasoning is not useful for the real-time systems, as in real time, facts get
changed, so we cannot use monotonic reasoning.
• Monotonic reasoning is used in conventional reasoning systems, and a logic-based system is
monotonic.
• Any theorem proving is an example of monotonic reasoning.
Example:
• Earth revolves around the Sun.
It is a true fact, and it cannot be changed even if we add another sentence in knowledge base
like, "The moon revolves around the earth" Or "Earth is not round," etc.
Non-monotonic Reasoning
• In Non-monotonic reasoning, some conclusions may be invalidated if we add some
more information to our knowledge base.
• Logic will be said as non-monotonic if some conclusions can be invalidated by
adding more knowledge into our knowledge base.
• Non-monotonic reasoning deals with incomplete and uncertain models.
• "Human perceptions for various things in daily life, "is a general example of non-
monotonic reasoning.
 Example: Let suppose the knowledge base contains the following knowledge:
• Birds can fly
• Penguins cannot fly
• Pitty is a bird
• So from the above sentences, we can conclude that Pitty can fly.
• However, if we add one another sentence into knowledge base "Pitty is a penguin",
which concludes "Pitty cannot fly", so it invalidates the above conclusion.
First-Order Logic
• propositional logic represent facts that are either true or untrue in propositional
logic.
• Represent complicated phrases or natural language statements, PL is insufficient.
The expressive power of propositional logic is quite restricted. Take a look at the
following sentence, which cannot be represented using PL logic.

1."Some humans are intelligent"


2."Sachin likes cricket."

PL logic is insufficient to represent the above statements, so we required some


more powerful logic, such as first-order logic.
First-Order logic
• In artificial intelligence, first-order logic is another method of knowledge representation.
It's a variant of propositional logic.
• FOL has enough expressiveness to convey natural language statements succinctly.
• Predicate logic or First-order predicate logic are other names for first-order logic. First-
order logic is a sophisticated language that makes it easier to build information about
objects and to articulate relationships between them.
 Like propositional logic, first-order logic (like natural language) implies that the world
contains facts, but it also assumes the following things in the world.
• Objects: A, B, people, numbers, colors, squares, pits, wars, theories, 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, ......
• First-order logic also has two main parts as a natural language:
• Syntax
• Semantics
Syntax of First-Order logic

• In first-order logic, the syntax of FOL determines which set of symbols represents a logical
expression. Symbols are the core syntactic constituents of first-order logic. In FOL, we use short-
hand notation to write statements.
Basic Elements of First-order logic:
The basic elements of FOL syntax are as follows:

Constant 1, 2, A, John, Mumbai,


cat,....
Variables x, y, z, a, b,....
Predicates Brother, Father, >,....
Functions sqrt, LeftLegOf, ....
Connectives ∧, v, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
Atomic sentences
• Atomic sentences are the most fundamental first-order logic sentences. These sentences are made
up of a predicate symbol, a parenthesis, and a series of terms.
• Predicate can be used to represent atomic sentences (term1, term2, ......, term n).
• Predicate logic or First-order predicate logic are other names for first-order logic. First-order logic
is a sophisticated language that makes it easier to build information about objects and to articulate
relationships between them.
• Example: Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).
Chinky is a cat: => cat (Chinky).
 Complex Sentences:
• Connectives are used to join atomic sentences to form complex sentences.
 The following are two types of first-order logic statements:
• Subject: The major component of the sentence is the subject.
• Predicate: A predicate is a relationship that ties two atoms together in a sentence.
 Consider the following statement: "x is an integer." It has two parts: the first
component, x, is the statement's subject, and the second half, "is an integer," is a
predicate.
Quantifiers in First-order logic
• Quantification describes the quantity of specimen in the universe of discourse, and a quantifier is a linguistic
element that generates quantification.
• These are the symbols that allow you to determine or identify the variable's range and scope in a logical
expression. There are two different kinds of quantifiers:
Universal Quantifier, (for all, everyone, everything)
Existential quantifier, (for some, at least one).
• Universal Quantifier:
• A universal quantifier is a logical symbol that indicates that a statement inside its range is true for everything
or every instance of a specific thing.

A symbol that resembles an inverted A is used to represent the Universal quantifier.


 the implication of universal quantifier is "→".
• If x is a variable, then ∀x is read as:
For all x
For each x
For every x.
• Example:
• All man drink coffee.
Let a variable x which refers to a cat so all x can be represented in UOD as below:

∀ x man(x) → drink (x, coffee).


It will be read as: There are all x where x is a man who
drink coffee.
• Existential Quantifier:
• Existential quantifiers are a sort of quantifier that expresses that a statement is true for at
least one instance of something within its scope.

The logical operator resembles an inverted E and is used to represent it. It is referred to be
an existential quantifier when it is employed with a predicate variable

Note: we always use the AND or Conjunction symbol (∧) in Existential quantifiers.

If x is a variable, the existential quantifier is either x or (x). And it will be written like follows:
• There exists a 'x.'
• For some 'x.'
• For at least one 'x.'
• ∃x: boys(x) ∧ intelligent(x)
It will be read as: There are some x where x is a boy who is intelligent.
 Properties of Quantifiers:
• In universal quantifier, ∀x ∀y is similar to ∀y ∀x.
• In Existential quantifier, ∃x ∃y is similar to ∃y ∃x.
• ∃x∀y is not similar to ∀y∃x.
• Some Examples of FOL using quantifier:
 All birds fly.
The predicate in this question is "fly(bird)."
Because all birds are able to fly, it will be portrayed as follows.
∀x bird(x) →fly(x).
• Every man respects his parent.
The predicate in this question is "respect(x, y)," where x=man, and y= parent.
Because there is every man so will use ∀, and it will be portrayed as follows:
∀x man(x) → respects (x, parent).
• Some boys play cricket.
In this question, the predicate is "play(x, y), " where x= boys, and y= game. Because there are some boys so we will use ∃, and it will be
portrayed as:
∃x boys(x) → play(x, cricket).
• Not all students like both Mathematics and Science.
The predicate in this question is "like(x, y)," where x= student, and y= subject. Because there are not all students, so we will use ∀ with
negation, so following portray for this:
¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)].
• Only one student failed in Mathematics.
The predicate in this question is "failed(x, y)," where x= student, and y= subject. Because there is only one student who failed in
Mathematics, so we will use following portray for this:
∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) → ¬failed (x, Mathematics)].

You might also like