0% found this document useful (0 votes)
33 views17 pages

AI Unit-III KNOWLEDGE REPRESENTATION-1

Ai unit 3 knowledge representation

Uploaded by

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

AI Unit-III KNOWLEDGE REPRESENTATION-1

Ai unit 3 knowledge representation

Uploaded by

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

Unit -III

Knowledge Representation

Humans are best at understanding, reasoning, and interpreting knowledge. Human


knows things, which is knowledge and as per their knowledge they perform various
actions in the real world. But how machines do all these things comes under
knowledge representation and reasoning. Hence we can describe Knowledge
representation as following:

o Knowledge representation and reasoning (KR, KRR) is the part of Artificial


intelligence which concerned with AI agents thinking and how thinking
contributes to intelligent behavior of agents.
o It is responsible for representing information about the real world so that a
computer can understand and can utilize this knowledge to solve the complex
real world problems such as diagnosis a medical condition or communicating
with humans in natural language.
o It is also a way which describes how we can represent knowledge in artificial
intelligence. Knowledge representation is not just storing data into some
database, but it also enables an intelligent machine to learn from that knowledge
and experiences so that it can behave intelligently like a human.

Knowledge-Based Agent in Artificial intelligence

o An intelligent agent needs knowledge about the real world for taking decisions
and reasoning to act efficiently.
o 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.
o Knowledge-based agents are composed of two main parts:
o Knowledge-base and
o Inference system.

A knowledge-based agent must able to do the following:

o An agent should be able to represent states, actions, etc.


o An agent Should be able to incorporate new percepts
o An agent can update the internal representation of the world
o An agent can deduce the internal representation of the world

1
o An agent can deduce appropriate actions.

The architecture of knowledge-based agent:

The above diagram is representing a generalized architecture for a knowledge-based


agent. The knowledge-based agent (KBA) take input from the environment by
perceiving the environment. The input is taken by the inference engine of the agent and
which also communicate with KB to decide as per the knowledge store in KB. The
learning element of KBA regularly updates the KB by learning new knowledge.

Knowledge base: Knowledge-base is a central component of a knowledge-based


agent, it is also known as KB. It is a collection of sentences (here 'sentence' is a technical
term and it is not identical to sentence in English). These sentences are expressed in a
language which is called a knowledge representation language. The Knowledge-base of
KBA stores fact about the world.

Why use a knowledge base?

Knowledge-base is required for updating knowledge for an agent to learn with


experiences and take action as per the knowledge.

Inference system

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.

Inference system generates new facts so that an agent can update the KB. An inference
system works mainly in two rules which are given as:

o Forward chaining
o Backward chaining

2
Operations Performed by KBA

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

1. TELL: This operation tells the knowledge base what it perceives from the
environment.
2. ASK: This operation asks the knowledge base what action it should perform.
3. Perform: It performs the selected action.

Approaches to designing a knowledge-based agent:

There are mainly two approaches to build a knowledge-based agent:

1. 1. Declarative approach: We can create a knowledge-based agent by initializing


with an empty knowledge base and telling the agent all the sentences with which
we want to start with. This approach is called Declarative approach.
2. 2. Procedural approach: In the procedural approach, we directly encode desired
behavior as a program code. Which means we just need to write a program that
already encodes the desired behavior or agent.

However, in the real world, a successful agent can be built by combining both
declarative and procedural approaches, and declarative knowledge can often be
compiled into more efficient procedural code.

Approaches to knowledge representation:

There are mainly four approaches to knowledge representation, which are givenbelow:

1. Simple relational knowledge:


o It is the simplest way of storing facts which uses the relational method, and each
fact about a set of the object is set out systematically in columns.
o This approach of knowledge representation is famous in database systems where
the relationship between different entities is represented.
o This approach has little opportunity for inference.

Example: The following is the simple relational knowledge representation.

Player Weight Age

3
Player1 65 23

Player2 58 18

Player3 75 24

2. Inheritable knowledge:
o In the inheritable knowledge approach, all data must be stored into a hierarchy of
classes.
o All classes should be arranged in a generalized form or a hierarchal manner.
o In this approach, we apply inheritance property.
o Elements inherit values from other members of a class.
o This approach contains inheritable knowledge which shows a relation between
instance and class, and it is called instance relation.
o Every individual frame can represent the collection of attributes and its value.
o In this approach, objects and values are represented in Boxed nodes.
o We use Arrows which point from objects to their values.
o Example:

3. Inferential knowledge:
o Inferential knowledge approach represents knowledge in the form of formal
logics.
o This approach can be used to derive more facts.
o It guaranteed correctness.
o Example: Let's suppose there are two statements:

a. Marcus is a man

4
b. All men are mortal
Then it can represent as;

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

