Sei sulla pagina 1di 7

Putting Fuzzy Logic to Work:

An Intro to Fuzzy Rules


By Will Dwinnell

Introduction about fuzzy logic is that definitions are 2. if (Input is Medium)


Fuzzy logic, a powerful and very useful allowed to be true in degrees, reflecting the then (Output is Medium)
technology, has yet to see its potential fully vague quality of many definitions used in 3. if (Input is Light)
exploited. This is ironic given that fuzzy heuristics, allowing rules to fire "partially" if then (Output is ReallyLight)
logic is relatively easy to understand they are only partially relevant.
(especially for non-technical people) and By giving precise mathematical
fills such a critical need in so many A Simple Example definitions to terms such as Dark, Light,
problems. This article presents a manager’s Consider the problem of enhancing the ReallyLight, and so forth, the above rules
level understanding of fuzzy logic, how it contrast of an image. An image with low- define a mathematical function that
contrast has many pixels with similar increases image contrast. These rules, in
works in practice and the type of
brightness. Without significant variation in fact appear exactly as listed in a small
applications for which it is best suited. Deep
brightness, low-contrast images have a fuzzy system built using MATLAB’s
technical issues and philosophical debates,
“washed-out” or hazy appearance. In a high- Fuzzy Logic Toolbox. Figure 1 shows
on the other hand, are not covered.
contrast image, there is a much larger (graphically) the definitions of the terms
Fuzzy Fundamentals variation in brightness, with many very Dark, Medium and Light, as used in this
bright and very dark pixels. Contrast fuzzy system. Notice that brightness
In this article, the focus is on the most
enhancement is the process of changing a varies from 0.0 (black) to 1.0 (white). As
common type of fuzzy rule-based system,
low-contrast image into a high-contrast figure 1 illustrates, the fuzzy definitions
one that accepts numeric inputs and
image and can be achieved by mapping the of words such as Light and Dark do not
outputs. The user supplies the numeric need to have hard cut-offs, but may fade
brightness values of the original image to a
inputs and receives numeric outputs, with from one to the other in between. In
new set of brightness values in the new
no knowledge of what is going on inside. image. Fuzzy logic can perform this other words, any given brightness level
The technician who implements the fuzzy transformation. Thinking in everyday terms, might be partially Light, partially
system has two basic tasks: how does one change the brightness of pixels Medium and partially Dark at the same
• encode human knowledge as fuzzy in a low-contrast image to increase the time.
rules (which resemble English) contrast? Light pixels in the input image When the brightness of an input
• create mathematical definitions for the should become lighter in the output image pixel is presented to this fuzzy logic
system components. and dark pixels should become darker (pixels system, it is “fuzzified”, which means that
in the middle should stay more or less the each of the terms defined for the input
Ordinarily, rules are implemented on same). We may encode these ideas as fuzzy brightness Dark, Medium and Light is
computers as an all-or-nothing affair: either rules: considered true to some degree. The
the condition (the rule's "if" part) triggers 1. if (Input is Dark) fuzzy degree of truth ranges from 0
the rule or it doesn't. What is different then (Output is ReallyDark) (absolutely false) to 1 (completely true)

PCAI 33 March/April 2002


Figure 1: Fuzzy Input Definitions
The height of each curve indicates the degree to which that concept is considered true. For instance, if the input, Pixel
Brightness, is 0.4 (a slightly dark gray), then “ Dark” (blue trace on the graph) and “ Medium” (green) are each rated at
roughly 0.4 true, while “ Light” (red) is considered to be approximately 0.13 true. The truth of these terms controls how
much each fuzzy rule contributes to the fuzzy system’s overall response.
and determines how strongly the rules ReallyLight are closer to 0.0 and 1.0, figures 3A (before enhancement) and 3B
will fire. Consider, for instance, a dark respectively, than Dark and Light on the (after enhancement) for a demonstration
pixel with a brightness of 0.1, which input scale. In this example, bell-shaped of our fuzzy contrast enhancer on a real
maps to approximately 0.95 truth for curves define the truth of the various image. Obviously, it is possible to adjust
“Dark”, and almost zero truth for terms, however, other shapes such as the exact definitions of the various terms
“Medium” and “Light”. Fuzzy rule 1, triangles and trapezoids are typical used in the fuzzy rules to suit whatever
above, (using “Dark” in its condition) alternatives. result is desired.
will fire approximately 0.95, while the Each time the fuzzy logic system Analysis
other rules (using “Medium” and “Light” executes, each input term (Light, Medium The demonstrated fuzzy system
in their conditions) will make almost no and Dark for pixel brightness) calculates effectively solves a real problem. Real images
contribution to the system output. as being true to some degree. The rules often suffer from poor contrast, leaving
A similar set of terms (ReallyDark, fire (to varying degrees), producing a visual features vague and indistinct. The
Medium and ReallyLight) is numerically collection of fuzzy outputs which are fuzzy rules are easy to audit, maintain or
defined for the output image’s brightness combined by the fuzzy logic software to modify and provide a self-documenting,
(see figure 2). Notice that to drive pixel produce the result- an ordinary number. easily understood format for the solution.
brightness to the light and dark extremes, The user of the fuzzy logic system does Fuzzy-models that are more complex may
the definitions of ReallyDark and not care how all this works internally. See include additional inputs, allowing more

PCAI 34 March/April 2002


Figure 2: Fuzzy Output Definitions
Each fuzzy rule may specify any of these fuzzy terms ( ReallyDark is the blue curve, Medium is green and ReallyLight is red)
as its output. The fuzzy logic software takes care of fusing these fuzzy terms to generate the system’s output. In our simple
fuzzy system, there are only 3 rules, and they directly connect Light input to ReallyLight output, Medium input to Medium
output and Dark input to ReallyDark output. Since ReallyLight is lighter than Light and ReallyDark is darker than Dark, pixel
brightness tends to move away from medium brightness toward the extremes.

conditions in each rule. Notice, too, that the into fuzzy rules. While there are algorithms (WokeUpThisMorning and NapLength)
fuzzy logic system is completely for deriving the fuzzy rules from data, here that predicts when the kids will become
deterministic: when given the same inputs we are only concerned with the more usual sleepy (BedTime). In contrast to the last
twice, its output will be exactly the same. method of building them manually. example, in which the fuzzy contrast
While a statistical regression or neural enhancer made a decision (that is
network could have solved this problem, An Example with Two Inputs “correct” only in terms of the policy we
they (in contrast to the fuzzy rule-based In my home, one daily challenge is created), this system makes a prediction
system) require an extensive set of examples putting the kids to bed. We have found (subject to some inaccuracies when
from which to learn the appropriate that putting children to bed when they compared to the actual experience).
mapping of pixel brightness from low- are ready to fall asleep helps. We have also The input, WokeUpThisMorning is
contrast to high-contrast. Fuzzy rules, on the found that when they are ready to fall the number of hours since midnight. In
other hand, mimic an existing base of asleep depends on (among other things) other words, if the child woke at 8:30am,
human knowledge. Construction of the when they woke up this morning (which WokeUpThisMorning is 8.5. The other
fuzzy rule base does not require an extensive indicates roughly how much sleep they input variable, NapLength, indicates the
database of “correct” mappings from input received the previous night) and how long length of the afternoon nap in hours. The
to output (although these would be helpful they napped during the afternoon. time to be predicted, BedTime, indicates
in validating its performance). Instead, it Consulting an expert (my wife), I built a hours after noon (8.75 would mean
requires some type of knowledge to translate fuzzy logic system using these two inputs 8:45pm). As in the previous example, we

PCAI 35 March/April 2002


Target Your Marketing
to Professionals that
Use your Products
Use a PC AI
Web
Banner Ad
Target your marketing to PC
AI readers and website
visitors.
PC AI readers are eager for the latest in
intelligent agents, data mining, knowledge
management, case based reasoning, fuzzy
logic, intelligent applications, genetic
algorithms, modeling and simulation
decision support, e-commerce,
and web technology.
Our readers are focused on using the
latest technology to improve
Figure 3A: A Low-Contrast Image their bottom line.
This image is typical of low-contrast images: pixel brightness does not vary
enough, giving a hazy, washed-out look.

Figure 3B: The Same Image After Contrast Enhancement


The Fuzzy Contrast Enhancer increases contrast by spreading out the brightness
of pixels in the image. Light pixels become lighter and dark pixels become
darker. Rough textures have been accentuated.

define three fuzzy terms along each and “Late”


variable. Note that three terms were used NapLength: “Short”, “Normal”
because it suited this problem. There is and “Long”
no reason that all variables must have the BedTime: “Early”, “Normal”
same number of concepts defined and and “Late”
some problems may have better solutions Now that there is more than one input,
with a different number of terms. First we we must decide how to combine the various
define the following terms: inputs to define the rules of the system. In
WokeUpThisMorning: “Early”, “Normal” this case, there are two inputs, having three

PCAI 36 March/April 2002


Figure 4: Bed Time Prediction
This figure illustrates the output of the Fuzzy Bed Time Predictor. Height of the colored surface indicates the predicted time,
in hours since noon (7.5 indicates 7:30pm, 8 means 8pm, and so forth). Likewise, the input WokeUpTime measures time in
hours since midnight (8 is 8am, 8.5 is 8:30am, and so on). NapLength is the length (in hours) of the child’s afternoon nap.
The color coding in this figure follows the height, with black indicating the earliest bed times, through red and orange, up
to yellow, which represents the latest bed times.

fuzzy terms each, yielding a maximum of and (NapLength is Short) in the fuzzy rule editor of the Fuzzy Logic
nine possible combinations with one term then (BedTime is Early) Toolbox. The expert on children’s bed times
from each variable. Nine rules are not If (WokeUpThisMorning is Normal) is not an expert in fuzzy logic (although she
difficult to manage, but consider how and (NapLength is Normal) is a mechanical engineer), but she had no
unwieldy four input variables with seven then (BedTime is Normal) difficulty defining the fuzzy terms or the
terms each would be, with potentially 2,401 If (WokeUpThisMorning is Normal) fuzzy rules. In this case, we used trapezoidal
distinct rules! There is no requirement to and (NapLength is Long) shapes to specify the fuzzy terms and the
define every possible rule at this level of then (BedTime is Late) system output was verified as producing
granularity. Since this system is so small, it If (WokeUpThisMorning is Late) appropriate (reasonably accurate) predictions
was developed with all 9 combinations: and (NapLength is Short) (see figure 4 for a graph of the system’s
If (WokeUpThisMorning is Early) then (BedTime is Early) output).
and (NapLength is Short) If (WokeUpThisMorning is Late) Though simple, this example
then (BedTime is Early) and (NapLength is Normal) illustrates the interaction of inputs in the
If (WokeUpThisMorning is Early) then (BedTime is Late) fuzzy rule base and is extensible to much
and (NapLength is Normal) If (WokeUpThisMorning is Late) larger problems. Again, not every possible
then (BedTime is Normal) and (NapLength is Long) fine-grained combination of input terms
If (WokeUpThisMorning is Early) then (BedTime is Late) needs its own rule. One rule may cover
and (NapLength is Long) These rules capture the relevant many such combinations. For instance,
then (BedTime is Late) knowledge in a very natural manner. These we can replace rules 3, 6 and 9 above by
If (WokeUpThisMorning is Normal) rules have been listed exactly as they appear the single rule “If(NapLength is Long)

PCAI 37 March/April 2002


then (BedTime is Late)”, since Definitions of fuzzy terms are precise and
WokeUpThisMorning does not affect fuzzy logic is a powerful tool for generating Some Fuzzy Twists
BedTime when NapLength is considered complex behaviors. The fuzzy systems developed in this
Long. article use only simple, pre-defined fuzzy
Further Exploration terms, but many fuzzy logic tools allow for
Conclusion You will find a number of good books variations on this idea. These variations
Mechanical control applications and on fuzzy logic and its application. Earl Cox’s expand the expressive power of the
other very technical uses, such as pattern modeling language, making system design
“The Fuzzy Systems Handbook”, now in its
recognition, have overshadowed fuzzy logic’s easier and more robust.
ease-of-use and wide applicability to other second edition, goes into much more
technical detail than this article and gives As an example, one might wish to
important, though much less exotic include a rule which begins “If
problems, such as new product pricing, excellent examples of effective fuzzy
solutions to difficult real-world problems. (SellingPrice is NearManufacturingCost)
project planning and stock selection.
Also consider “Fuzzy Logic and Neurofuzzy then…”. assuming that Manufacturing
Fuzzy logic is applicable when making
some type of prediction or decision, and cost changes over time and is one of the
Applications in Business and Finance” by
human experts can express the relationship inputs to the fuzzy system, then the
Constantin Von Altrock.
between the known and what needs to be definition of NearManufacturingCost
The math behind fuzzy logic is simple
decided. Note that the straightforward will obviously change as well. Some
enough that most programmers should have fuzzy logic software allow a fuzzy
nature of fuzzy rules not only allows non- no difficulty implementing it in their
technical people to understand the system, concept such as NearManufacturingCost,
language of choice. However, many existing to be defined dynamically, tracking the
but also encourages participation by them in
the construction of the fuzzy system. By software packages make fuzzy systems easy system input ManufacturingCost.
helping to define fuzzy terms and supplying to build, even for non-programmers. These Another idea that fuzzy designers
fuzzy rules, non-technical experts (the tools usually include easily-manipulated may wish to include are formulas that
people best qualified to indicate the behavior graphical interfaces, allowing the user to manipulate fuzzy values. A rule starting
of the system) are able to meaningfully visualize the system as it is being built. with “If (StockPriceToday is 1.1 *
contribute to development and achieve a MATLAB’s Fuzzy Logic Toolbox is a StockPriceYesterday) then…” requires the
sense of ownership. The technical folks still good example. ability to perform the multiplication
handle the real technical details, enabling an before making a comparison between
ideal separation of responsibilities. Despite Will Dwinnell, MBA is a quantitative analyst with over
12 years experience who lives in southeastern the two values.
the "rule-of-thumb" appearance of the rules, Sometimes, when initializing a target
Pennsylvania. His Web site is at will.dwinnell.com and
fuzzy logic is not arbitrary or happenstance. value, there is a need for unconditional
he may be reached by e-mail at predictor@dwinnell.com
rules. These rules have no “If” part and
always fire. Consider a rule such as
Target Your Marketing to Professionals “BedTime is NearEightPM”. Although
that Use your Products unconditional rules produce the same
output regardless of inputs, they are only a
Use a PC AI Web Banner Ad part of the entire fuzzy system. Overall,
system output still varies with the inputs
Target your marketing to PC AI readers (as per the conditional rules), but
unconditional rules are a method of
and website visitors. anchoring the system’s response.
Last, a very popular feature of fuzzy
PC AI readers are eager for the latest in intelligent agents, data logic is its ability to include hedges, a
mining, knowledge management, case based reasoning, fuzzy logic, means of modifying the meaning of
intelligent applications, genetic algorithms, modeling and fuzzy terms. The mathematical
simulation decision support, e-commerce, and web technology. definition of hedges allows their
Our readers are focused on using the latest technology to application to any fuzzy term and it
improve their bottom line. extends the language used in the fuzzy
system. For instance, in our bed time
For more information on example, the hedge Very might have
PC AI Web Banner advertising contact us at: been appended to the fuzzy term Long
(used with NapLength) to produce a rule
(602) 971-1869 beginning “If (NapLength is Very Long)
then…”. The fuzzy logic software
or at web-banner-info@pcai.com handles the mechanics of all this under
the covers, so users concentrate on the
everyday meaning of these words.
Consider some other common hedges
that could be employed in our examples,
such as Somewhat Dark, Extremely Light,
Fairly Short or Moderately Late.

PCAI 39 March/April 2002

Potrebbero piacerti anche