0% found this document useful (0 votes)
51 views38 pages

Ai Unit-3

Knowledge-based agents in artificial intelligence require a knowledge base and an inference system to make decisions and reason about the world. They can represent states and actions, update their knowledge, and deduce the best actions based on their internal representation. Various approaches to designing these agents include declarative and procedural techniques, and knowledge representation can be achieved through logical, semantic networks, frames, and production rules.

Uploaded by

anithapriyanka3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views38 pages

Ai Unit-3

Knowledge-based agents in artificial intelligence require a knowledge base and an inference system to make decisions and reason about the world. They can represent states and actions, update their knowledge, and deduce the best actions based on their internal representation. Various approaches to designing these agents include declarative and procedural techniques, and knowledge representation can be achieved through logical, semantic networks, frames, and production rules.

Uploaded by

anithapriyanka3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

AI UNIT-3

Knowledge-Based Agent in Artificial intelligence


 For efficient decision-making and reasoning, an intelligent agent need knowledge about
the real world.
 Knowledge-based agents are capable of maintaining an internal state of knowledge,
reasoning over that knowledge, updating their knowledge following observations, and
taking actions. These agents can use some type of formal representation to represent the
world and act intelligently.
 Knowledge-based agents are composed of two main parts:
o Knowledge-base and
o Inference system

The following must be able to be done by a knowledge-based agent:

 Agents should be able to represent states, actions, and other things.


 A representative New perceptions should be able to be incorporated.
 An agent's internal representation of the world can be updated.
 An agent can infer the world's intrinsic representation.
 An agent can deduce the best course of action.

The architecture of knowledge-based agent:

Dept of BCA, SKPFGC Mys Page 1


AI UNIT-3

Knowledge base: : A knowledge-based agent's knowledge base, often known as KB, is a critical
component. It's a group of sentences ('sentence' is a technical term that isn't the same as'sentence'
in English). These sentences are written in what is known as a knowledge representation
language. The KBA Knowledge Base contains information about the world.

Inference system
Inference is the process of creating new sentences from existing ones. We can add a new
sentence to the knowledge base using the inference mechanism. A proposition about the world is
a sentence. The inference system uses logical rules to deduce new information from the KB.
The inference system generates new facts for an agent to update the knowledge base. An
inference system is based on two rules, which are as follows:

 Forward chaining
 Backward chaining

Operations Performed by KBA


Following are three operations which are performed by KBA in order to show the
intelligent behavior:

 TELL: This operation tells the knowledge base, what it discern from the environment.
 ASK: This operation asks the knowledge base what action it should perform.
 Perform: It performs the selected action.

A generic knowledge-based agent:


The structure outline of a generic knowledge-based agents program:

function KB-AGENT(percept):
persistent: KB, a knowledge base
t, a counter, initially 0, indicating time
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

When the function is called, it conducts the following three operations:

Dept of BCA, SKPFGC Mys Page 2


AI UNIT-3

 To begin, it TELLS the KB what it sees.


 Second, it asks the KB what action it should take.
 Finally, the third agent program informs the KB of the action that was chosen.

The MAKE-PERCEPT-SENTENCE command constructs a sentence indicating that the agent


perceived the specified percept at the specified time.

The MAKE-ACTION-QUERY command provides a statement that asks which action should
be taken right now.

MAKE-ACTION-Statement creates a sentence stating that the selected action was carried out.

Various levels of knowledge-based agent:


1. Knowledge level:
The first level of a knowledge-based agent is the knowledge level, where we must explain what
the agent knows and what the agent's goals are. We can correct its behavior using these specs.
Let's say an automated taxi agent needs to get from station A to station B, and he knows how to
get there, so this is a knowledge problem.

2. Logical level:
We understand how the knowledge representation of knowledge is stored at this level. Sentences
are encoded in various logics at this level. At the logical level, knowledge is encoded into logical
statements. We can expect the automated taxi agent to arrive at destination B on a rational level.

3. Implementation level:
Physical representation of logic and knowledge (implementation level). Agents at the
implementation level take actions based on their logical and knowledge levels. At this phase, an
autonomous cab driver puts his knowledge and logic into action in order to go to his destination.

Approaches to designing a knowledge-based agent:


Building a knowledge-based agent can be done in one of two ways:

Dept of BCA, SKPFGC Mys Page 3


AI UNIT-3

1.Declarative approach:
A knowledge-based agent can be created by starting with an empty knowledge base and
informing the agent all the sentences we wish to start with. Declarative approach is the
name given to this method.

2. Procedural technique:
: We directly express desired behavior as a program code in the procedural approach. That
is, all we need to do is develop a program that already has the intended behavior or agent
encoded in it.
In the actual world, however, a successful agent can be created by mixing declarative and
procedural approaches, and declarative information can frequently be turned into more
efficient procedural code.

What is knowledge representation?


Humans excel in comprehending, reasoning, and interpreting information. Humans have
knowledge about things and use that knowledge to accomplish various activities in the real
world. However, knowledge representation and reasoning deal with how robots achieve all of
these things. As a result, the following is a description of knowledge representation:

