May 1, 2017 | Author: Franck Dernoncourt | Category: N/A
Download 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule...
Putting Fuzzy Logic to Work: An Intro to Fuzzy Rules By Will Dwinnell
Introduction Fuzzy logic, a powerful and very useful technology, has yet to see its potential fully exploited. This is ironic given that fuzzy logic is relatively easy to understand (especially for non-technical people) and fills such a critical need in so many problems. This article presents a manager’s level understanding of fuzzy logic, how it works in practice and the type of applications for which it is best suited. Deep technical issues and philosophical debates, on the other hand, are not covered.
Fuzzy Fundamentals In this article, the focus is on the most common type of fuzzy rule-based system, one that accepts numeric inputs and outputs. The user supplies the numeric inputs and receives numeric outputs, with no knowledge of what is going on inside. The technician who implements the fuzzy system has two basic tasks: • encode human knowledge as fuzzy rules (which resemble English) • create mathematical definitions for the system components. Ordinarily, rules are implemented on computers as an all-or-nothing affair: either the condition (the rule's "if" part) triggers the rule or it doesn't. What is different PCAI
about fuzzy logic is that definitions are allowed to be true in degrees, reflecting the vague quality of many definitions used in heuristics, allowing rules to fire "partially" if they are only partially relevant.
A Simple Example Consider the problem of enhancing the contrast of an image. An image with lowcontrast has many pixels with similar brightness. Without significant variation in brightness, low-contrast images have a “washed-out” or hazy appearance. In a highcontrast image, there is a much larger variation in brightness, with many very bright and very dark pixels. Contrast enhancement is the process of changing a low-contrast image into a high-contrast image and can be achieved by mapping the brightness values of the original image to a new set of brightness values in the new image. Fuzzy logic can perform this transformation. Thinking in everyday terms, how does one change the brightness of pixels in a low-contrast image to increase the contrast? Light pixels in the input image should become lighter in the output image and dark pixels should become darker (pixels in the middle should stay more or less the same). We may encode these ideas as fuzzy rules: 1. if (Input is Dark) then (Output is ReallyDark) 33
2. if (Input is Medium) then (Output is Medium) 3. if (Input is Light) then (Output is ReallyLight) By giving precise mathematical definitions to terms such as Dark, Light, ReallyLight, and so forth, the above rules define a mathematical function that increases image contrast. These rules, in fact appear exactly as listed in a small fuzzy system built using MATLAB’s Fuzzy Logic Toolbox. Figure 1 shows (graphically) the definitions of the terms Dark, Medium and Light, as used in this fuzzy system. Notice that brightness varies from 0.0 (black) to 1.0 (white). As figure 1 illustrates, the fuzzy definitions of words such as Light and Dark do not need to have hard cut-offs, but may fade from one to the other in between. In other words, any given brightness level might be partially Light, partially Medium and partially Dark at the same time. When the brightness of an input pixel is presented to this fuzzy logic system, it is “fuzzified”, which means that each of the terms defined for the input brightness Dark, Medium and Light is considered true to some degree. The fuzzy degree of truth ranges from 0 (absolutely false) to 1 (completely true) 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 will fire. Consider, for instance, a dark pixel with a brightness of 0.1, which maps to approximately 0.95 truth for “Dark”, and almost zero truth for “Medium” and “Light”. Fuzzy rule 1, above, (using “Dark” in its condition) will fire approximately 0.95, while the other rules (using “Medium” and “Light” in their conditions) will make almost no contribution to the system output. A similar set of terms (ReallyDark, Medium and ReallyLight) is numerically defined for the output image’s brightness (see figure 2). Notice that to drive pixel brightness to the light and dark extremes, the definitions of ReallyDark and PCAI
ReallyLight are closer to 0.0 and 1.0, respectively, than Dark and Light on the input scale. In this example, bell-shaped curves define the truth of the various terms, however, other shapes such as triangles and trapezoids are typical alternatives. Each time the fuzzy logic system executes, each input term (Light, Medium and Dark for pixel brightness) calculates as being true to some degree. The rules fire (to varying degrees), producing a collection of fuzzy outputs which are combined by the fuzzy logic software to produce the result- an ordinary number. The user of the fuzzy logic system does not care how all this works internally. See 34
figures 3A (before enhancement) and 3B (after enhancement) for a demonstration of our fuzzy contrast enhancer on a real image. Obviously, it is possible to adjust the exact definitions of the various terms used in the fuzzy rules to suit whatever result is desired.
Analysis The demonstrated fuzzy system effectively solves a real problem. Real images often suffer from poor contrast, leaving visual features vague and indistinct. The fuzzy rules are easy to audit, maintain or modify and provide a self-documenting, easily understood format for the solution. Fuzzy-models that are more complex may include additional inputs, allowing more 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 fuzzy logic system is completely deterministic: when given the same inputs twice, its output will be exactly the same. While a statistical regression or neural network could have solved this problem, they (in contrast to the fuzzy rule-based system) require an extensive set of examples from which to learn the appropriate mapping of pixel brightness from lowcontrast to high-contrast. Fuzzy rules, on the other hand, mimic an existing base of human knowledge. Construction of the fuzzy rule base does not require an extensive database of “correct” mappings from input to output (although these would be helpful in validating its performance). Instead, it requires some type of knowledge to translate PCAI
into fuzzy rules. While there are algorithms for deriving the fuzzy rules from data, here we are only concerned with the more usual method of building them manually.
An Example with Two Inputs In my home, one daily challenge is putting the kids to bed. We have found that putting children to bed when they are ready to fall asleep helps. We have also found that when they are ready to fall asleep depends on (among other things) when they woke up this morning (which indicates roughly how much sleep they received the previous night) and how long they napped during the afternoon. Consulting an expert (my wife), I built a fuzzy logic system using these two inputs 35
(WokeUpThisMorning and NapLength) that predicts when the kids will become sleepy (BedTime). In contrast to the last example, in which the fuzzy contrast enhancer made a decision (that is “correct” only in terms of the policy we created), this system makes a prediction (subject to some inaccuracies when compared to the actual experience). The input, WokeUpThisMorning is the number of hours since midnight. In other words, if the child woke at 8:30am, WokeUpThisMorning is 8.5. The other input variable, NapLength, indicates the length of the afternoon nap in hours. The time to be predicted, BedTime, indicates hours after noon (8.75 would mean 8:45pm). As in the previous example, we 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.
Figure 3A: A Low-Contrast Image This image is typical of low-contrast images: pixel brightness does not vary enough, giving a hazy, washed-out look.
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 their bottom line.
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 variable. Note that three terms were used because it suited this problem. There is no reason that all variables must have the same number of concepts defined and some problems may have better solutions with a different number of terms. First we define the following terms: WokeUpThisMorning: “Early”, “Normal” PCAI
and “Late” “Short”, “Normal” and “Long” BedTime: “Early”, “Normal” and “Late” Now that there is more than one input, we must decide how to combine the various inputs to define the rules of the system. In this case, there are two inputs, having three NapLength:
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 nine possible combinations with one term from each variable. Nine rules are not difficult to manage, but consider how unwieldy four input variables with seven terms each would be, with potentially 2,401 distinct rules! There is no requirement to define every possible rule at this level of granularity. Since this system is so small, it was developed with all 9 combinations: If (WokeUpThisMorning is Early) and (NapLength is Short) then (BedTime is Early) If (WokeUpThisMorning is Early) and (NapLength is Normal) then (BedTime is Normal) If (WokeUpThisMorning is Early) and (NapLength is Long) then (BedTime is Late) If (WokeUpThisMorning is Normal) PCAI
and (NapLength is Short) then (BedTime is Early) If (WokeUpThisMorning is Normal) and (NapLength is Normal) then (BedTime is Normal) If (WokeUpThisMorning is Normal) and (NapLength is Long) then (BedTime is Late) If (WokeUpThisMorning is Late) and (NapLength is Short) then (BedTime is Early) If (WokeUpThisMorning is Late) and (NapLength is Normal) then (BedTime is Late) If (WokeUpThisMorning is Late) and (NapLength is Long) then (BedTime is Late) These rules capture the relevant knowledge in a very natural manner. These rules have been listed exactly as they appear 37
in the fuzzy rule editor of the Fuzzy Logic Toolbox. The expert on children’s bed times is not an expert in fuzzy logic (although she is a mechanical engineer), but she had no difficulty defining the fuzzy terms or the fuzzy rules. In this case, we used trapezoidal shapes to specify the fuzzy terms and the system output was verified as producing appropriate (reasonably accurate) predictions (see figure 4 for a graph of the system’s output). Though simple, this example illustrates the interaction of inputs in the fuzzy rule base and is extensible to much larger problems. Again, not every possible fine-grained combination of input terms needs its own rule. One rule may cover many such combinations. For instance, we can replace rules 3, 6 and 9 above by the single rule “If(NapLength is Long) March/April 2002
then (BedTime is Late)”, since WokeUpThisMorning does not affect BedTime when NapLength is considered Long.
Definitions of fuzzy terms are precise and fuzzy logic is a powerful tool for generating complex behaviors.
Further Exploration
Conclusion Mechanical control applications and other very technical uses, such as pattern recognition, have overshadowed fuzzy logic’s ease-of-use and wide applicability to other important, though much less exotic problems, such as new product pricing, project planning and stock selection. Fuzzy logic is applicable when making some type of prediction or decision, and human experts can express the relationship between the known and what needs to be decided. Note that the straightforward nature of fuzzy rules not only allows nontechnical people to understand the system, but also encourages participation by them in the construction of the fuzzy system. By helping to define fuzzy terms and supplying fuzzy rules, non-technical experts (the people best qualified to indicate the behavior of the system) are able to meaningfully contribute to development and achieve a sense of ownership. The technical folks still handle the real technical details, enabling an ideal separation of responsibilities. Despite the "rule-of-thumb" appearance of the rules, fuzzy logic is not arbitrary or happenstance.
You will find a number of good books on fuzzy logic and its application. Earl Cox’s “The Fuzzy Systems Handbook”, now in its second edition, goes into much more technical detail than this article and gives excellent examples of effective fuzzy solutions to difficult real-world problems. Also consider “Fuzzy Logic and Neurofuzzy Applications in Business and Finance” by Constantin Von Altrock. The math behind fuzzy logic is simple enough that most programmers should have no difficulty implementing it in their language of choice. However, many existing software packages make fuzzy systems easy to build, even for non-programmers. These tools usually include easily-manipulated graphical interfaces, allowing the user to visualize the system as it is being built. MATLAB’s Fuzzy Logic Toolbox is a good example. Will Dwinnell, MBA is a quantitative analyst with over 12 years experience who lives in southeastern Pennsylvania. His Web site is at will.dwinnell.com and he may be reached by e-mail at
[email protected]
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 their bottom line.
For more information on PC AI Web Banner advertising contact us at:
(602) 971-1869 or at
[email protected]
PCAI
39
Some Fuzzy Twists The fuzzy systems developed in this article use only simple, pre-defined fuzzy terms, but many fuzzy logic tools allow for variations on this idea. These variations expand the expressive power of the modeling language, making system design easier and more robust. As an example, one might wish to include a rule which begins “If (SellingPrice is NearManufacturingCost) then…”. assuming that Manufacturing cost changes over time and is one of the inputs to the fuzzy system, then the definition of NearManufacturingCost will obviously change as well. Some fuzzy logic software allow a fuzzy concept such as NearManufacturingCost, to be defined dynamically, tracking the system input ManufacturingCost. Another idea that fuzzy designers may wish to include are formulas that manipulate fuzzy values. A rule starting with “If (StockPriceToday is 1.1 * StockPriceYesterday) then…” requires the ability to perform the multiplication before making a comparison between the two values. Sometimes, when initializing a target value, there is a need for unconditional rules. These rules have no “If” part and always fire. Consider a rule such as “BedTime is NearEightPM”. Although unconditional rules produce the same output regardless of inputs, they are only a part of the entire fuzzy system. Overall, system output still varies with the inputs (as per the conditional rules), but unconditional rules are a method of anchoring the system’s response. Last, a very popular feature of fuzzy logic is its ability to include hedges, a means of modifying the meaning of fuzzy terms. The mathematical definition of hedges allows their application to any fuzzy term and it extends the language used in the fuzzy system. For instance, in our bed time example, the hedge Very might have been appended to the fuzzy term Long (used with NapLength) to produce a rule beginning “If (NapLength is Very Long) then…”. The fuzzy logic software 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. March/April 2002