Ai Unit-3
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
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.
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
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.
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.
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 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.
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:
2. Procedural Knowledge:
3. Meta-knowledge:
Meta-knowledge is information about other sorts of knowledge.
4. Heuristic understanding:
5. Structural knowledge:
AI knowledge cycle:
For showing intelligent behavior, an artificial intelligence system must have the following
components:
Perception
Learning
Knowledge Representation and Reasoning
Planning
Execution
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.
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:
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.
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.
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
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.
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.
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.
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
4. Production Rules
Production rules system consists of (condition, action) pairs which means, "If condition then
action". It has basically three parts:
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).
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.
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.
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.
1. Atomic Propositions.
2. Compound propositions.
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:
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
For Disjunction:
P Q PVQ
For Implication:
P Q P→Q
For Biconditional:
P Q P⇔Q
P Q R ¬R PVQ P V Q → ¬R
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
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
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.
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.
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.
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.
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.
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.
Environment:
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].
Agent does not detect any wind or Stench in Room [1,1], indicating that the nearby squares are
similarly in good condition.
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.
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
Variables x, y, z, a, b,....
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.
Complex Sentences:
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.
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.
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:
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:
Example:
Some boys are intelligent.
Properties of Quantifiers:
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.
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:
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."
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.
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.
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.
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.
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.
9. The goal of forward chaining is to reach any Backward chaining is only for the data that is
conclusion. required.
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.
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.
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.
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.
If the predicate names in the two expressions are different, unification cannot occur as they
represent different relationships.
If the number of parameters in the two expressions is not the same, unification is not possible.
The algorithm will return a FAILURE response.
Establish an empty set to hold any variable substitutions required for unification.
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.
Determine the Most General Unifier (MGU) between WorksAt(TutorialsPoint, X, Manager) and
WorksAt(TutorialsPoint, John, Y).
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.
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.
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.
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 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.
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.