CS621: Artificial Intelligence
Pushpak Bhattacharyya
CSE Dept.,
IIT Bombay
Lecture 38: Fuzzy Logic
Uncertainty Studies
Uncertainty Study
Qualitative
Reasoning
Probability Based Information Theory Fuzzy Logic Based
based
Probabilistic Markov
Entropy
Reasoning Processes
Centric
& Graphical
Algos
Models
Bayesian Belief Network
Outlook Temp Humidit Windy Decision
(0) (T) y (W) to play
(H) (D)
Sunny High High F N
Sunny High High T N
Cloudy High High F Y
Rain Med High F Y
Rain Cold Low N Y
Rain Cold Low T N
Cloudy Cold Low T Y
To-play-or-not-to-play-tennis data vs. Climatic-Condition from
Ross Quinlan’s paper on ID3 (1986), C4.5 (1993)
Weather Temp Humidit Windy Decision
(0) (T) y (W) (D)
(H)
Sunny Med High F N
Sunny Cold Low F Y
Rain Med Low F Y
Sunny Med Low T Y
Cloudy Med High T Y
Cloudy High Low F Y
Rain High High T N
Outlook
Sunny Cloudy Rain
Humidity Yes Windy
High Low T F
No Yes No Yes
Rule Base
R1: If outlook is sunny and if humidity is high
then Decision is No.
R2: If outlook is sunny and if humidity is low
then Decision is Yes.
R3: If outlook is cloudy then Decision is Yes.
Fuzzy Logic
Fuzzy Logic tries to capture the
human ability of reasoning with
imprecise information
Models Human Reasoning
Works with imprecise statements such as:
In a process control situation, “If the
temperature is moderate and the pressure is
high, then turn the knob slightly right”
The rules have “Linguistic Variables”, typically
adjectives qualified by adverbs (adverbs are
hedges).
Underlying Theory: Theory of
Fuzzy Sets
Intimate connection between logic and set theory.
Given any set ‘S’ and an element ‘e’, there is a very
natural predicate, μs(e) called as the belongingness
predicate.
The predicate is such that,
μs(e) = 1, iff e ∈ S
= 0, otherwise
For example, S = {1, 2, 3, 4}, μs(1) = 1 and μs(5) =
0
A predicate P(x) also defines a set naturally.
S = {x | P(x) is true}
For example, even(x) defines S = {x | x is even}
Fuzzy Set Theory (contd.)
Fuzzy set theory starts by questioning the
fundamental assumptions of set theory viz., the
belongingness predicate, μ, value is 0 or 1.
Instead in Fuzzy theory it is assumed that,
μs(e) = [0, 1]
Fuzzy set theory is a generalization of classical set
theory also called Crisp Set Theory.
In real life belongingness is a fuzzy concept.
Example: Let, T = set of “tall” people
μT (Ram) = 1.0
μT (Shyam) = 0.2
Shyam belongs to T with degree 0.2.
Linguistic Variables
Fuzzy sets are named
by Linguistic Variables
(typically adjectives). μtall(h)
Underlying the LV is a
numerical quantity 1
E.g. For ‘tall’ (LV),
‘height’ is numerical
quantity.
0.4
Profile of a LV is the 4.5
plot shown in the figure
shown alongside. 0 1 2 3 4 5 6
height h
Example Profiles
μrich(w) μpoor(w)
wealth w wealth w
Example Profiles
μA (x) μA (x)
x x
Profile representing Profile representing
moderate (e.g. moderately rich) extreme
Concept of Hedge
Hedge is an intensifier
Example:
LV = tall, LV1 = very
tall, LV2 = somewhat somewhat tall tall
tall 1
‘very’ operation:
μtall(h) very tall
μvery tall(x) = μ2tall(x)
‘somewhat’ operation:
μsomewhat tall(x) =
0
√(μtall(x)) 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
A fuzzy set A is represented by a point in the n-dimensional
space as the point {μA(x1), μA(x2),……μA(xn)}
Degree of fuzziness
The centre of the hypercube is the “most
fuzzy” set. Fuzziness decreases as one nears
the corners
Measure of fuzziness
Called the entropy of a fuzzy set
Fuzzy set Farthest corner
E ( S ) d ( S , nearest ) / d ( S , farthest)
Entropy Nearest corner
(0,1) (1,1)
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
Let C = fuzzy set represented by the centre point
d(c,nearest) = |0.5-1.0| + |0.5 – 0.0|
=1
= d(C,farthest)
=> E(C) = 1
Definition
Cardinality of a fuzzy set
n
m( s ) s ( xi ) [generalization of cardinality of
i 1 classical sets]
Union, Intersection, complementation, subset hood
s s ( x) max[ s ( x), s ( x)]x U
1 2 1 2
s s ( x) min[ s ( x), s ( x)]x U
1 2 1 2
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
How to define subset hood?
Meaning of fuzzy subset
Suppose, following classical set theory we say
A B
if
A ( x) B ( x)x
Consider the n-hyperspace representation of A and B
(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
Measured in terms of “fit violation”, i.e. violating the
condition A ( x) B ( x)
Degree of subset hood = 1- degree of superset hood
= x
max( 0, A ( x) B ( x))
1
m( A)
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
A = hepatitis
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(P Q ) = min[1,1 -t(P)+t(Q)]
Lukasiewitz definition of implication
t ( P Q) min( t ( P), t (Q))
Eg: If pressure is high then Volume is low
t (high ( pressure ) low(volume))
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’
Controlling factors for appropriate current
.
Angle θ, Angular velocity θ
Some intuitive rules
.
If θ is +ve small and θ is –ve small
then current is zero
.
If θ is +ve small and θ is +ve small
then current is –ve medium
Control Matrix
.θ
-ve -ve +ve +ve
med Zero
θ small small med
-ve
med
-ve +ve +ve Region of
small Zero
med small interest
Zero +ve -ve
Zero
small small
+ve Zero -ve -ve
small small med
+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
.
1. Read actual numerical values of θ and θ
2. Get the corresponding μ values μZero, μ(+ve small),
μ(-ve small). This is called FUZZIFICATION
3. For different rules, get the fuzzy I-values from
the R.H.S of the rules.
4. “Collate” by some method and get ONE current
value. This is called DEFUZZIFICATION
5. Result is one numerical value of ‘i’.