1. Knowledge representation and reasoning (KR, KRR) is a branch of artificial intelligence


that studies how AI agents think and how their thinking influences their behavior.
2. It is in charge of describing information about the real world in such a way that a
computer can comprehend and use it to solve difficult real-world problems such as
diagnosing a medical ailment or conversing in natural language with humans.
3. It's also a means of describing how artificial intelligence can represent knowledge.
Knowledge representation is more than just storing data in a database; it also allows an
intelligent machine to learn from its knowledge and experiences in order to act
intelligently like a person.

What to Represent:
The types of knowledge that must be represented in AI systems are as follows:

 Object: All of the information on objects in our domain. Guitars, for example, have
strings, while trumpets are brass instruments.
 Events: Events are the actions that take place in our world.

Dept of BCA, SKPFGC Mys Page 4


AI UNIT-3

 Performance: Performance is a term used to describe behavior that entails knowing how
to perform things.
 Meta-knowledge: Meta-knowledge is information about what we already know.
 Facts: The truths about the real world and what we represent are known as facts.
 Knowledge base: The knowledge base is the most important component of knowledge-
based agents. It's abbreviated as KB. The Sentences are grouped together in the
Knowledgebase (Here, sentences are used as a technical term and not identical with the
English language).

Types of knowledge
The various types of knowledge are as follows:

1. Declarative Knowledge:

 Declarative knowledge is the ability to understand something.


 It contains ideas, facts, and objects.
 Declarative sentences are used to express descriptive knowledge, which is also known as
descriptive knowledge.

Dept of BCA, SKPFGC Mys Page 5


AI UNIT-3

 It is less complicated than procedural programming


 Games are modeled as a Search problem and a heuristic evaluation function, which are
the two primary variables that aid in the modeling and solving of games in AI.

2. Procedural Knowledge:

 It's sometimes referred to as "imperative knowledge."


 Procedure knowledge is a form of knowledge that entails knowing how to do something.
 It can be used to complete any assignment.
 It has rules, plans, procedures, and agendas, among other things.
 The use of procedural knowledge is contingent on the job at hand.

3. Meta-knowledge:
Meta-knowledge is information about other sorts of knowledge.

4. Heuristic understanding:

 Heuristic knowledge is the sum of the knowledge of a group of specialists in a certain


field or subject.
 Heuristic knowledge refers to rules of thumb that are based on prior experiences,
awareness of methodologies, and are likely to work but not guarantee

5. Structural knowledge:

 Basic problem-solving knowledge is structural knowledge.


 It describes the connections between distinct concepts such as kind, part of, and grouping.
 It is a term that describes the relationship between two or more concepts or objects.

AI knowledge cycle:
For showing intelligent behavior, an artificial intelligence system must have the following
components:

 Perception
 Learning
 Knowledge Representation and Reasoning
 Planning
 Execution

Dept of BCA, SKPFGC Mys Page 6


AI UNIT-3

Approaches to knowledge representation:


There are basically four approaches to knowledge representation, which are:

1. Simple relational knowledge:


It is the most basic technique of storing facts that use the relational method, with each fact about
a group of objects laid out in columns in a logical order.

 It is the most basic technique of storing facts that use the relational method, with each
fact about a group of objects laid out in columns in a logical order.
 This method of knowledge representation is often used in database systems to express the
relationships between various things.
 This method leaves minimal room for inference.

Example: The following is the simple relational knowledge representation.

Player Weight Age


Player1 65 23
Player2 58 18
Player3 75 24

Dept of BCA, SKPFGC Mys Page 7


AI UNIT-3

Inheritable knowledge:

 All data must be kept in a hierarchy of classes in the inheritable knowledge approach.
 All classes should be organized in a hierarchical or generic fashion.
 We use the inheritance property in this method.
 Other members of a class pass on their values to elements.g
 The instance relation is a type of inheritable knowledge that illustrates a relationship
between an instance and a class.
 Each individual frame might indicate a set of traits as well as their value.
 Objects and values are represented in Boxed nodes in this technique.
 Arrows are used to connect objects to their values.

Inferential knowledge:

 Knowledge is represented in the form of formal logics in the inferential knowledge


approach.
 More facts can be derived using this method.
 It ensured that everything was in order.
 Example: Let's suppose there are two statements:
1. Marcus is a man

Dept of BCA, SKPFGC Mys Page 8


AI UNIT-3

2. All men are mortal


3. Then it can represent as

man(Marcus)
∀x = man (x) ----------> mortal (x)s

4. Procedural knowledge:

 Small programs and codes are used in the procedural knowledge approach to specify how
to do specific things and how to proceed.
 One significant rule employed in this method is the If-Then rule.
 We may employ several coding languages, such as LISP and Prolog, with this
information.
 Using this method, we can readily represent heuristic or domain-specific information.
 But it is not important that we represent all the cases in this approach.

Techniques of knowledge representation

There are basically four ways of knowledge representation and these are given as follows:

