2nd YEAR UNIT-4 NOTES
2nd YEAR UNIT-4 NOTES
UNIT -4
KNOWLEDGE
Knowledge is the collection of facts, inference rules etc. which can be used for a particular purpose.
Knowledge requires the use of data and information.
It combines relationships, correlations, dependencies with data and information.
The basic components of knowledge are:
1) A set of collected data.
2) A form of belief or hypothesis
3) A kind of information.
TYPE OF KNOWLEDGE
The categorization of knowledge is very large and interesting. They can be of following types:
➢ Declarative knowledge
It is the passive knowledge expressed as statements of facts about the world. It gives simple factsand ideas
about any phenomenon. It means just the representation of facts or assertions.
For example, the facts about an organization may be its buildings,location, no.
of departments, no. of employees etc.
➢ Procedural knowledge
Procedural knowledge is the compiled knowledge related to the performance of some task.
For example, the steps used to solve an algebraic equation can be expressed as proceduralknowledge.
Knowledge representation
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 asdiagnosis a medical condition or
communicating with humans in natural language.
• Object: All the facts about objects in our world domain. E.g., Guitars contains strings
• Facts: Facts are the truths about the real world and what we represent.
21CSC206T AI NEHA GUPTA
Knowledge-base: The central component of the knowledge-based agents is the knowledge base.
b. Inferential Adequacy: It is the ability to manipulate the knowledge represented to produce new
knowledge corresponding to that inferred from the original.
c. Inferential Efficiency: The ability to direct the inferential mechanisms into the most productivedirections
by storing appropriate guides.
d. Acquisitional Efficiency: The ability to acquire new knowledge using automatic methods whereverpossible
rather than reliance on human intervention.
• Examine specific techniques that can be used for representing & manipulating knowledge within
programs.
• Facts :- truths in some relevant world . These are the things we want to represent.
• The knowledge level, at which facts concluding each agents behavior & current goals are described.
KNOWLEDGE-BASED AGENT
• A knowledge-based agent includes a knowledge base and an inference system.
• A knowledge base is a set of representations of facts of the world.
• Each individual representation is called a sentence.
• The sentences are expressed in a knowledge representation language.
• The agent operates as follows:
1. It TELLs the knowledge base what it perceives.
2. It ASKs the knowledge base what action it should perform.
3. It performs the chosen action.
21CSC206T AI NEHA GUPTA
• Example: A taxi agent might know that the Golden Gate Bridge connects San Francisco with theMarin
County.
➢ Logical Level.
• The level at which the knowledge is encoded into sentences.
➢ Implementation Level.
• The physical representation of the sentences in the logical level.
➢ The neighborhood of a node consists of the four squares north, south, east, and west of the given square.
➢ In a square the agent gets a vector of percepts, with components Stench, Breeze,Glitter, Bump, Scream For
example [Stench, None, Glitter, None, None].
➢ Stench is perceived at a square iff the wumpus is at this square or in its neighborhood.
➢ Breeze is perceived at a square iff a pit is in the neighborhood of this square.
➢ Glitter is perceived at a square iff gold is in this square.
➢ Bump is perceived at a square iff the agent goes Forward into a wall.
➢ Scream is perceived at a square iff the wumpus is killed anywhere in the cave.
➢ An agent can do the following actions (one at a time): Turn (Right), Turn (Left), Forward, Shoot, Grab, Release,
Climb .
➢ The agent can go forward in the direction it is currently facing, or Turn Right, or Turn Left. Going forward into
a wall will generate a Bump percept.
➢ The agent has a single arrow that it can shoot. It will go straight in the direction faced by the agent until it hits
(and kills) the wumpus,or hits (and is absorbed by) a wall.
➢ The agent can grab a portable object at the current square or it can Release an object that it is holding.
➢ The agent can climb out of the cave if at the Start square.The Start square is (1,1) and initially the agent is
facing east.
➢ The agent dies if it is in the same square as the wumpus.
➢ The objective of the game is to kill the wumpus, to pick up the gold, and to climb out with it.
PEAS description of Wumpus world:
To explain the Wumpus world we have given PEAS description as below:
• 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:
21CSC206T AI NEHA GUPTA
• 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 glitter in the room where the gold is present.
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].
Representing our Knowledge about the Wumpus World Percept(x, y) Where x must be a percept vector and
Exploring the Wumpus world:
Now we will explore the Wumpus world and will determine how the agent will find its goal by applying
logical reasoning.
Agent's First step:
Initially, the agent is in the first room or on the square [1,1], and we already know that this room is safe for
the agent, so to represent on the below diagram (a) that room is safe we will add symbol OK. Symbol A is
used to represent agent, symbol B for the breeze, G for Glitter or gold, V for the visited room, P for pits, W
for Wumpus.
At Room [1,1] agent does not feel any breeze or any Stench which means the adjacent squares are also OK.
room [2, 1], at this room agent perceives some breeze which means Pit is around this room. The pit can be
in [3, 1], or [2,2], so we will add symbol P? to say that, is this Pit room?
Now agent will stop and think and will not make any harmful move. The agent will go back to the [1, 1]
room. The room [1,1], and [2,1] are visited by the agent, so we will use symbol V to represent the visited
squares.
Logic
A logic is a formal language, with precisely defined syntax and semantics, which supports sound
inference. Different logics exist, which allow you to represent different kinds of things, and which
allow efficient inference.
TYPES:
➢ Propositional Logic
➢ Predicate Logic
Propositional logic
21CSC206T AI NEHA GUPTA
• 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.
• Operators, both unary and binary; when applied to logical values, yield logical values. The usual
operators are and, or, not, and implies.
Connectives:
Logical connectives are used to connect two simpler propositions or represent a sentence logically.
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,
21CSC206T AI NEHA GUPTA
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.
Following is the summarized table for Propositional Logic Connectives:
Truth Table: Following are the truth table for all logical connectives:
21CSC206T AI NEHA GUPTA
Inference by computer
To do inference (reasoning) by computer is basically a search process, taking logical expressions and
applying inference rules to them.
Reasoning in AI
Reasoning in artificial intelligence is the cognitive process by which AI systems draw logical
inferences, make decisions, solve problems, and reach conclusions based on available knowledge,
data, and rules.
Forward Reasoning: Starts with initial facts or premises and moves forward to derive conclusions
or reach goals.
Step 1. Begin building a tree of move sequences by starting with the initial configuration at the root
of the tree.
Step 2. Generate the next level of the tree by finding all rules whose left-hand side matches against
the root node. The right-hand side is used to create new configurations.
Step 3. Generate the next level by considering the nodes in the previous level and applying it to all
rules whose left-hand side match.
Backward Reasoning: Begins with a specific goal or desired outcome and works backward to
identify the facts or conditions needed to achieve it.
Step 1. Begin building a tree of move sequences by starting with the goal node configuration at the
root of the tree.
21CSC206T AI NEHA GUPTA
Step 2. Generate the next level of the tree by finding all rules whose right-hand side matches against
the root node. The left-hand side used to create new configurations.
Step 3. Generate the next level by considering the nodes in the previous level and applying it to all
rules whose right-hand side match.
Predicate Logic
Predicate Logic in AI is fundamentally a method for describing and modifying assertions about
objects and their characteristics. It includes a collection of rules and symbols that enable us to build
complex statements from simpler ones.
• All of propositional logic- Logical values true, false, Variables x, y, a, b,.& Connectives
• Constants e.g. KingJohn, 2, Villanova
• Predicates - Brother, >, ...
• Functions - Sqrt, MotherOf, ...
• Quantifiers-
➢ Universal Quantifiers
➢ Existential Quantifier
Universal Quantifier
Universal Quantification is the proposition that a property is true for all the values of a variable in a
particular domain, sometimes called the domain of discourse or the universe of discourse.
Existential quantification is the proposition that a property is true for some value in a particular
domain.
There exists an x such that P(x)
There exists an element x in the domain such that P(x)
For some x, P(x)
There is some x such that P(x)
21CSC206T AI NEHA GUPTA
More Examples:
21CSC206T AI NEHA GUPTA
Unification
• Unification is a “pattern-matching” procedure
• 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
• Takes two atomic sentences, called literals, as input
• Returns “Failure” if they do not match and a substitution list, θ, if they do
That is, unify(p,q) = θ means subst(θ, p) = subst(θ, q) for two atomic sentences, p and q.
θ is called the most general unifier (mgu) .
• All variables in the given two literals are implicitly universally quantified.
• To make literals match, replace (universally quantified) variables by terms.
Conditions for Unification:
Following are some basic conditions for unification:
• Predicate symbol must be same, atoms or expression with different predicate symbol can never be
unified.
• Number of Arguments in both expressions must be identical.
• Unification will fail if there are two similar variables present in the same expression.
Unification algorithm
procedure unify(p, q, θ)
Scan p and q left-to-right and find the first corresponding
terms where p and q “disagree” (i.e., p and q not equal)
If there is no disagreement, return θ (success!)
Let r and s be the terms in p and q, respectively,
where disagreement first occurs
If variable(r) then {
Let θ = union(θ, {r/s})
Return unify(subst(θ, p), subst(θ, q), θ)
} else if variable(s) then {
Let θ = union(θ, {s/r})
Return unify(subst(θ, p), subst(θ, q), θ)
} else return “Failure”
End.
Semantic network
A semantic network is a structure for representing knowledge as a pattern of interconnected nodes
and arc.
-- Entities
-- attributes
-- states or
-- Events
Arcs in the net gives the relationship between the nodes and labels on the arc specify the type of
relationship.
• A crow is a bird
Example:
Frames
• A frame is a knowledge representation formalism based on the idea of a frame of reference.
• A frame is a data structure that includes all the knowledge about a particular object
• Special terminology
• Class Frame
• A frame carries with it a set of slots that can represent objects that are normally associated with a
subject of the frame.
• Slots in structure are instantiated with particular values for a given instance of data
• ...translation to OO terminology:
• slots == variables/methods
21CSC206T AI NEHA GUPTA
e.g.
Production Rules
Production rules are a set of IF-THEN statements that represent knowledge. The IF part of a rule is
a condition, and the THEN part is an action to be taken if the condition is met.
Production rules can be used to represent a wide range of knowledge, including facts,
procedures, and heuristics.
However, there are also some drawbacks to the production rules system. They do not possess
any •learning
IF (at capabilities
auto-rickshawandstop
cannot
AND store the result
rickshaw of a problem
arrives) for future
THEN action (get use.
into Furthermore,
the rickshaw)
they• canIFbecome complex and
(in the rickshaw AND difficult
paid ANDto maintain as theTHEN
empty seat) number of rules
action increases.
(sit down).
• IF (in rickshaw AND unpaid) THEN action (pay charges).
• IF (rickshaw arrives at destination) THEN action (get down from the rickshaw).
Example:
•
21CSC206T AI NEHA GUPTA
➢ Fuzzy logic.
Probability
Probability is the degree of likeliness that an event will occur. It provides a certain degree of
belief in case of uncertain situations.
21CSC206T AI NEHA GUPTA
It is defined over a set of events U and assigns value P(e) i.e. probability of occurrence of event
e in the range [0,1].
Conditional Probability or Posterior Probability is the probability of event A given that B has
already occurred.
P(A|B) = (P(B|A) * P(A)) / P(B)
For example, P(It will rain tomorrow| It is raining today) represents conditional probability of
it raining tomorrow as it is raining today.
Joint probability is the probability of 2 independent events happening simultaneously like
rolling two dice or tossing two coins together. For example, Probability of getting 2 on one dice
and 6 on the other is equal to 1/36.
Bayes Theorem
It is based on the principle that every pair of features being classified is independent of each
other.
It calculates probability
P(A|B) where A is class of possible outcomes and B is given instance which has to be
classified.
P(A|B) = P(B|A) * P(A) / P(B)
P(A|B) = Probability that A is happening, given that B has occurred (posterior probability)
P(A) = prior probability of class
P(B) = prior probability of predictor
P(B|A) = likelihood
Example :
Question: what is the probability that a patient has diseases meningitis with a stiff neck?
• Given Data: A doctor is aware that disease meningitis causes a patient to have a stiff neck, and it occurs
80% of the time. He is also aware of some more facts, which are given as follows:
The Known probability that a patient has meningitis disease is 1/30,000. The Known probability that a
patient has a stiff neck is 2%. Let a be the proposition that patient has stiff neck and b be the proposition
that patient has meningitis. , so we can calculate the following as: P(a|b) = 0.8 P(b) = 1/30000 P(a)= .02 •
Hence, we can assume that 1 patient out of 750 patients has meningitis disease with a stiff neck.
Problem: Calculate the probability that alarm has sounded, but there is neither a burglary, nor an
earthquake occurred, and David and Sophia both called the Harry.
• Alarm(A)
• David Calls(D)
• Sophia calls(S)
We can write the events of problem statement in the form of probability: P[D, S, A, B, E], can
rewrite the above probability statement using joint probability distribution:
P[D, S, A, B, E]= P[D | S, A, B, E]. P[S, A, B, E]
= P[D | S, A, B, E]. P[S | A, B, E]. P[A, B, E]
= P [D| A]. P [ S| A, B, E]. P[ A, B, E]
= P[D | A]. P[ S | A]. P[A| B, E]. P[B, E]
= P[D | A ]. P[S | A]. P[A| B, E]. P[B |E]. P[E]