AI Unit 3

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

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.
The fundamental concept of Fuzzy Logic is the membership function, which defines the degree of
membership of an input value to a certain set or category. The membership function is a mapping from
an input value to a membership degree between 0 and 1, where 0 represents non-membership and 1
represents full membership.
Fuzzy Logic is implemented using Fuzzy Rules, which are if-then statements that express the
relationship between input variables and output variables in a fuzzy way. The output of a Fuzzy Logic
system is a fuzzy set, which is a set of membership degrees for each possible output value.
In summary, Fuzzy Logic is a mathematical method for representing vagueness and uncertainty in
decision-making, it allows for partial truths, and it is used in a wide range of applications. It is based on
the concept of membership function and the implementation is done using Fuzzy rules.
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.

ARCHITECTURE
Its Architecture contains four parts :
• RULE BASE: It contains the set of rules and the IF-THEN conditions provided by the experts to
govern the decision-making system, on the basis of linguistic information. Recent developments in
fuzzy theory offer several effective methods for the design and tuning of fuzzy controllers. Most of
these developments reduce the number of fuzzy rules.
• FUZZIFICATION: It is used to convert inputs i.e. crisp numbers into fuzzy sets. Crisp inputs are
basically the exact inputs measured by sensors and passed into the control system for processing,
such as temperature, pressure, rpm’s, etc.
• INFERENCE ENGINE: It determines the matching degree of the current fuzzy input with
respect to each rule and decides which rules are to be fired according to the input field. Next, the
fired rules are combined to form the control actions.
• DEFUZZIFICATION: It is used to convert the fuzzy sets obtained by the inference engine into a
crisp value. There are several defuzzification methods available and the best-suited one is used
with a specific expert system to reduce the error.

Membership function

Definition: A graph that defines how each point in the input space is mapped to membership value
between 0 and 1. Input space is often referred to as the universe of discourse or universal set (u),
which contains all the possible elements of concern in each particular application.
There are largely three types of fuzzifiers:
1) Singleton fuzzifier
2) Gaussian fuzzifier
3) Trapezoidal or triangular fuzzifier
What is Fuzzy Control?
1) It is a technique to embody human-like thinkings into a control system.
2) It may not be designed to give accurate reasoning but it is designed to give acceptable
reasoning.
3) It can emulate human deductive thinking, that is, the process people use to infer conclusions
from what they know.
4) Any uncertainties can be easily dealt with the help of fuzzy logic.
Advantages of Fuzzy Logic System
1) This system can work with any type of inputs whether it is imprecise, distorted or noisy input
information.
2) The construction of Fuzzy Logic Systems is easy and understandable.
3) Fuzzy logic comes with mathematical concepts of set theory and the reasoning of that is quite
simple.
4) It provides a very efficient solution to complex problems in all fields of life as it resembles
human reasoning and decision-making.
5) The algorithms can be described with little data, so little memory is required.
Disadvantages of Fuzzy Logic Systems
1) Many researchers proposed different ways to solve a given problem through fuzzy logic which
leads to ambiguity. There is no systematic approach to solve a given problem through fuzzy
logic.
2) Proof of its characteristics is difficult or impossible in most cases because every time we do not
get a mathematical description of our approach.
3) As fuzzy logic works on precise as well as imprecise data so most of the time accuracy is
compromised.
Application
1) It is used in the aerospace field for altitude control of spacecraft and satellites.
2) It has been used in the automotive system for speed control, traffic control.
3) It is used for decision-making support systems and personal evaluation in the large company
business.
4) It has application in the chemical industry for controlling the pH, drying, chemical distillation
process.
5) Fuzzy logic is used in Natural language processing and various intensive applications in Artificial
Intelligence.
6) Fuzzy logic is extensively used in modern control systems such as expert systems.
7) Fuzzy Logic is used with Neural Networks as it mimics how a person would make decisions, only
much faster. It is done by Aggregation of data and changing it into more meaningful data by
forming partial truths as Fuzzy sets.
Fuzzy operations
Fuzzy operations are performed on fuzzy sets, whereas crisp operations are performed on
crisp sets. Fuzzy operations are very useful in the design of a Fuzzy Logic Controller. It
allows the manipulation of fuzzy variables by different means.

Union:
In the case of the union of crisp sets, we simply have to select repeated elements only
once. In the case of fuzzy sets, when there are common elements in both fuzzy sets, we
should select the element with the maximum membership value.

