Fuzzy Logic
Fuzzy Logic
COMPILED BY :
ER. RAVI PRAKASH SHAHI
[email protected]
Uncertainty Studies
Uncertainty Study
Qualitative
Reasoning
Probability Based Information Theory Fuzzy Logic Based
based
Probabilistic Markov
Entropy
Reasoning Processes
Centric
& Graphical
Algos
Models
High Low T F
No Yes No Yes
Rule Base
μrich(w) μpoor(w)
wealth w wealth w
Example Profiles
μA (x) μA (x)
x x
0
h
Representation of Fuzzy sets
Let U = {x1,x2,…..,xn}
|U| = n
The various sets composed of elements from U are presented as
points on and inside the n-dimensional hypercube. The crisp
sets are the corners of the hypercube. μA(x1)=0.3
μA(x2)=0.4
(0,1) (1,1)
x2 (x1,x2)
U={x1,x2}
x2 A(0.3,0.4)
(0,0) (1,0)
x1 x1
Φ
E ( S ) d ( S , nearest ) / d ( S , farthest )
x2
A (0.5,0.5)
d(A, nearest)
(0,0) (1,0)
x1
d(A, farthest)
Definition
Distance between two fuzzy sets
n
d ( S1 , S 2 ) | s1 ( xi ) s2 ( xi ) |
i 1
L1 - norm
s ( x) 1 s ( x)
c
Note on definition by extension and intension
S1 = {xi|xi mod 2 = 0 } – Intension
S2 = {0,2,4,6,8,10,………..} – extension
if
A ( x) B ( x)x
(0,1) (1,1)
A
x2 . B1 Region where A ( x ) B ( x )
.B2
.B3
(0,0) (1,0)
x1
This effectively means
B P ( A) CRISPLY
P(A) = Power set of A
Eg: Suppose
A = {0,1,0,1,0,1,…………….,0,1} – 104 elements
B = {0,0,0,1,0,1,……………….,0,1} – 104 elements
Isn’t B A with a degree? (only differs in the 2nd element)
Fuzzy definition of subset
m(A) = cardinality of A
=
x
A ( x)
We can show that E ( A) S ( A Ac , A Ac )
Exercise 1:
Show the relationship between entropy and subset hood
Exercise 2:
Prove that
S ( B, A) m( A B ) / m( A)
Subset hood of B in A
Fuzzy sets to fuzzy logic
Forms the foundation of fuzzy rule based system or fuzzy expert system
Expert System
Rules are of the form
If
C1 C2 ...........Cn
then
Ai
Where Cis are conditions
Eg: C1=Colour of the eye yellow
C2= has fever
C3=high bilurubin
In fuzzy logic we have fuzzy predicates
Classical logic
P(x1,x2,x3…..xn) = 0/1
Fuzzy Logic
P(x1,x2,x3…..xn) = [0,1]
Fuzzy OR
P ( x) Q( y ) max( P ( x), Q( y ))
Fuzzy AND
P ( x) Q( y ) min( P ( x), Q( y ))
Fuzzy NOT
~ P( x) 1 P( x)
Fuzzy Implication
• Many theories have been advanced and many expressions exist
• The most used is Lukasiewitz formula
• t(P) = truth value of a proposition/predicate. In fuzzy logic t(P) = [0,1]
• t( ) = min[1,1 -t(P)+t(Q)]
PQ
Lukasiewitz definition of
implication
t ( P Q) min(t ( P ), t (Q))
High
Pressure
Pressure
Fuzzy Inferencing
Fuzzy Inferencing: illustration through inverted
pendulum control problem
Core
The Lukasiewitz rule
t( P Q ) = min[1,1 + t(P) – t(Q)]
An example
Controlling an inverted pendulum
.
θ d / dt = angular velocity
Motor i=current
The goal: To keep the pendulum in vertical position (θ=0)
in dynamic equilibrium. Whenever the pendulum departs
from vertical, a torque is produced by sending a current ‘i’
+ve
med
Each cell is a rule of the form
.
If θ is <> and θ is <>
then i is <>
4 “Centre rules”
.
1. if θ = = Zero and θ = = Zero then i = Zero
.
2. if θ is +ve small and θ = = Zero then i is –ve small
.
3. if θ is –ve small and θ = = Zero then i is +ve small
.
4. if θ = = Zero and θ is +ve small then i is –ve small
.
5. if θ = = Zero and θ is –ve small then i is +ve small
Linguistic variables
1. Zero
2. +ve small
3. -ve small
Profiles
1
-ve small +ve small
-ε3 -ε2 ε2 ε3
-ε +ε .
Quantity (θ, θ , i)
Inference procedure
• The fuzzy logic works on the levels of possibilities of input to achieve the
definite output.
FL IMPLEMENTATION
EXAMPLE 1
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%.
What is the probability that a patient has diseases meningitis with a stiff neck?
Let A be the proposition that patient has stiff neck and B be the proposition
that patient has meningitis. P(A|B) = 0.8, P(B) = 1/30000, P(A)= 0.02
Hence, we can assume that 1 patient out of 750 patients has meningitis disease
with a stiff neck.
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%.
What is the probability that a patient has disease
meningitis with a stiff neck?
SOLUTION:
Let A be the proposition that patient has stiff neck and
B be the proposition that patient has meningitis.
P(A|B) = 0.8, P(B) = 1/30000, P(A)= 0.02
P(B | A) = ?
1.333333/1000 = 4/3 divide by 1000 = 4/3000
=1/750
Hence, we can assume that 1 patient out of 750
patients has meningitis disease with a stiff neck.
Note: The Bayesian network graph does not contain any cyclic
graph. Hence, it is known as a directed acyclic graph or DAG.
Bayesian Network graph (2)
• The Bayesian network has mainly two components – a) Causal
component b) Actual numbers.
• Each node in Bayesian network has conditional prob distribution P(Xi |Parent(Xi) ),
which determines the effect of the parent on that node.
• Bayesian network is based on Joint probability distribution and
conditional probability.
• JOINT PROBABILITY DISTRIBUTION
• If we have variables x1, x2, x3,....., xn, then the probabilities of a different
combination of x1, x2, x3, ... xn, are known as Joint probability distribution.
• P[x1, x2, x3,....., xn], it can be written as the following way in terms of the joint
probability distribution.
= P[x1| x2, x3,....., xn]. P[x2, x3,....., xn]
= P[x1| x2, x3,....., xn] . P[x2|x3,....., xn]....P[xn-1|xn] . P[xn].
Creating a Directed Acyclic Graph(DAG)
• Harry installed a new burglar alarm at his home to detect burglary. The
alarm reliably responds at detecting a burglary but also responds for minor
earthquakes. Harry has two neighbors - David and Sophia, who have taken
a responsibility to inform Harry at work when they hear the alarm.
• David always calls Harry when he hears the alarm, but sometimes he gets
confused with the phone ringing and calls at that time too.
• On the other hand, Sophia likes to listen to high music, so sometimes she
misses to hear the alarm. Here we would like to compute the probability of
Burglary Alarm.
• We will assume we are trying to maximize a function. That is, we are trying to
find a point in the search space that is better than all the others. And by "better"
we mean that the evaluation is higher. We might also say that the solution is of
better quality than all the others.
• The idea behind hill climbing is as follows:
• Pick a random point in the search space.
• Consider all the neighbors of the current state.
• Choose the neighbor with the best quality and move to that state
• Repeat 2 thru 4 until all the neighboring states are of lower quality
• Return the current state as the solution state.
How do Expert Systems Deal with
Uncertainty?
Uncertainty?
Humans & Reasoning !!!
• Verifications or Adaptation.
• New deductions.
• Prior Knowledge.
• Imprecise representation.
• Data derived from defaults/assumptions.
• Inconsistency between knowledge from different
experts.
• “Best Guesses”.
• Knowledge Representation
• Restricted model of the real system.
• Limited expressiveness of the representation
mechanism.
• Rules or Inference Process
• Conflict Resolution
• Subsumption
• Derivation of the result may take very long.
• Intelligence in Reasoning
• Adaptability.
• Capability of adding and retracting beliefs as new
information is available.
• This requires non-monotonic reasoning.
• In a non-monotonic system:
• We make assumptions about unknown facts.
• The addition of new facts can reduce the set of logical
conclusions.
• S is a conclusion of D, but is not necessarily a
conclusion of D + {new fact}.
• Humans use non-monotonic reasoning constantly!
•b =
• The system should ignore a better-than-even probability and
refuse to bet.
Bel ( ) 0
Bel () 1
Bel ( A B ) Bel ( A) Bel ( B ) Bel ( A B )
Bel ( A) m( B )
B A
Pl ( A) m( B )
B A
pl ( A) Bel ( A)
m ( A)m ( B) 1 2
( m m )(C ) A B C
1 m ( A)m ( B )
1 2
1 2
A B
Advantages
• Uncertainty and ignorance can be expressed.
• Dempster’s rule can be used to combine evidences.
Disadvantages
• Computational complexity of applying Dempster’s rule is
high.
• Uncertainty is omnipresent.
• We can use symbolic and statistical methods like Default
Reasoning and Dempster – Shafer theory to handle
uncertainty to some extent.
• Default Reasoning guarantees a conclusion for the given
knowledge base and desired fact. Although for handling
exceptions they have to be explicitly quantified.
• Dempster – Shafer theory combines evidences from
different sources to draw conclusion.