home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / fuzzgn / fuzzgen.doc < prev    next >
Encoding:
Text File  |  1993-08-26  |  21.8 KB  |  477 lines

  1.  
  2.  
  3.  
  4.                                F U Z Z G E N
  5.  
  6.                       Fuzzy Logic Source Code Generator
  7.  
  8.                            Evaluation Version 1.10
  9.  
  10.  
  11.  
  12.                             U S E R    G U I D E 
  13.  
  14.  
  15.  
  16.       INTRODUCTION:
  17.  
  18.       As programmers, many of us have heard the terms NEURAL NETWORKS
  19.       and FUZZY LOGIC bandied about over the last couple of years. The 
  20.       odd thing is that very few of us that write code on a daily basis
  21.       really have a handle on what these things mean. 
  22.  
  23.       Fuzzy Logic is a decision making method for computers. It has 
  24.       taken many years for the merits of Fuzzy Logic to become clear. 
  25.       One of the reasons is the name: people hear "Fuzzy Logic" and 
  26.       immediately assume that it is imprecise. Actually, it is the
  27.       other way around -- Fuzzy Logic allows FOR imprecision in the
  28.       input in making a precise decision. 
  29.  
  30.       The idea that Fuzzy Logic is suited only to microcontroller
  31.       applications such as flow controllers and such is also quite
  32.       misleading. It is suitable for a wide variety of applications.
  33.  
  34.       Fuzzy Logic also allows for perspective to change without having
  35.       to completely recode massive programs. For instance, if you have
  36.       a program like a battle simulation that takes factors such as
  37.       the effect of heat into account on the troops, the perspective
  38.       of HOT changes depending on the origin of the troops. Swedish or
  39.       Russian troops may see 80 degrees F as hot, whereas troops from
  40.       countries nearer the equator see 100 degrees as hot and 80
  41.       degrees as mild. Being able to make this decision in a "Fuzzy"
  42.       manner means that you can read in the control variables as needed
  43.       and still guarantee the integrity of a decision made by the
  44.       program. 
  45.  
  46.       FuzzGen is a program intended to introduce you to Fuzzy concepts
  47.       and allow you to create Fuzzy decision sets for your own programs.
  48.       It allows you to graphically model the decision process to aid in
  49.       visualising a decision. It also produces source code in PASCAL,
  50.       BASIC, or C so that you can incorporate Fuzzy decision making in
  51.       your programs. It is intended to save time so that you do not need
  52.       to keep coding IF - THEN - ELSE blocks to make decisions in your
  53.       programs. Essentially, FuzzGen is a CASE tool that is additionally
  54.       educational in that it will introduce many of you to new concepts.
  55.  
  56.       
  57.       BASIC CONCEPTS:
  58.  
  59.       Fuzzy Logic is a little like the "new math" some of us were taught
  60.       (starting in the late 60's and early 70's in most districts) in
  61.       school. Fuzzy Logic uses the concept of SETS and membership. What
  62.       this means is that a data point is seen as either being a set
  63.       member or not, and more importantly, HOW MUCH of a member. Using 
  64.       triangular and trapezoidal shapes to model data allows you to plot
  65.       a data point on a slope. Rather than exclusively dealing with YES/NO,
  66.       you can deal with "65%" or "32%" membership. In essence, you can 
  67.       say that data point X is a Y% member of data set Z. This allows you
  68.       to have much more control over input data variance, as we can 
  69.       immediately see exactly where input data lies.
  70.  
  71.       The different shapes are collectively known as MEMBERSHIP FUNCTIONS.
  72.  
  73.       This allows for a different way to code than what you're used to.
  74.       (By the way, we'll be using code fragments done in C to illustrate
  75.       points as we go along.) For instance, here's how you may code for
  76.       a variable input in standard ways:
  77.  
  78.       if(INPUT_DATA <= .1) 
  79.          we_do_this();
  80.       else if(INPUT_DATA > .1 && INPUT_DATA <= .2) 
  81.          we_do_that();
  82.       else if(INPUT_DATA > .2 && INPUT_DATA <= .3)
  83.          do_something_else();
  84.       // AND SO ON...
  85.  
  86.       Fuzzy Logic tends to compartmentalise things. Therefore, instead 
  87.       of a big IF-ELSE construct, you could use the following:
  88.  
  89.       int i, SetNumber;
  90.       double testval, setpctg = 0;
  91.  
  92.       for(i = 0; i < NumOfSets; i++){          // loop
  93.           testval = InSet(i, INPUT_DATA);      // is data in the set?
  94.           if(testval > setpctg){               // if so,
  95.              setpctg = testval;                // reset high pctg marker 
  96.              SetNumber = i;                    // and record which set.      
  97.           }  
  98.       }
  99.       do_whatever_we_need_done(SetNumber);
  100.       
  101.  
  102.       What the above code does is record the set with the highest 
  103.       membership percentage so that we have a variable that shows what
  104.       set the data is in and also what action to take. At first blush,
  105.       this may not seem any better than the "old" way using the large
  106.       IF-ELSE construct. However, if you stop and think about it, you
  107.       have more control with the second method. Sure, we could change
  108.       the test points to variables in both cases, but the second method
  109.       does not need to be recompiled if you change your mind about the 
  110.       number of tests to make.  This is provided by variable NumOfSets.
  111.       Now, using the Fuzzy method, you can read your variable list in
  112.       PLUS you can read in how many tests to take. Sure, you could do
  113.       this yourself with IF-ELSE constructs, but this is easier. 
  114.  
  115.       The next step is to make it simpler to model a decision so that
  116.       it is simple to see what is happening.       
  117.             
  118.  
  119.       GRAPHICS AND DECISION VISUALISATION:
  120.  
  121.       FuzzGen uses a 2 axis graph to allow you to see data sets and 
  122.       their relationships. The Y axis of the graph is used to show
  123.       percentage and ranges from 0 - 100. The X axis is used to show
  124.       the ordinal range of input data values. See figure 1.
  125.  
  126.        
  127.        | 100
  128.        |
  129.        |
  130.        | <---------------- Percentage       
  131.        |
  132.        |                       Ordinal Data
  133.        |                            |
  134.        |                            |
  135.        |_0_________________________________________________________    
  136.             
  137.        4                                                          20
  138.        
  139.                -=-=-=-=-=-= 4-20 ma current input =-=-=-=-=-
  140.  
  141.                                   fig 1
  142.  
  143.  
  144.        Also, to be able to properly plot data values into sets, we use
  145.        shapes to clasiffy them. Common shapes (supported by FuzzGen) are
  146.        Triangular, Trapezoidal, and Square (Boolean.) There is infinite
  147.        variety possible using the Triangular and Trapezoidal shapes.
  148.  
  149.        As an example, we'll now graph out a simple Fuzzy Logic demo that
  150.        shows how to use the graphics and shapes to allow a change of 
  151.        perspective. The subject is temperature as seen by a Polar Bear 
  152.        and as seen by someone's grandmother.
  153.  
  154.              ______________________60            82_________ 
  155.        100  |                       \            /          |
  156.             |                        \          /           |
  157.           P |                         \        /            |
  158.           C |                          \      /             |
  159.           T |    C O L D                \    /  H O T       |
  160.           G |                            \  /               |
  161.             |                             \/                |
  162.             |                             /\                |
  163.          0  |____________________________/__\_______________|
  164.             0                           65  70             100
  165.  
  166.              -=-=-=-=TEMPERATURE AS SEEN BY GRANDMA =-=-=-=-
  167.                                  
  168.                                   fig 2                         
  169.        
  170.                       
  171.        So, in this scenario, if you wanted to find out what Grandma
  172.        would think of, say, 62 degrees, you would plot along the X
  173.        axis to 62 degrees and find out where the decision data
  174.        intersected the decision shapes at. In this case here, Grandma
  175.        would see 62 degrees as 75% COLD and not HOT at all. (It didn't
  176.        intersect the HOT decision at all.) The COLD decision set uses
  177.        a Trapezoidal shape: anything from 0 - 60 is seen as 100% COLD,
  178.        and at 60 degrees it starts tapering down to 70. HOT also uses 
  179.        a trapezoidal shape. 
  180.  
  181.  
  182.                _____10           34___________________________
  183.          100  |     \            /                            |
  184.               |      \          /                             |
  185.             P |       \        /                              |
  186.             C |        \      /                               |
  187.             T | MILD    \    /           H O T                |
  188.             G |          \  /                                 |
  189.               |           \/                                  |
  190.               |           /\                                  | 
  191.            0  |__________/__\_________________________________|
  192.               0         20  25                               100
  193.  
  194.              -=-=-=-=TEMPERATURE AS SEEN BY A POLAR BEAR =-=-=-=-  
  195.                          
  196.                                     fig 3
  197.  
  198.        On the other hand, we have in this scenario the EXACT SAME
  199.        decision shapes used, but now we see the SAME RANGE of the
  200.        temperature as seen by a Polar Bear. Note that the bear sees
  201.        anything under 10 degrees as MILD, and anything above this as
  202.        getting warmer. Downright HOT starts at 34 degrees.
  203.          
  204.        In these two cases we see the same data being looked at by use
  205.        of Fuzzy Logic decisions to base COLD or HOT on the perspective
  206.        of the viewer. While this is a very simple example, it should 
  207.        serve to explain the basic FuzzGen modeling of Fuzzy Logic.
  208.  
  209.           
  210.        USING FUZZGEN:
  211.  
  212.        As the program starts up, it will allow you to either get Help,
  213.        Open a data file, or start a New file. Once you get a filename 
  214.        started, you are allowed to SETUP the GRAPH. 
  215.  
  216.  
  217.        STEP 1: SET UP THE GRAPH BASICS
  218.  
  219.        In the graph setup, you may want to put a label on the X axis 
  220.        so that viewing of the graph is a little clearer. You can also 
  221.        optionally put tickmarks and Major Tickmarks along the X axis 
  222.        so that it is easier to see where a decision is intersected. 
  223.        You'll also need to specify the unit range of input data, which 
  224.        is required. For instance, if your input data is in degrees 
  225.        Farenheight, your range may be (like our example) 0 - 100. On 
  226.        the other hand, you may want to create code that reads a hardware
  227.        current loop device from 4 - 20 milliamps. In other words, the
  228.        range used is up to you and your application. The last thing to 
  229.        do is tell FuzzGen how many functions it will need to work with.
  230.        You may use up to 10 in this evaluation version.
  231.        
  232.        All of these settings can be changed later, such as changing your 
  233.        mind about how many functions are needed and so on.
  234.  
  235.       
  236.        STEP 2: ADD MEMBERSHIP FUNCTIONS
  237.  
  238.        You'll need to access SETUP | MEMBERSHIPS. This window allows you
  239.        to choose a general function shape by clicking the associated option
  240.        button. You can "fine-tune" the triangular and trapezoidal shapes
  241.        by clicking the picture underneath the option button. Each click
  242.        will cause the picture to cycle through the possible shapes.
  243.  
  244.        As you click the option buttons denoting shape, the data input
  245.        boxes denoting major hinge points of the shape (i.e. endpoints
  246.        and apexes) will change to reflect the number of inputs this 
  247.        shape will need: Boolean - 2, Trapezoidal - 4, Triangular - 3.
  248.        These data input boxes allow for full double-precision data, so
  249.        you're not limited to integer based decision-making.
  250.  
  251.        Once you decide on a basic shape, you can enter the data. FuzzGen
  252.        may sometimes disallow your input and warn you to that effect. If
  253.        this happens, look at the basic shape picture to see if it allows
  254.        you to do what you want. In general, the shapes that do not have
  255.        a straight side have the ability to place the apex hinge points 
  256.        anywhere you want.
  257.  
  258.        Next, you should pick a "Tag colour" by clicking the little box
  259.        with a colour in it. This allows you to pick a colour so that 
  260.        when the graph is drawn it is easier to associate the particular
  261.        membership function with a colour.
  262.  
  263.        Once these items are in order, you should click the RECORD button
  264.        to record the input. You can then select a new decision to enter
  265.        or edit data for by clicking the LEFT-RIGHT buttons in the lower
  266.        right. Above the buttons is a label showing you what decision 
  267.        you are working on (numbered) such as "1 of 4."
  268.  
  269.        At any time, you can access HELP by clicking the HELP button.
  270.        The HELP window shows you the basics of working with the functions
  271.        and shapes. As you get more accustomed to working with FuzzGen,
  272.        you'll rely on this a little less.
  273.  
  274.        Once you have essentially defined the membership function shapes, we
  275.        can then proceed to the next step.
  276.  
  277.  
  278.        STEP 3: MODELING
  279.  
  280.        You should now exit from the SETUP MEMBERSHIPS window by clicking
  281.        the CANCEL button. On the main FuzzGen window, click the GRAPH
  282.        button. Your graph and membership functions are shown. You may at
  283.        this time elect to go back to SETUP GRAPH or SETUP MEMBERSHIPS to
  284.        fine tune your model. In this sense, FuzzGen is interactive in
  285.        that you can make an adjustment and come back to click the GRAPH
  286.        button to see what the change looks like.
  287.  
  288.  
  289.        STEP 4: GENERATE SOURCE CODE
  290.  
  291.        The LANGUAGE menu allows you to select a source language to use
  292.        by clicking the language of choice so that it becomes "checked."
  293.  
  294.        If you are satisfied that your application is correctly done (i.e.
  295.        the graph seems to reflect what you're after) and the language
  296.        source is correct, go back to the LANGUAGE menu and select the
  297.        GENERATE CODE menu item. This will output a file with the appropriate
  298.        extension added to the name of your data file. For example, if
  299.        you are working with filename DUMMY, here's the source files that
  300.        would be generated depending on your language of choice:
  301.  
  302.        C ------- DUMMY.C
  303.        PASCAL -- DUMMY.PAS
  304.        BASIC --- DUMMY.BAS
  305.  
  306.  
  307.        STEP 5: FUZZY RULES
  308.  
  309.        FuzzGen allows you the ability to create a rule base. Essentially,
  310.        a rule base is pseudocode based on a simple IF-THEN construct
  311.        and names for the membership functions. In the SETUP MEMBERSHIPS
  312.        window, note that you can give each function shape a unique name.
  313.        In SETUP RULES, you can also specify a series of named output
  314.        states. The fuzzy rules should be able to specify the output state
  315.        based on input states. Also note that the input and output is named
  316.        as well. This allows you to have an input datum, for instance,
  317.        that is tested in the membership functions and called TEMPERATURE.
  318.        Let's also assume an output state named HEATER. Here's how a fuzzy
  319.        rule would look:
  320.  
  321.        if TEMPERATURE is HIGH then HEATER is <output state of choice>
  322.              ^            ^           ^                 ^
  323.              |            |           |                 |
  324.            datum    function name   output name    named state of output
  325.  
  326.        This is a distillation of:
  327.  
  328.        If the input datum is a member of the function named HIGH then the
  329.        corresponding output state is --
  330.  
  331.        You can also use boolean functions in fuzzy rules:
  332.  
  333.        if (TEMPERATURE is HIGH or TEMPERATURE is MEDIUM_HIGH) and...
  334.  
  335.        As you can see, the fuzzy rules try to distill a body of knowledge
  336.        about a decision making process into a simple set of plain english
  337.        rules.
  338.  
  339.        As of yet (November 1992) we don't yet have a fully coded rulebase
  340.        code generator, so the final implementation of your fuzzy code
  341.        will need to be a copy of your rulebase that you write. In practice
  342.        this takes very little time since the actual working code looks
  343.        almost exactly like the rulebase. We're hoping to have rulebase
  344.        code generation installed by (version 2.0) summer 1993.
  345.  
  346.  
  347.        STEP 6: DOCUMENTATION
  348.  
  349.        We've included a small text editor (click the WRITING icon button)
  350.        which you can use to add any pertinent notes to. You can use this
  351.        to outline the decision process as required, and you can also
  352.        import additional text from other files. The standard copy/paste
  353.        functions are included and work like any other Windows product --
  354.        select the text to manipluate by clicking the mouse and dragging
  355.        until all text is highlighted. You can have up to 32k of program
  356.        documentation in this editor file. The documentation file is
  357.        saved as FILENAME.DOC using the DOC extension.
  358.  
  359.        As you know, good programming practice is often less about code
  360.        than describing and documenting the problem to be solved using
  361.        the code. We suggest you keep a good set of notes and use the
  362.        editor to store them in.
  363.  
  364.  
  365.        STEP 8: DONE?
  366.  
  367.        Unless you have any second thoughts about the decision modeling,
  368.        you are pretty much done with FuzzGen at this point. You should
  369.        SAVE the data file you are working with for later recall. In the
  370.        FILE menu, select SAVE or SAVE AS. SAVE AS will ask you for a new
  371.        name to save under (other than the one you used). It will save in
  372.        the current data file directory.
  373.  
  374.  
  375.        
  376.        UNDERSTANDING FUZZGEN SOURCE CODE:
  377.  
  378.        Essentially, the code example we used earlier is a good idea of
  379.        what the output source looks like. Each function variable (i.e.
  380.        enpoints and apexes) is written to the disk in a file called
  381.        "FILENAME".VAR where "FILENAME" is the name you chose. The code
  382.        creates arrays that are filled upon reading the variables from
  383.        the disk. There is but one general membership test that works with
  384.        all function shapes. FuzzGen output source code is fully commented
  385.        such that you should be able to be able to read it without
  386.        difficulty. We think that you'll want code you can read cleanly
  387.        rather than highly optimised code that can be difficult to decipher.
  388.  
  389.  
  390.  
  391.        FUZZGEN DISTRIBUTION:
  392.        
  393.        FuzzGen evaluation version 1.10 is a program that will hopefully
  394.        give you enough of a taste of Fuzzy programming that you'll want
  395.        to give serious consideration to ordering FuzzGen II, which is
  396.        the enhanced retail version of this product.
  397.  
  398.        FuzzGen II Features:
  399.  
  400.        * Printed documentation with some more techniques and hints.
  401.        * Source code optimisation
  402.        * other features as we can add them
  403.   
  404.        FuzzGen is a shareware product, meaning that it has been released
  405.        in a functional format for BBS and disk vendor distribution.
  406.  
  407.  
  408.  
  409.        LEGAL STUFF:
  410.  
  411.        Shareware distribution sometimes is misunderstood. For instance,
  412.        FuzzGen is NOT public domain. It is a copyrighted product wholly
  413.        owned by Alston Software Labs, and licensees (as in standard retail
  414.        software) may use FuzzGen to create source code. Although we do not
  415.        charge any sort of royalty license to use FuzzGen generated source
  416.        code in your programs, you are strictly forbidden to use Fuzzgen 
  417.        code in your programs if you haven't paid for the product. Sorry,
  418.        but any money you paid to get a copy of this program from a vendor
  419.        or other source did not give you any rights to FuzzGen. 
  420.  
  421.         
  422.  
  423.        INDUSTRY STANDARD DISCLAIMER:
  424.  
  425.        FuzzGen evaluation version 1.0 is supplied as-is with no warranty
  426.        whatsoever with regard to merchanability or fitness for purpose.
  427.        Alston Software Labs assumes no responsibility for any consequenses
  428.        of use or misuse of this program.
  429.  
  430.        
  431.  
  432.        HOW TO ORDER:
  433.  
  434.        Product purchase comes in 2 forms: You may elect to "register" 
  435.        FuzzGen as-is for $15, at which point we'll send you a fully
  436.        licensed copy of FuzzGen minus the "Evaluation Copy" tags present
  437.        in this copy. For $25, you may purchase FuzzGen II, which contains
  438.        the added features outlined above. Either payment method will 
  439.        license you to be a registered user with rights to use the source
  440.        code produced by FuzzGen (or FuzzGen II) in your programs without
  441.        any royalty.
  442.  
  443.        Please use WINDOWS NOTEPAD or a similar editor to open ORDER.FRM
  444.        to be able to print the order form / invoice. You'll need to call
  445.        or Fax us for Site License information.
  446.  
  447.  
  448.  
  449.        IN CLOSING:
  450.  
  451.        We sincerely hope you'll be able to learn something from FuzzGen,
  452.        even if you don't order it. We encourage you to pass this product
  453.        on to associates, employees, and other interested parties. 
  454.        (providing, of course, that you charge no fee for it.)    
  455.  
  456.        If you have suggestions for improvement of FuzzGen, we'd sure like
  457.        to hear from you. Our aim is to produce a truly useful Fuzzy Logic
  458.        generator at the lowest possible end-user cost, and we're always
  459.        looking for ways to improve our product line. Speaking of product
  460.        lines, you can see what other ASL products are available by 
  461.        browsing the CATALOG.DOC file using NOTEPAD or a similar tool. 
  462.        
  463.  
  464.        Alston Software Labs
  465.        1320 Standiford Ave #242
  466.        Modesto CA 95350  USA
  467.        
  468.        Phone (209) LAB - 8666
  469.        FAX   (209) 522 - 8666
  470.        BBS   (209) 526 - 9987   ASL Home BBS
  471.  
  472.        Call The Programmer's Retreat (209) 526 - 9987 for the latest
  473.        updates. Log on and type ASL for the password to access the
  474.        Alston Software Labs section.
  475.  
  476.         
  477.