Unit 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 58

Introduction to Artificial Intelligence

and Machine Learning


M Sarat Chandra Prasad
Assistant Professor
Department of Mechanical Engineering
Aditya College of Engineering
Unit-II
• Knowledge–Representation and Reasoning:
Logical Agents: Knowledge based agents, the
Wumpus world, logic. Patterns in Propositional
Logic, Inference in First-Order Logic-Propositional
vs first order inference, unification and lifting
What is 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:
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.
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.
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.
What to Represent:
• Following are the kind of knowledge which needs
to be represented in AI systems:
• Object: All the facts about objects in our world
domain. E.g., Guitars contains strings, trumpets are
brass instruments.
• Events: Events are the actions which occur in our
world.
• Performance: It describe behavior which involves
knowledge about how to do things.
• Meta-knowledge: It is knowledge about what we
know.
• Facts: Facts are the truths about the real world and
what we represent.
• Knowledge-Base: The central component of the
knowledge-based agents is the knowledge base. It
is represented as KB. The Knowledgebase is a
group of the Sentences (Here, sentences are used
as a technical term and not identical with the
English language).
Knowledge: Knowledge is awareness or familiarity gained by
experiences of facts, data, and situations. Following are the types of
knowledge in artificial intelligence:
Declarative Knowledge:
• Declarative knowledge is to know about
something.
• It includes concepts, facts, and objects.
• It is also called descriptive knowledge and
expressed in declarativesentences.
• It is simpler than procedural language.
Procedural Knowledge
• It is also known as imperative knowledge.
• Procedural knowledge is a type of knowledge
which is responsible for knowing how to do
something.
• It can be directly applied to any task.
• It includes rules, strategies, procedures, agendas,
etc.
• Procedural knowledge depends on the task on
which it can be applied.
Meta Knowledge:
Knowledge about the other types of knowledge is
called Meta-knowledge.
Heuristic knowledge:
• Heuristic knowledge is representing knowledge of
some experts in a filed or subject.
• Heuristic knowledge is rules of thumb based on
previous experiences, awareness of approaches,
and which are good to work but not guaranteed.
Structural knowledge:
• Structural knowledge is basic knowledge to
problem-solving.
• It describes relationships between various concepts
such as kind of, part of, and grouping of
something.
• It describes the relationship that exists between
concepts or objects.
AI knowledge cycle:

• An Artificial intelligence system has the following components for


displaying intelligent behavior:
• Perception
• Learning
• Knowledge Representation and Reasoning
• Planning
• Execution
The above diagram is showing how an AI system can interact with
the real world and what components help it to show intelligence.
AI system has Perception component by which it retrieves
information from its environment. It can be visual, audio or
another form of sensory input. The learning component is
responsible for learning from data captured by Perception
comportment. In the complete cycle, the main components are
knowledge representation and Reasoning. These two components
are involved in showing the intelligence in machine-like humans.
These two components are independent with each other but also
coupled together. The planning and execution depend on analysis
of Knowledge representation and reasoning. .
Approaches to knowledge representation:

There are mainly four approaches to knowledge representation, which


are givenbelow:
Simple relational knowledge
Inheritable knowledge
Inferential knowledge
Procedural knowledge
Simple relational knowledge:

• 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.
• This approach of knowledge representation is famous
in database systems where the relationship between
different entities is represented.
• This approach has little opportunity for inference.
Player Weight Age

Player1 65 23

Player2 58 18

Player3 75 24
• Inheritable knowledge
In the inheritable knowledge approach, all data must be stored into a
hierarchy of classes.
All classes should be arranged in a generalized form or a hierarchal
manner
In this approach, we apply inheritance property
Elements inherit values from other members of a class
This approach contains inheritable knowledge which shows a relation
between instance and class, and it is called instance relation.
Every individual frame can represent the collection of attributes and its
value.
In this approach, objects and values are represented in Boxed nodes
Inferential knowledge
Inferential knowledge approach represents knowledge in the form of
formal logics.
This approach can be used to derive more facts.
It guaranteed correctness.
Example: Let's suppose there are two statements:
1.Marcus is a man
2.All men are mortal
Then it can represent as;
Procedural knowledge

