Fuzzy
Logic
Introduction
To Fuzzy Logic
Fuzzy
Membership Functions
A Simple Fuzzy Control System
Why
Fuzzy Logic?
Fuzzy logic is an interesting subject to contemplate.
-
The name implies that
you have to be a bit fuzzy headed to use fuzzy logic!
-
One main claim to fame
for fuzzy logic is that it is useful in designing control systems - in
spite of the fact that design techniques for control systems abound.
-
For any number of reasons,
fuzzy logic and fuzzy control system design methods have become a controversial
topic.
Why
Fuzzy Logic? - What the Experts Have to Say!
Fuzzy theory is wrong, wrong, and pernicious. What we need is more
logical thinking, not less. The danger of fuzzy logic is that it
will encourage the sort of imprecise thinking that has brought us so much
trouble. Fuzzy logic is the cocaine of science.
Professor
William Kahan
University of California
at Berkeley
"Fuzzification"
is a kind of scientific permissiveness. It tends to result in socially
appealing slogans unaccompanied by the discipline of hard scientific work
and patient observation.
Professor
Rudolf Kalman
University of Florida
at Gainesville
As complexity increases, precise statements
lose meaning and meaningful statements lose precision.
Professor
Lofti Zadeh
University of California
at Berkeley
quoted in McNeill
& Freiberger, p 43
So far as the laws of mathematics refer to reality,
they are not certain. And so far as they are certain, they do not
refer to reality.
Albert
Einstein
in Geometry &
Experience
Where
are the Fuzzy Systems? - What are They Doing Now?
-
Shifting gears in automatic
transmissions in cars
-
Focussing your camera
and camcorder
-
Running the cruise controls
on many cars
-
Running subways in Japan
-
Controlling dishwashers
and washing machines
-
and many, many more!
Fuzzy
Logic - Background- Your Goals
Goals of this lesson are:
Given
a system to be controlled,
Design a simple fuzzy controller using:
-
Membership functions for
the controlled variable,
-
A Simple Rule Base,
-
The Centroid Method for
Computation (Defuzzification) of the Control Effort
Introduction/Background
Study of Fuzzy logic is a study of a kind of logic. We are all familiar
with some of the principles of logic. Fuzzy logic builds on traditional
logic and extends traditional logic so that fuzzy logic can solve some
long standing problems in traditional logic.
Like many other things, it all started with the ancient Greeks, who first
formalized logic. Aristotle may not have been the first to assert
the one statement at the foundations of traditional logic, but he certainly
is the earliest on record to have done so. In one form or another,
Aristotle is credited with claiming:
A thing either is or
it is not.
The essence of the claim is that there is no other possibility, and in
particular, there is nothing between the two possibilities, and it has
come to be known as the law of the excluded middle. Let's look at
some examples.
Here are some examples of the law of the excluded middle.
-
A statement is either
true or it is not. In other words a statement is either TRUE
or FALSE.
-
A thing is either living
or dead.
-
A being is either intelligent
or not.
Let's
examine those examples of the law of the excluded middle.
-
A statement is either
true or it is not. In other words a statement is either TRUE or FALSE.
That seems pretty much the case.
-
A thing is either living
or dead. Now we have viruses that lie somewhere between the world
of inanimate molecules and living things.
-
A being is either intelligent
or not. But there are serious problems with chimpanzees that can
communicate with sign language.
And that leaves us with only the first statement
that we can be comfortable with.
Now consider this rather horrible little statement. If all statements
are either TRUE or FALSE, which is the case for this statement?
Think
carefully about this statement. Is it TRUE or is it FALSE?
Consider this then.
-
If the statement above
is TRUE, then
it must be FALSE
because that's what the statement says.
-
If the statement above
is FALSE, then
it must be TRUE.
Clearly
we have a problem here, and it is not trivial. This is a statement
that cannot be either TRUE or FALSE. But what else can it be?
Fuzzy logic and fuzzy set theory eliminate paradoxes like the statement
above by
assigning a continuum of truth values to
statements.
-
Instead of assuming a
statement must be true or false fuzzy logic permits degrees of truth.
-
For example, consider
the statement "Pat is tall". Suppose Pat is right around six feet
tall. Suppose, also, that we take tall to mean six feet or taller.
-
If Pat is .0001 inch under
six feet, then Pat is not tall.
-
In other words, the statement
"Pat is tall" would not be true.
-
If we were to increase
Pat's height by .0002 inches, then we would consider Pat tall, and the
statement "Pat is tall" would be true.
-
You would be right if
you thought that was a pretty fine distinction to make.
-
If you didn't think it
was a pretty fine line to draw consider what happens if Pat is above six
feet in the morning (After sleeping anyone is a little taller.) and just
under six feet in the evening. (After standing a day, anyone is a
little shorter.)
-
Do you think that Pat
is tall in the morning and not tall in the evening?
There's
an interesting situation here.
-
The problem doesn't lie
in the precision of the height measurement.
-
Actually, the more precisely
we know the height, the more difficult it is for us to accept the sharp,
arbitrary classification.
-
It's probably that our
concept of "tall" is inherently fuzzy.
In
life we sometimes must accept shades of truth, or grades of truth.
-
In formal logic and in
electronics we deal with things that have only two truth values, zero (0
or FALSE) and one (1 or TRUE).
-
When we design logic circuits
we use zeroes and ones for FALSE and TRUE. Let's keep the idea of
zero for FALSE and one for TRUE.
-
However, let's consider
the possibility of partial truth. If Pat is six feet tall, then the
statement "Pat is tall" might have a truth value of .9.
-
Another way of stating
this might be to say "Pat is a member of the set of tall people with a
membership grade of 0.9."
The
concept of grades of truth or grades of membership in sets is something
that, at this writing, does not seem to come naturally to many even though
it is something that many of us actually use in making decisions in our
life.
-
We choose a place to live
or a career to follow not because of yes or no factors.
-
Rather, we tend to think
in terms of the truth value of statements like "This place is a good place
to live." or "This career is one for which I am well suited".
-
We use fuzzy truth measures
in our lives, often because we have no choice.
-
However, engineers are
now choosing to incorporate fuzzy logic rules in control of trains, washing
machines and cameras.
If
the underlying reasoning seems a little obscure, then it is time to begin
to look at how ideas about fuzzy logic get to be incorporated into products
that work better. That's a pretty good distance to go, so let's get
started.
-
We need to formalize the
intuitive ideas about partial truth and partial membership that we uncovered
earlier.
Fuzzy
Membership Functions
An appealing way to represent some ideas about truth of statements and
membership functions is to draw a graph of a membership function.
-
Shown below is a graph
of a membership function for a traditional logic case where the graph is
a graph of the truth value of the statement:
-
X is Tall, assuming
-
Tall means more than 6
feet.
Next is a similar graph. It represents
a membership function for a fuzzy case.
-
Shown below is a graph
of a membership function for a fuzzy logic case where the graph is a graph
of the truth value of the statement:
-
X is Tall, assuming
-
Someone more than 6 feet
is tall.
In this fuzzy membership function you can give
varying interpretations to what it means. Here are some examples.
-
For a person exactly six
(6) feet tall, the value of the membership function is 0.5. That
means:
-
That person has a membership
value of 0.5 in the set of tall people.
-
In the usual case, that
isn't possible. You're either in (value of membership = 1) or you
are out (value of membership = 0).
-
The truth of the statement
"This person is tall"
is 0.5.
-
In the usual case, the
statement is either TRUE (value of the truth of the statement = 1) or it
is FALSE (value of the truth of the statement = 0).
This plot lets you compare the fuzzy membership
function with the crisp membership function.