The union of two fuzzy sets A and B is a fuzzy set C, written as C = A ∪ B

C = A ∪ B = {(x, μA ∪ B (x)) | ∀x ∈ X}

μC(x) = μA ∪ B (x) = μA(x) ∨ μB(x)

= max( μA(x), μB(x) ), ∀x ∈ X

Graphically, we can represent union operations as follows: Red and Blue membership
functions represent the fuzzy value for elements in sets A and B, respectively. Wherever
these fuzzy functions overlap, we have to consider the point with the maximum
membership value.

Fuzzy union
Example of Fuzzy Union:
C = A ∪ B = {(x, μA ∪ B (x)) | ∀x ∈ X}

A = { (x1, 0.2), (x2, 0.5), (x3, 0.6), (x4, 0.8), (x5, 1.0) }

B = { (x1, 0.8), (x2, 0.6), (x3, 0.4), (x4, 0.2), (x5, 0.1) }

μA ∪ B (x1) = max( μA(x1), μB(x1) ) = max { 0.2, 0.8 } = 0.8

μA ∪ B (x2) = max( μA(x2), μB(x2) ) = max { 0.5, 0.6 } = 0.6


μA ∪ B (x3) = max( μA(x3), μB(x3) ) = max { 0.6, 0.4 } = 0.6

μA ∪ B (x4) = max( μA(x4), μB(x4) ) = max { 0.8, 0.2 } = 0.8

μA ∪ B (x5) = max( μA(x5), μB(x5) ) = max { 1.0, 0.1 } = 1.0

So, A ∪ B = { (x1, 0.8), (x2, 0.6), (x3, 0.6), (x4, 0.8), (x5, 1.0) }

Intersection:
In the case of the intersection of crisp sets, we simply have to select common elements
from both sets. In the case of fuzzy sets, when there are common elements in both fuzzy
sets, we should select the element with minimum membership value.

The intersection of two fuzzy sets A and B is a fuzzy set C, written as C = A ∩ B

C = A ∩ B = {(x, μA ∩ B (x)) | ∀x ∈ X}

μC(x) = μA ∩ B (x) = μA(x) ⋀ μB(x)

= min( μA(x), μB(x) ), ∀x ∈ X

Graphically, we can represent the intersection operation as follows: Red and blue
membership functions represent the fuzzy value for elements in sets A and B,
respectively. Wherever these fuzzy functions overlap, we have to consider the point with
the minimum membership value.

Fuzzy intersection
Example of Fuzzy Intersection:
C = A ∩ B = {(x, μA ∩ B (x)) | ∀x ∈ X}

A = { (x1, 0.2), (x2, 0.5), (x3, 0.6), (x4, 0.8), (x5, 1.0) }

B = { (x1, 0.8), (x2, 0.6), (x3, 0.4), (x4, 0.2), (x5, 0.1) }

μA ∩ B (x1) = min( μA(x1), μB(x1) ) = max { 0.2, 0.8 } = 0.2


μA ∩ B (x2) = min( μA(x2), μB(x2) ) = max { 0.5, 0.6 } = 0.5

μA ∩ B (x3) = min( μA(x3), μB(x3) ) = max { 0.6, 0.4 } = 0.4

μA ∩ B (x4) = min( μA(x4), μB(x4) ) = max { 0.8, 0.2 } = 0.2

μA ∩ B (x5) = min( μA(x5), μB(x5) ) = max { 1.0, 0.1 } = 0.1

So, A ∩ B = { (x1, 0.2), (x2, 0.5), (x3, 0.4), (x4, 0.2), (x5, 0.1) }

Complement:
Fuzzy complement is identical to crisp complement operation. The membership value of
every element in the fuzzy set is complemented with respect to 1, i.e. it is subtracted from
1.

The complement of fuzzy set A, denoted by AC, is defined as

AC = {(x, μAC (x)) | ∀x ∈ X}

AC (x) = 1 – μA(x)

Fuzzy complement
Example of Fuzzy Complement:
AC (x) = 1 – μA(x)

A = { (x1, 0.2), (x2, 0.5), (x3, 0.6), (x4, 0.8), (x5, 1.0) }

AC = { (x1, 0.8), (x2, 0.5), (x3, 0.4), (x4, 0.2), (x5, 0.0) }

A ⋃ AC = { (x1, 0.8), (x2, 0.5), (x3, 0.6), (x4, 0.8), (x5, 1.0) } ≠ X