• Procedural knowledge approach uses small programs and codes


which describes how to do specific things, and how to proceed.
• In this approach, one important rule is used which is If-Then rule.
• In this knowledge, we can use various coding languages such as LISP
language and Prolog language.
• We can easily represent heuristic or domain-specific knowledge using
this approach.
• But it is not necessary that we can represent all cases in this
approach.
Wumpus world:
The Wumpus world is a simple world example to illustrate the worth of a
knowledge-based agent and to represent knowledge representation. It was
inspired by a video game Hunt the Wumpus by Gregory Yob in 1973.
The Wumpus world is a cave which has 4/4 rooms connected with
passageways. So there are total 16 rooms which are connected with each
other. We have a knowledge-based agent who will go forward in this world.
The cave has a room with a beast which is called Wumpus, who eats anyone
who enters the room. The Wumpus can be shot by the agent, but the agent
has a single arrow. In the Wumpus world, there are some Pits rooms which
are bottomless, and if agent falls in Pits, then he will be stuck there forever.
The exciting thing with this cave is that in one room there is a possibility of
finding a heap of gold. So the agent goal is to find the gold and climb out the
cave without fallen into Pits or eaten by Wumpus. The agent will get a
reward if he comes out with gold, and he will get a penalty if eaten by
Wumpus or falls in the pit.
• There are also some components which can help the agent to
navigate the cave. These components are given as follows:
1.The rooms adjacent to the Wumpus room are smelly, so that it
would have some stench.
2.The room adjacent to PITs has a breeze, so if the agent reaches
near to PIT, then he will perceive the breeze.
3.There will be glitter in the room if and only if the room has
gold.
4.The Wumpus can be killed by the agent if the agent is facing to
it, and Wumpus will emit a horrible scream which can be heard
anywhere in the cave.
PEAS description of Wumpus world

Performance measure
• +1000 reward points if the agent comes out of the cave with the gold.
• -1000 points penalty for being eaten by the Wumpus or falling into
the pit.
• -1 for each action, and -10 for using an arrow.
• The game ends if either agent dies or came out of the cave.
Environment:

• A 4*4 grid of rooms.


• The agent initially in room square [1, 1], facing toward the right.
• Location of Wumpus and gold are chosen randomly except the first
square [1,1].
• Each square of the cave can be a pit with probability 0.2 except the
first square.
Actuators

• Left turn,
• Right turn
• Move forward
• Grab
• Release
• Shoot.
Sensors

The agent will perceive the stench if he is in the room adjacent to the
Wumpus. (Not diagonally).
The agent will perceive breeze if he is in the room directly adjacent to
the Pit.
The agent will perceive the bump if he walks into a wall.
When the Wumpus is shot, it emits a horrible scream which can be
perceived anywhere in the cave
These percepts can be represented as five element list, in which we will
have different indicators for each sensor.
Example if agent perceives stench, breeze, but no glitter, no bump, and
no scream then it can be represented as:
[Stench, Breeze, None, None, None].
The Wumpus world Properties:

• Partially observable: The Wumpus world is partially observable


