Unit3 Ai
Unit3 Ai
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 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.
What to Represent:
o Object: All the facts about objects in our world domain. E.g., Guitars contains
strings, trumpets are brass instruments.
o Facts: Facts are the truths about the real world and what we represent.
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.
Syntax:
o Syntaxes are the rules which decide how we can construct legal sentences in the logic.
Semantics:
o Semantics are the rules by which we can interpret the sentence in the logic.
1. Propositional Logics
2. Predicate logics
Note: We will discuss Prepositional Logics and Predicate logics in later chapters.
1. Logical representations have some restrictions and are challenging to work with.
2. Logical representation technique may not be very natural, and inference may not be so
efficient.
Example: Following are some statements which we need to represent in the form of nodes
and arcs.
Statements:
1. Jerry is a cat.
2. Jerry is a mammal
3. Jerry is owned by Priya.
4. Jerry is brown colored.
5. All Mammals are animal.
n the above diagram, we have represented the different type of knowledge in the form of
nodes and arcs. Each object is connected with another object by some 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.
Facets: The various aspects of a slot is known as Facets. Facets are features of frames
which enable us to put constraints on the frames. Example: IF-NEEDED facts are
called when data of any particular slot is needed. A frame may consist of any number
of slots, and a slot may include any number of facets and facets may have any number
of values. A frame is also known as slot-filter knowledge representation in artificial
intelligence.
Frames are derived from semantic networks and later evolved into our modern-day
classes and objects. A single frame is not much useful. Frames system consist of a
collection of frames which are connected. In the frame, knowledge about an object or
event can be stored together in the knowledge base. The frame is a type of technology
which is widely used in various applications including Natural language processing
and machine visions.
Example: 1
Let's take an example of a frame for a book
Example 2:
Let's suppose we are taking an entity, Peter. Peter is an engineer as a profession, and his age
is 25, he lives in city London, and the country is England. So following is the frame
representation for this:
Advantages of frame representation:
1. The frame knowledge representation makes the programming easier by grouping the
related data.
2. The frame representation is comparably flexible and used by many applications in AI.
3. It is very easy to add slots for new attribute and relations.
4. It is easy to include default data and to search for missing values.
5. Frame representation is easy to understand and visualize.
4. Production Rules
Production rules system consist of (condition, action) pairs which mean, "If condition then
action". It has mainly three parts:
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.
The working memory contains the description of the current state of problems-solving and
rule can write knowledge to the working memory. This knowledge match and may fire other
rules.
If there is a new situation (state) generates, then multiple production rules will be fired
together, this is called conflict set. In this situation, the agent needs to select a rule from these
sets, and it is called a conflict resolution.
Example:
o IF (at bus stop AND bus arrives) THEN action (get into the bus)
o IF (on the bus AND paid AND empty seat) THEN action (sit down).
o IF (bus arrives at destination) THEN action (get down from the bus).
1. Production rule system does not exhibit any learning capabilities, as it does not store
the result of the problem for the future uses.
2. During the execution of the program, many rules may be active hence rule-based
production systems are inefficient.
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.
The syntax of propositional logic defines the allowable sentences for the knowledge
representation. There are two types of Propositions:
1. Atomic Propositions
2. Compound propositions
First-Order logic:
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 Syntax
o Semantics
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.
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 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.
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:
Universal Quantifier:
Universal quantifier is a symbol of logical representation, which specifies that the statement
within its range is true for everything or every instance of a particular thing.
o For all x
o For each x
o For every x.
Example:
It will be read as: There are all x where x is a man who drink coffee.
Existential Quantifier:
Existential quantifiers are the type of quantifiers, which express that the statement within its
scope is true for at least one instance of something.
It is denoted by the logical operator ∃, which resembles as inverted E. When it is used with a
predicate variable then it is called as an existential quantifier.
If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
Points to remember:
And since there are all birds who fly so it will be represented as follows.
∀x bird(x) →fly(x).
In this question, the predicate is "respect(x, y)," where x=man, and y= parent.
Since there is every man so will use ∀, and it will be represented as follows:
The quantifiers interact with variables which appear in a suitable way. There are two types of
variables in First-order logic which are given below:
Free Variable: A variable is said to be a free variable in a formula if it occurs outside the
scope of the quantifier.
Inference in First-Order Logic is used to deduce new facts or sentences from existing
sentences. Before understanding the FOL inference rule, let's understand some basic
terminologies used in FOL.
Substitution:
Equality:
First-Order logic does not only use predicate and terms for making atomic sentences but also
uses another way, which is equality in FOL. For this, we can use equality symbols which
specify that the two terms refer to the same object.
As in the above example, the object referred by the Brother (John) is similar to the object
referred by Smith. The equality symbol can also be used with negation to represent that two
terms are not the same objects.
As propositional logic we also have inference rules in first-order logic, so following are some
basic inference rules in FOL:
Universal Generalization
Universal Instantiation
Existential Instantiation
Existential introduction
1. Universal Generalization:
any arbitrary element c in the universe of discourse, then we can have a conclusion as ∀ x
Universal generalization is a valid inference rule which states that if premise P(c) is true for
P(x).
This rule can be used if we want to show that every element has a similar property.
Example: Let's represent, P(c): "A byte contains 8 bits", so for ∀ x P(x) "All bytes contain 8
bits.", it will also be true.
2. Universal Instantiation:
As per UI, we can infer any sentence obtained by substituting a ground term for the variable.
constant within domain x) from ∀ x P(x) for any object in the universe of discourse.
The UI rule state that we can infer any sentence P(c) by substituting a ground term c (a
Example:1.
Example: 2.
Let's take a famous example,"All kings who are greedy are Evil." So let our knowledge base
contains this detail as in the form of FOL:
So from this information, we can infer any of the following statements using Universal
Instantiation:
3. Existential Instantiation:
The new KB is not logically equivalent to old KB, but it will be satisfiable if old KB was
satisfiable.
This rule states that one can infer P(c) from the formula given in the form of ∃x P(x) for a
new constant symbol c.
The restriction with this rule is that c used in the rule must be a new term for which P(c ) is
true.
Example:
So we can infer: Crown(K) ∧ OnHead( K, John), as long as K does not appear in the
knowledge base.
4. Existential introduction
This rule states that if there is some element c in the universe of discourse which has a
property P, then we can infer that there exists something in the universe which has the
property P.
Generalized Modus Ponens can be summarized as, " P implies Q and P is asserted to be true,
therefore Q must be True."
According to Modus Ponens, for atomic sentences pi, pi', q. Where there is a substitution θ
such that SUBST (θ, pi',) = SUBST(θ, pi), it can be represented as:
Example:
We will use this rule for Kings are evil, so we will find some x such that x is king, and x is
greedy so we can infer that x is evil.
SUBST(θ,q).
Resolution in FOL
Resolution
Resolution is a theorem proving technique that proceeds by building refutation proofs, i.e.,
proofs by contradictions. It was invented by a Mathematician John Alan Robinson in the year
1965.
Resolution is used, if there are various statements are given, and we need to prove a
conclusion of those statements. Unification is a key concept in proofs by resolutions.
Resolution is a single inference rule which can efficiently operate on the conjunctive normal
form or clausal form.
Clause: Disjunction of literals (an atomic sentence) is called a clause. It is also known as a
unit clause.
Example:
In the first step we will convert all the given statements into its first order logic.
In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes
easier for resolution proofs.
o ∀x ¬ food(x) V likes(John, x)
o food(Apple) Λ food(vegetables)
o ∀x ¬ eats(Anil, x) V eats(Harry, x)
o ∀x¬ [¬ killed(x) ] V alive(x)
o ∀x ¬ alive(x) V ¬ killed(x)
o likes(John, Peanuts).
o ∀x ¬ food(x) V likes(John, x)
o food(Apple) Λ food(vegetables)
o ∀x ¬ eats(Anil, x) V eats(Harry, x)
o ∀x ¬killed(x) ] V alive(x)
o ∀x ¬ alive(x) V ¬ killed(x)
o likes(John, Peanuts).
o ∀x ¬ food(x) V likes(John, x)
o food(Apple) Λ food(vegetables)
o ∀g ¬killed(g) ] V alive(g)
o ∀k ¬ alive(k) V ¬ killed(k)
o likes(John, Peanuts).
In this step, we will eliminate existential quantifier ∃, and this process is known
o Eliminate existential instantiation quantifier by elimination.
o ¬ food(x) V likes(John, x)
o food(Apple)
o food(vegetables)
o alive(Anil)
o ¬ eats(Anil, w) V eats(Harry, w)
o killed(g) V alive(g)
o ¬ alive(k) V ¬ killed(k)
o likes(John, Peanuts).
In this statement, we will apply negation to the conclusion statements, which will be written
as ¬likes(John, Peanuts)
Now in this step, we will solve the problem by resolution tree using substitution. For the
above problem, it will be given as follows:
Hence the negation of the conclusion has been proved as a complete contradiction with the
given set of statements.