4. Procedural knowledge:
o Procedural knowledge approach uses small programs and codes which describes
how to do specific things, and how to proceed.
o In this approach, one important rule is used which is If-Then rule.
o In this knowledge, we can use various coding languages such as LISP
language and Prolog language.
o We can easily represent heuristic or domain-specific knowledge using this
approach.
o But it is not necessary that we can represent all cases in this approach.

Techniques of knowledge representation

There are mainly four ways of knowledge representation which are given as follows:

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

1. Logical Representation

Logical representation is a language with some concrete rules which deals with
propositions and has no ambiguity in representation. Logical representation means
drawing a conclusion based on various conditions. This representation lays down some
important communication rules. It consists of precisely defined syntax and semantics
which supports the sound inference. Each sentence can be translated into logics using
syntax and semantics.

o Syntaxes are the rules which decide how we can construct legal sentences in the
logic.
o It determines which symbol we can use in knowledge representation.
o How to write those symbols.

5
Semantics:
o Semantics are the rules by which we can interpret the sentence in the logic.
o Semantic also involves assigning a meaning to each sentence.

Logical representation can be categorised into mainly two logics:

a. Propositional Logics
b. Predicate logics

2. Semantic Network Representation

Semantic networks are alternative of predicate logic for knowledge representation. In


Semantic networks, we can represent our knowledge in the form of graphical networks.
This network consists of nodes representing objects and arcs which describe the
relationship between those objects. Semantic networks can categorize the object in
different forms and can also link those objects. Semantic networks are easy to
understand and can be easily extended.

This representation consist of mainly two types of relations:

a. IS-A relation (Inheritance)


b. Kind-of-relation

3. Frame Representation

A frame is a record like structure which consists of a collection of attributes and its
values to describe an entity in the world. Frames are the AI data structure which divides
knowledge into substructures by representing stereotypes situations. It consists of a
collection of slots and slot values. These slots may be of any type and sizes. Slots have
names and values which are called facets.

4. Production Rules

Production rules system consist of (condition, action) pairs which mean, "If condition then
action". It has mainly three parts:

o The set of production rules


o Working Memory
o The recognize-act-cycle

In production rules agent checks for the condition and if the condition exists then production
rule fires and corresponding action is carried out. The condition part of the rule determines
which rule may be applied to a problem. And the action part carries out the associated problem-
solving steps. This complete process is called a recognize-act cycle.

6
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:
1. a) It is Sunday.
2. b) The Sun rises from West (False proposition)
3. c) 3+3= 7(False proposition)
4. d) 5 is a prime number.

Following are some basic facts about propositional logic:

o Propositional logic is also called Boolean logic as it works on 0 and 1.


o In propositional logic, we use symbolic variables to represent the logic, and we can use
any symbol for a representing a proposition, such A, B, C, P, Q, R, etc.
o Propositions can be either true or false, but it cannot be both.
o Propositional logic consists of an object, relations or function, and logical connectives.
o These connectives are also called logical operators.
o The propositions and connectives are the basic elements of the propositional logic.
o Connectives can be said as a logical operator which connects two sentences.
o A proposition formula which is always true is called tautology, and it is also called a
valid sentence.
o A proposition formula which is always false is called Contradiction.
o A proposition formula which has both true and false values is called
o 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.

Syntax of propositional logic:

The syntax of propositional logic defines the allowable sentences for the knowledge
representation. There are two types of Propositions:

a. Atomic Propositions
b. Compound propositions

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

7
1. a) 2+2 is 4, it is an atomic proposition as it is a true fact.
2. b) "The Sun is cold" is also a proposition as it is a false fact.
o Compound proposition: Compound propositions are constructed by combining simpler
or atomic propositions, using parenthesis and logical connectives.

Example:

1. a) "It is raining today, and street is wet."


2. b) "Ankit is a doctor, and his clinic is in Mumbai."

Logical Connectives:
Logical connectives are used to connect two simpler propositions or representing a sentence
logically. We can create compound propositions with the help of logical connectives. There are
mainly five connectives, which are given as follows:

1. Negation: A sentence such as ¬ P is called negation of P. A literal can be either Positive


literal or negative literal.
2. Conjunction: A sentence which has ∧ connective such as, P ∧ Q is called a conjunction.
Example: Rohan is intelligent and hardworking. It can be written as,
P= Rohan is intelligent,
Q= Rohan is hardworking. → P∧ Q.
3. Disjunction: A sentence which has ∨ connective, such as P ∨ Q. is called disjunction,
where P and Q are the propositions.
Example: "Ritika is a doctor or Engineer",
Here P= Ritika is Doctor. Q= Ritika is Doctor, so we can write it as P ∨ Q.
4. Implication: A sentence such as P → Q, is called an implication. Implications are also
known as if-then rules. It can be represented as
If it is raining, then the street is wet.
Let P= It is raining, and Q= Street is wet, so it is represented as P → Q
5. Biconditional: A sentence such as P⇔ Q is a Biconditional sentence, example If I am
breathing, then I am alive
P= I am breathing, Q= I am alive, it can be represented as P ⇔ Q.