A ∩ AC = { (x1, 0.2), (x2, 0.5), (x3, 0.4), (x4, 0.2), (x5, 0.0) } ≠ Φ

Unlike crisp sets, fuzzy sets do not hold the law of contradiction and the law of excluded
middle.

Watch on YouTube: Fuzzy operations


fuzzy operations on youtube
Test Your Knowledge:
For following fuzzy sets, perform union, complement and intersection operations.

A = { (x1, 0.4), (x2, 0.5), (x3, 0.2), (x4, 0.4), (x5, 0.8) }

B = { (x1, 1.0), (x2, 0.3), (x3, 0.5), (x4, 0.7), (x5, 0.1) }
Probabilistic reasoning in Artificial intelligence
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.

So to represent uncertain knowledge, where we are not sure about the predicates, we
need uncertain reasoning or probabilistic reasoning.

Causes of uncertainty:
Following are some leading causes of uncertainty to occur in the real world.

Information occurred from unreliable sources.


Experimental Errors
Equipment fault
Temperature variation
Climate change.
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.

We use probability in probabilistic reasoning because it provides a way to handle the


uncertainty that is the result of someone's laziness and ignorance.

In the real world, there are lots of scenarios, where the certainty of something is not
confirmed, such as "It will rain today," "behavior of someone for some situations," "A
match between two teams or two players." These are probable sentences for which we
can assume that it will happen but not sure about it, so here we use probabilistic
reasoning.

Need of probabilistic reasoning in AI:

When there are unpredictable outcomes.


When specifications or possibilities of predicates becomes too large to handle.
When an unknown error occurs during an experiment.
In probabilistic reasoning, there are two ways to solve problems with uncertain
knowledge:
Bayes' rule
Bayesian Statistics
Note: We will learn the above two rules in later chapters.
As probabilistic reasoning uses probability and related terms, so before understanding
probabilistic reasoning, let's understand some common terms:

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.

0 ≤ P(A) ≤ 1, where P(A) is the probability of an event A.


P(A) = 0, indicates total uncertainty in an event A.
P(A) =1, indicates total certainty in an event A.
We can find the probability of an uncertain event by using the below formula.

Probabilistic reasoning in Artificial intelligence


P(¬A) = probability of a not happening event.
P(¬A) + P(A) = 1.
Event: Each possible outcome of a variable is called an event.

Sample space: The collection of all possible events is called sample space.

Random variables: Random variables are used to represent the events and objects in the
real world.

Prior probability: The prior probability of an event is probability computed before


observing new information.

Posterior Probability: The probability that is calculated after all evidence or information
has taken into account. It is a combination of prior probability and new information.

Conditional probability:
Conditional probability is a probability of occurring an event when another event has
already happened.

Let's suppose, we want to calculate the event A when event B has already occurred,
"the probability of A under the conditions of B", it can be written as:

Probabilistic reasoning in Artificial intelligence


Where P(A⋀B)= Joint probability of a and B

P(B)= Marginal probability of B.

If the probability of A is given and we need to find the probability of B, then it will be
given as:

Probabilistic reasoning in Artificial intelligence


It can be explained by using the below Venn diagram, where B is occurred event, so
sample space will be reduced to set B, and now we can only calculate event A when
event B is already occurred by dividing the probability of P(A⋀B) by P( B ).

Probabilistic reasoning in Artificial intelligence


Example:

In a class, there are 70% of the students who like English and 40% of the students who
likes English and mathematics, and then what is the percent of students those who like
English also like mathematics?

Solution:

Let, A is an event that a student likes Mathematics

B is an event that a student likes English.

Probabilistic reasoning in Artificial intelligence


Hence, 57% are the students who like English also like Mathematics.

Bayes' theorem in Artificial intelligence


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.

In probability theory, it relates the conditional probability and marginal probabilities of


two random events.

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.
It is a way to calculate the value of P(B|A) with the knowledge of P(A|B).

Bayes' theorem in Artificial intelligence


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.

In probability theory, it relates the conditional probability and marginal probabilities of


two random events.

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.

It is a way to calculate the value of P(B|A) with the knowledge of P(A|B).


Bayes' theorem allows updating the probability prediction of an event by observing new
information of the real world.

Example: If cancer corresponds to one's age then by using Bayes' theorem, we can
determine the probability of cancer more accurately with the help of age.

Bayes' theorem can be derived using product rule and conditional probability of event A
with known event B:

As from product rule we can write:

P(A ⋀ B)= P(A|B) P(B) or