1. Logical Representation
2. Semantic Network Representation
3. Frame Representation
4. Production Rules

What to Represent:
The types of knowledge that must be represented in AI systems are as follows:

1.Logical Representation
A language with certain concrete principles that deals with propositions and has no ambiguity in
representation is referred to as logical representation. Drawing a conclusion based on numerous
criteria is referred to as logical representation. Some important communication guidelines are
laid out in this diagram. It's made up of well-defined syntax and semantics that facilitate sound
inference. Each sentence could be translated into logics using the syntax and semantics.

Dept of BCA, SKPFGC Mys Page 9


AI UNIT-3

Syntax:

 Syntaxes are the principles that govern how legal sentences are constructed in logic.
 It determines the symbol we can use to express knowledge.
 What is the best way to write those symbols?

Semantics:

 The rules by which we can comprehend a phrase in logic are known as semantics.
 Semantic also entails giving each statement a meaning.
 There are primarily two logics that can be used to represent logic:
o Propositional Logics
o Predicate logics

Advantages of logical representation:

 We can do logical reasoning with the help of logical representation.


 Programming languages are built on the foundation of logical representation.

Disadvantages of logical Representation:


The various types of knowledge are as follows:

 Logical representations have some limitations and are difficult to use.


 It's possible that the logical representation technique isn't very natural, and inference isn't
particularly efficient.

Note: That logical representation and logical reasoning are not the same thing; logical
representation is a representation language, and reasoning is a logical thinking process.

2. Semantic Network Representation


For knowledge representation, semantic networks are an alternative to predicate logic. We can
express our knowledge in Semantic Networks as graphical networks. This network is made up of
nodes that represent things and arcs that describe their relationships. Semantic networks may
classify objects in a variety of ways and link them together.

This representation consists of basically two types of relations:

1. IS-A relation (Inheritance)


2. Kind-of-relation

Dept of BCA, SKPFGC Mys Page 10


AI UNIT-3

Example: Some statements which we have to represent in the form of nodes and arcs are as
follows.

Statements:

 Jerry is a cat.
 Jerry is a mammal.
 Jerry is owned by Priya.
 Jerry is brown colored.
 All Mammals are animal.

We've used nodes and arcs to represent different types of knowledge in the diagram above. Each
object has some sort of relationship with another object.

Disadvantage in Semantic representation:

 Because we need to traverse the entire network tree to answer some questions, semantic
networks take longer to compute at runtime. In the worst-case situation, we may discover
that the answer does not exist in this network after traversing the entire tree.
 Semantic networks attempt to replicate human-like memory (which has 1015 neurons and
linkages) in order to store information, however in actuality, such a large semantic
network is impossible to construct.
 These types of representations are insufficient since they lack an equivalent quantifier,
such as all, some, none, and so on.
 The link names in semantic networks are not defined in any way.

Dept of BCA, SKPFGC Mys Page 11


AI UNIT-3

 These networks aren't intelligent and rely on the system's inventor.

Advantages of Semantic network:

 Semantic networks are a natural way to represent information.


 Semantic networks are a transparent way of conveying meaning.
 These networks are straightforward and simple to comprehend.

3. Frame Representation

A frame is a record-like structure that contains a set of properties and their values to describe a
physical thing. Frames are a sort of artificial intelligence data structure that splits knowledge into
substructures by depicting stereotyped situations. It is made up of a set of slots and slot values.
These slots can come in any shape or size. Facets are the names and values assigned to slots.
Facets: Facets are the numerous aspects of a slot machine. Facets are characteristics of frames
that allow us to constrain them. Example: When data from a specific slot is required, IF-
NEEDED facts are used. A frame can have any number of slots, each of which can contain any
number of facets, each of which can have any number of values.

Semantic networks gave rise to frames, which later evolved into our modern-day classes and
objects. A single frame is of limited utility. A frames system is made up of a group of
interconnected frames. Knowledge about an object or event can be kept in the knowledge base in
the frame. The frame is a form of technology that can be used in a wide range of applications.

Example: 1
Let's take an example of a frame for a book

Slots Filter
Title Artificial Intelligence
Genre Computer Science
Author Peter Norvig
Edition PThird Edition
Year 1996
Page 1152

Dept of BCA, SKPFGC Mys Page 12


AI UNIT-3

Advantages of frame representation:

 By grouping related facts, the frame knowledge representation makes programming


easier.
 Many AI applications employ the frame representation because it is rather flexible.
 Adding slots for additional attributes and relations is a breeze.
 It's simple to add default data and look for missing variables.
 The frame representation is simple to grasp and visualize.

Disadvantages of frame representation:

 The inference mechanism in a frame system is difficult to process.


 Frame representation does not allow for a smooth progression of the inference procedure.
 The approach to frame representation is rather broad

4. Production Rules
Production rules system consists of (condition, action) pairs which means, "If condition then
action". It has basically three parts:

 The set of production rules


 Working Memory
 The recognize-act-cycled