8
Following is the summarized table for Propositional Logic
Connectives:

Truth Table:
In propositional logic, we need to know the truth values of propositions in all possible scenarios.
We can combine all the possible combination with logical connectives, and the representation of
these combinations in a tabular format is called Truth table. Following are the truth table for all
logical connectives:

9
Truth table with three propositions:

We can build a proposition composing three propositions P, Q, and R. This truth table is made-
up of 8n Tuples as we have taken three proposition symbols.

10
Logical equivalence:

Logical equivalence is one of the features of propositional logic. Two propositions are said to be
logically equivalent if and only if the columns in the truth table are identical to each other.

Let's take two propositions A and B, so for logical equivalence, we can


write it as A⇔B. In below truth table we can see that column for ¬A∨ B and A→B, are identical
hence A is Equivalent to B

Properties of Operators:
o Commutativity:
o P∧ Q= Q ∧ P, or
o P ∨ Q = Q ∨ P.
o Associativity:
o (P ∧ Q) ∧ R= P ∧ (Q ∧ R),
o (P ∨ Q) ∨ R= P ∨ (Q ∨ R)
o Identity element:
o P ∧ True = P,
o P ∨ True= True.
o Distributive:
o P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
o P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
o DE Morgan's Law:
o ¬ (P ∧ Q) = (¬P) ∨ (¬Q)
o ¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
11
o Double-negation elimination:
o ¬ (¬P) = P.

First-Order Logic

In the topic of Propositional logic, we have seen that how to represent statements using
propositional logic. But unfortunately, 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. Consider the
following sentence, which we cannot represent using PL logic.

o "Some humans are intelligent", or


o "Sachin likes cricket."

To represent the above statements, PL logic is not sufficient, so we required some more
powerful logic, such as first-order logic.

First-Order logic:
o First-order logic is another way of knowledge representation in artificial intelligence. It is
an extension to propositional logic.
o FOL is sufficiently expressive to represent the natural language statements in a concise
way.
o First-order logic is also known as Predicate logic or First-order predicate logic. First-
order logic is a powerful language that develops information about the objects in a more
easy way and can also express the relationship between those objects.
o First-order logic (like natural language) does not only assume that the world contains
facts like propositional logic but also assumes the following things in the world:
o Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus, ......
o 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
o Function: Father of, best friend, third inning of, end of, ......
o As a natural language, first-order logic also has two main parts:

a. Syntax
b. Semantics

Syntax of First-Order logic:

The syntax of FOL determines which collection of symbols is a logical expression in first-order
logic. The basic syntactic elements of first-order logic are symbols. We write statements in short-
hand notation in FOL.

12
Basic Elements of First-order logic:

Following are the basic elements of FOL syntax:

Constant 1, 2, A, John, Mumbai, cat,....

Variables x, y, z, a, b,....

Predicates Brother, Father, >,....

Function sqrt, LeftLegOf, ....

Connectives ∧, ∨, ¬, ⇒, ⇔

Equality ==

Quantifier ∀, ∃

Atomic sentences:
o 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.
o We can represent atomic sentences as Predicate (term1, term2, ......, term n).

Example: Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).


Chinky is a cat: => cat (Chinky).

Complex Sentences:
o Complex sentences are made by combining atomic sentences using connectives.

First-order logic statements can be divided into two parts:

o Subject: Subject is the main part of the statement.


o Predicate: A predicate can be defined as a relation, which binds two atoms together in a
statement.

Consider the statement: "x is an integer.", it consists of two parts, the first part x is the subject
of the statement and second part "is an integer," is known as a predicate.

13
Quantifiers in First-order logic:
o A quantifier is a language element which generates quantification, and quantification
specifies the quantity of specimen in the universe of discourse.
o These are the symbols that permit to determine or identify the range and scope of the
variable in the logical expression. There are two types of quantifier:

a. Universal Quantifier, (for all, everyone, everything)


b. Existential quantifier, (for some, at least one).

Unification

o Unification is a process of making two different logical atomic expressions identical by


finding a substitution. Unification depends on the substitution process.
o It takes two literals as input and makes them identical using substitution.
o Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it
can be expressed as UNIFY(Ψ1, Ψ2).
o Example: Find the MGU for Unify{King(x), King(John)}

Let Ψ1 = King(x), Ψ2 = King(John),

Substitution θ = {John/x} is a unifier for these atoms and applying this substitution, and both
expressions will be identical.

