2002 - putting fuzzy logic to work - an intro to fuzzy rule

Upload: franck-dernoncourt

Post on 09-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule

    1/7

    IntroductionFuzzy logic, a powerful and very useful

    technology, has yet to see its potential fullyexploited. 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 manyproblems. This article presents a managerslevel understanding of fuzzy logic, how itworks in practice and the type of

    applications for which it is best suited. Deeptechnical issues and philosophical debates,

    on the other hand, are not covered.

    Fuzzy FundamentalsIn 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 numericinputs and receives numeric outputs, withno knowledge of what is going on inside.

    The technician who implements the fuzzysystem 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: eitherthe condition (the rule's "if" part) triggersthe rule or it doesn't. What is different

    about fuzzy logic is that definitions areallowed to be true in degrees, reflecting thevague quality of many definitions used inheuristics, allowing rules to fire "partially" ifthey are only partially relevant.

    A Simple ExampleConsider the problem of enhancing thecontrast of an image. An image with low-contrast has many pixels with similarbrightness. Without significant variation inbrightness, low-contrast images have awashed-out or hazy appearance. In a high-contrast image, there is a much largervariation in brightness, with many verybright and very dark pixels. Contrastenhancement is the process of changing alow-contrast image into a high-contrastimage and can be achieved by mapping thebrightness values of the original image to a

    new set of brightness values in the newimage. Fuzzy logic can perform thistransformation. Thinking in everyday terms,how does one change the brightness of pixelsin a low-contrast image to increase thecontrast? Light pixels in the input imageshould become lighter in the output imageand dark pixels should become darker (pixelsin the middle should stay more or less thesame). We may encode these ideas as fuzzyrules:

    1. if (Input is Dark)then (Output is ReallyDark)

    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 asDark, Light,ReallyLight, and so forth, the above rulesdefine a mathematical function thatincreases image contrast. These rules, infact appear exactly as listed in a smallfuzzy system built using MATLABsFuzzy Logic Toolbox. Figure 1 shows(graphically) the definitions of the termsDark, Medium and Light, as used in thisfuzzy system. Notice that brightnessvaries from 0.0 (black) to 1.0 (white). Asfigure 1 illustrates, the fuzzy definitionsof words such asLightand Darkdo notneed to have hard cut-offs, but may fade

    from one to the other in between. Inother words, any given brightness levelmight be partiallyLight, partiallyMedium and partiallyDarkat the sametime.

    When the brightness of an inputpixel is presented to this fuzzy logicsystem, it is fuzzified, which means thateach of the terms defined for the inputbrightnessDark, Medium and Lightisconsidered true to some degree. Thefuzzy degree of truth ranges from 0(absolutely false) to 1 (completely true)

    By Will DwinnellBy Will Dwinnell

    Putting Fuzzy Logic to Work:

    An Int ro to Fuzzy Rules

    PCAI 33 March/April 2002

  • 8/7/2019 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule

    2/7

    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 images brightness

    (see figure 2). Notice that to drive pixel

    brightness to the light and dark extremes,

    the definitions ofReallyDarkand

    Figure 1 : Fuzzy Input Definitions

    The height of each curve ind icates the degree to w hich th at concept is considered tr ue. For instance, if th e input, Pix elBr ightness, is 0.4 (a s l ight ly d ark gray) , then Dark (b lue trace on the graph) and Medium (green) are each rated atroughly 0.4 tr ue, w hile Light (red) is considered to be appro x ima tely 0.13 true. The truth of these term s controls how

    much each fuzzy rule contr ibutes to th e fuzzy systems overall response.

    ReallyLightare closer to 0.0 and 1.0,

    respectively, thanDarkand Lighton 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 typicalalternatives.

    Each time the fuzzy logic system

    executes, each input term (Light, Medium

    and Darkfor 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

    figures 3A (before enhancement) and 3B(after enhancement) for a demonstrationof our fuzzy contrast enhancer on a realimage. Obviously, it is possible to adjustthe exact definitions of the various terms

    used in the fuzzy rules to suit whateverresult is desired.

    AnalysisThe demonstrated fuzzy system

    effectively solves a real problem. Real imagesoften suffer from poor contrast, leavingvisual features vague and indistinct. Thefuzzy rules are easy to audit, maintain ormodify and provide a self-documenting,easily understood format for the solution.Fuzzy-models that are more complex mayinclude additional inputs, allowing more

    PCAI 34 March/April 2002

  • 8/7/2019 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule

    3/7

    conditions in each rule. Notice, too, that thefuzzy logic system is completelydeterministic: when given the same inputstwice, 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-basedsystem) require an extensive set of examplesfrom which to learn the appropriatemapping of pixel brightness from low-contrast to high-contrast. Fuzzy rules, on theother hand, mimic an existing base ofhuman knowledge. Construction of thefuzzy rule base does not require an extensivedatabase of correct mappings from inputto output (although these would be helpfulin validating its performance). Instead, itrequires some type of knowledge to translate

    into fuzzy rules. While there are algorithmsfor deriving the fuzzy rules from data, herewe are only concerned with the more usualmethod of building them manually.

    An Example with Two InputsIn my home, one daily challenge isputting the kids to bed. We have foundthat putting children to bed when theyare ready to fall asleep helps. We have alsofound that when they are ready to fallasleep depends on (among other things)when they woke up this morning (whichindicates roughly how much sleep theyreceived the previous night) and how longthey napped during the afternoon.Consulting an expert (my wife), I built afuzzy logic system using these two inputs

    (WokeUpThisMorningand NapLength)that predicts when the kids will becomesleepy (BedTime). In contrast to the lastexample, in which the fuzzy contrastenhancer made a decision (that is

    correct only in terms of the policy wecreated), this system makes a prediction(subject to some inaccuracies whencompared to the actual experience).

    The input, WokeUpThisMorningisthe number of hours since midnight. Inother words, if the child woke at 8:30am,WokeUpThisMorningis 8.5. The otherinput variable,NapLength, indicates thelength of the afternoon nap in hours. Thetime to be predicted,BedTime, indicateshours after noon (8.75 would mean8:45pm). As in the previous example, we

    Figure 2 : Fuzzy Ou tput DefinitionsEach fuzzy rule m ay specify any of th ese fuzzy term s ( ReallyDark is the blue curv e, Medium is green and ReallyLight is red)

    as its output. The fuzzy log ic softw are tak es care of fusing these fuzzy term s to generate the systems output. In our simplefuzzy system, there ar e only 3 rules, and they d irectly connect Light inp ut to ReallyLight output, M edium in put to M ediumoutput a nd Dark input to ReallyDark output. Since ReallyLight is l ighter than Light and ReallyDark is dar k er than Dark , pix el

    br ightness tends to move aw ay f rom m edium br ightness towa rd the extremes.

    PCAI 35 March/April 2002

  • 8/7/2019 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule

    4/7

    define three fuzzy terms along each

    variable. Note that three terms were usedbecause 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

    and Late

    NapLength: 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

    Figure 3 A: A Low -Contra st Ima geThis image is typical of low -contra st images: pixel br ightness does not varyenough, g iv ing a hazy, w ashed-out look.

    Figu re 3B: The Sam e Imag e After Contra st Enha ncement

    The Fuzzy Contr ast Enha ncer increases contra st by sprea din g out th e brig htnessof pixels in the image. Light pixels become lighter and dark pixels becomedar k er. Rough t extu res have been accentuated.

    PCAI 36 March/April 2002

    Target Your Marketingto Professionals that

    Use your Products

    Use aPC AI

    WebBannerAdTarget your marketing toPC

    AIreaders and websitevisitors.

    PC AIreaders are eager for the latest inintelligent agents, data mining, knowledgemanagement, case based reasoning, fuzzy

    logic, intelligent applications, geneticalgorithms, modeling and simulation

    decision support, e-commerce,and web technology.

    Our readers are focused on using the

    latest technology to improvetheir bottom line.

  • 8/7/2019 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule

    5/7

    fuzzy terms each, yielding a maximum ofnine possible combinations with one termfrom each variable. Nine rules are notdifficult to manage, but consider howunwieldy four input variables with seventerms each would be, with potentially 2,401distinct rules! There is no requirement todefine every possible rule at this level ofgranularity. Since this system is so small, itwas 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)

    Figur e 4: Bed Time PredictionThis 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 ind icates 7:30pm , 8 m eans 8pm, a nd so for th). Likew ise, the input Wo k eUpTime m easures time inhours since midn ight (8 is 8am, 8 .5 is 8:30a m, a nd so on). NapLength is the length ( in hours) of the childs afternoon na p.

    The color coding in this figure follow s the height, w ith black indicating the earl iest bed times, through r ed and or ange, upto y ellow, w hich repr esents the latest bed tim es.

    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. Theserules have been listed exactly as they appear

    in the fuzzy rule editor of the Fuzzy LogicToolbox. The expert on childrens bed timesis not an expert in fuzzy logic (although sheis a mechanical engineer), but she had nodifficulty defining the fuzzy terms or thefuzzy rules. In this case, we used trapezoidalshapes to specify the fuzzy terms and thesystem output was verified as producingappropriate (reasonably accurate) predictions(see figure 4 for a graph of the systemsoutput).

    Though simple, this exampleillustrates the interaction of inputs in thefuzzy rule base and is extensible to muchlarger problems. Again, not every possiblefine-grained combination of input termsneeds its own rule. One rule may covermany such combinations. For instance,we can replace rules 3, 6 and 9 above bythe single rule If(NapLength isLong)

    PCAI 37 March/April 2002

  • 8/7/2019 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule

    6/7

  • 8/7/2019 2002 - Putting Fuzzy Logic to Work - An Intro to Fuzzy Rule

    7/7

    then (BedTimeisLate), sinceWokeUpThisMorningdoes not affectBedTimewhen NapLength is consideredLong.

    ConclusionMechanical control applications and

    other very technical uses, such as patternrecognition, have overshadowed fuzzy logicsease-of-use and wide applicability to otherimportant, though much less exoticproblems, such as new product pricing,project planning and stock selection.

    Fuzzy logic is applicable when makingsome type of prediction or decision, andhuman experts can express the relationshipbetween the known and what needs to bedecided. Note that the straightforwardnature of fuzzy rules not only allows non-technical people to understand the system,but also encourages participation by them inthe construction of the fuzzy system. Byhelping to define fuzzy terms and supplyingfuzzy rules, non-technical experts (thepeople best qualified to indicate the behaviorof the system) are able to meaningfullycontribute to development and achieve asense of ownership. The technical folks stillhandle the real technical details, enabling anideal separation of responsibilities. Despitethe "rule-of-thumb" appearance of the rules,fuzzy logic is not arbitrary or happenstance.

    Definitions of fuzzy terms are precise and

    fuzzy logic is a powerful tool for generating

    complex behaviors.

    Further ExplorationYou will find a number of good books

    on fuzzy logic and its application. Earl Coxs

    The Fuzzy Systems Handbook, now in its

    second edition, goes into much more

    technical detail than this article and givesexcellent 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.

    MATLABs Fuzzy Logic Toolbox is a

    good example.

    Will Dw innell, MBA is a quantit ative analyst w ith 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 predictor@ dwinnell.com

    PCAI 39 March/April 2002

    Some Fuzzy Tw ist sThe 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 toinclude a rule which begins If

    (SellingPrice isNearManufacturingCost)

    then. assuming that Manufacturing

    cost changes over time and is one of the

    inputs to the fuzzy system, then the

    definition ofNearManufacturingCost

    will obviously change as well. Some

    fuzzy logic software allow a fuzzy

    concept such asNearManufacturingCost,

    to be defined dynamically, tracking the

    system inputManufacturingCost.

    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 systems 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 havebeen appended to the fuzzy termLong

    (used withNapLength) 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 Shortor Moderately Late.

    Target Your Marketing to Professionalsthat Use your Products

    Use aPC AIWeb Banner AdTarget your marketing toPC AIreaders

    and website visitors.PC AIreaders 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 onPC AI Web Banner advertising contact us at:

    (602) 971-1869or at [email protected]