because the agent can only perceive the close environment such as
an adjacent room.
• Deterministic: It is deterministic, as the result and outcome of the
world are already known.
• Sequential: The order is important, so it is sequential.
• Static: It is static as Wumpus and Pits are not moving.
• Discrete: The environment is discrete.
• One agent: The environment is a single agent as we have one agent
only and Wumpus is not considered as an agent.
Propositional logic in Artificial intelligence

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.
It is a Sunday
The sun rises from the west
3+3=7
5 is a prime number
Following are some basic facts about
propositional logic:
Propositional logic is also called Boolean logic as it works on 0 and 1.
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.
Propositions can be either true or false, but it cannot be both.
Propositional logic consists of an object, relations or function, and
logical connectives
These connectives are also called logical operators.
The propositions and connectives are the basic elements of the
propositional logic.
Connectives can be said as a logical operator which connects two
sentences.
A proposition formula which is always true is called tautology, and it is
also called a valid sentence.
A proposition formula which is always false is called Contradiction.
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:
1.Atomic Propositions
2.Compound propositions
Atomic Proposition: Atomic propositions are the simple propositions. It
consists of a single proposition symbol. These are the sentences which
must be either true or false.
2+2 is 4 it is an atomic proposition and is a true fact
The sun is cold is also a proposition and it is a false fact
Compound proposition: Compound propositions are constructed by
combining simpler or atomic propositions, using parenthesis and logical
connectives.
"It is raining today, and street is wet."
"Ankit is a doctor, and his clinic is in Mumbai."
• Logical Connectives: Logical connectives are used to 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:
• Negation: A sentence such as ¬ P is called negation of P. A literal can
be either Positive literal or negative literal.
• 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.
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.
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
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.
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:
Negation
P Negation P
True False
False True
Conjunction
P Q P conjunction Q
T T T
T F F
F T F
F F F
Disjunction
P Q PVQ
T T T
F T T
T F T
F F F
IMPLICATION
P Q P--→Q
T T T
T F F
F T T
F F T
For Biconditional
P Q P Q
T T T
T F F
F T F
F F T
Rules of Inference in Artificial intelligence

•Inference: In artificial intelligence, we need


intelligent computers which can create new
logic from old logic or by evidence, so
generating the conclusions from evidence
and facts is termed as Inference.
• Inference rules: Inference rules are the templates for
generating valid arguments. Inference rules are
applied to derive proofs in artificial intelligence, and
the proof is a sequence of the conclusion that leads to
the desired goal.
In inference rules, the implication among all the
connectives plays an important role. Following are
some terminologies related to inference rules:
Compound proposition: Compound propositions are constructed by
combining simpler or atomic propositions, using parenthesis and logical
connectives.
“It is raining today and the street is wet”
“Ankit is a doctor and his clinic is in Mumbai”
Implication: It is one of the logical connectives which
can be represented as P → Q. It is a Boolean
expression.
Converse: The converse of implication, which means
the right-hand side proposition goes to the left-hand
side and vice-versa. It can be written as Q → P.
Inverse: The negation of implication is called inverse. It
can be represented as ¬ P → ¬ Q.
Contrapositive: The negation of converse is termed as
contrapositive, and it can be represented as ¬ Q → ¬ P.
First-Order Logic in Artificial intelligence

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.
"Some humans are intelligent",
“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:
• First-order logic is another way of knowledge representation in
artificial intelligence. It is an extension to propositional logic.
• FOL is sufficiently expressive to represent the natural language
statements in a concise way.
• 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.
• 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:
• Objects: A, B, people, numbers, colors, wars, theories, squares, pits,
wumpus, ......
• Relations: It can be unary relation such as: red, round, is adjacent, or
n-any relation such as: the sister of, brother of, has color, comes
between
• Function: Father of, best friend, third inning of, end of, ......
What is knowledge-engineering?

• The process of constructing a knowledge-base in first-order logic is


called as knowledge- engineering. In knowledge-engineering,
someone who investigates a particular domain, learns important
concept of that domain, and generates a formal representation of the
objects, is known as knowledge engineer.
Inference in First-Order Logic

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:
Substitution is a fundamental operation performed on terms and
formulas. It occurs in all inference systems in first-order logic. The
substitution is complex in the presence of quantifiers in FOL. If we write
F[a/x], so it refers to substitute a constant "a" in place of variable "x".
• Example: Brother (John) = Smith.
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.
Example: ¬(x=y) which is equivalent to x ≠y.
What is Unification?

What is Unification?
Unification is a process of making two different logical atomic
expressions identical by finding a substitution. Unification depends on
the substitution process.
It takes two literals as input and makes them identical using
substitution.
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).
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.
• The UNIFY algorithm is used for unification, which takes two atomic
sentences and returns a unifier for those sentences (If any exist).
• Unification is a key component of all first-order inference algorithms.
• It returns fail if the expressions do not match with each other.
• The substitution variables are called Most General Unifier or MGU.

You might also like