o The UNIFY algorithm is used for unification, which takes two atomic sentences and
returns a unifier for those sentences (If any exist).
o Unification is a key component of all first-order inference algorithms.
o It returns fail if the expressions do not match with each other.
o The substitution variables are called Most General Unifier or MGU.

E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).

In this example, we need to make both above statements identical to each other. For this, we will
perform the substitution.

P(x, y)......... (i)


P(a, f(z))......... (ii)

14
o 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.
o 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].

Forward Chaining and backward chaining in AI

In artificial intelligence, forward and backward chaining is one of the important topics, but
before understanding forward and backward chaining lets first understand that from where
these two terms came.

Inference engine:

The inference engine is the component of the intelligent system in artificial intelligence, which
applies logical rules to the knowledge base to infer new information from known facts. The first
inference engine was part of the expert system. Inference engine commonly proceeds in two
modes, which are:

a. Forward chaining
b. Backward chaining

a. Forward Chaining
Forward chaining is a data-driven inference technique. It starts with the available data and
applies rules to infer new data until a goal is reached. This method is commonly used in
situations where the initial data set is extensive, and the goal is to derive conclusions from it.

Forward Chaining Works


1. Start with Known Facts: The inference engine begins with the known facts in the knowledge
base.
2. Apply Rules: It looks for rules whose conditions are satisfied by the known facts.
3. Infer New Facts: When a rule is applied, new facts are inferred and added to the knowledge
base.
4. Repeat: This process is repeated until no more rules can be applied or a specified goal is
achieved.

Example of Forward Chaining


Consider a medical diagnosis system where rules are used to diagnose diseases based on
symptoms:
 Fact: The patient has a fever.
 Rule: If a patient has a fever and a rash, they might have measles.
Starting with the known fact (fever), the system checks for other symptoms (rash). If the patient
also has a rash, the system infers the possibility of measles.

A
A -> B
B
15
—————————–
He is running.
If he is running, he sweats.
He is sweating.

Advantages of Forward Chaining


1. Simplicity: Forward chaining is straightforward and easy to implement.
2. Automatic Data Processing: It processes data as it arrives, making it suitable for dynamic
environments where new data continuously becomes available.
3. Comprehensive: It explores all possible inferences, ensuring that all relevant conclusions are
reached.
4. Efficiency in Certain Scenarios: It can be efficient when all possible inferences need to be
made from a set of data.

b. Backward Chaining
 Backward chaining is a goal-driven inference technique. It starts with the goal and works
backward to determine which facts must be true to achieve that goal. This method is ideal
for situations where the goal is clearly defined, and the path to reach it needs to be
established.
How Backward Chaining Works
 Start with a Goal: The inference engine begins with the goal or hypothesis it wants to prove.
 Identify Rules: It looks for rules that could conclude the goal.
 Check Conditions: For each rule, it checks if the conditions are met, which may involve
proving additional sub-goals.
 Recursive Process: This process is recursive, working backward through the rule set until the
initial facts are reached or the goal is deemed unattainable.
Example of Backward Chaining
In a troubleshooting system for network issues:
Goal: Determine why the network is down.
Rule: If the router is malfunctioning, the network will be down.
The system starts with the goal (network down) and works backward to check if the router is
malfunctioning, verifying the necessary conditions to confirm the hypothesis.

B
A -> B
A
—————————–
He is sweating.
If he is running, he sweats.
He is running.

Advantages of Backward Chaining


 Goal-Oriented: It is efficient for goal-specific tasks as it only generates the facts needed to
achieve the goal.
 Resource Efficient: It typically requires less memory, as it focuses on specific goals rather
than exploring all possible inferences.

16
 Interactive: It is well-suited for interactive applications where the system needs to answer
specific queries or solve particular problems.
 Suitable for Diagnostic Systems: It is particularly effective in diagnostic systems where the
goal is to determine the cause of a problem based on symptoms.

Difference between Forwarding Chaining and Backward Chaining:


Forward Chaining Backward Chaining

When based on available data a


Backward chaining starts from the goal and works
decision is taken then the
1. process is called as Forward
backward to determine what facts must be asserted
so that the goal can be achieved.
chaining.

Forward chaining is known as


Backward chaining is known as goal-driven
data-driven technique because
2. we reaches to the goal using the
technique because we start from the goal and
reaches the initial state in order to extract the facts.
available data.

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

It applies the Breadth-First


4. Strategy.
It applies the Depth-First Strategy.

Its goal is to get the possible facts or the required


5. Its goal is to get the conclusion.
data.

Slow as it has to use all the


6. rules.
Fast as it has to use only a few rules.

It operates in forward direction i.e


It operates in backward direction i.e it works from
7. it works from initial state to final
goal to reach initial state.
decision.

Forward chaining is used for the It is used in automated inference engines, theorem
8. planning, monitoring, control, and proofs, proof assistants and other artificial
interpretation application. intelligence applications.

17

You might also like