Fuzzy Logic
Andrew Kusiak
Intelligent Systems Laboratory
2139 Seamans Center
The University of Iowa
Iowa City, IA 52242 1527
andrew-kusiak@uiowa.edu
@
http://www.icaen.uiowa.edu/~ankusiak
What is Fuzzy Logic?
Fuzzy logic is a tool for embedding
human knowledge
(experience, expertise, heuristics)
(Based on the material provided by Professor V. Kecman)
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Why Fuzzy Logic ?
Human knowledge is fuzzy: expressed
in fuzzy
fuzzy linguistic terms
terms, e.g.,
e g young,
young
old, large, cheap.
Temperature is expressed as cold,
warm or hot.
No quantitative meaning.
The University of Iowa
Intelligent Systems Laboratory
Intelligent Systems Laboratory
Fuzzy Logic
Fuzzy
Fuzzy logic may be viewed as a bridge
between the excessively wide gap between
the precision of classical crisp logic and
the imprecision of both the real world and
its human interpretation
Paraphrasing L. Zadeh
The University of Iowa
Intelligent Systems Laboratory
Fuzzy Logic
The World is Not Binary!
Gradual transitions and ambiguities at the boundaries
Fuzzy logic attempts to model the way of
reasoning
i off the
th human
h
brain.
b i
Bad, Night, Old, Ill
NO
False, Sad, Short
, ,1
Almost all human experience can be expressed in
the form of the IF - THEN rules.
H
Human reasoning
i is
i pervasively
i l approximate,
i t
non-quantitative, linguistic, and dispositional
(meaning, usually qualified).
Good, Day, Young, Healthy,
YES,
True, Happy, Tall, , 0
The University of Iowa
Intelligent Systems Laboratory
When and Why to Apply FL?
The University of Iowa
Intelligent Systems Laboratory
When and Why to Apply FL?
Human knowledge is available
Mathematical model is unknown or
impossible to obtain
At higher levels of hierarchical
control systems
Process substantially nonlinear
Lack of precise sensor information
The University of Iowa
Intelligent Systems Laboratory
In decision making processes
The University of Iowa
Intelligent Systems Laboratory
How to Transfer Human Knowledge
Into the Model ?
Knowledge should be structured
structured.
Possible shortcomings:
Fuzzy Sets vs Crisp Sets
Crisp Sets
Fuzzy Sets
Knowledge is subjective
Experts may bounce between extreme points
of view:
Have problems with structuring the knowledge,
knowledge or
Too aware in his/her expertise, or
Tend to hide knowledge, or ...
Venn Diagrams
Solution: Find a good expert.
The University of Iowa
Intelligent Systems Laboratory
Fuzzy Sets vs Crisp Sets
Crisp Sets
Intelligent Systems Laboratory
Modeling or Approximating a Function:
Curve or Surface Fitting
Fuzzy Sets
- membership degree, possibility distribution,
grade of belonging
The University of Iowa
The University of Iowa
Intelligent Systems Laboratory
Terms used in other disciplines:
regression (L or NL), estimation, identification, filtering
The University of Iowa
Intelligent Systems Laboratory
Modeling a Function
Modeling a Function
Standard mathematical approach of curve fitting
((more or less satisfactory
y fit))
Curve fitting by using fuzzy rules (patches)
Surface approximation for 2 inputs or
a hyper
hyper-surface
surface (3 or more inputs)
Small number of rules - Large patches or rough approximation
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Modeling a Function
Intelligent Systems Laboratory
Example 1
Consider modeling two different functions by
fuzzy rules
y
More rules - more smaller patches and better approximation
What is the origin of the patches and how do they work?
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Intelligent Systems Laboratory
Example 1
Example 1
Lesser number of rules decreases the
approximation accuracy. An increase in a number
of rules, increases the precision at the cost of a
computation time needed to process these rules.
This is the most classical soft computing dilemma
- A trade-off between the imprecision and
uncertainty on one hand and low solution cost,
tractability and robustness on the other.
other
IF x is low THEN y is high.
IF x is low THEN y is high.
IF x is medium THEN y is low.
IF x is medium THEN y is
medium.
IF x is large THEN y is low.
The appropriate rules for the two functions are:
IF x is large THEN y is high.
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Intelligent Systems Laboratory
Example 2
Example 1
These rules define three large rectangular patches
that cover the functions. They are shown in the
next slide together with two possible
approximators for each function.
Modeling two different functions by fuzzy rules
y
The two original functions (solid lines in both graphs) covered by
three patches produced by IF-THEN rules and modeled by two
possible approximators (dashed and dotted curves).
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Intelligent Systems Laboratory
Example 2
Example 2
Humans do not (or only rarely) think in terms of
nonlinear functions.
Humans do not draw these functions in their
mind.
We neither try to see them as geometrical
artifacts.
Even more,
more our expertise or understanding of
some functional dependencies is often not a
structured piece of knowledge at all.
We typically perform complex tasks without being
able to express how they are executed.
executed
In general, we do not process geometrical figures,
curves, surfaces or hypersurfaces while
performing tasks or expressing our knowledge.
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Intelligent Systems Laboratory
Car Example
Example 2
Th steps
The
t
in
i fuzzy
f
modeling
d li are always
l
the
th same.
Explain to your colleague in the form of IFTHEN rules how to ride a bike.
i) Define the variables of relevance, interest or importance:
In engineering we call them input and output variables
ii) Define the subsets intervals:
Small - medium, or negative - positive, or
Left - right (labels of dependent variables)
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Intelligent Systems Laboratory
Car Example
Car Example
iii) Choose the shapes and the positions of fuzzy
subsets, i.e.,
Membership functions, i.e., attributes
INPUTS: D = DISTANCE,
INPUTS
DISTANCE v = SPEED
OUTPUT: B = BRAKING FORCE
iv) Set the rule form, i.e., IF - THEN Rules
v) Perform computation and (if needed) tune (learn,
adjust, adapt) the positions and the shapes of both
the input and the output attributes of the model
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Car Example
Car Example
D
Intelligent Systems Laboratory
Velocity
Low
Braking Force
Medium High
Small Medium High
1
v
120 (km/h) 0
10
Analyze the rules for a given distance D and for
different velocity v, i.e., B = f(v)
The University of Iowa
Intelligent Systems Laboratory
100 (%)
IF the Velocity is Low, THEN the Braking Force is Small
IF the Velocity is Medium, THEN the Braking Force is Medium
IF the Velocity is High, THEN the Braking Force is High
,
The University of Iowa
Intelligent Systems Laboratory
Car Example
Car Example
Braking Force
100
Braking Force
100
High
High
The fuzzy
Th
f
patch
Medium
Low
Medium
The fuzzy
patches
Low
(%)
(%)
Velocity
Velocity
10
120
Small Medium High
The University of Iowa
10
120
Small Medium High
Intelligent Systems Laboratory
The University of Iowa
Car Example
Intelligent Systems Laboratory
The Fuzzy Patches Define the Function
Braking Force
The fuzzy patches
100
Braking Force
Low
(%)
Note the overlapping
fuzzy subsets smooth
approximation
of the function between the
Velocity and Braking Force
Velocity
Caar Examplee
High
Medium
The University of Iowa
Three possible
dependencies
p
between the Velocity
and Breaking force.
High
Medium
Low
0
100
Each of us drives
differently
(%)
Velocity
10
120
Small Medium High
10
120
Small Medium High
Intelligent Systems Laboratory
The University of Iowa
Intelligent Systems Laboratory
Example:
Room Temperature Control
FUNCTIONAL DEPENDENCE OF THE VARIABLES
SURFACE OF KNOWLEDGE
Fuzzy Control of the Distance Between Two Cars
Braking Force
Visualization of 2 INPUTS: D and v, and 1 OUTPUT B is possible.
For more inputs everything remains the same but visualization is not possible.
Cold Warm
90
Hot
80
Fan Speed
Room Temperature
Slow Medium Fast
1
70
60
50
40
0
30
20
100
10
200
80
Speed100
40
20
50
The University of Iowa
Room Temperature
The University of Iowa
Cold
Warm
100 (%)
If Room Temperature is Cold, then Fan Speed is Slow
The University of Iowa
Example:
Room Temperature Control
Slow Medium Fast
1
30 (oC)
Intelligent Systems Laboratory
Room Temperature
Fan Speed
Hot
10
100 (%)
Distance
Intelligent Systems Laboratory
Example:
Room Temperature Control
Cold Warm
30 (oC)
10
60
150
Intelligent Systems Laboratory
Fan Speed
Hot
Slow Medium Fast
1
10
30 (oC)
0
100 (%)
If Room Temperature is Cold, then Fan Speed is Slow
If Room Temperature is Warm, then Fan Speed is Medium
The University of Iowa
Intelligent Systems Laboratory
Example:
Room Temperature Control
Room Temperature
Cold
Warm
Fan Speed
Hot
Slow Medium Fast
Fan Speed
1
100
Example:
Room Temperature Control
Fast
The fuzzy
Th
f
patches
Medium
Slow
(%)
10
30 (oC)
0
100 (%)
If Room Temperature is Cold, then Fan Speed is Slow
Room
Temperature
If Room Temperature is Warm, then Fan Speed is Medium
10
If Room Temperature is Hot, then Fan Speed is Fast
The University of Iowa
Intelligent Systems Laboratory
Example:
Room Temperature Control
Fan Speed
The University of Iowa
30 (oC)
Intelligent Systems Laboratory
Example:
Room Temperature Control
Fan Speed
100
100
Cold Warm Hot
Fast
Fast
The fuzzy
patches
Medium
Slow
Slow
0
(%)
Room
Temperature
10
The University of Iowa
Cold Warm Hot
The fuzzy
patches
Medium
(%)
Note the overlapping
of fuzzy subsets smoothes
approximation
of the function between the
Fan Speed and Temperature
Room
Temperature
10
30 (oC)
Intelligent Systems Laboratory
The University of Iowa
Cold Warm Hot
30 (oC)
Intelligent Systems Laboratory
Example:
Example:
Room Temperature Control
There must be some overlapping of the input fuzzy subsets
(membership or characteristic functions) if we want to obtain
a smooth model
12
VL
O
U
T
P
U
T
12
If there was no
overlapping.
one would
obtain the
stepwise
p
function as
shown next
10
VS
0
0
VS
2
The University of Iowa
S
4
VL
10
INPUT
Warm
12
Intelligent Systems Laboratory
Hot
10
Slow Medium Fast
1
22
30 (oC)
O
U
T
P
U
T
VB
B
10
VS
VS
0
0
Output Computation: Fuzzification, Inference and
Defuzzifaction
Fan Speed
Room Temperature
Cold
Room Temperature Control
There must be some overlapping of the input fuzzy subsets
(membership or characteristic functions) if we want to obtain
a smooth model
100 (%)
R1: If Room Temperature is Cold, Then Fan Speed is Slow
The University of Iowa
M
6
INPUT
B
8
VB
10
12
Intelligent Systems Laboratory
Example:
Room Temperature Control
After the fuzzy modeling is done there is an
operational phase:
Compute the fan speed when the room
temperature = 22 oC
NOTE
NOTE: 22 oC belongs
b l
to
t the
th subsets
b t Warm
W
andd
Hot
R2: If Room Temperature is Warm, Then Fan Speed is Medium
R3: If Room Temperature is Hot,Then Fan Speed is Fast
The University of Iowa
Intelligent Systems Laboratory
The University of Iowa
Intelligent Systems Laboratory
Fuzzification and Inference
Room Temperature
Cold
Warm
Fuzzification and Inference
Fan Speed
Hot
Room Temperature
Slow Medium Fast
Cold
Warm
Fan Speed
Hot
Slow Medium Fast
0.6
0.6
0.3
10
30 (oC))
22
100 ((%))
10
22
30 (oC))
100 ((%))
If Room Temperature is Cold, Then Fan Speed is Slow
If Room Temperature is Cold, then Fan Speed is Slow
If Room Temperature is Warm, Then Fan Speed is Medium
If Room Temperature is Warm, then Fan Speed is Medium
If Room Temperature is Hot, Then Fan Speed is Fast
The University of Iowa
If Room Temperature is Hot, then Fan Speed is Fast
Intelligent Systems Laboratory
Cold
Warm
Defuzzification
Fan Speed
Hot
Intelligent Systems Laboratory
Fan Speed
Fuzzification and Inference
Room Temperature
The University of Iowa
Slow Medium Fast
1
0.6
0
0.3
10
22
30 (oC)
100 (%)
WHAT IS THE OUTPUT VALUE?
If Room Temperature is Cold then Fan Speed is Slow
If Room Temperature is Warm then Fan Speed is Medium
If Room Temperature is Hot then Fan Speed is Fast
The University of Iowa
Intelligent Systems Laboratory
60
100
(%)
The result of the fuzzy inference is a fuzzy subset composed of
the slices of fan speed: Medium (blue) and Fast (red)
How to find a crisp (useful in the real world application) value?
One of several methods used to obtain a crisp output value is
the center of area formula
The University of Iowa
Intelligent Systems Laboratory
Example: Vehicle Turning
Problem
Configuration of the Vehicle Turning Problem
Finish
= Car angle
(INPUT 1)
d = Distance from center line
(INPUT 2)
max = /4: Upper bound of steering angle (OUTPUT)
Generic fuzzy logic controller
v = 10.0 m/s
- Developed in Matlab
- User friendly
- Multiple inputs
Many other commercial applications are possible
The University of Iowa
Intelligent Systems Laboratory
Start
The University of Iowa
Intelligent Systems Laboratory
Conclusions
Conclusions
Finding good (dependable) expert
Fuzzy logic can be implemented wherever there is
structured
t t d human
h
knowledge,
k
l d expertise,
ti heuristics,
h i ti
experience.
Fuzzy logic is not needed whenever there is an
analytical closed-form model that, using a
reasonable
bl number
b off equations,
i
can solve
l a
problem in a reasonable time, at the reasonable
costs and with higher accuracy.
The University of Iowa
Intelligent Systems Laboratory
Right choice of the variables
Increasing the number of inputs, as well as the number of
fuzzy subsets per input variable, the number of rules
increases exponentially (curse of dimensionality)
Good news is that there are plenty of real life problems and
situations that can be solved with small number of rules
only
The University of Iowa
Intelligent Systems Laboratory