The agent in production rules checks for the condition, and if it exists, the production rule fires
and the appropriate action is taken. The rule's condition component determines which rule can be
used to solve an issue. The action portion, on the other hand, is responsible for carrying out the
corresponding problem-solving actions. A recognize-act cycle is the name given to the entire
procedure.

Working memory stores a description of the present state of problem-solving, and rules can be
used to write knowledge to it. Other rules may be triggered by this knowledge.

If a new scenario (state) arises, numerous production rules will be fired at the same time, which
is known as a conflict set. In this case, the agent must choose a rule from among these sets, and it
is called a recognize-act cycle.

Example:
IF (at bus stop AND bus arrives) THEN action (get into the bus)
IF (on the bus AND paid AND empty seat) THEN action (sit down).

Dept of BCA, SKPFGC Mys Page 13


AI UNIT-3

IF (on bus AND unpaid) THEN action (pay charges).


IF (bus arrives at destination) THEN action (get down from the bus.

Advantages of Production rule:

1. The production rules are written in plain English.


2. We can quickly delete, add, or modify an individual rule because the production rules are
relatively modular

Disadvantages of Production rule:

1. The production rule system has no learning capabilities because it does not save the
solution to the problem for future use.
2. Many rules may be active during the execution of the program, making rule-based
production systems inefficient.

Propositional logic in Artificial intelligence


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:

1. It is Sunday.
2. The Sun rises from West (False proposition)
3. 3 + 3 = 7 (False proposition)
4. 5 is a prime number.

Following are some basic facts about propositional logic:

 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.

Dept of BCA, SKPFGC Mys Page 14


AI UNIT-3

 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:

1. Atomic Propositions.
2. 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:
1. 2+2 is 4, it is an atomic proposition as it is a true fact.
2. "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:
1. "It is raining today, and street is wet."
2. "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:

1. 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.
2. 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.
3. Disjunction: A disjunction is a sentence with a connective ∨ , such as P ∨ Q, where P
and Q are the propositions.

Dept of BCA, SKPFGC Mys Page 15


AI UNIT-3

4. 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
5. 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.

Following is the summarized table for Propositional Logic Connectives:

Connective Symbol Technical Term Word Example


∧ 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:
P ¬P

True false

False true

For Conjunction:
P Q P∧Q

True true true

True false false

False true false

Dept of BCA, SKPFGC Mys Page 16


AI UNIT-3

false false false

For Disjunction:
P Q PVQ

true true true

true false true

false true true

false false false

For Implication:
P Q P→Q

true true true

true false false

false true true

false false true

For Biconditional:
P Q P⇔Q

true true true

true false false

false true false

false false true

Truth table with three propositions:


You can build a proposition composing three propositions P, Q, and R. The truth table is made
up of 8Xn Tuples as we have taken three proposition symbols.

P Q R ¬R PVQ P V Q → ¬R

true true true false true false

Dept of BCA, SKPFGC Mys Page 17


AI UNIT-3

true true false true true true

true false true false true false

true false false true true true

false true true false true false

false true false true true True

false false true false true True

false false false true true 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

Note: Use parenthesis to make sure of the correct interpretations for a better
understanding. For example: ¬R∨ Q, It can be interpreted as (¬R) ∨ Q.

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

Dept of BCA, SKPFGC Mys Page 18


AI UNIT-3

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:
o P ∧ Q= Q ∧ P, or
o P ∨ Q = Q ∨ P.
 Associativity:
o (P ∧ Q) ∧ R = P ∧ (Q ∧ R),
o (P ∨ Q) ∨ R= P ∨ (Q ∨ R).
 Identity element:
o P ∧ True = P,
o P ∨ True= True.
 Distributive:
o P ∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
o P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
 DE Morgan's Law:
o ¬(P ∧ Q) = (¬P) ∨ (¬Q),
o ¬(P ∨ Q) = (¬ P) ∧ (¬Q).
 Double-negation elimination:
o ¬(¬P) = P.

Limitations of Propositional logic:

 This is not possible to represent relations like ALL, some, or none with propositional
logic. Example:
o All the girls are intelligent.
o Some apples are sweet.
 The expressive power of propositional logic is restricted.
 We can't explain propositions in propositional logic in terms of their qualities or logical
relationships.

Dept of BCA, SKPFGC Mys Page 19


AI UNIT-3

The Wumpus World in Artificial intelligence


The Wumpus world is a basic world example that demonstrates the value of a knowledge-based
agent and how knowledge representation is represented. It was inspired by Gregory Yob's 1973
video game Hunt the Wumpus.

The Wumpus world is a cave with 4/4 rooms and pathways connecting them. As a result, there
are a total of 16 rooms that are interconnected. We now have a knowledge-based AI capable of
progressing in this world. There is an area in the cave with a beast named Wumpus who eats
everybody who enters. The agent can shoot the Wumpus, but he only has a single arrow. There
are some Pits chambers in the Wumpus world that are bottomless, and if an agent falls into one,
he will be stuck there indefinitely. The intriguing thing about this cave is that there is a chance of
finding a gold heap in one of the rooms. So the agent's mission is to find the gold and get out of
the cave without getting eaten by Wumpus or falling into Pits. the agent returns with gold, he
will be rewarded, but if he is devoured by Wumpus or falls into the pit, he will be penalized.

Note: Wumpus is immobile in this scene.

A sample diagram for portraying the Wumpus world is shown below. It depicts some rooms with
Pits, one room with Wumpus, and one agent in the world's (1, 1) square position.

Dept of BCA, SKPFGC Mys Page 20


AI UNIT-3

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 stinky, thus there is a stench there.
 The room next to PITs has a breeze, so if the agent gets close enough to PIT, he will feel
it.
 If and only if the room contains gold, there will be glitter.
 If the agent is facing the Wumpus, the agent can kill it, and Wumpus will cry horribly,
which can be heard anywhere.

PEAS description of Wumpus world:


We have given PEAS description as below to explain the Wumpus world:

Following are some basic facts about propositional logic:


Performance measure:

 If the agent emerges from the cave with the gold, he will receive 1000 bonus points.
 If you are devoured by the Wumpus or fall into the pit, you will lose 1000 points.
 For each action, you get a -1, and for using an arrow, you get a -10.
 If either agent dies or emerges from the cave, the game is over.

Dept of BCA, SKPFGC Mys Page 21


AI UNIT-3

Environment:

 A 4*4 grid of rooms.


 Initially, the agent is in room square [1, 1], facing right.
 Except for the first square [1,1], the locations of Wumpus and gold are picked at random.
 Except for the initial square, every square of the cave has a 0.2 chance of being a pit.

Actuators:

 Left turn
 Right turn
 Move forward
 Grab
 Release
 Shoot

Sensors:

 If the agent is in the same room as the Wumpus, he will smell the stench. (Not on a
diagonal.)
 If the agent is in the room directly adjacent to the Pit, he will feel a breeze.
 The agent will notice the gleam in the room where the gold is located.
 If the agent walks into a wall, he will feel the bump.
 RWhen the Wumpus is shot, it lets out a horrifying scream that can be heard from
anywhere in the cave.
 These perceptions can be expressed as a five-element list in which each sensor will have
its own set of indicators.
 For instance, if an agent detects smell and breeze but not glitter, bump, or shout, it might
be represented as [Stench, Breeze, None, None, None].

The Wumpus world Properties:


 Partially observable: The Wumpus universe is only partially viewable because the agent
can only observe the immediate environment, such as a nearby room.
 Deterministic: It's deterministic because the world's result and outcome are already
known.
 Sequential: It is sequential because the order is critical.
 Static: Wumpus and Pits are not moving, thus it is static.
 Discrete: There are no discrete elements in the environment.
 One agent: We only have one agent, and Wumpus is not regarded an agent, hence the
environment is single agent.

Dept of BCA, SKPFGC Mys Page 22


AI UNIT-3

Exploring the Wumpus world:


Now we will explore Wumpus world a bit and will explain how the agent will find its goal
applying logical reasoning.

Agent's First step:


At first, the agent is in the first room, or square [1,1], and we all know that this room is safe for
the agent, thus we will add the sign OK to the below diagram (a) to represent that room is safe.
The agent is represented by the letter A, the breeze by the letter B, the glitter or gold by the letter
G, the visited room by the letter V, the pits by the letter P, and the Wumpus by the letter W.

Agent does not detect any wind or Stench in Room [1,1], indicating that the nearby squares are
similarly in good condition.

Agent's second Step:


Now that the agent must go forward, it will either go to [1, 2] or [2, 1]. Let's say agent enters
room [2, 1], where he detects a breeze, indicating Pit is present. Because the pit might be in [3, 1]
or [2, 2], we'll add the sign P? to indicate that this is a Pit chamber.

Now the agent will pause and consider his options before doing any potentially destructive
actions. The agent will return to room [1, 1]. The agent visits the rooms [1,1] and [2,1], thus we'll
use the symbol V to symbolize the squares he's been to.

Dept of BCA, SKPFGC Mys Page 23


AI UNIT-3

Agent's third step:


The agent will now proceed to the room [1,2], which is fine. Agent detects a stink in the room
[1,2], indicating the presence of a Wumpus nearby. However, according to the rules of the game,
Wumpus cannot be in the room [1,1], and he also cannot be in [2,2]. (Agent had not detected any
stench when he was at [2,1]). As a result, the agent infers that Wumpus is in the room [1,3], and
there is no breeze at the moment, implying that there is no Pit and no Wumpus in [2,2]. So that's
safe, and we'll designate it as OK, and the agent will advance [2,2]

Agent's fourth step:


Because there is no odor and no breeze in room [2,2], let's assume the agent decides to move to
room [2,3]. Agent detects glitter in room [2,3], thus it should collect the gold and ascend out of
the cave.

What is First Order Logic in Artificial intelligence?


We have seen how to represent statements using propositional logic in the topic of propositional
logic. Unfortunately, we can only represent facts that are either true or untrue in propositional
logic. To 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,

Dept of BCA, SKPFGC Mys Page 24


AI UNIT-3

which cannot be represented using PL logic.

1."Some humans are intelligent", or


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.
1. Objects: A, B, people, numbers, colors, squares, pits, wars, theories, wumpus,
......
2. 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
3. Function: Father of, best friend, third inning of, end of, ......
 First-order logic also has two main parts as a natural language:
1. Syntax
2. 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, >,....

Dept of BCA, SKPFGC Mys Page 25


AI UNIT-3

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.

Dept of BCA, SKPFGC Mys Page 26


AI UNIT-3

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.

Note: 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:

Dept of BCA, SKPFGC Mys Page 27


AI UNIT-3

∀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.'

Example:
Some boys are intelligent.

∃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.

Dept of BCA, SKPFGC Mys Page 28


AI UNIT-3

 ∃x∀y is not similar to ∀y∃x.

Some Examples of FOL using quantifier:

1. 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).
2. 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).
3. 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).
4. 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)].
5. 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)].