Similarly, the probability of event B with known event A:

P(A ⋀ B)= P(B|A) P(A)


Equating right hand side of both the equations, we will get:

Bayes theorem in Artificial intelligence


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(A|B) is known as posterior, which we need to calculate, and it will be read as
Probability of hypothesis A when we have occurred an evidence B.

P(B|A) is called the likelihood, in which we consider that hypothesis is true, then we
calculate the probability of evidence.

P(A) is called the prior probability, probability of hypothesis before considering the
evidence

P(B) is called marginal probability, pure probability of an evidence.

In the equation (a), in general, we can write P (B) = P(A)*P(B|Ai), hence the Bayes' rule
can be written as:

Bayes theorem in Artificial intelligence


Where A1, A2, A3,........, An is a set of mutually exclusive and exhaustive events.

Applying Bayes' rule:


Bayes' rule allows us to compute the single term P(B|A) in terms of P(A|B), P(B), and
P(A). This is very useful in cases where we have a good probability of these three terms
and want to determine the fourth one. Suppose we want to perceive the effect of some
unknown cause, and want to compute that cause, then the Bayes' rule becomes:

Bayes theorem in Artificial intelligence


Example-1:

Question: what is the probability that a patient has diseases meningitis with a stiff neck?

Given Data:

A doctor is aware that disease meningitis causes a patient to have a stiff neck, and it
occurs 80% of the time. He is also aware of some more facts, which are given as follows:

The Known probability that a patient has meningitis disease is 1/30,000.


The Known probability that a patient has a stiff neck is 2%.
Let a be the proposition that patient has stiff neck and b be the proposition that patient
has meningitis. , so we can calculate the following as:

P(a|b) = 0.8
P(b) = 1/30000

P(a)= .02

Bayes theorem in Artificial intelligence


Hence, we can assume that 1 patient out of 750 patients has meningitis disease with a
stiff neck.

Example-2:

Question: From a standard deck of playing cards, a single card is drawn. The probability
that the card is king is 4/52, then calculate posterior probability P(King|Face), which
means the drawn face card is a king card.

Solution:

Bayes theorem in Artificial intelligence


P(king): probability that the card is King= 4/52= 1/13

P(face): probability that a card is a face card= 3/13

P(Face|King): probability of face card when we assume it is a king = 1

Putting all values in equation (i) we will get:

Bayes theorem in Artificial intelligence


Application of Bayes' theorem in Artificial intelligence:
Following are some applications of Bayes' theorem:

It is used to calculate the next step of the robot when the already executed step is given.
Bayes' theorem is helpful in weather forecasting.
Hidden Markov models

A stochastic process is a collection of random variables that are indexed by some mathematical
sets. That is, each random variable of the stochastic process is uniquely associated with an
element in the set. The set that is used to index the random variables is called the index set and
the set of random variables forms the state space. A stochastic process can be classified in many
ways based on state space, index set, etc.

When the stochastic process is interpreted as time, if the process has a finite number of elements
such as integers, numbers, and natural numbers then it is Discrete Time.

Stochastic Model
It is a discrete-time process indexed at time 1,2,3,…that takes values called states which are
observed.

For an example if the states (S) ={hot , cold }

State series over time => z∈ S_T

Weather for 4 days can be a sequence => {z1=hot, z2 =cold, z3 =cold, z4 =hot}

Markov and Hidden Markov models are engineered to handle data which can be represented as
‘sequence’ of observations over time. Hidden Markov models are probabilistic frameworks
where the observed data are modeled as a series of outputs generated by one of several (hidden)
internal states.

Markov Assumptions
Markov models are developed based on mainly two assumptions.

Limited Horizon assumption: Probability of being in a state at a time t depend only on the state at
the time (t-1).

Eq.1. Limited Horizon Assumption


That means state at time t represents enough summary of the past reasonably to predict the
future. This assumption is an Order-1 Markov process. An order-k Markov process assumes
conditional independence of state z_t from the states that are k + 1-time steps before it.

2. Stationary Process Assumption: Conditional (probability) distribution over the next state,
given the current state, doesn't change over time.

Eq.2. Stationary Process Assumption


That means states keep on changing over time but the underlying process is stationary.
Notation Convention
There is an initial state and an initial observation z_0 = s_0
s_0 — initial probability distribution over states at time 0.
Initial state probability — (π)
at t=1, probability of seeing first real state z_1 is p(z_1/z_0)
Since z0 = s0 ,

You might also like