Unit 3 Notes AI
Unit 3 Notes AI
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-base and
o Inference system.
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
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.
The knowledge-based agent takes percept as input and returns an action as output. The agent maintains
the knowledge base, KB, and it initially has some background knowledge of the real world. It also has a
counter to indicate the time for the whole process, and this counter is initialized with zero.
Each time when the function is called, it performs its three operations:
o Third agent program TELLS the KB that which action was chosen.
The MAKE-PERCEPT-SENTENCE generates a sentence as setting that the agent perceived the given
percept at the given time.
The MAKE-ACTION-QUERY generates a sentence to ask which action should be done at the current
time.
MAKE-ACTION-SENTENCE generates a sentence which asserts that the chosen action was executed.
1. Knowledge level
Knowledge level is the first level of knowledge-based agent, and in this level, we need to specify what the
agent knows, and what the agent goals are. With these specifications, we can fix its behavior. For
example, suppose an automated taxi agent needs to go from a station A to station B, and he knows the
way from A to B, so this comes at the knowledge level.
2. Logical level:
At this level, we understand that how the knowledge representation of knowledge is stored. At this level,
sentences are encoded into different logics. At the logical level, an encoding of knowledge into logical
sentences occurs. At the logical level we can expect to the automated taxi agent to reach to the destination
B.
3. Implementation level:
This is the physical representation of logic and knowledge. At the implementation level agent perform
actions as per logical and knowledge level. At this level, an automated taxi agent actually implement his
knowledge and logic so that he can reach to the destination.
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.
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.
What to Represent:
Following are the kind of knowledge which needs to be represented in AI systems:
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.
o 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).
Types of knowledge
1. Declarative Knowledge:
2. Procedural Knowledge
3. Meta-knowledge:
4. Heuristic knowledge:
5. Structural knowledge:
o It describes relationships between various concepts such as kind of, part of, and grouping of
something.
Let's suppose if you met some person who is speaking in a language which you don't know, then how you
will able to act on that. The same thing applies to the intelligent behavior of the agents.
As we can see in below diagram, there is one decision maker which act by sensing the environment and
using knowledge. But if the knowledge part will not present then, it cannot display intelligent behavior.
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.
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 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 Example:
3. Inferential knowledge:
o Inferential knowledge approach represents knowledge in the form of formal logics.
o It guaranteed correctness.
o Marcus is a man
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 knowledge, we can use various coding languages such as LISP language and Prolog
language.
o But it is not necessary that we can represent all cases in this approach.
1. Representational Accuracy- KR system should have the ability to represent all kind of
required knowledge.
2. Inferential Adequacy: KR system should have ability to manipulate the representational
structures to produce new knowledge corresponding to existing structure.
3. Inferential Efficiency: The ability to direct the inferential knowledge mechanism into
the most productive directions by storing appropriate guides.
4. Acquisitional efficiency- The ability to acquire the new knowledge easily using
automatic methods.
1. Logical 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.
a. Propositional Logics
b. Predicate logics
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.
a. Kind-of-relation
Example: Following are some statements which we need to represent in the form of nodes and arcs.
Statements:
a. Jerry is a cat.
b. Jerry is a mammal
1. Semantic networks take more computational time at runtime as we need to traverse the complete
network tree to answer some questions. It might be possible in the worst case scenario that after
traversing the entire tree, we find that the solution does not exist in this network.
2. Semantic networks try to model human-like memory (Which has 1015 neurons and links) to store
the information, but in practice, it is not possible to build such a vast semantic network.
3. These types of representations are inadequate as they do not have any equivalent quantifier, e.g.,
for all, for some, none, etc.
4. Semantic networks do not have any standard definition for the link names.
5. These networks are not intelligent and depend on the creator of the system.
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.
Slots Filter
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
Slots Filters
Year 1996
Page 1152
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:
Name Peter
Profession Doctor
Age 25
Weight 78
2. The frame representation is comparably flexible and used by many applications in AI.
4. Production Rules
Production rules system consist of (condition, action) pairs which mean, "If condition then action". It has
mainly three parts:
o The recognize-act-cycle
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.
a. Atomic Propositions
b. Compound propositions
Example:
Example:
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:
Q= Rohan is hardworking. → 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:
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.
Precedence of connectives:
Just like arithmetic operators, there is a precedence order for propositional
connectors or logical operators. This order should be followed while evaluating a
propositional problem. Following is the list of the precedence order for operators:
Precedence Operators
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:
2. Modus Tollens:
The Modus Tollens rule state that if P→ Q is true and ¬ Q is true, then ¬ P will also
true. It can be represented as:
ADVERTISEMENT
Example:
Statement-1: If you have my home key then you can unlock my home. P→Q
Statement-2: If you can unlock my home then you can take my money. Q→R
Conclusion: If you have my home key then you can take my money. P→R
4. Disjunctive Syllogism:
The Disjunctive syllogism rule state that if P∨Q is true, and ¬P is true, then Q will be
true. It can be represented as:
Example:
Proof by truth-table:
5. Addition:
The Addition rule is one the common inference rule, and it states that If P is true,
then P∨Q will be true.
Example:
Proof by Truth-Table:
6. Simplification:
The simplification rule state that if P∧ Q is true, then Q or P will also be true. It can
be represented as:
Proof by Truth-Table:
7. Resolution:
The Resolution rule state that if P∨Q and ¬ P∧R is true, then Q∨R will also be true. It
can be represented as
Proof by Truth-Table:
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
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).
Complex Sentences:
o Complex sentences are made by combining atomic sentences using
connectives.
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.
Example:
All man drink coffee.
Let a variable x which refers to a cat so all x can be represented in UOD as below:
∀x man(x) → drink (x, coffee).
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.
If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
It will be read as: There are some x where x is a boy who is intelligent.
Properties of Quantifiers:
o In universal quantifier, ∀x∀y is similar to ∀y∀x.
o In Existential quantifier, ∃x∃y is similar to ∃y∃x.
o ∃x∀y is not similar to ∀y∃x.
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)}
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) y
P(a, f(z))......... (ii)
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].
Unification Algorithm:
Algorithm: Unify(Ψ1, Ψ2)
Step. 1: If Ψ1 or Ψ2 is a variable or constant, then:
a) If Ψ1 or Ψ2 are identical, then return NIL.
b) Else if Ψ1is a variable,
a. then if Ψ1 occurs in Ψ2, then return FAILURE
b. Else return { (Ψ2/ Ψ1)}.
c) Else if Ψ2 is a variable,
a. If Ψ2 occurs in Ψ1 then return FAILURE,
b. Else return {( Ψ1/ Ψ2)}.
d) Else return FAILURE.
Step.2: If the initial Predicate symbol in Ψ1 and Ψ2 are not same, then
return FAILURE.
Step. 3: IF Ψ1 and Ψ2 have a different number of arguments, then return
FAILURE.
Step. 4: Set Substitution set(SUBST) to NIL.
Step. 5: For i=1 to the number of elements in Ψ1.
a) Call Unify function with the ith element of Ψ1 and ith element of
Ψ2, and put the result into S.
b) If S = failure then returns Failure
c) If S ≠ NIL then do,
a. Apply S to the remainder of both L1 and L2.
b. SUBST= APPEND(S, SUBST).
Step.6: Return SUBST.
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.
This rule is also called the binary resolution rule because it only resolves exactly
two literals.
Example:
We can resolve two clauses which are given below:
Where two complimentary literals are: Loves (f(x), x) and ¬ Loves (a, b)
These literals can be unified with unifier θ= [a/f(x), and b/x] , and it will
generate a resolvent clause:
To better understand all the above steps, we will take an example in which we will
apply resolution.
Example:
a. John likes all kind of food.
b. Apple and vegetable are food
c. Anything anyone eats and not killed is food.
d. Anil eats peanuts and still alive
e. Harry eats everything that Anil eats.
Prove by resolution that:
f. John likes peanuts.
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.
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.
Probabilistic reasoning
Uncertainty:
Till now, we have learned knowledge representation using first-order logic and
propositional logic with certainty, which means we were sure about the
predicates. With this knowledge representation, we might write A→B, which
means if A is true then B is true, but consider a situation where we are not sure
about whether A is true or not then we cannot express this statement, this
situation is called uncertainty.
Causes of uncertainty:
Following are some leading causes of uncertainty to occur in the real world.
Probabilistic reasoning:
Probabilistic reasoning is a way of knowledge representation where we apply the
concept of probability to indicate the uncertainty in knowledge. In probabilistic
reasoning, we combine probability theory with logic to handle the uncertainty.
In probabilistic reasoning, there are two ways to solve problems with uncertain
knowledge:
o Bayes' rule
o Bayesian Statistics
o As probabilistic reasoning uses probability and related terms, so before understanding
probabilistic reasoning, let's understand some common terms:
o Probability: Probability can be defined as a chance that an uncertain event will occur. It
is the numerical measure of the likelihood that an event will occur. The value of
probability always remains between 0 and 1 that represent ideal uncertainties.
Bayes' theorem
Bayes' theorem is also known as Bayes' rule, Bayes' law, or Bayesian reasoning,
which determines the probability of an event with uncertain knowledge.
Bayes' theorem was named after the British mathematician Thomas Bayes.
The Bayesian inference is an application of Bayes' theorem, which is
fundamental to Bayesian statistics.
Bayes' theorem can be derived using product rule and conditional probability of
event A with known event B:
The above equation (a) is called as Bayes' rule or Bayes' theorem. This equation
is basic of most modern AI systems for probabilistic inference.
It shows the simple relationship between joint and conditional probabilities. Here,
P(B|A) is called the likelihood, in which we consider that hypothesis is true, then
we calculate the probability of evidence.
Where A1, A2, A3,........, An is a set of mutually exclusive and exhaustive events.
Bayesian networks are probabilistic, because these networks are built from
a probability distribution, and also use probability theory for prediction and
anomaly detection.
Bayesian Network can be used for building models from data and experts
opinions, and it consists of two parts:
The generalized form of Bayesian network that represents and solve decision
problems under uncertain knowledge is known as an Influence diagram.
o Causal Component
o Actual numbers
P[x1, x2, x3,....., xn], it can be written as the following way in terms of the joint
probability distribution.
Fuzzy Logic
The term fuzzy refers to things that are not clear or are vague. In the real world many times we encounter
a situation when we can’t determine whether the state is true or false, their fuzzy logic provides very
valuable flexibility for reasoning. In this way, we can consider the inaccuracies and uncertainties of any
situation.
Fuzzy Logic is a form of many-valued logic in which the truth values of variables may be any real
number between 0 and 1, instead of just the traditional values of true or false. It is used to deal with
imprecise or uncertain information and is a mathematical method for representing vagueness and
uncertainty in decision-making.
Fuzzy Logic is based on the idea that in many cases, the concept of true or false is too restrictive, and that
there are many shades of gray in between. It allows for partial truths, where a statement can be partially
true or false, rather than fully true or false.
Fuzzy Logic is used in a wide range of applications, such as control systems, image processing, natural
language processing, medical diagnosis, and artificial intelligence.
In the boolean system truth value, 1.0 represents the absolute truth value and 0.0 represents the absolute
false value. But in the fuzzy system, there is no logic for the absolute truth and absolute false value. But
in fuzzy logic, there is an intermediate value too present which is partially true and partially false.
Data Minning
Data mining, also known as knowledge discovery in data (KDD), is the process of uncovering patterns
and other valuable information from large data sets. Given the evolution of data warehousing technology
and the growth of big data, adoption of data mining techniques has rapidly accelerated over the last
couple of decades, assisting companies by transforming their raw data into useful knowledge. However,
despite the fact that that technology continuously evolves to handle data at a large scale, leaders still face
challenges with scalability and automation.
Data mining has improved organizational decision-making through insightful data analyses. The data
mining techniques that underpin these analyses can be divided into two main purposes; they can either
describe the target dataset or they can predict outcomes through the use of machine learning algorithms.
These methods are used to organize and filter data, surfacing the most interesting information, from fraud
detection to user behaviors, bottlenecks and even security breaches.
When combined with data analytics and visualization tools, like Apache Spark, delving into the world of
data mining has never been easier and extracting relevant insights has never been faster. Advances
within artificial intelligence only continue to expedite adoption across industries.
Data mining works by using various algorithms and techniques to turn large volumes of data into useful
information. Here are some of the most common ones:
Association rules: An association rule is a rule-based method for finding relationships between variables
in a given dataset. These methods are frequently used for market basket analysis, allowing companies to
better understand relationships between different products. Understanding consumption habits of
customers enables businesses to develop better cross-selling strategies and recommendation engines.
Neural networks: Primarily leveraged for deep learning algorithms, neural networks process training data
by mimicking the interconnectivity of the human brain through layers of nodes. Each node is made up of
inputs, weights, a bias (or threshold) and an output. If that output value exceeds a given threshold, it
“fires” or activates the node, passing data to the next layer in the network. Neural networks learn this
mapping function through supervised learning, adjusting based on the loss function through the process of
gradient descent. When the cost function is at or near zero, we can be confident in the model’s accuracy
to yield the correct answer.
Decision tree: This data mining technique uses classification or regression methods to classify or predict
potential outcomes based on a set of decisions. As the name suggests, it uses a tree-like visualization to
represent the potential outcomes of these decisions.
K- nearest neighbor (KNN): K-nearest neighbor, also known as the KNN algorithm, is a non-parametric
algorithm that classifies data points based on their proximity and association to other available data. This
algorithm assumes that similar data points can be found near each other. As a result, it seeks to calculate
the distance between data points, usually through Euclidean distance, and then it assigns a category based
on the most frequent category or average.