Membership functions are a useful and integral part of fuzzy control systems.
However, in fuzzy control, it is often more convenient to use membership
functions that are not smooth - like the one above. Instead, it is
often the case that membership functions are composed of straight lines
- because the computation of the membership value is much simpler in that
case.
Here's a membership function of the type we want to examine. This
particular membership
function can be used to determine the truth
value of the statement:
The room is very hot.

Problem
P1
Assume that you measure the temperature of the root, and you get 80 degrees.
Determine the truth value of the statement:
"The room is very hot."
Here's another kind of membership function. This membership function
gives truth value for the statement:
The room is very cold.

Problem
P2
Assume that you measure the temperature of the root, and you get 60 degrees.
Determine the truth value of the statement:
"The room is very cold."
Finally, here's a triangular membership function that gives truth values
for the statement:
The temperature of
the room is OK.

Problem
P3
Assume that you measure the temperature of the root, and you get 60 degrees.
Determine the truth value of the statement:
"The temperature of
the room is OK."
Let's review all of these membership functions. Here they are together.
There's one interesting observation to make.

-
Two different membership
functions can both have non-zero truth values.
-
Assuming a measurement
of 80 degrees, the truth value of the statement
-
"The temperature of the
room is OK." is 0.67. (The black function)
-
While, the truth value
of the statement
-
"The temperature of the
room is very hot." is 0.33. (The red function)
Fuzzy
Control
Membership functions are a useful and integral part of fuzzy control systems.
Let us examine a control problem that we can solve with a fuzzy approach.
Let's take a look at a very simple fuzzy control system. We'll use
the membership functions from the last section.
-
Here are the membership
functions. They can be used to measure the truth value of the three
statements:
-
The room is very cold.
-
The temperature of the
room is OK.
-
The room is very hot.
-
And, for any temperature,
one or more of these functions can have a non-zero value.
Now,
to build/design a control system, we will need something else - something
we haven't encountered before - a rule base. A rule base is exactly
what the phrase implies. It is a set of rules for doing the control.
The rule base tells you how to change the control effort. Here's
an example rule base for a simple fuzzy control system.
-
If the room is very cold,
then the control effort is high.
-
If the temperature of the room is OK, then the
control effort is medium.
-
If the room is very hot,
then the control effort is low.
Different
colors are used here to show the correlation between the statements in
the rule base and the function. The rule
base consists of statements with two parts. Here's the
rule base again.
-
If the room is very
cold, then the control effort is high.
-
If the temperature of the room is OK,
then the control effort is medium.
-
If the room is very
hot, then the control effort is low.
The
statements in bold text are the antecedents,
and the regular text parts are the consequents
in the rule base. In any event, this rule base - when implemented
- will give us a fuzzy control system.
Now, let's examine the control algorithm for fuzzy control - proportional
and others. Here's the algorithm.
-
Measure the variable to
be controlled. Temperature would be an example of a variable to be
controlled.
-
From the measured value,
determine the truth value of all antecedents in the rule base.
-
NOTE: These truth
values are usually referred to as the firing
levels for the rules in the rule base.
-
From the firing levels
of the rules in the rule base, defuzzify to obtain the level(s) of control
effort.
We'll
take these different steps up separately. The first step in the algorithm
is:
-
Measure the variable to
be controlled. Temperature would be an example of a variable to be
controlled.
We'll
assume that you have a way of measuring temperature and getting the resultant
value into a computer program, say one written in C or Visual Basic.
The second step in the algorithm is:
-
From the measured value,
determine the truth value of all antecedents in the rule base.
-
NOTE: These truth
values are usually referred to as the firing
levels for the rules in the rule base.
Problem
P4
Assume that you measure the temperature of
the root, and you get 60 degrees. Determine the firing level of the
antecedent statment:
"If the room is
very cold, then the control effort is high."
Use this set of graphs
for your calculation.

