home *** CD-ROM | disk | FTP | other *** search
-
-
-
- F U Z Z G E N
-
- Fuzzy Logic Source Code Generator
-
- Evaluation Version 1.10
-
-
-
- U S E R G U I D E
-
-
-
- INTRODUCTION:
-
- As programmers, many of us have heard the terms NEURAL NETWORKS
- and FUZZY LOGIC bandied about over the last couple of years. The
- odd thing is that very few of us that write code on a daily basis
- really have a handle on what these things mean.
-
- Fuzzy Logic is a decision making method for computers. It has
- taken many years for the merits of Fuzzy Logic to become clear.
- One of the reasons is the name: people hear "Fuzzy Logic" and
- immediately assume that it is imprecise. Actually, it is the
- other way around -- Fuzzy Logic allows FOR imprecision in the
- input in making a precise decision.
-
- The idea that Fuzzy Logic is suited only to microcontroller
- applications such as flow controllers and such is also quite
- misleading. It is suitable for a wide variety of applications.
-
- Fuzzy Logic also allows for perspective to change without having
- to completely recode massive programs. For instance, if you have
- a program like a battle simulation that takes factors such as
- the effect of heat into account on the troops, the perspective
- of HOT changes depending on the origin of the troops. Swedish or
- Russian troops may see 80 degrees F as hot, whereas troops from
- countries nearer the equator see 100 degrees as hot and 80
- degrees as mild. Being able to make this decision in a "Fuzzy"
- manner means that you can read in the control variables as needed
- and still guarantee the integrity of a decision made by the
- program.
-
- FuzzGen is a program intended to introduce you to Fuzzy concepts
- and allow you to create Fuzzy decision sets for your own programs.
- It allows you to graphically model the decision process to aid in
- visualising a decision. It also produces source code in PASCAL,
- BASIC, or C so that you can incorporate Fuzzy decision making in
- your programs. It is intended to save time so that you do not need
- to keep coding IF - THEN - ELSE blocks to make decisions in your
- programs. Essentially, FuzzGen is a CASE tool that is additionally
- educational in that it will introduce many of you to new concepts.
-
-
- BASIC CONCEPTS:
-
- Fuzzy Logic is a little like the "new math" some of us were taught
- (starting in the late 60's and early 70's in most districts) in
- school. Fuzzy Logic uses the concept of SETS and membership. What
- this means is that a data point is seen as either being a set
- member or not, and more importantly, HOW MUCH of a member. Using
- triangular and trapezoidal shapes to model data allows you to plot
- a data point on a slope. Rather than exclusively dealing with YES/NO,
- you can deal with "65%" or "32%" membership. In essence, you can
- say that data point X is a Y% member of data set Z. This allows you
- to have much more control over input data variance, as we can
- immediately see exactly where input data lies.
-
- The different shapes are collectively known as MEMBERSHIP FUNCTIONS.
-
- This allows for a different way to code than what you're used to.
- (By the way, we'll be using code fragments done in C to illustrate
- points as we go along.) For instance, here's how you may code for
- a variable input in standard ways:
-
- if(INPUT_DATA <= .1)
- we_do_this();
- else if(INPUT_DATA > .1 && INPUT_DATA <= .2)
- we_do_that();
- else if(INPUT_DATA > .2 && INPUT_DATA <= .3)
- do_something_else();
- // AND SO ON...
-
- Fuzzy Logic tends to compartmentalise things. Therefore, instead
- of a big IF-ELSE construct, you could use the following:
-
- int i, SetNumber;
- double testval, setpctg = 0;
-
- for(i = 0; i < NumOfSets; i++){ // loop
- testval = InSet(i, INPUT_DATA); // is data in the set?
- if(testval > setpctg){ // if so,
- setpctg = testval; // reset high pctg marker
- SetNumber = i; // and record which set.
- }
- }
- do_whatever_we_need_done(SetNumber);
-
-
- What the above code does is record the set with the highest
- membership percentage so that we have a variable that shows what
- set the data is in and also what action to take. At first blush,
- this may not seem any better than the "old" way using the large
- IF-ELSE construct. However, if you stop and think about it, you
- have more control with the second method. Sure, we could change
- the test points to variables in both cases, but the second method
- does not need to be recompiled if you change your mind about the
- number of tests to make. This is provided by variable NumOfSets.
- Now, using the Fuzzy method, you can read your variable list in
- PLUS you can read in how many tests to take. Sure, you could do
- this yourself with IF-ELSE constructs, but this is easier.
-
- The next step is to make it simpler to model a decision so that
- it is simple to see what is happening.
-
-
- GRAPHICS AND DECISION VISUALISATION:
-
- FuzzGen uses a 2 axis graph to allow you to see data sets and
- their relationships. The Y axis of the graph is used to show
- percentage and ranges from 0 - 100. The X axis is used to show
- the ordinal range of input data values. See figure 1.
-
-
- | 100
- |
- |
- | <---------------- Percentage
- |
- | Ordinal Data
- | |
- | |
- |_0_________________________________________________________
-
- 4 20
-
- -=-=-=-=-=-= 4-20 ma current input =-=-=-=-=-
-
- fig 1
-
-
- Also, to be able to properly plot data values into sets, we use
- shapes to clasiffy them. Common shapes (supported by FuzzGen) are
- Triangular, Trapezoidal, and Square (Boolean.) There is infinite
- variety possible using the Triangular and Trapezoidal shapes.
-
- As an example, we'll now graph out a simple Fuzzy Logic demo that
- shows how to use the graphics and shapes to allow a change of
- perspective. The subject is temperature as seen by a Polar Bear
- and as seen by someone's grandmother.
-
- ______________________60 82_________
- 100 | \ / |
- | \ / |
- P | \ / |
- C | \ / |
- T | C O L D \ / H O T |
- G | \ / |
- | \/ |
- | /\ |
- 0 |____________________________/__\_______________|
- 0 65 70 100
-
- -=-=-=-=TEMPERATURE AS SEEN BY GRANDMA =-=-=-=-
-
- fig 2
-
-
- So, in this scenario, if you wanted to find out what Grandma
- would think of, say, 62 degrees, you would plot along the X
- axis to 62 degrees and find out where the decision data
- intersected the decision shapes at. In this case here, Grandma
- would see 62 degrees as 75% COLD and not HOT at all. (It didn't
- intersect the HOT decision at all.) The COLD decision set uses
- a Trapezoidal shape: anything from 0 - 60 is seen as 100% COLD,
- and at 60 degrees it starts tapering down to 70. HOT also uses
- a trapezoidal shape.
-
-
- _____10 34___________________________
- 100 | \ / |
- | \ / |
- P | \ / |
- C | \ / |
- T | MILD \ / H O T |
- G | \ / |
- | \/ |
- | /\ |
- 0 |__________/__\_________________________________|
- 0 20 25 100
-
- -=-=-=-=TEMPERATURE AS SEEN BY A POLAR BEAR =-=-=-=-
-
- fig 3
-
- On the other hand, we have in this scenario the EXACT SAME
- decision shapes used, but now we see the SAME RANGE of the
- temperature as seen by a Polar Bear. Note that the bear sees
- anything under 10 degrees as MILD, and anything above this as
- getting warmer. Downright HOT starts at 34 degrees.
-
- In these two cases we see the same data being looked at by use
- of Fuzzy Logic decisions to base COLD or HOT on the perspective
- of the viewer. While this is a very simple example, it should
- serve to explain the basic FuzzGen modeling of Fuzzy Logic.
-
-
- USING FUZZGEN:
-
- As the program starts up, it will allow you to either get Help,
- Open a data file, or start a New file. Once you get a filename
- started, you are allowed to SETUP the GRAPH.
-
-
- STEP 1: SET UP THE GRAPH BASICS
-
- In the graph setup, you may want to put a label on the X axis
- so that viewing of the graph is a little clearer. You can also
- optionally put tickmarks and Major Tickmarks along the X axis
- so that it is easier to see where a decision is intersected.
- You'll also need to specify the unit range of input data, which
- is required. For instance, if your input data is in degrees
- Farenheight, your range may be (like our example) 0 - 100. On
- the other hand, you may want to create code that reads a hardware
- current loop device from 4 - 20 milliamps. In other words, the
- range used is up to you and your application. The last thing to
- do is tell FuzzGen how many functions it will need to work with.
- You may use up to 10 in this evaluation version.
-
- All of these settings can be changed later, such as changing your
- mind about how many functions are needed and so on.
-
-
- STEP 2: ADD MEMBERSHIP FUNCTIONS
-
- You'll need to access SETUP | MEMBERSHIPS. This window allows you
- to choose a general function shape by clicking the associated option
- button. You can "fine-tune" the triangular and trapezoidal shapes
- by clicking the picture underneath the option button. Each click
- will cause the picture to cycle through the possible shapes.
-
- As you click the option buttons denoting shape, the data input
- boxes denoting major hinge points of the shape (i.e. endpoints
- and apexes) will change to reflect the number of inputs this
- shape will need: Boolean - 2, Trapezoidal - 4, Triangular - 3.
- These data input boxes allow for full double-precision data, so
- you're not limited to integer based decision-making.
-
- Once you decide on a basic shape, you can enter the data. FuzzGen
- may sometimes disallow your input and warn you to that effect. If
- this happens, look at the basic shape picture to see if it allows
- you to do what you want. In general, the shapes that do not have
- a straight side have the ability to place the apex hinge points
- anywhere you want.
-
- Next, you should pick a "Tag colour" by clicking the little box
- with a colour in it. This allows you to pick a colour so that
- when the graph is drawn it is easier to associate the particular
- membership function with a colour.
-
- Once these items are in order, you should click the RECORD button
- to record the input. You can then select a new decision to enter
- or edit data for by clicking the LEFT-RIGHT buttons in the lower
- right. Above the buttons is a label showing you what decision
- you are working on (numbered) such as "1 of 4."
-
- At any time, you can access HELP by clicking the HELP button.
- The HELP window shows you the basics of working with the functions
- and shapes. As you get more accustomed to working with FuzzGen,
- you'll rely on this a little less.
-
- Once you have essentially defined the membership function shapes, we
- can then proceed to the next step.
-
-
- STEP 3: MODELING
-
- You should now exit from the SETUP MEMBERSHIPS window by clicking
- the CANCEL button. On the main FuzzGen window, click the GRAPH
- button. Your graph and membership functions are shown. You may at
- this time elect to go back to SETUP GRAPH or SETUP MEMBERSHIPS to
- fine tune your model. In this sense, FuzzGen is interactive in
- that you can make an adjustment and come back to click the GRAPH
- button to see what the change looks like.
-
-
- STEP 4: GENERATE SOURCE CODE
-
- The LANGUAGE menu allows you to select a source language to use
- by clicking the language of choice so that it becomes "checked."
-
- If you are satisfied that your application is correctly done (i.e.
- the graph seems to reflect what you're after) and the language
- source is correct, go back to the LANGUAGE menu and select the
- GENERATE CODE menu item. This will output a file with the appropriate
- extension added to the name of your data file. For example, if
- you are working with filename DUMMY, here's the source files that
- would be generated depending on your language of choice:
-
- C ------- DUMMY.C
- PASCAL -- DUMMY.PAS
- BASIC --- DUMMY.BAS
-
-
- STEP 5: FUZZY RULES
-
- FuzzGen allows you the ability to create a rule base. Essentially,
- a rule base is pseudocode based on a simple IF-THEN construct
- and names for the membership functions. In the SETUP MEMBERSHIPS
- window, note that you can give each function shape a unique name.
- In SETUP RULES, you can also specify a series of named output
- states. The fuzzy rules should be able to specify the output state
- based on input states. Also note that the input and output is named
- as well. This allows you to have an input datum, for instance,
- that is tested in the membership functions and called TEMPERATURE.
- Let's also assume an output state named HEATER. Here's how a fuzzy
- rule would look:
-
- if TEMPERATURE is HIGH then HEATER is <output state of choice>
- ^ ^ ^ ^
- | | | |
- datum function name output name named state of output
-
- This is a distillation of:
-
- If the input datum is a member of the function named HIGH then the
- corresponding output state is --
-
- You can also use boolean functions in fuzzy rules:
-
- if (TEMPERATURE is HIGH or TEMPERATURE is MEDIUM_HIGH) and...
-
- As you can see, the fuzzy rules try to distill a body of knowledge
- about a decision making process into a simple set of plain english
- rules.
-
- As of yet (November 1992) we don't yet have a fully coded rulebase
- code generator, so the final implementation of your fuzzy code
- will need to be a copy of your rulebase that you write. In practice
- this takes very little time since the actual working code looks
- almost exactly like the rulebase. We're hoping to have rulebase
- code generation installed by (version 2.0) summer 1993.
-
-
- STEP 6: DOCUMENTATION
-
- We've included a small text editor (click the WRITING icon button)
- which you can use to add any pertinent notes to. You can use this
- to outline the decision process as required, and you can also
- import additional text from other files. The standard copy/paste
- functions are included and work like any other Windows product --
- select the text to manipluate by clicking the mouse and dragging
- until all text is highlighted. You can have up to 32k of program
- documentation in this editor file. The documentation file is
- saved as FILENAME.DOC using the DOC extension.
-
- As you know, good programming practice is often less about code
- than describing and documenting the problem to be solved using
- the code. We suggest you keep a good set of notes and use the
- editor to store them in.
-
-
- STEP 8: DONE?
-
- Unless you have any second thoughts about the decision modeling,
- you are pretty much done with FuzzGen at this point. You should
- SAVE the data file you are working with for later recall. In the
- FILE menu, select SAVE or SAVE AS. SAVE AS will ask you for a new
- name to save under (other than the one you used). It will save in
- the current data file directory.
-
-
-
- UNDERSTANDING FUZZGEN SOURCE CODE:
-
- Essentially, the code example we used earlier is a good idea of
- what the output source looks like. Each function variable (i.e.
- enpoints and apexes) is written to the disk in a file called
- "FILENAME".VAR where "FILENAME" is the name you chose. The code
- creates arrays that are filled upon reading the variables from
- the disk. There is but one general membership test that works with
- all function shapes. FuzzGen output source code is fully commented
- such that you should be able to be able to read it without
- difficulty. We think that you'll want code you can read cleanly
- rather than highly optimised code that can be difficult to decipher.
-
-
-
- FUZZGEN DISTRIBUTION:
-
- FuzzGen evaluation version 1.10 is a program that will hopefully
- give you enough of a taste of Fuzzy programming that you'll want
- to give serious consideration to ordering FuzzGen II, which is
- the enhanced retail version of this product.
-
- FuzzGen II Features:
-
- * Printed documentation with some more techniques and hints.
- * Source code optimisation
- * other features as we can add them
-
- FuzzGen is a shareware product, meaning that it has been released
- in a functional format for BBS and disk vendor distribution.
-
-
-
- LEGAL STUFF:
-
- Shareware distribution sometimes is misunderstood. For instance,
- FuzzGen is NOT public domain. It is a copyrighted product wholly
- owned by Alston Software Labs, and licensees (as in standard retail
- software) may use FuzzGen to create source code. Although we do not
- charge any sort of royalty license to use FuzzGen generated source
- code in your programs, you are strictly forbidden to use Fuzzgen
- code in your programs if you haven't paid for the product. Sorry,
- but any money you paid to get a copy of this program from a vendor
- or other source did not give you any rights to FuzzGen.
-
-
-
- INDUSTRY STANDARD DISCLAIMER:
-
- FuzzGen evaluation version 1.0 is supplied as-is with no warranty
- whatsoever with regard to merchanability or fitness for purpose.
- Alston Software Labs assumes no responsibility for any consequenses
- of use or misuse of this program.
-
-
-
- HOW TO ORDER:
-
- Product purchase comes in 2 forms: You may elect to "register"
- FuzzGen as-is for $15, at which point we'll send you a fully
- licensed copy of FuzzGen minus the "Evaluation Copy" tags present
- in this copy. For $25, you may purchase FuzzGen II, which contains
- the added features outlined above. Either payment method will
- license you to be a registered user with rights to use the source
- code produced by FuzzGen (or FuzzGen II) in your programs without
- any royalty.
-
- Please use WINDOWS NOTEPAD or a similar editor to open ORDER.FRM
- to be able to print the order form / invoice. You'll need to call
- or Fax us for Site License information.
-
-
-
- IN CLOSING:
-
- We sincerely hope you'll be able to learn something from FuzzGen,
- even if you don't order it. We encourage you to pass this product
- on to associates, employees, and other interested parties.
- (providing, of course, that you charge no fee for it.)
-
- If you have suggestions for improvement of FuzzGen, we'd sure like
- to hear from you. Our aim is to produce a truly useful Fuzzy Logic
- generator at the lowest possible end-user cost, and we're always
- looking for ways to improve our product line. Speaking of product
- lines, you can see what other ASL products are available by
- browsing the CATALOG.DOC file using NOTEPAD or a similar tool.
-
-
- Alston Software Labs
- 1320 Standiford Ave #242
- Modesto CA 95350 USA
-
- Phone (209) LAB - 8666
- FAX (209) 522 - 8666
- BBS (209) 526 - 9987 ASL Home BBS
-
- Call The Programmer's Retreat (209) 526 - 9987 for the latest
- updates. Log on and type ASL for the password to access the
- Alston Software Labs section.
-
-
-