Free and Bound Variables:


The quantifiers interact with variables that exist in the right order. First-order logic has two sorts
of variables, which are listed below:

Free Variable: In a formula, a variable is said to be a free variable if it exists outside of the
quantifier's scope.
Example: ∀x ∃(y)[P (x, y, z)], where z is a free variable.

Bound Variable: In a formula, a variable is considered to be a bound variable if it exists within


the quantifier's scope.
Example: ∀x [A (x) B( y)], here x and y are the bound variables.

Dept of BCA, SKPFGC Mys Page 29


AI UNIT-3

What is Forward Chaining and backward


chaining in AI?
Forward and backward chaining is an essential topic in artificial intelligence, but before we go
into forward and backward chaining, let's look at where these two phrases come from.

What is Inference engine?


In artificial intelligence, the inference engine is a component of the intelligent system that
applies logical rules to the knowledge base to infer new information from known facts. The
expert system included the first inference engine. Inference engines often operate in one of two
modes:
a)Forwardchaining
b) Backward chaining

Horn Clause and Definite clause:


Horn clause and definite clause are sentence types that allow the knowledge base to apply a more
limited and efficient inference algorithm. Forward and backward chaining techniques are used in
logical inference algorithms, and they both need KB in the form of a first-order definite
sentence.
Definite clause: sometimes known as a strict horn clause, is a clause that is a disjunction of
literals with exactly one affirmative literal.
Horn clause: A horn clause is a clause that is a disjunction of literals with at most one
affirmative literal. As a result, all of the definite clauses are horn clauses.
Example: (¬ p V ¬ q V k). It has only one positive literal k.
It is equivalent to p ∧ q → k.

