1. INTRODUCTION TO FUZZY LOGIC TOOLBOX

Contents

Each work team will create a directory named representatively, in which to save all the results from the exercises (Matlab scripts and a Word file with the numerical and graphical results).

Objective

Functions and graphical interfaces

The functions and graphical interfaces are divided into six categories, as follows:

In order to visualize the available functions and graphical interfaces in Matlab, type the following in the command line:

 close all % close all open windows
 clear all % delete all the variables from the workspace
 clc       % clear the command line
 help fuzzy
  Fuzzy Logic Toolbox
  Version 2.2.11 (R2010a) 25-Jan-2010
 
  GUI editors
    anfisedit  - ANFIS training and testing UI tool.
    findcluster- Clustering UI tool.
    fuzzy      - Basic FIS editor.
    mfedit     - Membership function editor.
    ruleedit   - Rule editor and parser.
    ruleview   - Rule viewer and fuzzy inference diagram.
    surfview   - Output surface viewer.
 
  Membership functions.
    dsigmf     - Difference of two sigmoid membership functions.
    gauss2mf   - Two-sided Gaussian curve membership function.
    gaussmf    - Gaussian curve membership function.
    gbellmf    - Generalized bell curve membership function.
    pimf       - Pi-shaped curve membership function.
    psigmf     - Product of two sigmoid membership functions.
    smf        - S-shaped curve membership function.
    sigmf      - Sigmoid curve membership function.
    trapmf     - Trapezoidal membership function.
    trimf      - Triangular membership function.
    zmf        - Z-shaped curve membership function.
 
  Command line FIS functions
    addmf      - Add membership function to FIS
    addrule    - Add rule to FIS.
    addvar     - Add variable to FIS.
    defuzz     - Defuzzify membership function.
    evalfis    - Perform fuzzy inference calculation.
    evalmf     - Generic membership function evaluation.
    gensurf    - Generate FIS output surface.
    getfis     - Get fuzzy system properties.
    mf2mf      - Translate parameters between functions.
    newfis     - Create new FIS.
    parsrule   - Parse fuzzy rules.
    plotfis    - Display FIS input-output diagram.
    plotmf     - Display all membership functions for one variable.
    readfis    - Load FIS from disk.
    rmmf       - Remove membership function from FIS.
    rmvar      - Remove variable from FIS.
    setfis     - Set fuzzy system properties.
    showfis    - Display annotated FIS.
    showrule   - Display FIS rules.
    writefis   - Save FIS to file.
 
  Advanced techniques
    anfis      - Training routine for Sugeno-type FIS (MEX only).
    fcm        - Find clusters with fuzzy c-means clustering.
    genfis1    - Generate FIS matrix using generic method.
    genfis2    - Generate FIS matrix using subtractive clustering.
    subclust   - Estimate cluster centers with subtractive clustering.
 
  Miscellaneous functions
    convertfis - Convert v1.0 fuzzy matrix to v2.0 fuzzy structure.
    discfis    - Discretize a fuzzy inference system.
    evalmmf    - For multiple membership functions evaluation.
    fstrvcat   - Concatenate matrices of varying size.
    fuzarith   - Fuzzy arithmatic function.
    findrow    - Find the rows of a matrix that match the input string.
    genparam   - Generates initial premise parameters for ANFIS learning.
    probor     - Probabilistic OR.
    sugmax     - Maximum output range for a Sugeno system.
 
  GUI helper files
    cmfdlg     - Add customized membership function dialog.
    cmthdlg    - Add customized inference method dialog.
    fisgui     - Generic GUI handling for the Fuzzy Logic Toolbox
    gfmfdlg    - Generate fis using grid partition method dialog.
    mfdlg      - Add membership function dialog.
    mfdrag     - Drag membership functions using mouse.
    popundo    - Pull the last change off the undo stack.
    pushundo   - Push the current FIS data onto the undo stack.
    savedlg    - Save before closing dialog.
    statmsg    - Display messages in a status field.
    updtfis    - Update Fuzzy Logic Toolbox GUI tools.
    wsdlg      - Open from/save to workspace dialog.


fuzzy is both a directory and a function.

 FUZZY  Basic FIS editor.
    The FIS Editor displays high-level information about a 
    Fuzzy Inference System. At the top is a diagram of the 
    system with each input and output clearly labeled. By 
    double-clicking on the input or output boxes, you can bring 
    up the Membership Function Editor. Double-clicking on the 
    fuzzy rule box in the center of the diagram will bring up 
    the Rule Editor.                     
                                                 
    Just below the diagram is a text field that displays the 
    name of the current FIS. In the lower left of the window are 
    a series of popup menus that allow you to specify the various 
    functions used in the fuzzy implication process. In the lower 
    right are fields that provide information about the current 
    variable. The current variable is determined by clicking once
    on one of the input or output boxes.
 
    See also MFEDIT, RULEEDIT, RULEVIEW, SURFVIEW, ANFISEDIT.

    Reference page in Help browser
       doc fuzzy