Problem
P5
Assume that you measure the temperature of the root, and you get 60 degrees.
Determine the firing level of the antecedent statment:
"If the temperature
of the room is OK, then the control
effort is medium."
Use this set of graphs
for your calculation.

Problem
P6
Assume that you measure the temperature of the root, and you get 60 degrees.
Determine the firing level of the antecedent statment:
"If
the room is very hot, then the control
effort is low."
Use this set of graphs
for your calculation.

Click on the box to
enter your answer.
We need to go a little slower when it comes to computing the control effort.
-
We will assume that the
control effort is represented with membership functions also. In
particular, we need to have membership functions for the three different
antecedents:
-
Control effort is high.
-
Control effort is medium.
-
Control effort is low.
-
Here are some membership
functions we can use. These are not unique, but they will work for
us.
-
L is for "Control effort
is low" (red),
-
M is for "Control effort
is medium" (blue).
-
H is for "Control effor
is high" (black).
Now, we need an algorithm for defuzzification
(and isn't that a great word?).
-
The defuzzification algorithm
should use the firing levels calculated in the first steps of the
control algorithm.
-
One way - commonly used
- is to use the firing levels to weight the control effort membership functions.
-
In other words, we will
first multiply the appropriate control effort membership functions by the
firing levels.
-
Next, we add up the resulting
functions.
Here are the membership functions for the antecedents
again.

Go back to the problems above where you got
the firing levels for each of the membership functions. The firing
levels you should have found are as follows.
-
If the room is very cold
- 0.333
-
If the temperature of
the room is OK - 0.667
-
If the room is very hot
- 0
Then, we are going to multiply these firing
levels by L(C), M(C) and H(C) - the membership functions for the control
effort. If we multiply the control effort membership functions by
the firing levels, we will get the graphs shown below - which actually
contains three graphs!

-
0.333 (firing level for
very cold) * H(C) (high control effort)
-
That's the smaller triangular
function at the right in the plot.
-
0.667 (firing level for
OK) * M(C) (M(C) is for medium control effort.)
-
That's the larger blue
triangle in the middle of the plot.
-
0.00 (firing level for
very hot) * L(C) (L(C) is for low control effort.)
-
That's the black triangle
of ZERO height. It's not really visible.
Here is the sum of those three functions - shown
in orange.

We still have one unanswered question - and it is important.
-
How do we get from this
composite function to a value for the control effort?
-
The commonest way to get
a single number for the control effort is this:
-
Compute the center of
gravity (centroid) of the composite function.
Good
grief, now we have to remember how to compute a centroid! Well, here's
the definition of the centroid of a function.
Centroid = Moment of
Function/Area of Function
-
For the composite function,
the area is the integral of the function over the entire function.
-
For the composite function,
the moment of the function is the integral of the function multiplied by
the variable.
-
In practice, the integral
will only be taken over a finite interval since the function is non-zero
only on a finite interval.
Now,
if we can express the centroid as a function of the parameters of the membership
functions, we have a chance to get a simple expression. Let's work
on that.
-
The composite function
(shown in orange in the plot above) is a weighted sum of the individual
membership functions for the control effort (Low, Medium and High in our
example).
-
Call the membership functions
Cold(T)
(Cold),
OK(T)
(OK) and
Hot(T)
(Hot).
-
The weights are the firing
levels of the associated antecedent functions in the rule base.
-
Call the firing levels
aC,
aO,
and aH.
-
Now, we multiply the firing
levels my the control effort functions.
-
Call the control effort
functions L(C) (Low),
M(C)
(Medium) and H(C)
(High).
-
Here's the expression
for the composite function.
-
Composite function = aCH(C)
+ aOM(C)
+ aH.L(C)
-
Next, note that each of
the control effort membership functions is a triangle.
-
For each triangle, the
height is 1, and we will call the width, W.
-
Then the area of each
triangle is W/2.
-
Note, for our example
functions, the width is 100 (percent of max control effort).
-
Now, we can compute the
area of the composite function in terms of these areas.
Now,
the area of the composite function can be computed. Note that the
areas (integrals) of H(C), M(C) and L(C) all equal W/2, where W is the
total width of the triangle.
Next examine the moment of a triangle function. Here's the derivation
for the moment.
-
The integration should
be broken into two parts - two intervals - to simplify.
-
For C in the interval
from L (Left/Low point) to M (Mid point), Tri(C) can be written as:
-
For C in the interval
from M to R (Rightmost point),Tri(C) can be written as:
-
Tri(C) = 1 - (C - M)/(R
- M)
-
Now, integrate from L
to M:
-
The result is:
MomentLeft = (1/3)M2 - (1/6)LM - (1/6)L2
-
Similarly, integrate the
function over the right half of the interval:
-
The result is:
MomentRight = (-1/3)M2 + (1/6)MR +
(1/6)R2
-
Add the two to get the
moment:
-
Moment =
MomentLeft + MomentRight
-
Moment = (1/3)M2
- (1/6)LM - (1/6)L2 + (-1/3)M2 + (1/6)MR
+ (1/6)R2
-
Moment = (1/6)MR + (1/6)R2
- (1/6)LM - (1/6)L2
-
Moment = (1/6)[R(M + R)
- L(M + L)]
Example
E1
In the graph below, compute the moment of the Medium Control Effort Membership
function (shown in blue as M(C)). Note, for this function:

Putting the values for
L, M and R into the expression above, we have:
-
Moment = (1/6)[R(M + R)
- L(M + L)]
-
Moment = (1/6)[100(50
+ 100) - 0(50 + 0)]
-
Moment = (1/6)[15,000]
= 2500
Problem
P7
In the graph below, compute the moment of the High Control Effort Membership
function (shown in black as H(C)). Note, for this function:

Now,
let's compute the centroid of the medium function, M(C). In the example
above we found:
We can also compute the area as half of the
product of the height (1) and the width (from 0 to 100):
-
Area = (1/2)[100 - 0]
= 50
Then, we know that the centroid is given by:
-
Centroid = Moment/Area
-
Centroid = 2500/50 = 50
And, that should make sense to you.
Problem
P8
In the graph below, compute the centroid of the High Control Effort Membership
function (shown in black as H(C)). Note, for this function:

Now,
let's go back to the control computation we were looking at earlier.
We now have all the numerical results we need. Here is the composite
function discussed earlier. The control effort is the centroid of
the composite function.

Previously, we computed the firing levels
of the three membership functions for Very Cold, OK (Medium) and Very Hot.
Here are those firing levels.
-
0.333 (firing level for
very cold)
-
0.667 (firing level for
OK)
-
0.00 (firing level for
very hot)
From these firing levels, we constructed a composite
membership function for the Control Effort. That composite function
is shown in the graph above. It is constructed as follows.
-
0.333 (firing level for
very cold) * H(C) (high control effort)
-
That's the smaller triangular
function at the right in the plot.
-
0.667 (firing level for
OK) * M(C) (M(C) is for medium control effort.)
-
That's the larger blue
triangle in the middle of the plot.
-
0.00 (firing level for
very hot) * L(C) (L(C) is for low control effort.)
-
That's the black triangle
of ZERO height. It's not really visible.
The sum of these three functions (Firing level
x Control Effort Membership Function) is the orange function shown in the
figure. The "orange" function - the composite function is given by:
-
Composite function(C)
= 0.333*H(C) + 0.667*M(C)
+ 0.0*L(C)
The centroid for the composite function is the
control effort level that we will use in this situation. That centroid
is given by:
-
Centroid of Composite
function(C) =
-
0.333*Centroid of H(C)
+
-
0.667*Centroid of M(C)
+
-
0.0*Centroid of L(C)
Here is the function again.

The numerical values for the centroids are:
-
Centroids of Control Effort
Membership Functions:
-
Centroid of H(C) = 100
-
Centroid of M(C) = 50
-
Centroid of L(C) = 0
-
The computed control effort
is then:
-
Control Effort = 0.333x100
+ 0.667x50 + 0x0
-
Control Effort = 0.667
So, the control law (the computation for the
actual control effort) reduces to:
-
Determine the firing levels
for each of the membership functions in the antecedents.
-
This is usually referred
to as measuring the "firing levels".
-
Multiply the firing levels
by the corresponding Control Effort Membership Functions to obtain a composite
function.
-
The correspondence is
determined by the rule base.
-
Determine the centroid
of the composite function to determine the control effort to apply.
-
This last step is referred
to as "defuzzification".
Simple as this approach seems, it does often
work, and it is a reasonable way to implement a control system. It
has some pros and cons.
-
You can easily add more
rules to the rule base, and they can be compound rules:
-
Example: If A is
true and B is false, then do C.
-
You can't easily predict
performance.
Marks
of Acceptance of Fuzzy Logic
At this point, Fuzzy Logic, Fuzzy Set Theory and Fuzzy control are all
accepted and widely used. As illustrations:
-
Visit one of many fuzzy
web pages.
-
Note Zadeh's "Profile"
in IEEE Spectrum, June 1995, pp32-35 and Bart Kosko's "Profile" in IEEE
Spectrum, February 1996, pp58-62.
-
Read any copy of IEEE
Transactions on Fuzzy Systems.
-
Note that MatLab sells
two toolboxes
-
The Fuzzy Systems Toolbox
-
The Fuzzy Logic Toolbox.
-
Buy one of Bart Kosko's
books, especially "Fuzzy Thinking" to get yourself started.