A. Forward Chaining
When employing an inference engine, forward chaining is also known as forward deduction or
forward reasoning. Forward chaining is a type of reasoning that starts with atomic sentences in a
knowledge base and uses inference rules (Modus Ponens) to extract more data in the forward
direction until a goal is attained.

The Forward-chaining algorithm begins with known facts, then activates all rules with satisfied
premises and adds their conclusion to the known facts. This process continues until the issue is
resolved.

Properties of Forward-Chaining:

Dept of BCA, SKPFGC Mys Page 30


AI UNIT-3

 As it moves from bottom to top, it is a down-up method.


 It is a method of arriving at a conclusion based on known facts or data by starting at the
beginning and working one's way to the end.
 Forward-chaining is also known as data-driven since it allows us to achieve our goal by
utilizing existing data.
 Expert systems, such as CLIPS, business, and production rule systems, frequently employ
the forward-chaining approach.

Consider the following well-known example, which we'll apply to both ways.
Example:

"As per the law, it is a crime for an American to sell weapons to hostile nations. Country A,
an enemy of America, has some missiles, and all the missiles were sold to it by Robert, who
is an American citizen."

Prove that "Robert is criminal."


To answer the problem, we'll turn all of the facts above into first-order definite clauses, then
utilize a forward-chaining procedure to get to the goal.

Facts Conversion into FOL:

 Selling weapons to unfriendly or hostile countries is illegal in the United States. (Let's
say p, q, and r are variables)
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
 It is a method of arriving at a conclusion based on known facts or data by starting at the
beginning and working one's way to the end.
 Forward-chaining is also known as data-driven since it allows us to achieve our goal by
utilizing existing data.
 Expert systems, such as CLIPS, business, and production rule systems, frequently employ
the forward-chaining approach.

Difference between backward chaining and forward


chaining
Following is the difference between the forward chaining and backward chaining:

 Forward chaining begins with known facts and moves forward by applying inference
rules to extract more data until it reaches the goal, whereas backward chaining begins
with the goal and moves backward by applying inference rules to determine the facts that
satisfy the goal.

Dept of BCA, SKPFGC Mys Page 31


AI UNIT-3

 The down-up strategy is known as forward chaining, and the top-down approach is
known as backward chaining.
 Forward chaining employs a breadth-first search approach, whereas reverse chaining