Working with the functions

In order to see how the functions work, type "help [function_name]" in the command line. For example, for the "trimf" function, you will type:

help trimf
 TRIMF Triangular membership function.
    TRIMF(X, PARAMS) returns a matrix which is the triangular
    membership function evaluated at X. PARAMS = [A B C] is a 3-element
    vector that determines the break points of this membership function.
    Usually we require A <= B <= C.
 
    Note that this MF always has a height of unity. To have a triangular
    MF with a height less than unity, use TRAPMF instead.
 
    For example:
 
        x = (0:0.2:10)';
        y1 = trimf(x, [3 4 5]);
        y2 = trimf(x, [2 4 7]);
        y3 = trimf(x, [1 4 9]);
        subplot(211), plot(x, [y1 y2 y3]);
        y1 = trimf(x, [2 3 5]);
        y2 = trimf(x, [3 4 7]);
        y3 = trimf(x, [4 5 9]);
        subplot(212), plot(x, [y1 y2 y3]);
        set(gcf, 'name', 'trimf', 'numbertitle', 'off');
 
    See also DSIGMF, EVALMF, GAUSS2MF, GAUSSMF, GBELLMF, MF2MF, PIMF, PSIGMF,
    SIGMF, SMF, TRAPMF, ZMF.

    Reference page in Help browser
       doc trimf

Explore the information given by Matlab about working with this function

Exercise 1

Run the example presented in the "trimf" function help. Use "copy and paste" for the entire sequence. Analyze what happens, line by line.

Remember: you can always use "help [function_name]" to view details about any function.

Exercise 2

Re - run Exercise 1 for any other function in the "Membership functions" group.

Launching the graphical editor for creating a FLS

Type the following in the command line:

fuzzy

Exercise 3

Import an existing FLS in the graphical editor, namely the FLS for computing the tip for a meal at the restaurant. Follow these steps:

Explore the options available from the menus.

Functions for creating/modifying/exploring a FLS from the command line

Load "tip.fis" in the workspace variable "tip" using:

close all
clear all
clc
tip = readfis ('tip.fis');

Use the following command to see the existing workspace variables:

who
Your variables are:

tip  

Use the following command to see the properties of the fuzzy system:

getfis(tip)
      Name      = tip
      Type      = mamdani
      NumInputs = 2
      InLabels  = 
            service
            food
      NumOutputs = 1
      OutLabels = 
            tip
      NumRules = 3
      AndMethod = min
      OrMethod = max
      ImpMethod = min
      AggMethod = max
      DefuzzMethod = centroid

ans =

tip

Use the following command to display the fuzzy system's diagram:

plotfis(tip)

Use the following command to display the control surface generated by the fuzzy system:

gensurf(tip)

Use "newfis" to create a new fuzzy system. For additional information, type:

help newfis
 NEWFIS Create new FIS.
    FIS=NEWFIS(FISNAME) creates a new Mamdani-style FIS structure
 
    FIS=NEWFIS(FISNAME, FISTYPE) creates a FIS structure for a Mamdani or 
    Sugeno-style system with the name FISNAME.
 
    FIS=NEWFIS(FISNAME, FISTYPE, andMethod, orMethod, impMethod, ...
               aggMethod, defuzzMethod)
    specifies the methods for AND, OR, implication, aggregation, and 
    defuzzification, respectively.
 
    See Also
        readfis, writefis
 
    Kelly Liu 4-5-96 
    Copyright 1994-2003 The MathWorks, Inc.
    $Revision: 1.18.2.2 $  $Date: 2004/04/10 23:15:32 $

    Reference page in Help browser
       doc newfis

Fuzzy systems in Simulink

In order to see how a fuzzy system behaves in Simulink, load the model, "tip_sim.mdl", by typing the following sequence in the command line:

close all
clear all
clc
tip = readfis ('tip.fis');

tip_sim;

The model consists of:

To run the model, press the "Run" button from the toolbar, or type the following command:

sim('tip_sim.mdl');

Exercise 4

Change the values for "food" and/or "service", and notice how they influence the value of the tip.

Note: the values for "food" and "service" must be between 0 and 10.

Use the mouse to modify the values for "food" and "service" from the rule viewer window. The value of the tip will change consequently.

The control surface (graphical representation of the output variable (tip) as a function of the two input variables (service, food)) generated by the FLS can be displayed.

To that effect, form the Rule Viewer window use the menu "View - Surface".