AI UNIT - 4 FINAL
AI UNIT - 4 FINAL
Logic concepts: First order logic. Inference in first order logic, propositional vs. first order
inference, unification & lifts forward chaining, Backward chaining, Resolution, Learning from
observation Inductive learning, Decision trees, Explanation based learning, Statistical Learning
methods, Reinforcement Learning.
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.
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:
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, ......
Syntax
Semantics
The syntax of FOL determines which collection of symbols is a logical expression in first-order
logic. The basic syntactic elements of first-order logic are symbols. We write statements in short-
hand notation in FOL.
1
Following are the basic elements of FOL syntax:
Atomic sentences:
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.
We can represent atomic sentences as Predicate (term1, term2, ......, term n).
Complex Sentences:
Consider the statement: "x is an integer.", it consists of two parts, the first part x is the subject
of the statement and second part "is an integer," is known as a predicate.
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.
For all x
For each x
For every x.
2
Example:
Let a variable x which refers to a cat so all x can be represented in UOD as below:
It will be read as: There are all x where x is a man who drink coffee.
Existential Quantifier:
Existential quantifiers are the type of quantifiers, which express that the statement within its scope
is true for at least one instance of something.
It is denoted by the logical operator ∃, which resembles as inverted E. When it is used with a
predicate variable then it is called as an existential quantifier.
If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
Example:
3
∃x: boys(x) ∧ intelligent(x)
It will be read as: There are some x where x is a boy who is intelligent.
Points to remember:
Properties of Quantifiers:
∀x bird(x) →fly(x).
And since there are all birds who fly so it will be represented as follows.
Since there is every man so will use ∀, and it will be represented as follows:
In this question, the predicate is "respect(x, y)," where x=man, and y= parent.
Since there are not all students, so we will use ∀ with negation, so following representation for
In this question, the predicate is "like(x, y)," where x= student, and y= subject.
4
5. Only one student failed in Mathematics.
In this question, the predicate is "failed(x, y)," where x= student, and y= subject.
Since there is only one student who failed in Mathematics, so we will use following
∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) → ¬failed (x,
representation for this:
Mathematics)].
The quantifiers interact with variables which appear in a suitable way. There are two types of
variables in First-order logic which are given below:
Free Variable: A variable is said to be a free variable in a formula if it occurs outside the
scope of the quantifier.
Inference in First-Order Logic is used to deduce new facts or sentences from existing sentences.
Before understanding the FOL inference rule, let's understand some basic terminologies used in
FOL.
Substitution:
Note: First-order logic is capable of expressing facts about some or all objects in the universe.
Equality:
First-Order logic does not only use predicate and terms for making atomic sentences but also uses
another way, which is equality in FOL. For this, we can use equality symbols which specify that
the two terms refer to the same object.
As in the above example, the object referred by the Brother (John) is similar to the object
referred by Smith. The equality symbol can also be used with negation to represent that two terms
are not the same objects.
5
As propositional logic we also have inference rules in first-order logic, so following are some
basic inference rules in FOL:
Universal Generalization
Universal Instantiation
Existential Instantiation
Existential introduction
1. Universal Generalization:
any arbitrary element c in the universe of discourse, then we can have a conclusion as ∀ x P(x).
Universal generalization is a valid inference rule which states that if premise P(c) is true for
2. Universal Instantiation:
constant within domain x) from ∀ x P(x) for any object in the universe of discourse.
The UI rule state that we can infer any sentence P(c) by substituting a ground term c (a
Example:1.
Example: 2.
"All kings who are greedy are Evil." So let our knowledge base contains this detail as in the form
of FOL:
So from this information, we can infer any of the following statements using Universal
Instantiation:
3. Existential Instantiation:
This rule states that one can infer P(c) from the formula given in the form of ∃x P(x) for a
satisfiable.
Example:
So we can infer: Crown(K) ∧ OnHead( K, John), as long as K does not appear in the
knowledge base.
4. Existential introduction
For the inference process in FOL, we have a single inference rule which is called Generalized
Modus Ponens. It is lifted version of Modus ponens.
Generalized Modus Ponens can be summarized as, " P implies Q and P is asserted to be true,
therefore Q must be True."
According to Modus Ponens, for atomic sentences pi, pi', q. Where there is a substitution θ such
that SUBST (θ, pi',) = SUBST(θ, pi), it can be represented as:
7
Example:
We will use this rule for Kings are evil, so we will find some x such that x is king, and x is
greedy so we can infer that x is evil.
What is Unification?
Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it can
It takes two literals as input and makes them identical using substitution.
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.
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.
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.
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].
8
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:
e. If both the expressions are functions, then function name must be similar, and the number
of arguments must be the same in both the expression.
For each pair of the following atomic sentences find the most general unifier (If exist).
9
S1 => Ψ1 = p(f(a), g(Y)), and Ψ2 = p(f(a), f(a))
SUBST θ= {f(a) / g(y)},
Unification failed.
Unified Successfully.
And Unifier = { b/Z, f(Y) /X , g(b) /Y}.
Unification Failed.
Successfully unified.
Unifier: {11/y}.
5. Find the MGU of Q(a, g(x, a), f(y)), Q(a, g(f(b), a), x)}
Successfully Unified.
Successfully Unified.
Unifier: {John/x}.
Resolution in FOL:
Resolution:
Resolution is a theorem proving technique that proceeds by building refutation proofs, i.e., proofs
by contradictions. It was invented by a Mathematician John Alan Robinson in the year 1965.
Resolution is used, if there are various statements are given, and we need to prove a
conclusion of those statements. Unification is a key concept in proofs by resolutions.
Resolution is a single inference rule which can efficiently operate on the conjunctive
normal form or clausal form.
Clause: Disjunction of literals (an atomic sentence) is called a clause. It is also known as a
unit clause.
Conjunctive Normal Form: A sentence represented as a conjunction of clauses is said to
be conjunctive normal form or CNF.
Note: To better understand this topic, firstly learns the FOL in AI.
The resolution rule for first-order logic is simply a lifted version of the propositional rule.
Resolution can resolve two clauses if they contain complementary literals, which are assumed to
be standardized apart so that they share no variables.
This rule is also called the binary resolution rule because it only resolves exactly two literals.
Example:
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:
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.
12
a. ∀x ¬ [food(x)] V likes(John, x)
∀x ¬ eats(Anil, x) V eats(Harry, x)
d. eats (Anil, Peanuts) Λ alive(Anil)
∀x ¬ alive(x) V ¬ killed(x)
f.
g.
h. likes(John, Peanuts).
[Link] negation (¬)inwards and rewrite:
a. ∀x ¬ food(x) V likes(John, x)
∀x ¬ eats(Anil, x) V eats(Harry, x)
d. eats (Anil, Peanuts) Λ alive(Anil)
∀x killed(x) V alive(x)
e.
∀x ¬ alive(x) V ¬ killed(x)
f.
g.
h. likes(John, Peanuts).
[Link] variables or standardize variables:
a. ∀x ¬ food(x) V likes(John, x)
∀g ¬killed(g) ] V alive(g)
e.
∀k ¬ alive(k) V ¬ killed(k)
f.
g.
h. likes(John, Peanuts).
In this step, we will eliminate existential quantifier ∃, and this process is known
[Link] existential instantiation quantifier by elimination:
as Skolemization. But in this example problem since there is no existential quantifier so all the
statements will remain same in this step.
i. ¬ food(x) V likes(John, x)
j. food(Apple)
k. food(vegetables)
l. ¬ eats(y, z) V killed(y) V food(z)
m. eats (Anil, Peanuts)
n. alive(Anil)
o. ¬ eats(Anil, w) V eats(Harry, w)
p. killed(g) V alive(g)
q. ¬ alive(k) V ¬ killed(k)
r. likes(John, Peanuts).
Note: Statements "food(Apple) Λ food(vegetables)" and "eats (Anil, Peanuts) Λ alive(Anil)" can
be written in two separate statements.
13
[Link] conjunction ∧ over disjunction ¬:
This step will not make any change in this problem.
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.
In the first step of resolution graph, ¬likes(John, Peanuts) , and likes(John, x) get
resolved(canceled) by substitution of {Peanuts/x}, and we are left with ¬ food(Peanuts)
In the second step of the resolution graph, ¬ food(Peanuts) , and food(z) get resolved
(canceled) by substitution of { Peanuts/z}, and we are left with ¬ eats(y, Peanuts) V killed(y) .
In the third step of the resolution graph, ¬ eats(y, Peanuts) and eats (Anil, Peanuts) get
resolved by substitution {Anil/y}, and we are left with Killed(Anil) .
In the fourth step of the resolution graph, Killed(Anil) and ¬ killed(k) get resolve by
substitution {Anil/k}, and we are left with ¬ alive(Anil) .
In the last step of the resolution graph ¬ alive(Anil) and alive(Anil) get resolved.
In artificial intelligence, forward and backward chaining is one of the important topics, but before
understanding forward and backward chaining lets first understand that from where these two
terms came.
Inference engine:
The inference engine is the component of the intelligent system in artificial intelligence, which
applies logical rules to the knowledge base to infer new information from known facts. The first
14
inference engine was part of the expert system. Inference engine commonly proceeds in two
modes, which are:
a. Forward chaining
b. Backward chaining
Horn clause and definite clause are the forms of sentences, which enables knowledge base to use a
more restricted and efficient inference algorithm. Logical inference algorithms use forward and
backward chaining approaches, which require KB in the form of the first-order definite clause.
Definite clause: A clause which is a disjunction of literals with exactly one positive literal is
known as a definite clause or strict horn clause.
Horn clause: A clause which is a disjunction of literals with at most one positive literal is
known as horn clause. Hence all the definite clauses are horn clauses.
It is equivalent to p ∧ q → k.
A. Forward Chaining:
Forward chaining is also known as a forward deduction or forward reasoning method when using
an inference engine. Forward chaining is a form of reasoning which start with atomic sentences in
the knowledge base and applies inference rules (Modus Ponens) in the forward direction to extract
more data until a goal is reached.
The Forward-chaining algorithm starts from known facts, triggers all rules whose premises
are satisfied, and add their conclusion to the known facts. This process repeats until the
problem is solved.
Properties of Forward-Chaining:
Consider the following famous example which we will use in both approaches:
Example:1
"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."
15
To solve the above problem, first, we will convert all the above facts into first-order definite
clauses, and then we will use a forward-chaining algorithm to reach the goal.
It is a crime for an American to sell weapons to hostile nations. (Let's say p, q, and r are
Step-1:
In the first step we will start with the known facts and will choose the sentences which do not
have implications, such as: American(Robert), Enemy(A, America), Owns(A, T1), and
Missile(T1). All these facts will be represented as below.
Step-2:
At the second step, we will see those facts which infer from available facts and with satisfied
premises.
Rule-(1) does not satisfy premises, so it will not be added in the first iteration.
Rule-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is added, which infers from
the conjunction of Rule (2) and (3).
Rule-(6) is satisfied with the substitution(p/A), so Hostile(A) is added and which infers from
Rule-(7).
16
Step-3:
At step-3, as we can check Rule-(1) is satisfied with the substitution {p/Robert, q/T1, r/A}, so we
can add Criminal(Robert) which infers all the available facts. And hence we reached our goal
statement.
Example:2
17
Problem: Does situation Z exists or not ?
The first rule that fires is A->D because A is already in the database. Next we infer D.
Existence of C and D causes second rule to fire and as a consequence F is inferred and placed
in the database. This in turn, causes the third rule F?B->Z to fire, placing Z in the database.
This technique is called forward chaining.
Rule 1
IF the car overheats , THEN the car will stall.
Rule 2
IF the car stalls
THEN it will cost me money
AND I will be late getting home
Now, the question is
How do you arrive at conclusion that this situation will cost money and cause you to be late ?
The condition that triggers the chain of events is the car overheating.
B. Backward Chaining:
18
It is known as a top-down approach.
Backward-chaining is based on modus ponens inference rule.
In backward chaining, the goal is broken into sub-goal or sub-goals to prove the facts true.
It is called a goal-driven approach, as a list of goals decides which rules are selected and
used.
Backward -chaining algorithm is used in game theory, automated theorem proving tools,
inference engines, proof assistants, and various AI applications.
The backward-chaining method mostly used a depth-first search strategy for proof.
Example:
In backward-chaining, we will use the same above example, and will rewrite all the rules.
Backward-Chaining proof:
In Backward chaining, we will start with our goal predicate, which is Criminal(Robert), and then
infer further rules.
Step-1:
At the first step, we will take the goal fact. And from the goal fact, we will infer other facts, and at
last, we will prove those facts true. So our goal fact is "Robert is Criminal," so following is the
predicate of it.
Step-2:
At the second step, we will infer other facts form goal fact which satisfies the rules. So as we can
see in Rule-1, the goal predicate Criminal (Robert) is present with substitution {Robert/P}. So we
will add all the conjunctive facts below the first level and will replace p with Robert.
19
Step-3:t At step-3, we will extract further fact Missile(q) which infer from Weapon(q), as it
satisfies Rule-(5). Weapon (q) is also true with the substitution of a constant T1 at q.
Step-4:
At step-4, we can infer facts Missile(T1) and Owns(A, T1) form Sells(Robert, T1, r) which
satisfies the Rule- 4, with the substitution of A in place of r. So these two statements are proved
here.
20
Step-5:
At step-5, we can infer the fact Enemy(A, America) from Hostile(A) which satisfies Rule- 6.
And hence all the statements are proved true using backward chaining.
Rule 1
IF the car is not tuned AND the battery is weak
THEN not enough current will reach the starter.
Rule 2
IF not enough current reaches the starter
21
THEN the car will not start.
Given facts:
The car is not tuned
The battery is weak.
Now, the question is
How would you arrive at the conditions that have resulted in the car failing to
start?
In such a situation backward chaining might be more cost-effective. With this inference
method the system starts with what it wants to prove, e.g., that situation Z exists, and only
executes rules that are relavent to establishing it. Figure following shows how backward
chaining would work using the rules from the forward chaining example.
In step 1 the system is told to establish (if it can) that situation Z exists, It first checks the
data base for Z, and when that fails, searches for rules that conclude Z, i.e., have Z on the right
side of the arrow. It finds the rule F?B->Z, and decides that it must establish F and B in order to
conclude Z.
In step 2 the system tries to establish F, first checking the data base and then finding a rule
that concludes F. From this rule, C?D->F, the system decides it must establish C and D to
conclude F.
In steps 3 through 5 the system finds C in the data base but decides it must establish A
before it can conclude D. It then finds A in the data base.
In steps 6 through 8 the system executes the third rule to establish D, then executes the
second rule to establish the original goal, Z. The inference chain created here is identical to the
one created by forward chaining. The difference in two approaches hinges on the method in
which data and rules are searched.
22
23
Difference between backward chaining and forward chaining.
Following is the difference between the forward chaining and backward chaining:
Forward chaining as the name suggests, start from the known facts and move forward by
applying inference rules to extract more data, and it continues until it reaches to the goal, whereas
backward chaining starts from the goal, move backward by using inference rules to determine the
facts that satisfy the goal.
Forward chaining is called a data-driven inference technique, whereas backward chaining is
called a goal-driven inference technique.
Forward chaining is known as the down-up approach, whereas backward chaining is known
as a top-down approach.
Forward chaining uses breadth-first search strategy, whereas backward chaining
uses depth-first search strategy.
Forward and backward chaining both applies Modus ponens inference rule.
Forward chaining can be used for tasks such as planning, design process monitoring,
diagnosis, and classification, whereas backward chaining can be used for classification and
diagnosis tasks.
Forward chaining can be like an exhaustive search, whereas backward chaining tries to avoid
the unnecessary path of reasoning.
In forward-chaining there can be various ASK questions from the knowledge base, whereas
in backward chaining there can be fewer ASK questions.
Forward chaining is slow as it checks for all the rules, whereas backward chaining is fast as it
checks few required rules only.
24
What is Reinforcement Learning?
Example:
Suppose there is an AI agent present within a maze environment, and his goal is to find the
diamond. The agent interacts with the environment by performing some actions, and based
on those actions, the state of the agent gets changed, and it also receives a reward or
penalty as feedback.
The agent continues doing these three things (take action, change state/remain in the
same state, and get feedback), and by doing these actions, he learns and explores the
environment.
25
The agent learns that what actions lead to positive feedback or rewards and what actions
lead to negative feedback penalty. As a positive reward, the agent gets a positive point,
and as a penalty, it gets a negative point.
Agent(): An entity that can perceive/explore the environment and act upon it.
Environment(): A situation in which an agent is present or surrounded by. In RL, we
assume the stochastic environment, which means it is random in nature.
Action(): Actions are the moves taken by an agent within the environment.
State(): State is a situation returned by the environment after each action taken by the
agent.
Reward(): A feedback returned to the agent from the environment to evaluate the action
of the agent.
Policy(): Policy is a strategy applied by the agent for the next action based on the current
state.
Value(): It is expected long-term retuned with the discount factor and opposite to the
short-term reward.
Q-value(): It is mostly similar to the value, but it takes one additional parameter as a
current action (a).
In RL, the agent is not instructed about the environment and what actions need to be taken.
It is based on the hit and trial process.
The agent takes the next action and changes states according to the feedback of the
previous action.
The agent may get a delayed reward.
The environment is stochastic, and the agent needs to explore it to reach to get the
maximum positive rewards.
There are mainly three ways to implement reinforcement-learning in ML, which are:
1. Value-based:
The value-based approach is about to find the optimal value function, which is the
maximum value at a state under any policy. Therefore, the agent expects the long-term
return at any state(s) under policy π.
2. Policy-based:
Policy-based approach is to find the optimal policy for the maximum future rewards
26
without using the value function. In this approach, the agent tries to apply such a policy
that the action performed in each step helps to maximize the future reward.
The policy-based approach has mainly two types of policy:
Deterministic: The same action is produced by the policy (π) at any state.
Stochastic: In this policy, probability determines the produced action.
There are four main elements of Reinforcement Learning, which are given below:
1. Policy
2. Reward Signal
3. Value Function
4. Model of the environment
1) Policy: A policy can be defined as a way how an agent behaves at a given time. It maps the
perceived states of the environment to the actions taken on those states. A policy is the core
element of the RL as it alone can define the behavior of the agent. In some cases, it may be a
simple function or a lookup table, whereas, for other cases, it may involve general computation as
a search process. It could be deterministic or a stochastic policy:
2) Reward Signal: The goal of reinforcement learning is defined by the reward signal. At each
state, the environment sends an immediate signal to the learning agent, and this signal is known as
a reward signal. These rewards are given according to the good and bad actions taken by the
agent. The agent's main objective is to maximize the total number of rewards for good actions.
The reward signal can change the policy, such as if an action selected by the agent leads to low
reward, then the policy may change to select other actions in the future.
3) Value Function: The value function gives information about how good the situation and action
are and how much reward an agent can expect. A reward indicates the immediate signal for each
good and bad action, whereas a value function specifies the good state and action for the
future. The value function depends on the reward as, without reward, there could be no value.
The goal of estimating values is to achieve more rewards.
4) Model: The last element of reinforcement learning is the model, which mimics the behavior of
the environment. With the help of the model, one can make inferences about how the environment
will behave. Such as, if a state and an action are given, then a model can predict the next state and
reward.
The model is used for planning, which means it provides a way to take a course of action by
considering all future situations before actually experiencing those situations. The approaches for
solving the RL problems with the help of the model are termed as the model-based approach.
Comparatively, an approach without using a model is called a model-free approach.
27
To understand the working process of the RL, we need to consider two main things:
Let's take an example of a maze environment that the agent needs to explore. Consider the below
image:
In the above image, the agent is at the very first block of the maze. The maze is consisting of an
S6 block, which is a wall, S8 a fire pit, and S4 a diamond block.
The agent cannot cross the S6 block, as it is a solid wall. If the agent reaches the S 4 block,
then get the +1 reward; if it reaches the fire pit, then gets -1 reward point. It can take
four actions: move up, move down, move left, and move right.
The agent can take any path to reach to the final point, but he needs to make it in possible
fewer steps. Suppose the agent considers the path S9-S5-S1-S2-S3, so he will get the +1-
reward point.
The agent will try to remember the preceding steps that it has taken to reach the final step.
To memorize the steps, it assigns 1 value to each previous step. Consider the below step:
Now, the agent has successfully stored the previous steps assigning the 1 value to each previous
block. But what will the agent do if he starts moving from the block, which has 1 value block on
both sides? Consider the below diagram:
28
It will be a difficult condition for the agent whether he should go up or down as each block has the
same value. So, the above approach is not suitable for the agent to reach the destination. Hence to
solve the problem, we will use the Bellman equation, which is the main concept behind
reinforcement learning.
The Bellman equation was introduced by the Mathematician Richard Ernest Bellman in the
year 1953, and hence it is called as a Bellman equation. It is associated with dynamic
programming and used to calculate the values of a decision problem at a certain point by
including the values of previous states.
It is a way of calculating the value functions in dynamic programming or environment that leads
to modern reinforcement learning.
Where,
γ = Discount factor
In the above equation, we are taking the max of the complete values because the agent tries to find
the optimal solution always.
29
So now, using the Bellman equation, we will find value at each state of the given environment.
We will start from the block, which is next to the target block.
V(s3) = max [R(s,a) + γV(s`)], here V(s')= 0 because there is no further state to move.
V(s2) = max [R(s,a) + γV(s`)], here γ= 0.9(lets), V(s')= 1, and R(s, a)= 0, because there is no
reward at this state.
V(s1) = max [R(s,a) + γV(s`)], here γ= 0.9(lets), V(s')= 0.9, and R(s, a)= 0, because there is no
reward at this state also.
V(s5) = max [R(s,a) + γV(s`)], here γ= 0.9(lets), V(s')= 0.81, and R(s, a)= 0, because there is no
reward at this state also.
V(s9) = max [R(s,a) + γV(s`)], here γ= 0.9(lets), V(s')= 0.73, and R(s, a)= 0, because there is no
reward at this state also.
30
Now, we will move further to the 6 th block, and here agent may change the route because it always
tries to find the optimal path. So now, let's consider from the block next to the fire pit.
Now, the agent has three options to move; if he moves to the blue box, then he will feel a bump if
he moves to the fire pit, then he will get the -1 reward. But here we are taking only positive
rewards, so for this, he will move to upwards only. The complete block values will be calculated
using this formula. Consider the below image:
Positive Reinforcement
Negative Reinforcement
Positive Reinforcement:
The positive reinforcement learning means adding something to increase the tendency that
expected behavior would occur again. It impacts positively on the behavior of the agent
and increases the strength of the behavior.
This type of reinforcement can sustain the changes for a long time, but too much positive
reinforcement may lead to an overload of states that can reduce the consequences.
Negative Reinforcement:
31
It can be more effective than the positive reinforcement depending on situation and
behavior, but it provides reinforcement only to meet minimum behavior.
[Link]:
[Link]:
RL can be used for adaptive control such as Factory processes, admission control in
telecommunication, and Helicopter pilot is an example of reinforcement learning.
[Link] Playing:
[Link]:
[Link]:
[Link]:
In various automobile manufacturing companies, the robots use deep reinforcement learning to
pick goods and put them in some containers.
[Link] Sector:
The RL is currently used in the finance sector for evaluating trading strategies.
Conclusion:
From the above discussion, we can say that Reinforcement Learning is one of the most interesting
and useful parts of Machine learning. In RL, the agent explores the environment by exploring it
without any human intervention. It is the main learning algorithm that is used in Artificial
32
Intelligence. But there are some cases where it should not be used, such as if you have enough
data to solve the problem, then other ML algorithms can be used more efficiently. The main issue
with the RL algorithm is that some of the parameters may affect the speed of the learning, such as
delayed feedback.
Introduction:
What is learning?
Learning denotes changes in the system that are adaptive in the sense that they enable
the system to do the same task or tasks drawn from the same population more
effectively the next time (Simon, 1983).
Learning is making useful changes in our minds (Minsky, 1985).
Learning is constructing or modifying representations of what is being experienced
(Michalski, 1986).
(Mitchell, 1997).
So what is learning?
(1) acquire and organize knowledge (by building, modifying and organizing internal
representations of some external reality);
(2) discover new knowledge and theories (by creating hypotheses that explain some data
or phenomena);
(3) acquire skills (by gradually improving their motor or cognitive skills through repeated
practice,
(4) Learning results in changes in the agent (or mind) that improve its competence and/or
efficiency.
(5) Learning is essential for unknown environments, (1) i.e., when designer lacks
omniscience
FORMS OF LEARNING:
Learning agents:
33
Four Components:
1. Performance Element: collection of knowledge and procedures to decide on the next action
[Link] Element: takes in feedback from the critic and modifies the performance element
accordingly.
3. Critic: provides the learning element with information on how well the agent is doing based
on a fixed performance standard. E.g. the audience
[Link] Generator: provides the performance element with suggestions on new actions to
take. Components of the Performance Element
• Information about the results of possible actions the agent can take
Learning element
INDUCTIVE LEARNING:
Inductive Learning in supervised learning we have a set of {xi, f (xi)} for 1≤i≤n, and our aim is to
determine 'f' by some adaptive algorithm. It is a machine learning approach in which rules are
inferred from facts or data. In logic, reasoning from the specific to the general Conditional or
antecedent reasoning. Theoretical results in machine learning mainly deal with a type of inductive
learning called supervised learning. In supervised learning, an algorithm is given samples that are
labeled in some useful way. In case of inductive learning algorithms, like artificial neural
networks, the real robot may learn only from previously gathered data. Another option is to let the
bot learn everything around him by inducing facts from the environment. This is known as
inductive learning. Finally, you could get the bot to evolve, and optimise his performance over
several generations.
1.F(x) gives a training set of examples D = {[xi, f(xi) ]}, i = 1,2,…,N Construct h so that it agrees
with f.
35
Simplest: Construct a decision tree with one leaf for every example = memory based
learning. Not very good generalization.
Advanced: Split on each variable so that the purity of each split increases (i.e. either only yes
or only no)
INTRODUCTION:
Decision Tree is a Supervised learning technique that can be used for both classification
and Regression problems, but mostly it is preferred for solving Classification problems. It
is a tree-structured classifier, where internal nodes represent the features of a dataset,
branches represent the decision rules and each leaf node represents the outcome.
In a Decision tree, there are two nodes, which are the Decision Node and Leaf Node.
Decision nodes are used to make any decision and have multiple branches, whereas Leaf
nodes are the output of those decisions and do not contain any further branches.
The decisions or the test are performed on the basis of features of the given dataset.
It is a graphical representation for getting all the possible solutions to a problem/decision
based on given conditions.
It is called a decision tree because, similar to a tree, it starts with the root node, which
expands on further branches and constructs a tree-like structure.
In order to build a tree, we use the CART algorithm, which stands for Classification and
Regression Tree algorithm.
A decision tree simply asks a question, and based on the answer (Yes/No), it further split
the tree into sub trees.
36
APPROPRIATE PROBLEMS FOR DECISION TREE LEARNING :
Decision tree learning is generally best suited to problems with the following characteristics:
1. Instances are represented by attribute-value pairs – Instances are described by a fixed set of
attributes and their values
2. The target function has discrete output values – The decision tree assigns a Boolean
classification (e.g., yes or no) to each example. Decision tree methods easily extend to learning
functions with more than two possible output values.
4. The training data may contain errors – Decision tree learning methods are robust to errors, both
errors in classifications of the training examples and errors in the attribute values that describe
these examples.
5. The training data may contain missing attribute values – Decision tree methods can be used
even when some training examples have unknown values
The basic algorithm is ID3 which learns decision trees by constructing them top-down
Examples are the training examples. Target_attribute is the attribute whose value is tobe
predicted by the tree. Attributes is a list of other attributes that may be tested by the learned
decision tree. Returns a decision tree that correctly classifies the given Examples.
• If all Examples are positive, Return the single-node tree Root, with label = +
• If all Examples are negative, Return the single-node tree Root, with label = -
37
• If Attributes is empty, Return the single-node tree Root, with label = most common value of
Target_attribute in Examples
• Otherwise Begin
• Let Examples vi, be the subset of Examples that have value vi for A
• If Examples vi , is empty
• Then below this new branch add a leaf node with label = most common value of
Target_attribute in Examples
• Else below this new branch add the subtree ID3(Examples vi, Targe_tattribute,
Attributes – {A}))
• End
• Return Root
TABLE: Summary of the ID3 algorithm specialized to learning Boolean-valued functions. ID3 is
a greedy algorithm that grows the tree top-down, at each node selecting the attribute that best
classifies the local training examples. This process continues until the tree perfectly classifies the
training examples, or until all attributes have been used
• The central choice in the ID3 algorithm is selecting which attribute to test at each node in the
tree.
• A statistical property called information gain that measures how well a given attribute separates
the training examples according to their target classification.
• ID3 uses information gain measure to select among the candidate attributes at each step while
growing the tree.
To define information gain, we begin by defining a measure called entropy. Entropy measures the
impurity of a collection of examples.
Given a collection S, containing positive and negative examples of some target concept, the
entropy of S relative to this Boolean classification is
38
Where, p+ is the proportion of positive examples in S
• The entropy is 1 when the collection contains an equal number of positive and negative
examples
• If the collection contains unequal numbers of positive and negative examples, the entropy is
between 0 and 1
• Information gain, is the expected reduction in entropy caused by partitioning the examples
according to this attribute.
An Illustrative Example:
• To illustrate the operation of ID3, consider the learning task represented by the training
examples of below table.
• Here the target attribute PlayTennis, which can have values yes or no for different days.
• Consider the first step through the algorithm, in which the topmost node of the decision tree is
created.
39
• ID3 determines the information gain for each candidate attribute (i.e., Outlook, Temperature,
Humidity, and Wind), then selects the one with highest information gain.
[Link]=outlook:
s=[9+,5-]
= 0.409+0.530 = 0.940
values(outlook)=sunny,rain,overcast
[Link]:(s sunny)=[2+,3-]
=0.970
[Link]:(s overcast)=[4+,0-]
=0
[Link]:(s rain)=[3+,2-]
=0.970
=0.246
we have to perform the same process for temperature, humidity, wind and find their information
gain values.
• According to the information gain measure, the Outlook attribute provides the best prediction of
the target attribute, PlayTennis, over the training examples. Therefore, Outlook is selected as the
decision attribute for the root node, and branches are created below the root for each of its
possible values i.e., Sunny, Overcast, and Rain.
41
Rain Mild High Strong No
42
Decision Tree algorithm belongs to the family of supervised learning algorithms. Unlike other
supervised learning algorithms, the decision tree algorithm can be used for solving regression
and classification problems too.
The goal of using a Decision Tree is to create a training model that can use to predict the class
or value of the target variable by learning simple decision rules inferred from prior
data(training data).
In Decision Trees, for predicting a class label for a record we start from the root of the tree. We
compare the values of the root attribute with the record’s attribute. On the basis of comparison,
we follow the branch corresponding to that value and jump to the next node.
Types of decision trees are based on the type of target variable we have. It can be of two types:
1. Categorical Variable Decision Tree: Decision Tree which has a categorical target variable
then it called a Categorical variable decision tree.
2. Continuous Variable Decision Tree: Decision Tree has a continuous target variable then it
is called Continuous Variable Decision Tree.
Example:- Let’s say we have a problem to predict whether a customer will pay his renewal
premium with an insurance company (yes/ no). Here we know that the income of customers is a
significant variable but the insurance company does not have income details for all customers.
Now, as we know this is an important variable, then we can build a decision tree to predict
customer income based on occupation, product, and various other variables. In this case, we are
predicting values for the continuous variables.
1. Root Node: It represents the entire population or sample and this further gets divided into
two or more homogeneous sets.
3. Decision Node: When a sub-node splits into further sub-nodes, then it is called the decision
node.
4. Leaf / Terminal Node: Nodes do not split is called Leaf or Terminal node.
5. Pruning: When we remove sub-nodes of a decision node, this process is called pruning. You
can say the opposite process of splitting.
7. Parent and Child Node: A node, which is divided into sub-nodes is called a parent node of
sub-nodes whereas sub-nodes are the child of a parent node.
43
Decision trees classify the examples by sorting them down the tree from the root to some
leaf/terminal node, with the leaf/terminal node providing the classification of the example.
Each node in the tree acts as a test case for some attribute, and each edge descending from the
node corresponds to the possible answers to the test case. This process is recursive in nature
and is repeated for every sub tree rooted at the new node.
INTRODUCTION
Since its beginning, machine learning has come a long way. While early machine-learning
algorithms depended on statistical analysis to spot patterns and forecast outcomes,
contemporary machine-learning models are intended to learn from subject experts'
explanations. Explanation-based learning in artificial intelligence has proven to be a potent tool
in its development that can handle complicated issues more efficiently.
44
The environment provides two inputs to the EBL architecture:
The problem solver analyses these sources and provides reasoning to the generalizer.
The generalizer uses general ideas from the knowledge base as input and compares them to the
problem solver's reasoning to come up with an answer to the given problem.
Problem Solver: It takes 3 kinds of external inputs: The goal idea is a complex
problem statement that the agent must learn. Training instances are facts that illustrate a
specific instance of a target idea. Inference rules reflect facts and procedures that
demonstrate what the learner already understands.
Generalizer: The problem solver's output is fed into the generalizer, which compares
the problem solver's explanation to the knowledge base and outputs to the operational
pruner.
Operational pruner: It takes two inputs, one from generalized and the other from
operationally standard. The operational standard describes the final concept and defines
the format in which the learned concept should be conveyed.
45
According to the Explanation based learning hypothesis, if a system has an explanation for how
to tackle a comparable problem it faced previously, it will utilize that explanation to handle the
current problem more efficiently. This hypothesis is founded on the concept that learning via
explanations is more successful than learning through instances alone.
Conclusion
♦ More specifically, input data (or evidence), learn probabilistic theories of the world (or
hypotheses)
46
View learning as Bayesian updating of a probability distribution over the hypothesis space
H is the hypothesis variable, values h1, h2, . . ., prior P(H) jth observation dj gives the outcome
of random variable Dj training data d = d1, . . . , dN
P(hi|d) = αP(d|hi)P(hi)
Example
Suppose there are five kinds of bags of candies: 10% are h1: 100% cherry candies
20% are h2: 75% cherry candies + 25% lime candies 40% are h3: 50% cherry candies + 50%
lime candies 20% are h4: 25% cherry candies + 75% lime candies 10% are h5: 100% lime
candies
What kind of bag is it? What flavour will the next candy be?
[Link] true hypothesis eventually dominates the Bayesian prediction given that the true
hypothesis is in the prior
[Link] Bayesian prediction is optimal, whether the data set be small or large[?]
[Link] hypothesis space is usually very large or infinite summing over the hypothesis space is
often intractable.
[Link] when the hypothesis space is too expressive such that some hypotheses fit the
date set well.
47