employs a depth-first search approach.
 The Modus ponens inference rule is used in both forward and backward chaining.
 Forward chaining is useful for jobs like planning, design process monitoring,
diagnosis, and classification, whereas backward chaining is useful for tasks
like categorization and diagnosis.
 Backward chaining aims to avoid the needless path of reasoning, whereas forward
chaining can be like an exhaustive search.
 There may be a variety of ASK questions from the knowledge base in forward-chaining,
whereas there may be fewer ASK questions in backward-chaining.
 Forward chaining is sluggish because it tests all of the rules, whereas backward chaining
is quick since it simply checks the rules that are required.

Forward chaining Backward chaining

1. Forward chaining begins with known facts and Backward chaining starts with the objective and
uses inference rules to extract more data units until works backwards using inference rules to locate
it gets the desired outcome. the necessary facts to support it.

2. It is a bottom-up approach. It is a top-down approach.

3. Forward chaining is also regarded as a data- Backward chaining is a goal-driven strategy


driven inference strategy because it allows us to since it begins with the objective and divides it
attain our goal using the data we already have. into sub-goals in order to extract the facts.

4. Forward chaining is also regarded as a data-driven Backward chaining is a goal-driven strategy since
inference strategy because it allows us to attain our it begins with the objective and divides it into
goal using the data we already have. sub-goals in order to extract the facts.

5. All of the available rules are subjected to forward Only a few required rules are tested via backward
chaining testing. chaining.

6. Forward chaining is appropriate for applications Backward chaining is a useful technique for
such as planning, monitoring, control, and diagnosing, prescribing, and debugging.
interpretation.

7. Forward chaining can lead to an unlimited number The number of possible conclusions generated by
of different outcomes. backward chaining is finite.

Dept of BCA, SKPFGC Mys Page 32


AI UNIT-3

8. It works in the forward direction. It works in the backward direction.

9. The goal of forward chaining is to reach any Backward chaining is only for the data that is
conclusion. required.

Unification in First-Order Logic (FOL)


Unification is a key concept in first-order logic (FOL) that involves finding a common
substitution for two logical expressions, making them identical. This process is crucial for
automated reasoning, theorem proving, and various inference methods in artificial intelligence.

 All FOL inference techniques depend on unified reasoning.


 The algorithm returns failure if two expressions do not match.
 The replacement variables achieved from unification are called Most General Unifier, or simply
MGU.

Example

Let us say we have the following predicates − P(x, Dog) and P(Alex, y). To unify them, we must
find substitutions such that both predicates become the same. The solution is −

 x → Alex
 y → Dog

After substitution, both predicates become P(Alex, Dog), meaning they are unified.

Conditions for Unification


Following are some basic conditions for unification −

 To achieve unification, the predicate names in both formulations must be same. For example,
Loves(x, y) and Hates(A, B) cannot be combined since "Loves" and "Hates" are not synonyms.
 Both expressions must have an equal number of parameters. If one expression is P(A, B) and
another is P(x, y, z), they cannot be combined because the first has two arguments and the latter
has three.

Dept of BCA, SKPFGC Mys Page 33


AI UNIT-3

 A constant can only unify with itself. For example, if one phrase contains Apple and another
contains Orange, unification fails since the two are distinct things.
 A variable can be swapped for a constant or another variable. For example, we can unify P(x, B)
and P(A, y) by assigning x to A and y to B.
 A variable cannot be replaced with an expression containing itself. It is impossible to unify x
with f(x) because it would create a cycle, and therefore, unification is not possible.
 If the same variable occurs twice in different places in an expression, unification fails. For
instance, P(x, x) and P(A, B) cannot be unified since x cannot simultaneously be A and B.

Unification Algorithm
Unification is a crucial technique in first-order logic (FOL) that allows two logical expressions to
be made equal by finding an appropriate substitution. The UNIFY algorithm determines whether
two expressions can be unified and provides the necessary substitutions to achieve this.

Algorithm: UNIFY(Expression1, Expression2)

Step 1: Check if either expression is a variable or constant.

 If the expressions are identical, return an empty substitute (no changes are needed).
 If one of them is a variable, check if the variable occurs in the other expression (to avoid circular
dependency). If so, return FAILURE. Otherwise, substitute the variable with the corresponding
term.
 If neither is a variable expression, then proceed to the next step.

Step 2: Compare the names of the predicates

 If the predicate names in the two expressions are different, unification cannot occur as they
represent different relationships.

Step 3: Verify the number of arguments.

 If the number of parameters in the two expressions is not the same, unification is not possible.
The algorithm will return a FAILURE response.

Step 4: Create an empty substitution set.

 Establish an empty set to hold any variable substitutions required for unification.

Step 5: Attempt to unify each argument recursively.

Dept of BCA, SKPFGC Mys Page 34


AI UNIT-3

Examine the arguments of the two expressions −

 Recursively use the UNIFY function on each pair of parameters.


 If a failure occurs at any point, return a FAILURE.
 If a substitution is identified, apply it to the remaining expressions.

Step 6: Return to the Most General Unifier (MGU)

 Once all the words have been successfully unified, present the final substitution set, known as
the Most General Unifier (MGU).
 This ensures that the expressions are simplified to be equal using the simplest substitutions
available.

Implementation of the Unification Algorithm

Example: Unifying Employee Roles

Determine the Most General Unifier (MGU) between WorksAt(TutorialsPoint, X, Manager) and
WorksAt(TutorialsPoint, John, Y).

Step 1: Start with an empty set of substitutes.

Step 2: Combine the atomic statements step by step.

 The predicate "WorksAt" is identical, so we can proceed.


 The first argument "TutorialsPoint" matches in both cases.
 For the second argument, "X" is a variable, so we substitute X with John.
 For the third parameter, "Manager" and "Y": since Y is a variable, we substitute Y with
Manager.
 Unified Expression: WorksAt (TutorialsPoint, John, Manager). Unifier: {X/John, Y/Manager}.

Importance of Unification in AI
Unification plays a crucial role in artificial intelligence as it enables effective pattern recognition,
logical reasoning, and decision-making across various fields.

 Automated Reasoning: It allows AI to generate new information and apply inference rules
within knowledge-based systems.
 Logic Programming and Prolog: This allows AI to align queries with real stored facts, which
is crucial for making decisions.

Dept of BCA, SKPFGC Mys Page 35


AI UNIT-3

 Natural Language Processing (NLP): Aids in comprehending and interpreting human language
more effectively.
 Expert Systems: Utilizes rule-based decision-making in areas such as medicine, law, and
finance.
 Theorem Proving: Facilitates automated verification of proofs in AI-driven mathematical
reasoning.

Role of Unification in AI-Based Knowledge Representation


Unification in AI-based knowledge representation is critical for improving logical reasoning,
inference, and pattern matching. This method enables AI to create facts, answer questions, and
find answers in fields such as expert systems, theorem proving, and natural language processing,
resulting in faster knowledge processing and increased problem-solving automation.

 Unification allows AI to engage in automated reasoning by aligning logical statements and


drawing conclusions.
 It finds applications in logic programming (like Prolog), natural language processing (NLP), and
expert systems to address queries and make decisions based on established rules.

Examples of Unification in AI
The unification of AI enables the seamless integration of various technologies, enhancing
computers' ability to analyze information and make improved decisions across different fields.

 IBM Watson unifies natural language processing, data analytics, and machine learning to help
professionals in healthcare, finance, and customer service make better decisions by providing AI-
driven insights.
 Amazon Alexa integrates and unifies speech recognition, natural language understanding, and
AI-generated responses to create a seamless user experience, making smart home control more
efficient.
 DeepMinds AlphaFold demonstrates unification by combining AI and biology to predict protein
structures, transforming drug discovery and medical research by accelerating disease
understanding and treatment development.
 Chatbots like Metas BlenderBot improve conversations by understanding context, retrieving
knowledge, and recognizing user intent, creating more natural and meaningful interactions.
 AI in financial fraud detection helps banks monitor transactions, detect anomalies, and prevent
fraud in real-time, ensuring better security and risk management.

Dept of BCA, SKPFGC Mys Page 36


AI UNIT-3

Challenges in Unification
Following are the challenges in Unification −

 Complex Terms: Dealing with deeply nested functions can complicate computations.
 Circular substitutions: Cases like x = f(x), can result in infinite loops, causing unification to
fail.
 Inconsistent expressions: Using a different predicate names or mismatched arguments, prevents
unification.
 High Computational Cost: Unification can be resource-intensive in large AI systems.
 Constraint Handling: Managing constraints by introducing rules or type restrictions can make
the process more complicate.

Unification and Lifting in Artificial Intelligence


Unification is the process of finding a way to make two logical expressions the same. It serves
as the foundation for automated theorem proving, logic programming (like Prolog), and
knowledge representation.

Lifting takes unification a step further by applying it to higher-level representations, enabling AI


to generalize rules and draw inferences across various domains. This approach supports
predicate-based reasoning, making logical deduction more flexible and scalable.

Differences between Unification and Lifting


The following are the key differences between unification and lifting in AI −

Unification Lifting

The process of finding a substitution that makes Extends unification to work at a higher level by
two logical expressions identical. applying inference rules to generalized statements.

Works at the ground level with specific Works at the predicate level, dealing with quantified
constants and variables. expressions and rules.

Used in logic programming (Prolog), theorem Used in automated reasoning, generalized inference,
proving, and knowledge representation. and predicate-based logic systems.

Dept of BCA, SKPFGC Mys Page 37


AI UNIT-3

Unifying P(A, x) and P(A, B) → Substitution: x Inferring x P(x) → Q(x) and P(A) to derive Q(A) by
→B lifting from predicates.

Helps AI match patterns and resolve queries by Enables AI to generalize rules and apply logical
making expressions identical. inference across multiple domains.

Dept of BCA, SKPFGC Mys Page 38

You might also like