Visualization
Programming
Fuzzy Logic Toolbox
For Use with MATLAB
User s Guide
Version 2
How to Contact The MathWorks:
5086477000 Phone
5086477001 Fax
The Mat hWor ks, Inc. Mail
24 Pr ime Par k Way
Nat ick, MA 017601500
http://www.mathworks.com Web
ftp.mathworks.com Anonymous FTP ser ver
comp.softsys.matlab Newsgr oup
support@mathworks.com Technical suppor t
suggest@mathworks.com Pr oduct enhancement suggest ions
bugs@mathworks.com Bug r epor t s
doc@mathworks.com Document at ion er r or r epor t s
subscribe@mathworks.com Subscr ibing user r egist r at ion
service@mathworks.com Or der st at us, license r enewals, passcodes
info@mathworks.com Sales, pr icing, and gener al infor mat ion
Fuzzy Logic Toolbox Users Guide
COPYRIGHT 1995  1999 by The Mat hWor ks, Inc.
The soft war e descr ibed in t his document is fur nished under a license agr eement . The soft war e may be used
or copied only under t he t er ms of t he license agr eement . No par t of t his manual may be phot ocopied or r epr o
duced in any for m wit hout pr ior wr it t en consent fr om The Mat hWor ks, Inc.
U.S. GOVERNMENT: If Licensee is acquir ing t he Pr ogr ams on behalf of any unit or agency of t he U.S.
Gover nment , t he following shall apply: (a) For unit s of t he Depar t ment of Defense: t he Gover nment shall
have only t he r ight s specified in t he license under which t he commer cial comput er soft war e or commer cial
soft war e document at ion was obt ained, as set for t h in subpar agr aph (a) of t he Right s in Commer cial
Comput er Soft war e or Commer cial Soft war e Document at ion Clause at DFARS 227.72023, t her efor e t he
r ight s set for t h her ein shall apply; and (b) For any ot her unit or agency: NOTICE: Not wit hst anding any
ot her lease or license agr eement t hat may per t ain t o, or accompany t he deliver y of, t he comput er soft war e
and accompanying document at ion, t he r ight s of t he Gover nment r egar ding it s use, r epr oduct ion, and disclo
sur e ar e as set for t h in Clause 52.22719 (c)(2) of t he FAR.
MATLAB, Simulink, St at eflow, Handle Gr aphics, and RealTime Wor kshop ar e r egist er ed t r ademar ks and
Tar get Language Compiler ar e t r ademar ks of The Mat hWor ks, Inc.
Ot her pr oduct or br and names ar e t r ademar ks or r egist er ed t r ademar ks of t heir r espect ive holder s.
Pr int ing Hist or y: J anuar y 1995 Fir st pr int ing
Apr il 1997 Second pr int ing
J anuar y 1998 Thir d pr int ingRevised for MATLAB 5.2
J anuar y 1999 Minor r evisions for Release 11 (Online only)
PHONE
FAX
u
MAIL
INTERNET
@
Forward
The past few year s have wit nessed a r apid gr owt h in t he number and var iet y
of applicat ions of fuzzy logic. The applicat ions r ange fr om consumer pr oduct s
such as camer as, camcor der s, washing machines, and micr owave ovens t o
indust r ial pr ocess cont r ol, medical inst r ument at ion, decisionsuppor t syst ems,
and por t folio select ion.
To under st and t he r easons for t he gr owing use of fuzzy logic it is necessar y,
fir st , t o clar ify what is meant by fuzzy logic.
Fuzzy logic has t wo differ ent meanings. In a nar r ow sense, fuzzy logic is a
logical syst em, which is an ext ension of mult ivalued logic. But in a wider
sensewhich is in pr edominant use t odayfuzzy logic (FL) is almost
synonymous wit h t he t heor y of fuzzy set s, a t heor y which r elat es t o classes of
object s wit h unshar p boundar ies in which member ship is a mat t er of degr ee.
In t his per spect ive, fuzzy logic in it s nar r ow sense is a br anch of FL. What is
impor t ant t o r ecognize is t hat , even in it s nar r ow sense, t he agenda of fuzzy
logic is ver y differ ent bot h in spir it and subst ance fr om t he agendas of
t r adit ional mult ivalued logical syst ems.
In t he Fuzzy Logic Toolbox, fuzzy logic should be int er pr et ed as FL, t hat is,
fuzzy logic in it s wide sense. The basic ideas under lying FL ar e explained ver y
clear ly and insight fully in t he Int r oduct ion. What might be added is t hat t he
basic concept under lying FL is t hat of a linguist ic var iable, t hat is, a var iable
whose values ar e wor ds r at her t han number s. In effect , much of FL may be
viewed as a met hodology for comput ing wit h wor ds r at her t han number s.
Alt hough wor ds ar e inher ent ly less pr ecise t han number s, t heir use is closer t o
human int uit ion. Fur t her mor e, comput ing wit h wor ds exploit s t he t oler ance
for impr ecision and t her eby lower s t he cost of solut ion.
Anot her basic concept in FL, which plays a cent r al r ole in most of it s
applicat ions, is t hat of a fuzzy ift hen r ule or , simply, fuzzy r ule. Alt hough
r ulebased syst ems have a long hist or y of use in AI, what is missing in such
syst ems is a machiner y for dealing wit h fuzzy consequent s and/or fuzzy
ant ecedent s. In fuzzy logic, t his machiner y is pr ovided by what is called t he
calculus of fuzzy r ules. The calculus of fuzzy r ules ser ves as a basis for what
might be called t he Fuzzy Dependency and Command Language (FDCL).
Alt hough FDCL is not used explicit ly in Fuzzy Logic Toolbox, it is effect ively
one of it s pr incipal const it uent s. In t his connect ion, what is impor t ant t o
Forward
r ecognize is t hat in most of t he applicat ions of fuzzy logic, a fuzzy logic solut ion
is in r ealit y a t r anslat ion of a human solut ion int o FDCL.
What makes t he Fuzzy Logic Toolbox so power ful is t he fact t hat most of
human r easoning and concept for mat ion is linked t o t he use of fuzzy r ules. By
pr oviding a syst emat ic fr amewor k for comput ing wit h fuzzy r ules, t he Fuzzy
Logic Toolbox gr eat ly amplifies t he power of human r easoning. Fur t her
amplificat ion r esult s fr om t he use of MATLAB and gr aphical user int er faces
ar eas in which The Mat hWor ks has unpar alleled exper t ise.
A t r end which is gr owing in visibilit y r elat es t o t he use of fuzzy logic in
combinat ion wit h neur ocomput ing and genet ic algor it hms. Mor e gener ally,
fuzzy logic, neur ocomput ing, and genet ic algor it hms may be viewed as t he
pr incipal const it uent s of what might be called soft comput ing. Unlike t he
t r adit ional, har d comput ing, soft comput ing is aimed at an accommodat ion
wit h t he per vasive impr ecision of t he r eal wor ld. The guiding pr inciple of soft
comput ing is: Exploit t he t oler ance for impr ecision, uncer t aint y, and par t ial
t r ut h t o achieve t r act abilit y, r obust ness, and low solut ion cost . In coming
year s, soft comput ing is likely t o play an incr easingly impor t ant r ole in t he
concept ion and design of syst ems whose MIQ (Machine IQ) is much higher t han
t hat of syst ems designed by convent ional met hods.
Among var ious combinat ions of met hodologies in soft comput ing, t he one which
has highest visibilit y at t his junct ur e is t hat of fuzzy logic and neur ocomput ing,
leading t o socalled neur ofuzzy syst ems. Wit hin fuzzy logic, such syst ems play
a par t icular ly impor t ant r ole in t he induct ion of r ules fr om obser vat ions. An
effect ive met hod developed by Dr . Roger J ang for t his pur pose is called ANFIS
(Adapt ive Neur oFuzzy Infer ence Syst em). This met hod is an impor t ant
component of t he Fuzzy Logic Toolbox.
The Fuzzy Logic Toolbox is highly impr essive in all r espect s. It makes fuzzy
logic an effect ive t ool for t he concept ion and design of int elligent syst ems. The
Fuzzy Logic Toolbox is easy t o mast er and convenient t o use. And last , but not
least impor t ant , it pr ovides a r eader fr iendly and upt odat e int r oduct ion t o t he
met hodology of fuzzy logic and it s wider anging applicat ions.
Lot fi A. Zadeh
Ber keley, CA
J anuar y 10, 1995
i
Contents
Before You Begi n
What Is t he Fuzzy Logic Toolbox? . . . . . . . . . . . . . . . . . . . . . . . . . 6
How t o Use This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Inst allat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Typogr aphical Convent ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1
Introducti on
What Is Fuzzy Logic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Why Use Fuzzy Logic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
When Not t o Use Fuzzy Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
What Can t he Fuzzy Logic Toolbox Do? . . . . . . . . . . . . . . . . . . . 16
An Introductory Example: Fuzzy vs. NonFuzzy . . . . . . . . . 18
The NonFuzzy Appr oach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
The Fuzzy Appr oach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Some Obser vat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
2
Tutori al
The Bi g Pi ct ure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Foundati ons of Fuzzy Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Fuzzy Set s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Member ship Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Logical Oper at ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
i i Contents
IfThen Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Fuzzy Inference Syst ems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Dinner for Two, Repr ise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Fuzzy Infer ence Diagr am . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Cust omizat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Bui ldi ng Syste ms wi th t he Fuzzy Logi c Toolbox . . . . . . . . . . 45
Dinner for Two, fr om t he Top . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Get t ing St ar t ed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
The FIS Edit or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
The Member ship Funct ion Edit or . . . . . . . . . . . . . . . . . . . . . . . . . 52
The Rule Edit or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
The Rule Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
The Sur face Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Impor t ing and Expor t ing fr om t he GUI Tools . . . . . . . . . . . . . . . 62
Cust omizing Your Fuzzy Syst em . . . . . . . . . . . . . . . . . . . . . . . . . 63
Worki ng from t he Command Li ne . . . . . . . . . . . . . . . . . . . . . . . 65
Syst em Display Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Building a Syst em fr om Scr at ch . . . . . . . . . . . . . . . . . . . . . . . . . . 70
FIS Evaluat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
The FIS St r uct ur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Worki ng wit h Si muli nk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
An Example: Wat er Level Cont r ol . . . . . . . . . . . . . . . . . . . . . . . . 78
Building Your Own Fuzzy Simulink Models . . . . . . . . . . . . . . . . 83
SugenoType Fuzzy Inference . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
An Example: Two Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
anfi s and the ANFIS Edi tor GUI . . . . . . . . . . . . . . . . . . . . . . . . . 92
A Modeling Scenar io . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Model Lear ning and Infer ence Thr ough ANFIS . . . . . . . . . . . . . 93
Familiar it y Br eeds Validat ion: Know Your Dat a . . . . . . . . . . . . . 94
Some Const r aint s of anfis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
The ANFIS Edit or GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
ANFIS Edit or GUI Example 1:
i i i
Checking Dat a Helps Model Validat ion . . . . . . . . . . . . . . . . . . . 98
ANFIS Edit or GUI Example 2:
Checking Dat a Doesnt Validat e Model . . . . . . . . . . . . . . . . . . 106
anfis fr om t he Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Mor e on anfis and t he ANFIS Edit or GUI . . . . . . . . . . . . . . . . . 114
Fuzzy Clusteri ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Fuzzy CMeans Clust er ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Subt r act ive Clust er ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
St andAlone CCode Fuzzy Inference Engi ne . . . . . . . . . . . . 130
Glos sary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
3
Reference
GUI Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Member ship Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
FIS Dat a St r uct ur e Management . . . . . . . . . . . . . . . . . . . . . . . . 33
Advanced Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Simulink Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
i v Contents
Befor e You Begin
What Is t he Fuzzy Logic Toolbox? . . . . . . . . . . . . . 2
How t o Use This Guide . . . . . . . . . . . . . . . . . 3
Inst allat ion . . . . . . . . . . . . . . . . . . . . . . 3
Typogr aphical Convent ions . . . . . . . . . . . . . . . 4
Before You Begin
6
This sect ion descr ibes how t o use t he Fuzzy Logic Toolbox. It explains how t o
use t his guide and point s you t o addit ional books for t oolbox inst allat ion
infor mat ion.
What Is the Fuzzy Logic Toolbox?
The Fuzzy Logic Toolbox is a collect ion of funct ions built on t he MATLAB
numer ic comput ing envir onment . It pr ovides t ools for you t o cr eat e and edit
fuzzy infer ence syst ems wit hin t he fr amewor k of MATLAB, or if you pr efer you
can int egr at e your fuzzy syst ems int o simulat ions wit h Simulink
, or you can
even build st andalone C pr ogr ams t hat call on fuzzy syst ems you build wit h
MATLAB. This t oolbox r elies heavily on gr aphical user int er face (GUI) t ools t o
help you accomplish your wor k, alt hough you can wor k ent ir ely fr om t he
command line if you pr efer .
The t oolbox pr ovides t hr ee cat egor ies of t ools:
Command line funct ions
Gr aphical, int er act ive t ools
Simulink blocks and examples
The fir st cat egor y of t ools is made up of funct ions t hat you can call fr om t he
command line or fr om your own applicat ions. Many of t hese funct ions ar e
MATLAB Mfiles, ser ies of MATLAB st at ement s t hat implement specialized
fuzzy logic algor it hms. You can view t he MATLAB code for t hese funct ions
using t he st at ement
type function_name
You can change t he way any t oolbox funct ion wor ks by copying and r enaming
t he Mfile, t hen modifying your copy. You can also ext end t he t oolbox by adding
your own Mfiles.
Secondly, t he t oolbox pr ovides a number of int er act ive t ools t hat let you access
many of t he funct ions t hr ough a GUI. Toget her , t he GUI based t ools pr ovide
an envir onment for fuzzy infer ence syst em design, analysis, and
implement at ion.
The t hir d cat egor y of t ools is a set of blocks for use wit h t he Simulink
simulat ion soft war e. These ar e specifically designed for high speed fuzzy logic
infer ence in t he Simulink envir onment .
7
How to Use This Guide
If you are new to fuzzy logi c, begin wit h Chapt er 1, Int r oduct ion. This
chapt er int r oduces t he mot ivat ion behind fuzzy logic and leads you smoot hly
int o t he t ut or ial.
If you are an expe ri enced fuzzy logi c us er, you may want t o st ar t at t he
beginning of Chapt er 2, Tut or ial, t o make sur e you ar e comfor t able wit h t he
fuzzy logic t er minology in t he Fuzzy Logic Toolbox. If you just want an
over view of each gr aphical t ool and examples of specific fuzzy syst em t asks,
t ur n dir ect ly t o t he sect ion in Chapt er 2 ent it led, Building Syst ems wit h t he
Fuzzy Logic Toolbox. This sect ion does not include infor mat ion on t he
adapt ive dat a modeling applicat ion cover ed by t he t oolbox funct ion anfis. The
basic funct ionalit y of t his t ool can be found in t he sect ion in Chapt er 2 ent it led,
anfis and t he ANFIS Edit or GUI.
If you jus t want t o s tart as soon as poss i ble and exper iment , you can open an
example syst em r ight away by t yping
fuzzy tipper
This br ings up t he Fuzzy Infer ence Syst em (FIS) edit or for an example decision
making pr oblem t hat has t o do wit h how t o t ip in a r est aur ant .
All t oolbox user s should use Chapt er 3, Refer ence, for infor mat ion on specific
t ools or funct ions. Refer ence descr ipt ions include a synopsis of t he funct ions
synt ax, as well as a complet e explanat ion of opt ions and oper at ion. Many
r efer ence descr ipt ions also include helpful examples, a descr ipt ion of t he
funct ions algor it hm, and r efer ences t o addit ional r eading mat er ial. For
GUIbased t ools, t he descr ipt ions include opt ions for invoking t he t ool.
Installation
To inst all t his t oolbox on a wor kst at ion or a lar ge machine, see t he Installation
Guide for UNIX. To inst all t he t oolbox on a PC or Macint osh, see t he
Installation Guide for PC and Macintosh.
To det er mine if t he Fuzzy Logic Toolbox is alr eady inst alled on your syst em,
check for a subdir ect or y named fuzzy wit hin t he main t oolbox dir ect or y or
folder .
Before You Begin
8
Typographical Conventions
To Indicate This Guide Uses Example
Example code Monospace type
(Use Code tag.)
To assign t he value 5 t o A,
ent er
A = 5
Funct ion
names
Monospace type
(Use Code tag.)
The cos funct ion finds t he
cosine of each ar r ay
element .
Funct ion
synt ax
Monospace type for t ext
t hat must appear as
shown. (Use Code t ag.)
Monospace italics for
component s you can
r eplace wit h any var iable.
(Use Codei tal t ag.)
The magic funct ion uses
t he synt ax
M = magic(n)
Keys Boldface wit h an init ial
capit al let t er
(Use MenuBodytext t ag.)
Pr ess t he Return key.
Mat hemat ical
expr essions
Var iables in italics.
Funct ions, oper at or s, and
const ant s in st andar d
t ype. (Use
Equati onVari ables t ag.)
This vect or r epr esent s t he
polynomial
p = x
2
+ 2x + 3
MATLAB
out put
Monospace type
(Use Code tag.)
MATLAB r esponds wit h
A =
5
9
Menu names,
menu it ems,
and cont r ols
Boldface wit h an init ial
capit al let t er
(Use Me nuBodyte xt t ag.)
Choose t he File menu.
New t er ms NCS italics
(Use Body te xti tal t ag.)
An array is an or der ed
collect ion of infor mat ion.
To Indicate This Guide Uses Example
Before You Begin
10
1
Int r oduct ion
What Is Fuzzy Logic? . . . . . . . . . . . . . . . . 12
Why Use Fuzzy Logic? . . . . . . . . . . . . . . . . 15
When Not t o Use Fuzzy Logic . . . . . . . . . . . . . 16
What Can t he Fuzzy Logic Toolbox Do? . . . . . . . . . 16
An Introductory Example: Fuzzy vs. NonFuzzy . . . . 18
The NonFuzzy Appr oach . . . . . . . . . . . . . . . 19
The Fuzzy Appr oach . . . . . . . . . . . . . . . . . 113
Some Obser vat ions . . . . . . . . . . . . . . . . . . 114
1 Introduction
12
What Is Fuzzy Logic?
Fuzzy logic is all about t he r elat ive impor t ance of pr ecision: How impor t ant is
it t o be exact ly r ight when a r ough answer will do? All books on fuzzy logic
begin wit h a few good quot es on t his ver y t opic, and t his is no except ion. Her e
is what some clever people have said in t he past :
Pr ecision is not t r ut h.
Henr i Mat isse
S ometimes the more measurable drives out the most important.
Ren Dubos
Vagueness is no more to be done away with in the world of logic than friction in
mechanics.
Char les Sander s Peir ce
I believe that nothing is unconditionally true, and hence I am opposed to every
statement of positive truth and every man who makes it.
H. L. Mencken
S o far as the laws of mathematics refer to reality, they are not certain. And so
far as they are certain, they do not refer to reality.
Alber t Einst ein
As complexity rises, precise statements lose meaning and meaningful statements
lose precision.
Lot fi Zadeh
Some pear ls of folk wisdom also echo t hese t hought s:
Dont lose sight of the forest for the trees.
Dont be penny wise and pound foolish.
The Fuzzy Logic Toolbox for use wit h MATLAB is a t ool for solving pr oblems
wit h fuzzy logic. Fuzzy logic is a fascinat ing ar ea of r esear ch because it does a
good job of t r ading off bet ween significance and pr ecisionsomet hing t hat
humans have been managing for a ver y long t ime.
Fuzzy logic somet imes appear s exot ic or int imidat ing t o t hose unfamiliar wit h
it , but once you become acquaint ed wit h it , it seems almost sur pr ising t hat no
one at t empt ed it sooner . In t his sense fuzzy logic is bot h old and new because,
What Is Fuzzy Logic?
13
alt hough t he moder n and met hodical science of fuzzy logic is st ill young, t he
concept s of fuzzy logic r each r ight down t o our bones.
Fuzzy logic is a convenient way t o map an input space t o an out put space. This
is t he st ar t ing point for ever yt hing else, and t he gr eat emphasis her e is on t he
wor d convenient .
What do I mean by mapping input space t o out put space? Her e ar e a few
examples: You t ell me how good your ser vice was at a r est aur ant , and Ill t ell
you what t he t ip should be. You t ell me how hot you want t he wat er , and Ill
adjust t he faucet valve t o t he r ight set t ing. You t ell me how far away t he
subject of your phot ogr aph is, and Ill focus t he lens for you. You t ell me how
fast t he car is going and how har d t he mot or is wor king, and Ill shift t he gear s
for you.
A 1500 kg mass
is approaching
your head at
45.3 m/sec.
LOOK
OUT!!
Precision Significance
Precision and Significance in the Real World
1 Introduction
14
A gr aphical example of an input out put map is shown below.
It s all just a mat t er of mapping input s t o t he appr opr iat e out put s. Bet ween t he
input and t he out put well put a black box t hat does t he wor k. What could go in
t he black box? Any number of t hings: fuzzy syst ems, linear syst ems, exper t
syst ems, neur al net wor ks, differ ent ial equat ions, int er polat ed
mult idimensional lookup t ables, or even a spir it ual advisor , just t o name a few
of t he possible opt ions. Clear ly t he list could go on and on.
Of t he dozens of ways t o make t he black box wor k, it t ur ns out t hat fuzzy is
oft en t he ver y best way. Why should t hat be? As Lot fi Zadeh, who is consider ed
t o be t he fat her of fuzzy logic, once r emar ked: In almost ever y case you can
build t he same pr oduct wit hout fuzzy logic, but fuzzy is fast er and cheaper .
Input Space
(all possible service
quality ratings)
Output Space
(all possible tips)
the right tip
for tonight
tonight's service
quality
An inputoutput map for the tipping problem:
Given the quality of service, how much should I tip?
Black
Box
What Is Fuzzy Logic?
15
Why Use Fuzzy Logic?
Her e is a list of gener al obser vat ions about fuzzy logic.
Fuzzy logic is concept ually easy t o under st and.
The mat hemat ical concept s behind fuzzy r easoning ar e ver y simple. What
makes fuzzy nice is t he nat ur alness of it s appr oach and not it s far r eaching
complexit y.
Fuzzy logic is flexible.
Wit h any given syst em, it s easy t o massage it or layer mor e funct ionalit y on
t op of it wit hout st ar t ing again fr om scr at ch.
Fuzzy logic is t oler ant of impr ecise dat a.
Ever yt hing is impr ecise if you look closely enough, but mor e t han t hat , most
t hings ar e impr ecise even on car eful inspect ion. Fuzzy r easoning builds t his
under st anding int o t he pr ocess r at her t han t acking it ont o t he end.
Fuzzy logic can model nonlinear funct ions of ar bit r ar y complexit y.
You can cr eat e a fuzzy syst em t o mat ch any set of input out put dat a. This
pr ocess is made par t icular ly easy by adapt ive t echniques like ANFIS
(Adapt ive Neur oFuzzy Infer ence Syst ems), which ar e available in t he Fuzzy
Logic Toolbox.
Fuzzy logic can be built on t op of t he exper ience of exper t s.
In dir ect cont r ast t o neur al net wor ks, which t ake t r aining dat a and gener at e
opaque, impenet r able models, fuzzy logic let s you r ely on t he exper ience of
people who alr eady under st and your syst em.
Fuzzy logic can be blended wit h convent ional cont r ol t echniques.
Fuzzy syst ems dont necessar ily r eplace convent ional cont r ol met hods. In
many cases fuzzy syst ems augment t hem and simplify t heir implement at ion.
Fuzzy logic is based on nat ur al language.
The basis for fuzzy logic is t he basis for human communicat ion. This
obser vat ion under pins many of t he ot her st at ement s about fuzzy logic.
The last st at ement is per haps t he most impor t ant one and deser ves mor e
discussion. Nat ur al language, t hat which is used by or dinar y people on a daily
basis, has been shaped by t housands of year s of human hist or y t o be convenient
and efficient . Sent ences wr it t en in or dinar y language r epr esent a t r iumph of
efficient communicat ion. We ar e gener ally unawar e of t his because or dinar y
language is, of cour se, somet hing we use ever y day. Since fuzzy logic is built
1 Introduction
16
at op t he st r uct ur es of qualit at ive descr ipt ion used in ever yday language, fuzzy
logic is easy t o use.
When Not to Use Fuzzy Logic
Fuzzy logic is not a cur eall. When should you not use fuzzy logic? The safest
st at ement is t he fir st one made in t his int r oduct ion: fuzzy logic is a convenient
way t o map an input space t o an out put space. If you find it s not convenient ,
t r y somet hing else. If a simpler solut ion alr eady exist s, use it . Fuzzy logic is t he
codificat ion of common senseuse common sense when you implement it and
you will pr obably make t he r ight decision. Many cont r oller s, for example, do a
fine job wit hout using fuzzy logic. However , if you t ake t he t ime t o become
familiar wit h fuzzy logic, youll see it can be a ver y power ful t ool for dealing
quickly and efficient ly wit h impr ecision and nonlinear it y.
What Can the Fuzzy Logic Toolbox Do?
The Fuzzy Logic Toolbox allows you t o do sever al t hings, but t he most
impor t ant t hing it let s you do is cr eat e and edit fuzzy infer ence syst ems. You
can cr eat e t hese syst ems using gr aphical t ools or commandline funct ions, or
you can gener at e t hem aut omat ically using eit her clust er ing or adapt ive
neur ofuzzy t echniques.
If you have access t o Simulink, you can easily t est your fuzzy syst em in a block
diagr am simulat ion envir onment .
The t oolbox also let s you r un your own st andalone C pr ogr ams dir ect ly,
wit hout t he need for Simulink. This is made possible by a st andalone Fuzzy
Infer ence Engine t hat r eads t he fuzzy syst ems saved fr om a MATLAB session.
What Is Fuzzy Logic?
17
You can cust omize t he st andalone engine t o build fuzzy infer ence int o your
own code. All pr ovided code is ANSI compliant .
Because of t he int egr at ed nat ur e of MATLABs envir onment , you can cr eat e
your own t ools t o cust omize t he Fuzzy Logic Toolbox or har ness it wit h anot her
t oolbox, such as t he Cont r ol Syst em, Neur al Net wor k, or Opt imizat ion Toolbox,
t o ment ion only a few of t he possibilit ies.
Fuzzy
Inference
System
Standalone
Fuzzy Engine
MATLAB
Fuzzy
Logic
Toolbox
Userwritten
Mfiles
Other toolboxes
Simulink
1 Introduction
18
An Introductory Example: Fuzzy vs. NonFuzzy
A specific example would be helpful at t his point . To illust r at e t he value of
fuzzy logic, well show t wo differ ent appr oaches t o t he same pr oblem: linear
and fuzzy. Fir st we will wor k t hr ough t his pr oblem t he convent ional
(nonfuzzy) way, wr it ing MATLAB commands t hat spell out linear and
piecewiselinear r elat ions. Then well t ake a quick look at t he same syst em
using fuzzy logic.
Consider t he t ipping pr oblem: what is t he r ight amount t o t ip your
wait per son? Her e is a clear st at ement of t he pr oblem.
The Basi c Ti ppi ng Proble m. Given a number bet ween 0 and 10 t hat
r epr esent s t he qualit y of ser vice at a r est aur ant (wher e 10 is excellent ), what
should t he t ip be?
Cultural footnote: This pr oblem is based on t ipping as it is t ypically pr act iced
in t he Unit ed St at es. An aver age t ip for a meal in t he U.S. is 15%, t hough t he
act ual amount may var y depending on t he qualit y of t he ser vice pr ovided.
An Introductory Example: Fuzzy vs. NonFuzzy
19
The NonFuzzy Approach
Let s st ar t wit h t he simplest possible r elat ionship. Suppose t hat t he t ip always
equals 15% of t he t ot al bill.
tip = 0.15
This doesnt r eally t ake int o account t he qualit y of t he ser vice, so we need t o
add a new t er m t o t he equat ion. Since ser vice is r at ed on a scale of 0 t o 10, we
might have t he t ip go linear ly fr om 5% if t he ser vice is bad t o 25% if t he ser vice
is excellent . Now our r elat ion looks like t his:
tip=0.20/10*service+0.05
0 2 4 6 8 10
0
0.05
0.1
0.15
0.2
0.25
service
t
i
p
0 2 4 6 8 10
0.05
0.1
0.15
0.2
0.25
service
t
i
p
1 Introduction
110
So far so good. The for mula does what we want it t o do, and it s pr et t y
st r aight for war d. However , we may want t he t ip t o r eflect t he qualit y of t he food
as well. This ext ension of t he pr oblem is defined as follows:
The Extended Tipping Problem. Given t wo set s of number s bet ween 0 and 10
(wher e 10 is excellent ) t hat r espect ively r epr esent t he qualit y of t he ser vice and
t he qualit y of t he food at a r est aur ant , what should t he t ip be?
Let s see how t he for mula will be affect ed now t hat weve added anot her
var iable. Suppose we t r y:
tip = 0.20/20*(service+food)+0.05;
In t his case, t he r esult s look pr et t y, but when you look at t hem closely, t hey
dont seem quit e r ight . Suppose you want t he ser vice t o be a mor e impor t ant
0
5
10
0
5
10
0.05
0.1
0.15
0.2
0.25
service
food
t
i
p
An Introductory Example: Fuzzy vs. NonFuzzy
111
fact or t han t he food qualit y. Let s say t hat t he ser vice will account for 80% of
t he over all t ipping gr ade and t he food will make up t he ot her 20%. Tr y:
servRatio=0.8;
tip=servRatio*(0.20/10*service+0.05) + ...
(1servRatio)*(0.20/10*food+0.05);
The r esponse is st ill somehow t oo unifor mly linear . Suppose you want mor e of
a flat r esponse in t he middle, i.e., you want t o give a 15% t ip in gener al, and
will depar t fr om t his plat eau only if t he ser vice is except ionally good or bad.
This, in t ur n, means t hat t hose nice linear mappings no longer apply. We can
st ill salvage t hings by using a piecewise linear const r uct ion. Let s r et ur n t o t he
onedimensional pr oblem of just consider ing t he ser vice. You can st r ing
t oget her a simple condit ional st at ement using br eakpoint s like t his:
if service<3,
tip=(0.10/3)*service+0.05;
elseif service<7,
tip=0.15;
elseif service<=10,
tip=(0.10/3)*(service7)+0.15;
end
0
5
10
0
5
10
0.05
0.1
0.15
0.2
0.25
service
food
t
i
p
1 Introduction
112
The plot looks like t his.
If we ext end t his t o t wo dimensions, wher e we t ake food int o account again,
somet hing like t his r esult s:
servRatio=0.8;
if service<3,
tip=((0.10/3)*service+0.05)*servRatio + ...
(1servRatio)*(0.20/10*food+0.05);
elseif service<7,
tip=(0.15)*servRatio + ...
(1servRatio)*(0.20/10*food+0.05);
else,
tip=((0.10/3)*(service7)+0.15)*servRatio + ...
(1servRatio)*(0.20/10*food+0.05);
end
0 2 4 6 8 10
0.05
0.1
0.15
0.2
0.25
service
t
i
p
0
5
10
0
5
10
0.05
0.1
0.15
0.2
0.25
service
food
t
i
p
An Introductory Example: Fuzzy vs. NonFuzzy
113
Wow! The plot looks good, but t he funct ion is sur pr isingly complicat ed. It was
a lit t le t r icky t o code t his cor r ect ly, and it s definit ely not easy t o modify t his
code in t he fut ur e. Mor eover , it s even less appar ent how t he algor it hm wor ks
t o someone who didnt wit ness t he or iginal design pr ocess.
The Fuzzy Approach
It would be nice if we could just capt ur e t he essent ials of t his pr oblem, leaving
aside all t he fact or s t hat could be ar bit r ar y. If we make a list of what r eally
mat t er s in t his pr oblem, we might end up wit h t he following r ule descr ipt ions:
1. If service is poor, then tip is cheap
2. If service is good, then tip is average
3. If service is excellent, then tip is generous
The or der in which t he r ules ar e pr esent ed her e is ar bit r ar y. It doesnt mat t er
which r ules come fir st . If we want ed t o include t he foods effect on t he t ip, we
might add t he following t wo r ules:
4. If food is rancid, then tip is cheap
5. If food is delicious, then tip is generous
In fact , we can combine t he t wo differ ent list s of r ules int o one t ight list of t hr ee
r ules like so:
1. If service is poor or the food is rancid, then tip is cheap
2. If service is good, then tip is average
3. If service is excellent or food is delicious, then tip is generous
These t hr ee r ules ar e t he cor e of our solut ion. And coincident ally, weve just
defined t he r ules for a fuzzy logic syst em. Now if we give mat hemat ical
meaning t o t he linguist ic var iables (what is an aver age t ip, for example?) we
would have a complet e fuzzy infer ence syst em. Of cour se, t her es a lot left t o t he
met hodology of fuzzy logic t hat wer e not ment ioning r ight now, t hings like:
How ar e t he r ules all combined?
How do I define mat hemat ically what an aver age t ip is?
These ar e quest ions we pr ovide det ailed answer s t o in t he next few chapt er s.
The det ails of t he met hod dont r eally change much fr om pr oblem t o pr oblem
t he mechanics of fuzzy logic ar ent t er r ibly complex. What mat t er s is what
1 Introduction
114
weve shown in t his pr eliminar y exposit ion: fuzzy is adapt able, simple, and
easily applied.
Her e is t he pict ur e associat ed wit h t he fuzzy syst em t hat solves t his pr oblem.
The pict ur e above was gener at ed by t he t hr ee r ules above. The mechanics of
how fuzzy infer ence wor ks is explained The Big Pict ur e on page 218,
Foundat ions of Fuzzy Logic on page 220, and in Fuzzy Infer ence Syst ems
on page 236. In t he Building Syst ems wit h t he Fuzzy Logic Toolbox on page
245, t he ent ir e t ipping pr oblem is wor ked t hr ough using t he gr aphical t ools in
t he Fuzzy Logic Toolbox.
Some Observations
Her e ar e some obser vat ions about t he example so far . We found a piecewise
linear r elat ion t hat solved t he pr oblem. It wor ked, but it was somet hing of a
nuisance t o der ive, and once we wr ot e it down as code, it wasnt ver y easy t o
int er pr et . On t he ot her hand, t he fuzzy syst em is based on some common
sense st at ement s. Also, we wer e able t o add t wo mor e r ules t o t he bot t om of
t he list t hat influenced t he shape of t he over all out put wit hout needing t o undo
what had alr eady been done. In ot her wor ds, t he subsequent modificat ion was
pr et t y easy.
Mor eover , by using fuzzy logic r ules, t he maint enance of t he st r uct ur e of t he
algor it hm decouples along fair ly clean lines. The not ion of an aver age t ip might
change fr om day t o day, cit y t o cit y, count r y t o count r y, but t he under lying logic
is t he same: if t he ser vice is good, t he t ip should be aver age. You can r ecalibr at e
t he met hod quickly by simply shift ing t he fuzzy set t hat defines aver age
wit hout r ewr it ing t he fuzzy r ules.
0
5
10
0
5
10
0.05
0.1
0.15
0.2
0.25
service
food
t
i
p
An Introductory Example: Fuzzy vs. NonFuzzy
115
You can do t his sor t of t hing wit h list s of piecewise linear funct ions, but t her e
is a gr eat er likelihood t hat r ecalibr at ion will not be so quick and simple.
For example, her e is t he piecewise linear t ipping pr oblem slight ly r ewr it t en t o
make it mor e gener ic. It per for ms t he same funct ion as befor e, only now t he
const ant s can be easily changed.
% Establish constants
lowTip=0.05; averTip=0.15; highTip=0.25;
tipRange=highTiplowTip;
badService=0; okayService=3;
goodService=7; greatService=10;
serviceRange=greatServicebadService;
badFood=0; greatFood=10;
foodRange=greatFoodbadFood;
% If service is poor or food is rancid, tip is cheap
if service<okayService,
tip=(((averTiplowTip)/(okayServicebadService)) ...
*service+lowTip)*servRatio + ...
(1servRatio)*(tipRange/foodRange*food+lowTip);
% If service is good, tip is average
elseif service<goodService,
tip=averTip*servRatio + (1servRatio)* ...
(tipRange/foodRange*food+lowTip);
% If service is excellent or food is delicious, tip is generous
else,
tip=(((highTipaverTip)/ ...
(greatServicegoodService))* ...
(servicegoodService)+averTip)*servRatio + ...
(1servRatio)*(tipRange/foodRange*food+lowTip);
end
Not ice t he t endency her e, as wit h all code, for cr eeping gener alit y t o r ender t he
algor it hm mor e and mor e opaque, t hr eat ening event ually t o obscur e it
complet ely. What wer e doing her e isnt (shouldnt be!) t hat complicat ed. Tr ue,
we can fight t his t endency t o be obscur e by adding st ill mor e comment s, or
per haps by t r ying t o r ewr it e it in slight ly mor e selfevident ways, but t he
medium is not on our side.
1 Introduction
116
The t r uly fascinat ing t hing t o not ice is t hat if we r emove ever yt hing except for
t hr ee comment s, what r emain ar e exact ly t he fuzzy r ules we wr ot e down
befor e:
% If service is poor or food is rancid, tip is cheap
% If service is good, tip is average
% If service is excellent or food is delicious, tip is generous
If, as wit h a fuzzy syst em, t he comment is ident ical wit h t he code, t hink how
much mor e likely your code is t o have comment s! Fuzzy logic let s t he language
t hat s clear est t o you, high level comment s, also have meaning t o t he machine,
which is why it s a ver y successful t echnique for br idging t he gap bet ween
people and machines.
Or t hink of it t his way: by making t he equat ions as simple as possible (linear )
we make t hings simpler for t he machine but mor e complicat ed for us. But
r eally t he limit at ion is no longer t he comput er it s our ment al model of what
t he comput er is doing. We all know t hat comput er s have t he abilit y t o make
t hings hopelessly complex; fuzzy logic is r eally about r eclaiming t he middle
gr ound and let t ing t he machine wor k wit h our pr efer ences r at her t han t he
ot her way ar ound. It s about t ime.
2
Tut or ial
The Bi g Pi ct ure . . . . . . . . . . . . . . . . . . 22
Foundati ons of Fuzzy Logic . . . . . . . . . . . . . 24
Fuzzy Inference Sys te ms . . . . . . . . . . . . . . 220
Buildi ng Systems wi th t he Fuzzy Logi c Toolbox . . . . 229
Worki ng from t he Command Li ne . . . . . . . . . . 249
Worki ng wi th Simuli nk . . . . . . . . . . . . . . . 262
SugenoType Fuzzy Inference . . . . . . . . . . . . 270
anfi s and the ANFIS Edi tor GUI . . . . . . . . . . . 276
Fuzzy Clusteri ng . . . . . . . . . . . . . . . . . 2104
St andAlone CCode Fuzzy Inference Engine . . . . 2114
Glos s ary . . . . . . . . . . . . . . . . . . . . . 2116
Refe re nce s . . . . . . . . . . . . . . . . . . . . 2118
2 Tutorial
218
The Big Picture
Well st ar t wit h a lit t le mot ivat ion for wher e we ar e headed in t his chapt er . The
point of fuzzy logic is t o map an input space t o an out put space, and t he pr imar y
mechanism for doing t his is a list of ift hen st at ement s called r ules. All r ules
ar e evaluat ed in par allel, and t he or der of t he r ules is unimpor t ant . The r ules
t hemselves ar e useful because t hey r efer t o var iables and t he adject ives t hat
descr ibe t hose var iables. Befor e we can build a syst em t hat int er pr et s r ules, we
have t o define all t he t er ms we plan on using and t he adject ives t hat descr ibe
t hem. If we want t o t alk about how hot t he wat er is, we need t o define t he r ange
t hat t he wat er s t emper at ur e can be expect ed t o var y over as well as what we
mean by t he wor d hot . These ar e all t hings well be discussing in t he next
sever al sect ions of t he manual. The diagr am below is somet hing like a r oadmap
for t he fuzzy infer ence pr ocess. It shows t he gener al descr ipt ion of a fuzzy
syst em on t he left and a specific fuzzy syst em (t he t ipping example fr om t he
Int r oduct ion) on t he r ight .
To summar ize t he concept of fuzzy infer ence depict ed in t his figur e, fuzzy
inference is a method that interprets the values in the input vector and, based
on some set of rules, assigns values to the output vector.
This chapt er is designed t o guide you t hr ough t he fuzzy logic pr ocess st ep by
st ep by pr oviding an int r oduct ion t o t he t heor y and pr act ice of fuzzy logic. The
fir st t hr ee sect ions of t his chapt er ar e t he most impor t ant t hey move fr om
Input
The General Case... A Specific Example...
Rules
Input
terms
(interpret)
Output
terms
(assign)
Output service
if service is poor then tip is cheap
if service is good then tip is average
if service is excellent then tip is generous
{poor,
good,
excellent}
{cheap,
average,
generous}
service
is interpreted as
tip
is assigned to be
tip
The Big Picture
219
gener al t o specific, fir st int r oducing under lying ideas and t hen discussing
implement at ion det ails specific t o t he t oolbox. These t hr ee ar eas ar e
Foundati ons of fuzzy logi c, which is an int r oduct ion t o t he gener al
concept s. If your e alr eady familiar wit h fuzzy logic, you may want t o skip
t his sect ion.
Fuzzy i nfere nce systems, which explains t he specific met hods of fuzzy
infer ence used in t he Fuzzy Logic Toolbox. Since t he field of fuzzy logic uses
many t er ms t hat do not yet have st andar d int er pr et at ions, you should
consider r eading t his sect ion just t o become familiar wit h t he fuzzy infer ence
pr ocess as it is employed her e.
Bui ldi ng s ys te ms wi th the Fuzzy Logi c Toolbox, which goes int o det ail
about how you build and edit a fuzzy syst em using t his t oolbox. This
int r oduces t he gr aphical user int er face t ools available in t he Fuzzy Logic
Toolbox and guides you t hr ough t he const r uct ion of a complet e fuzzy
infer ence syst em fr om st ar t t o finish. If you just want t o get up t o speed as
quickly as possible, st ar t her e.
Aft er t his t her e ar e sect ions t hat t ouch on a var iet y of t opics, such as Simulink
use, aut omat ic r ule gener at ion, and demonst r at ions. But fr om t he point of view
of get t ing t o know t he t oolbox, t hese fir st t hr ee sect ions ar e t he most cr ucial.
2 Tutorial
220
Foundations of Fuzzy Logic
Everything is vague to a degree you do not realize till you have tried to make it
precise. Ber t r and Russell
Fuzzy Sets
Fuzzy logic st ar t s wit h t he concept of a fuzzy set . A fuzzy set is a set wit hout a
cr isp, clear ly defined boundar y. It can cont ain element s wit h only a par t ial
degr ee of member ship.
To under st and what a fuzzy set is, fir st consider what is meant by what we
might call a classical set. A classical set is a cont ainer t hat wholly includes or
wholly excludes any given element . For example, t he set of days of t he week
unquest ionably includes Monday, Thur sday, and Sat ur day. It just as
unquest ionably excludes but t er , liber t y, and dor sal fins, and so on.
We call t his set a classical set because it s been ar ound for such a long t ime. It
was Ar ist ot le who fir st for mulat ed t he Law of t he Excluded Middle, which says
X must eit her be in set A or in set not A. Anot her ver sion r uns like t his:
Of any subject , one t hing must be eit her asser t ed or denied.
Her e is a r est at ement of t he law wit h annot at ions: Of any subject (say
Monday), one t hing (being a day of t he week) must be eit her asser t ed or denied
(I asser t t hat Monday is a day of t he week). This law demands t hat opposit es,
t he t wo cat egor ies A and not A, should bet ween t hem cont ain t he ent ir e
univer se. Ever yt hing falls int o eit her one gr oup or t he ot her . Ther e is no t hing
t hat is bot h a day of t he week and not a day of t he week.
Monday
Thursday
Liberty
Shoe
Polish
Dorsal
Fins
Butter
Saturday
Days of the week
Foundations of Fuzzy Logic
221
Now consider t he set of days compr ising a weekend. The diagr am below is one
at t empt at classifying t he weekend days.
Most would agr ee t hat Sat ur day and Sunday belong, but what about Fr iday?
It feels like a par t of t he weekend, but somehow it seems like it should be
t echnically excluded. So in t he diagr am above Fr iday t r ies it s best t o sit on t he
fence. Classical or nor mal set s wouldnt t oler at e t his kind of t hing. Eit her
your e in or your e out . Human exper ience suggest s somet hing differ ent ,
t hough: fence sit t ing is a par t of life.
Of cour se wer e on t r icky gr ound her e, because wer e st ar t ing t o t ake individual
per cept ions and cult ur al backgr ound int o account when we define what
const it ut es t he weekend. But t his is exact ly t he point . Even t he dict ionar y is
impr ecise, defining t he weekend as t he per iod fr om Fr iday night or Sat ur day
t o Monday mor ning. Wer e ent er ing t he r ealm wher e shar p edged yesno logic
st ops being helpful. Fuzzy r easoning becomes valuable exact ly when wer e
t alking about how people r eally per ceive t he concept weekend as opposed t o
a simpleminded classificat ion useful for account ing pur poses only. Mor e t han
anyt hing else, t he following st at ement lays t he foundat ions for fuzzy logic:
In fuzzy logic, the truth of any statement becomes a matter of degree.
Any st at ement can be fuzzy. The t ool t hat fuzzy r easoning gives is t he abilit y
t o r eply t o a yesno quest ion wit h a not quit eyesor no answer . This is t he kind
of t hing t hat humans do all t he t ime (t hink how r ar ely you get a st r aight
answer t o a seemingly simple quest ion) but it s a r at her new t r ick for
comput er s.
How does it wor k? Reasoning in fuzzy logic is just a mat t er of gener alizing t he
familiar yesno (Boolean) logic. If we give t r ue t he numer ical value of 1 and
Monday
Thursday
Liberty Shoe
Polish
Dorsal
Fins
Butter
Saturday
Sunday
Days of the weekend
Friday
2 Tutorial
222
false t he numer ical value of 0, wer e saying t hat fuzzy logic also per mit s
inbet ween values like 0.2 and 0.7453. For inst ance:
Q: Is Sat ur day a weekend day?
A: 1 (yes, or t r ue)
Q: Is Tuesday a weekend day?
A: 0 (no, or false)
Q: Is Fr iday a weekend day?
A: 0.8 (for t he most par t yes, but not complet ely)
Q: Is Sunday a weekend day?
A: 0.95 (yes, but not quit e as much as Sat ur day).
Below on t he left is a plot t hat shows t he t r ut h values for weekendness if we
ar e for ced t o r espond wit h an absolut e yes or no r esponse. On t he r ight is a plot
t hat shows t he t r ut h value for weekendness if we ar e allowed t o r espond wit h
fuzzy inbet ween values.
Technically, t he r epr esent at ion on t he r ight is fr om t he domain of multivalued
logic (or mult ivalent logic). If I ask t he quest ion Is X a member of set A? t he
answer might be yes, no, or any one of a t housand int er mediat e values in
bet ween. In ot her wor ds, X might have par t ial member ship in A. Mult ivalued
logic st ands in dir ect cont r ast t o t he mor e familiar concept of t wovalued (or
bivalent yesno) logic. Twovalued logic has played a cent r al r ole in t he hist or y
of science since Ar ist ot le fir st codified it , but t he t ime has come for it t o shar e
t he st age.
To r et ur n t o our example, now consider a cont inuous scale t ime plot of
weekendness shown below.
Days of the weekend multivalued membership
w
e
e
k
e
n
d

n
e
s
s
w
e
e
k
e
n
d

n
e
s
s
Friday Saturday Sunday Monday Thursday
1.0
0.0
Days of the weekend twovalued membership
Friday Saturday Sunday Monday Thursday
1.0
0.0
Foundations of Fuzzy Logic
223
By making t he plot cont inuous, wer e defining t he degr ee t o which any given
inst ant belongs in t he weekend r at her t han an ent ir e day. In t he plot on t he
left , not ice t hat at midnight on Fr iday, just as t he second hand sweeps past 12,
t he weekendness t r ut h value jumps discont inuously fr om 0 t o 1. This is one
way t o define t he weekend, and while it may be useful t o an account ant , it
doesnt r eally connect wit h our r ealwor ld exper ience of weekendness.
The plot on t he r ight shows a smoot hly var ying cur ve t hat account s for t he fact
t hat all of Fr iday, and, t o a small degr ee, par t s of Thur sday, par t ake of t he
qualit y of weekendness and t hus deser ve par t ial member ship in t he fuzzy set
of weekend moment s. The cur ve t hat defines t he weekendness of any inst ant
in t ime is a funct ion t hat maps t he input space (t ime of t he week) t o t he out put
space (weekendness). Specifically it is known as a membership function. Well
discuss t his in gr eat er det ail in t he next sect ion.
As anot her example of fuzzy set s, consider t he quest ion of seasons. What
season is it r ight now? In t he nor t her n hemispher e, summer officially begins at
t he exact moment in t he ear t hs or bit when t he Nor t h Pole is point ed most
dir ect ly t owar d t he sun. It occur s exact ly once a year , in lat e J une. Using t he
ast r onomical definit ions for t he season, we get shar p boundar ies as shown on
t he left in t he figur e on t he next page. But what we exper ience as t he seasons
var ies mor e or less cont inuously as shown on t he r ight below (in t emper at e
nor t her n hemispher e climat es).
Days of the weekend multivalued membership
w
e
e
k
e
n
d

n
e
s
s
w
e
e
k
e
n
d

n
e
s
s
Friday Saturday Sunday Monday Thursday
1.0
0.0
Days of the weekend twovalued membership
Friday Saturday Sunday Monday Thursday
1.0
0.0
2 Tutorial
224
Membership Functions
A membership function (MF) is a cur ve t hat defines how each point in t he input
space is mapped t o a member ship value (or degr ee of member ship) bet ween 0
and 1. The input space is somet imes r efer r ed t o as t he universe of discourse, a
fancy name for a simple concept .
One of t he most commonly used examples of a fuzzy set is t he set of t all people.
In t his case t he univer se of discour se is all pot ent ial height s, say fr om 3 feet t o
9 feet , and t he wor d t all would cor r espond t o a cur ve t hat defines t he degr ee
t o which any per son is t all. If t he set of t all people is given t he welldefined
(cr isp) boundar y of a classical set , we might say all people t aller t han six feet
ar e officially consider ed t all. But such a dist inct ion is clear ly absur d. It may
make sense t o consider t he set of all r eal number s gr eat er t han six because
number s belong on an abst r act plane, but when we want t o t alk about r eal
people, it is unr easonable t o call one per son shor t and anot her one t all when
t hey differ in height by t he widt h of a hair .
But if t he kind of dist inct ion shown above is unwor kable, t hen what is t he r ight
way t o define t he set of t all people? Much as wit h our plot of weekend days, t he
Time of the year
March March
spring summer fall winter
June September December
1.0
0.0
degree
of
member
ship
degree
of
member
ship
Time of the year
March March
spring summer fall winter
June September December
1.0
0.0
You must
be taller
than this
line to be
considered
TALL
excellent!
Foundations of Fuzzy Logic
225
figur e below shows a smoot hly var ying cur ve t hat passes fr om not t all t o t all.
The out put axis is a number known as t he member ship value bet ween 0 and 1.
The cur ve is known as a member ship funct ion and is oft en given t he
designat ion of . This cur ve defines t he t r ansit ion fr om not t all t o t all. Bot h
people ar e t all t o some degr ee, but one is significant ly less t all t han t he ot her .
Subject ive int er pr et at ions and appr opr iat e unit s ar e built r ight int o fuzzy set s.
If I say Shes t all, t he member ship funct ion t all should alr eady t ake int o
account whet her Im r efer r ing t o a sixyear old or a gr own woman. Similar ly,
t he unit s ar e included in t he cur ve. Cer t ainly it makes no sense t o say Is she
t all in inches or in met er s?
Membership Functions in the Fuzzy Logic Toolbox
The only condit ion a member ship funct ion must r eally sat isfy is t hat it must
var y bet ween 0 and 1. The funct ion it self can be an ar bit r ar y cur ve whose
height
degree of
membership,
definitely a tall
person ( = 0.95)
1.0
0.0
really not very
tall at all ( = 0.30)
sharpedged
membership
function for
TALL
height
degree of
membership,
tall ( = 1.0) 1.0
0.0
not tall ( = 0.0)
continuous
membership
function for
TALL
2 Tutorial
226
shape we can define as a funct ion t hat suit s us fr om t he point of view of
simplicit y, convenience, speed, and efficiency.
A classical set might be expr essed as
A = {x  x > 6}
A fuzzy set is an ext ension of a classical set . If X is t he univer se of discour se
and it s element s ar e denot ed by x, t hen a fuzzy set A in X is defined as a set of
or der ed pair s:
A = {x,
A
(x)  x X}
A
(x) is called t he member ship funct ion (or MF) of x in A. The member ship
funct ion maps each element of X t o a member ship value bet ween 0 and 1.
The Fuzzy Logic Toolbox includes 11 built in member ship funct ion t ypes.
These 11 funct ions ar e, in t ur n, built fr om sever al basic funct ions: piecewise
linear funct ions, t he Gaussian dist r ibut ion funct ion, t he sigmoid cur ve, and
quadr at ic and cubic polynomial cur ves. For det ailed infor mat ion on any of t he
member ship funct ions ment ioned below, t ur n t o Chapt er 3, Refer ence . By
convent ion, all member ship funct ions have t he let t er s mf at t he end of t heir
names.
The simplest member ship funct ions ar e for med using st r aight lines. Of t hese,
t he simplest is t he triangular member ship funct ion, and it has t he funct ion
name trimf. It s not hing mor e t han a collect ion of t hr ee point s for ming a
t r iangle. The trapezoidal member ship funct ion, trapmf, has a flat t op and
r eally is just a t r uncat ed t r iangle cur ve. These st r aight line member ship
funct ions have t he advant age of simplicit y.
0 2 4 6 8 10
0
0.25
0.5
0.75
1
trimf, P = [3 6 8]
trimf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
trapmf, P = [1 5 7 8]
trapmf
Foundations of Fuzzy Logic
227
Two member ship funct ions ar e built on t he Gaussian dist r ibut ion cur ve: a
simple Gaussian cur ve and a t wosided composit e of t wo differ ent Gaussian
cur ves. The t wo funct ions ar e gaussmf and gauss2mf.
The generalized bell member ship funct ion is specified by t hr ee par amet er s and
has t he funct ion name gbellmf. The bell member ship funct ion has one mor e
par amet er t han t he Gaussian member ship funct ion, so it can appr oach a
nonfuzzy set if t he fr ee par amet er is t uned. Because of t heir smoot hness and
concise not at ion, Gaussian and bell member ship funct ions ar e popular
met hods for specifying fuzzy set s. Bot h of t hese cur ves have t he advant age of
being smoot h and nonzer o at all point s.
Alt hough t he Gaussian member ship funct ions and bell member ship funct ions
achieve smoot hness, t hey ar e unable t o specify asymmet r ic member ship
funct ions, which ar e impor t ant in cer t ain applicat ions. Next we define t he
sigmoidal member ship funct ion, which is eit her open left or r ight . Asymmet r ic
and closed (i.e. not open t o t he left or r ight ) member ship funct ions can be
synt hesized using t wo sigmoidal funct ions, so in addit ion t o t he basic sigmf, we
also have t he differ ence bet ween t wo sigmoidal funct ions, dsigmf, and t he
pr oduct of t wo sigmoidal funct ions psigmf.
Polynomial based cur ves account for sever al of t he member ship funct ions in
t he t oolbox. Thr ee r elat ed member ship funct ions ar e t he Z, S , and Pi curves, all
0 2 4 6 8 10
0
0.25
0.5
0.75
1
gaussmf, P = [2 5]
gaussmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
gauss2mf, P = [1 3 3 4]
gauss2mf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
gbellmf, P = [2 4 6]
gbellmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
dsigmf, P = [5 2 5 7]
dsigmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
psigmf, P = [2 3 5 8]
psigmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
sigmf, P = [2 4]
sigmf
2 Tutorial
228
named because of t heir shape. The funct ion zmf is t he asymmet r ical
polynomial cur ve open t o t he left , smf is t he mir r or image funct ion t hat opens
t o t he r ight , and pimf is zer o on bot h ext r emes wit h a r ise in t he middle.
Ther es a ver y wide select ion t o choose fr om when your e select ing your favor it e
member ship funct ion. And t he Fuzzy Logic Toolbox also allows you t o cr eat e
your own member ship funct ions if you find t his list t oo r est r ict ive. On t he ot her
hand, if t his list seems bewilder ing, just r emember t hat you could pr obably get
along ver y well wit h just one or t wo t ypes of member ship funct ions, for example
t he t r iangle and t r apezoid funct ions. The select ion is wide for t hose who want
t o explor e t he possibilit ies, but exot ic member ship funct ions ar e by no means
r equir ed for per fect ly good fuzzy infer ence syst ems. Finally, r emember t hat
mor e det ails ar e available on all t hese funct ions in t he r efer ence sect ion, which
makes up t he second half of t his manual.
Summary of Membership Functions
Fuzzy set s descr ibe vague concept s (fast r unner , hot weat her , weekend
days).
A fuzzy set admit s t he possibilit y of par t ial member ship in it . (Fr iday is sor t
of a weekend day, t he weat her is r at her hot ).
The degr ee an object belongs t o a fuzzy set is denot ed by a member ship value
bet ween 0 and 1. (Fr iday is a weekend day t o t he degr ee 0.8).
A member ship funct ion associat ed wit h a given fuzzy set maps an input
value t o it s appr opr iat e member ship value.
Logical Operations
We now know what s fuzzy about fuzzy logic, but what about t he logic?
The most impor t ant t hing t o r ealize about fuzzy logical r easoning is t he fact
t hat it is a super set of st andar d Boolean logic. In ot her wor ds, if we keep t he
0 2 4 6 8 10
0
0.25
0.5
0.75
1
pimf, P = [1 4 5 10]
pimf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
smf, P = [1 8]
zmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
zmf, P = [3 7]
smf
Foundations of Fuzzy Logic
229
fuzzy values at t heir ext r emes of 1 (complet ely t r ue), and 0 (complet ely false),
st andar d logical oper at ions will hold. As an example, consider t he st andar d
t r ut h t ables below:
Now r emember ing t hat in fuzzy logic t he t r ut h of any st at ement is a mat t er of
degr ee, how will t hese t r ut h t ables be alt er ed? The input values can be r eal
number s bet ween 0 and 1. What funct ion will pr eser ve t he r esult s of t he AND
t r ut h t able (for example) and also ext end t o all r eal number s bet ween 0 and 1?
One answer is t he min oper at ion. That is, r esolve t he st at ement A AND B,
wher e A and B ar e limit ed t o t he r ange (0,1), by using t he funct ion min(A,B).
Using t he same r easoning, we can r eplace t he OR oper at ion wit h t he max
funct ion, so t hat A OR B becomes equivalent t o max(A,B). Finally, t he
oper at ion NOT A becomes equivalent t o t he oper at ion . Not ice how t he
t r ut h t able above is complet ely unchanged by t his subst it ut ion.
Mor eover , since t her e is a funct ion behind t he t r ut h t able r at her t han just t he
t r ut h t able it self, we can now consider values ot her t han 1 and 0.
The next figur e uses a gr aph t o show t he same infor mat ion. Weve conver t ed
t he t r ut h t able t o a plot of t wo fuzzy set s applied t oget her t o cr eat e one fuzzy
AND
0
0
1
1
A B A a nd B A B A or B A not A
0
1
0
1
0
0
0
1
OR
0
0
1
1
0
1
0
1
0
1
1
1
NOT
0
1
1
0
1 A
AND
0
0
1
1
A B mi n(A , B) A B ma x(A , B) A 1  A
0
1
0
1
0
0
0
1
OR
0
0
1
1
0
1
0
1
0
1
1
1
NOT
0
1
1
0
2 Tutorial
230
set . The upper par t of t he figur e displays plot s cor r esponding t o t he t wovalued
t r ut h t ables above, while t he lower par t of t he figur e displays how t he
oper at ions wor k over a cont inuously var ying r ange of t r ut h values A and B
accor ding t o t he fuzzy oper at ions weve defined.
Given t hese t hr ee funct ions, we can r esolve any const r uct ion using fuzzy set s
and t he fuzzy logical oper at ion AND, OR, and NOT.
Additional Fuzzy Operators
Weve only defined her e one par t icular cor r espondence bet ween t wovalued
and mult ivalued logical oper at ions for AND, OR, and NOT. This
cor r espondence is by no means unique.
In mor e gener al t er ms, wer e defining what ar e known as t he fuzzy int er sect ion
or conjunct ion (AND), fuzzy union or disjunct ion (OR), and fuzzy complement
(NOT). We have defined above what well call t he classical oper at or s for t hese
funct ions: AND = min, OR = max, and NOT = addit ive complement . Typically
most fuzzy logic applicat ions make use of t hese oper at ions and leave it at t hat .
In gener al, however , t hese funct ions ar e ar bit r ar y t o a sur pr ising degr ee. The
Fuzzy Logic Toolbox uses t he classical oper at or for t he fuzzy complement as
shown above, but also enables you t o cust omize t he AND and OR oper at or s.
The int er sect ion of t wo fuzzy set s A and B is specified in gener al by a binar y
mapping T, which aggr egat es t wo member ship funct ions as follows:
AB
(x) = T(
A
(x),
B
(x))
AND
A a nd B
Twovalued
logic
Multivalued
logic
A a nd B
A
B
A
A
B
B
A
B
A or B
A or B
A
A
not A
not A
OR NOT
min(A,B) max(A,B) (1A)
Foundations of Fuzzy Logic
231
For example, t he binar y oper at or T may r epr esent t he mult iplicat ion of
. These fuzzy int er sect ion oper at or s, which ar e usually
r efer r ed t o as Tnor m (Tr iangular nor m) oper at or s, meet t he following basic
r equir ement s.
A Tnorm oper at or is a binar y mapping T( ) sat isfying:
boundary: T(0, 0) = 0, T(a, 1) = T(1, a) = a
monotonicity: T(a, b) <= T(c, d) if a <= c and b <= d
commutativity: T(a, b) = T(b, a)
associativity: T(a, T(b, c)) = T(T(a, b), c)
The fir st r equir ement imposes t he cor r ect gener alizat ion t o cr isp set s. The
second r equir ement implies t hat a decr ease in t he member ship values in A or
B cannot pr oduce an incr ease in t he member ship value in A int er sect ion B. The
t hir d r equir ement indicat es t hat t he oper at or is indiffer ent t o t he or der of t he
fuzzy set s t o be combined. Finally, t he four t h r equir ement allows us t o t ake t he
int er sect ion of any number of set s in any or der of pair wise gr oupings.
Like fuzzy int er sect ion, t he fuzzy union oper at or is specified in gener al by a
binar y mapping S :
AB
(x) = S(
A
(x),
B
(x))
For example, t he binar y oper at or S can r epr esent t he addit ion of
. These fuzzy union oper at or s, which ar e oft en r efer r ed t o as
Tconor m (or S nor m) oper at or s, must sat isfy t he following basic r equir ement s.
A Tconorm (or S norm) oper at or is a binar y mapping S ( ) sat isfying:
boundary: S (1, 1) = 1, S (a, 0) = S (0, a) = a
monotonicity: S (a, b) <= S(c, d) if a <= c and b <= d
commutativity: S (a, b) = S (b, a)
associativity: S (a, S (b, c)) = S (S (a, b), c)
Sever al par amet er ized Tnor ms and dual Tconor ms have been pr oposed in t he
past , such as t hose of Yager [Yag80], Dubois and Pr ade [Dub80], Schweizer and
Sklar [Sch63], and Sugeno [Sug77]. Each of t hese pr ovides a way t o var y t he
gain on t he funct ion so t hat it can be ver y r est r ict ive or ver y per missive.
A
x ( ) and
B
x ( )
.
,
.
A
x ( ) and
B
x ( )
.
,
.
2 Tutorial
232
IfThen Rules
Fuzzy set s and fuzzy oper at or s ar e t he subject s and ver bs of fuzzy logic. These
ift hen r ule st at ement s ar e used t o for mulat e t he condit ional st at ement s t hat
compr ise fuzzy logic.
A single fuzzy ift hen r ule assumes t he for m
if x is A t hen y is B
wher e A and B ar e linguist ic values defined by fuzzy set s on t he r anges
(univer ses of discour se) X and Y, r espect ively. The ifpar t of t he r ule x is A is
called t he antecedent or pr emise, while t he t henpar t of t he r ule y is B is called
t he consequent or conclusion. An example of such a r ule might be
if service is good then tip is average
Not e t hat good is r epr esent ed as a number bet ween 0 and 1, and so t he
ant ecedent is an int er pr et at ion t hat r et ur ns a single number bet ween 0 and 1.
On t he ot her hand, average is r epr esent ed as a fuzzy set , and so t he consequent
is an assignment t hat assigns t he ent ir e fuzzy set B t o t he out put var iable y. In
t he ift hen r ule, t he wor d is get s used in t wo ent ir ely differ ent ways
depending on whet her it appear s in t he ant ecedent or t he consequent . In
MATLAB t er ms, t his is t he dist inct ion bet ween a r elat ional t est using == and
a var iable assignment using t he = symbol. A less confusing way of wr it ing t he
r ule would be
if service == good then tip = average
In gener al, t he input t o an ift hen r ule is t he cur r ent value for t he input
var iable (in t his case, service) and t he out put is an ent ir e fuzzy set (in t his case,
average). This set will lat er be defuzzified, assigning one value t o t he out put .
The concept of defuzzificat ion is descr ibed in t he next sect ion, on page 241.
Int er pr et ing an ift hen r ule involves dist inct par t s: fir st evaluat ing t he
ant ecedent (which involves fuzzifying t he input and applying any necessar y
fuzzy operators) and second applying t hat r esult t o t he consequent (known as
implication). In t he case of t wovalued or binar y logic, ift hen r ules dont
pr esent much difficult y. If t he pr emise is t r ue, t hen t he conclusion is t r ue. If we
r elax t he r est r ict ions of t wovalued logic and let t he ant ecedent be a fuzzy
st at ement , how does t his r eflect on t he conclusion? The answer is a simple one:
Foundations of Fuzzy Logic
233
if t he ant ecedent is t r ue t o some degr ee of member ship, t hen t he consequent is
also t r ue t o t hat same degr ee. In ot her wor ds
in binar y logic: p q (p and q ar e eit her bot h t r ue or bot h false)
in fuzzy logic: 0.5 p 0.5 q (par t ial ant ecedent s pr ovide par t ial implicat ion)
The ant ecedent of a r ule can have mult iple par t s:
if sky is gray and wind is strong and barometer is falling, then ...
in which case all par t s of t he ant ecedent ar e calculat ed simult aneously and
r esolved t o a single number using t he logical oper at or s descr ibed in t he
pr eceding sect ion. The consequent of a r ule can also have mult iple par t s:
if temperature is cold then hot water valve is open and cold water valve is shut
in which case all consequent s ar e affect ed equally by t he r esult of t he
ant ecedent . How is t he consequent affect ed by t he ant ecedent ? The consequent
specifies a fuzzy set be assigned t o t he out put . The implication function t hen
modifies t hat fuzzy set t o t he degr ee specified by t he ant ecedent . The most
common ways t o modify t he out put fuzzy set ar e t r uncat ion using t he min
funct ion (wher e t he fuzzy set is chopped off as shown below) or scaling using
t he prod funct ion (wher e t he out put fuzzy set is squashed). Bot h ar e
suppor t ed by t he Fuzzy Logic Toolbox, but we use t r uncat ion for t he examples
in t his sect ion.
2 Tutorial
234
Summary of IfThen Rules
Int er pr et ing ift hen r ules is a t hr eepar t pr ocess. This pr ocess is explained in
det ail in t he next sect ion.
delicious
excellent
generous
If service i s excellent food i s delicious then or tip = generous
food (crisp)
tip (fuzzy)
service (crisp)
3. Apply
i mpli cati on
operator (mi n)
2. Apply
O R operator
(max)
1. Fuzzi fy
i nputs
(food==deli ci ous)
= 0 .7
(servi ce==excellent)
= 0 .0
mi n(0.7, generous)
Antecedent Consequent
0.0
0.7
0.7
If ( 0.0 0.7 ) then or tip = generous
max(0.0, 0.7) = 0.7
If ( 0.7 ) then tip = generous
0.0
0.7 0.7
Foundations of Fuzzy Logic
235
1 Fuzzify inputs: Resolve all fuzzy st at ement s in t he ant ecedent t o a degr ee of
member ship bet ween 0 and 1. If t her e is only one par t t o t he ant ecedent , t his
is t he degr ee of suppor t for t he r ule.
2 Apply fuzzy operator to multiple part antecedents: If t her e ar e mult iple par t s
t o t he ant ecedent , apply fuzzy logic oper at or s and r esolve t he ant ecedent t o
a single number bet ween 0 and 1. This is t he degr ee of suppor t for t he r ule.
3 Apply implication method: Use t he degr ee of suppor t for t he ent ir e r ule t o
shape t he out put fuzzy set . The consequent of a fuzzy r ule assigns an ent ir e
fuzzy set t o t he out put . This fuzzy set is r epr esent ed by a member ship
funct ion t hat is chosen t o indicat e t he qualit ies of t he consequent . If t he
ant ecedent is only par t ially t r ue, (i.e., is assigned a value less t han 1), t hen
t he out put fuzzy set is t r uncat ed accor ding t o t he implicat ion met hod.
In gener al, one r ule by it self doesnt do much good. What s needed ar e t wo or
mor e r ules t hat can play off one anot her . The out put of each r ule is a fuzzy set .
The out put fuzzy set s for each r ule ar e t hen aggregated int o a single out put
fuzzy set . Finally t he r esult ing set is defuzzified, or r esolved t o a single
number . The next sect ion shows how t he whole pr ocess wor ks fr om beginning
t o end for a par t icular t ype of fuzzy infer ence syst em called a Mamdani t ype.
2 Tutorial
236
Fuzzy Inference Systems
Fuzzy infer ence is t he pr ocess of for mulat ing t he mapping fr om a given input
t o an out put using fuzzy logic. The mapping t hen pr ovides a basis fr om which
decisions can be made, or pat t er ns discer ned. The pr ocess of fuzzy infer ence
involves all of t he pieces t hat ar e descr ibed in t he pr evious sect ions:
member ship funct ions, fuzzy logic oper at or s, and ift hen r ules. Ther e ar e t wo
t ypes of fuzzy infer ence syst ems t hat can be implement ed in t he Fuzzy Logic
Toolbox: Mamdanit ype and Sugenot ype. These t wo t ypes of infer ence syst ems
var y somewhat in t he way out put s ar e det er mined. Descr ipt ions of t hese t wo
t ypes of fuzzy infer ence syst ems can be found in t he r efer ences, [J an97,
Mam75, Sug85].
Fuzzy infer ence syst ems have been successfully applied in fields such as
aut omat ic cont r ol, dat a classificat ion, decision analysis, exper t syst ems, and
comput er vision. Because of it s mult idisciplinar y nat ur e, fuzzy infer ence
syst ems ar e associat ed wit h a number of names, such as fuzzyr ulebased
syst ems, fuzzy exper t syst ems, fuzzy modeling, fuzzy associat ive memor y,
fuzzy logic cont r oller s, and simply (and ambiguously) fuzzy syst ems. Since t he
t er ms used t o descr ibe t he var ious par t s of t he fuzzy infer ence pr ocess ar e far
fr om st andar d, we will t r y t o be as clear as possible about t he differ ent t er ms
int r oduced in t his sect ion.
Mamdanis fuzzy infer ence met hod is t he most commonly seen fuzzy
met hodology. Mamdanis met hod was among t he fir st cont r ol syst ems built
using fuzzy set t heor y. It was pr oposed in 1975 by Ebr ahim Mamdani [Mam75]
as an at t empt t o cont r ol a st eam engine and boiler combinat ion by synt hesizing
a set of linguist ic cont r ol r ules obt ained fr om exper ienced human oper at or s.
Mamdanis effor t was based on Lot fi Zadehs 1973 paper on fuzzy algor it hms
for complex syst ems and decision pr ocesses [Zad73]. Alt hough t he infer ence
pr ocess we descr ibe in t he next few sect ions differ s somewhat fr om t he met hods
descr ibed in t he or iginal paper , t he basic idea is much t he same.
Mamdanit ype infer ence, as we have defined it for t he Fuzzy Logic Toolbox,
expect s t he out put member ship funct ions t o be fuzzy set s. Aft er t he
aggr egat ion pr ocess, t her e is a fuzzy set for each out put var iable t hat needs
defuzzificat ion. It s possible, and in many cases much mor e efficient , t o use a
single spike as t he out put member ship funct ion r at her t han a dist r ibut ed fuzzy
set . This is somet imes known as a singleton out put member ship funct ion, and
it can be t hought of as a pr edefuzzified fuzzy set . It enhances t he efficiency of
t he defuzzificat ion pr ocess because it gr eat ly simplifies t he comput at ion
Fuzzy Inference Systems
237
r equir ed by t he mor e gener al Mamdani met hod, which finds t he cent r oid of a
t wodimensional funct ion. Rat her t han int egr at ing acr oss t he t wodimensional
funct ion t o find t he cent r oid, we use t he weight ed aver age of a few dat a point s.
Sugenot ype syst ems suppor t t his t ype of model. In gener al, Sugenot ype
syst ems can be used t o model any infer ence syst em in which t he out put
member ship funct ions ar e eit her linear or const ant .
Dinner for Two, Reprise
In t his sect ion we pr ovide t he same t woinput oneout put t hr eer ule t ipping
pr oblem t hat you saw in t he int r oduct ion, only in mor e det ail. The basic
st r uct ur e of t his example is shown in t he diagr am below.
Infor mat ion flows fr om left t o r ight , fr om t wo input s t o a single out put . The
par allel nat ur e of t he r ules is one of t he mor e impor t ant aspect s of fuzzy logic
syst ems. Inst ead of shar p swit ching bet ween modes based on br eakpoint s, we
will glide smoot hly fr om r egions wher e t he syst ems behavior is dominat ed by
eit her one r ule or anot her .
In t he Fuzzy Logic Toolbox, t her e ar e five par t s of t he fuzzy infer ence pr ocess:
fuzzificat ion of t he input var iables, applicat ion of t he fuzzy oper at or (AND or
OR) in t he ant ecedent , implicat ion fr om t he ant ecedent t o t he consequent ,
aggr egat ion of t he consequent s acr oss t he r ules, and defuzzificat ion. These
somet imes cr ypt ic and odd names have ver y specific meaning t hat well define
car efully as we st ep t hr ough each of t hem in mor e det ail below.
Input 1
Service (010)
Output
Tip (525%)
Input 2
Food (010)
t ( )
0.2x t ( )
1 x
10
t ( ) +
 0.1x t ( ) =
anfis and the ANFIS Editor GUI
2111
fr om D sample dat a point s, sampled ever y unit s in t ime, (x(t(D1)),..., x(t ),
x(t )), t o a pr edict ed fut ur e value x(t +P). Following t he convent ional set t ings for
pr edict ing t he MG t ime ser ies, we set D = 4 and = P = 6. For each t, t he input
t r aining dat a for anfis is a four dimensional vect or of t he following for m:
w(t) = [x(t18) x(t12) x(t6) x(t)]
The out put t r aining dat a cor r esponds t o t he t r aject or y pr edict ion:
s(t) = x(t+6)
For each t, r anging in values fr om 118 t o 1117, t he t r aining input /out put dat a
will be a st r uct ur e whose fir st component is t he four dimensional input w, and
whose second component is t he out put s. Ther e will be 1000 input /out put dat a
values. We use t he fir st 500 dat a values for t he anfis t r aining (t hese become
t he t r aining dat a set ), while t he ot her s ar e used as checking dat a for validat ing
t he ident ified fuzzy model. This r esult s in t wo 500point dat a st r uct ur es:
trnData and chkData.
Her e is t he code t hat gener at es t his dat a:
for t=118:1117,
Data(t117,:)=[x(t18) x(t12) x(t6) x(t) x(t+6)];
end
trnData=Data(1:500, :);
chkData=Data(501:end, :);
To st ar t t he t r aining, we need an FIS st r uct ur e t hat specifies t he st r uct ur e and
init ial par amet er s of t he FIS for lear ning. This is t he t ask of genfis1:
fismat = genfis1(trnData);
Since we did not specify number s and t ypes of member ship funct ions used in
t he FIS, default values ar e assumed. These default s pr ovide t wo gener alized
bell member ship funct ions on each of t he four input s, eight alt oget her . The
gener at ed FIS st r uct ur e cont ains 16 fuzzy r ules wit h 104 par amet er s. In or der
t o achieve good gener alizat ion capabilit y, it is impor t ant t o have t he number of
t r aining dat a point s be sever al t imes lar ger t han t he number par amet er s being
est imat ed. In t his case, t he r at io bet ween dat a and par amet er s is about five
(500/104).
2 Tutorial
2112
The funct ion genfis1 gener at es init ial member ship funct ions t hat ar e equally
spaced and cover t he whole input space. You can plot t he input member ship
funct ions using t he following commands.
subplot(2,2,1)
plotmf(fismat, 'input', 1)
subplot(2,2,2)
plotmf(fismat, 'input', 2)
subplot(2,2,3)
plotmf(fismat, 'input', 3)
subplot(2,2,4)
plotmf(fismat, 'input', 4)
These init ial member ship funct ions ar e shown below.
To st ar t t he t r aining, t ype
[fismat1,error1,ss,fismat2,error2] = ...
anfis(trnData,fismat,[],[],chkData);
This t akes about four minut es on a Sun SPARCst at ion 2 for 10 epochs of
t r aining. Because t he checking dat a opt ion of anfis was invoked, t he final FIS
you choose would or dinar ily be t he one associat ed wit h t he minimum checking
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 1
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 2
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 3
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 4
anfis and the ANFIS Editor GUI
2113
er r or . This is st or ed in fismat2. The following code will plot t hese new
member ship funct ions:
subplot(2,2,1)
plotmf(fismat2, 'input', 1)
subplot(2,2,2)
plotmf(fismat2, 'input', 2)
subplot(2,2,3)
plotmf(fismat2, 'input', 3)
subplot(2,2,4)
plotmf(fismat2, 'input', 4)
Her e is t he r esult :.
To plot t he er r or signals t ype
plot([error1; error2]);
Her e error1 and error2 ar e t he r oot mean squar ed er r or for t he t r aining and
checking dat a, r espect ively.
In addit ion t o t hese er r or plot s, you may want t o plot t he FIS out put ver sus t he
t r aining or checking dat a. To compar e t he or iginal MG t ime ser ies and t he
fuzzy pr edict ion side by side, t r y
anfis_output = evalfis([trnData; chkData], fismat2);
index = 125:1124;
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 1
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 2
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 3
0.6 0.8 1 1.2
0
0.2
0.4
0.6
0.8
1
Input 4
2 Tutorial
2114
subplot(211), plot(t(index), [x(index) anfis_output]);
subplot(212), plot(t(index), x(index) anfis_output);
Not e t hat t he differ ence bet ween t he or iginal MG t ime ser ies and t he anfis
est imat ed values is ver y small. This is why you can only see one cur ve in t he
fir st plot . The pr edict ion er r or is shown in t he second plot wit h a much finer
scale. Not e t hat we have only t r ained for 10 epochs. Bet t er per for mance is
expect ed if we apply mor e ext ensive t r aining.
More on anfis and the ANFIS Editor GUI
The command anfis t akes at least t wo and at most six input ar gument s. The
gener al for mat is
[fismat1,trnError,ss,fismat2,chkError] = ...
anfis(trnData,fismat,trnOpt,dispOpt,chkData,method);
wher e trnOpt (t r aining opt ions), dispOpt (display opt ions), chkData (checking
dat a), and method (t r aining met hod), ar e opt ional. All of t he out put ar gument s
ar e also opt ional. In t his sect ion we discuss t he ar gument s and r ange
component s of t he command line funct ion anfis, as well as t he analogous
funct ionalit y of t he ANFIS Edit or GUI.
When t he ANFIS Edit or GUI is invoked using anfisedit, only t he t r aining
dat a set must exist pr ior t o implement ing anfis.In addit ion, t he st epsize will
be fixed when t he adapt ive neur ofuzzy syst em is t r ained using t his GUI t ool.
200 300 400 500 600 700 800 900 1000 1100
10
5
0
5
x 10
3
Prediction Errors
200 300 400 500 600 700 800 900 1000 1100
0.6
0.8
1
1.2
MG Time Serise and ANFIS Prediction
anfis and the ANFIS Editor GUI
2115
Training Data
The t r aining dat a, trnData, is a r equir ed ar gument t o anfis, as well as t o t he
ANFIS Edit or GUI. Each r ow of trnData is a desir ed input /out put pair of t he
t ar get syst em t o be modeled. Each r ow st ar t s wit h an input vect or and is
followed by an out put value. Ther efor e, t he number of r ows of trnData is equal
t o t he number of t r aining dat a pair s, and, since t her e is only one out put , t he
number of columns of trnData is equal t o t he number of input s plus one.
Input FIS Structure
The input FIS st r uct ur e, fismat, can be obt ained eit her fr om any of t he fuzzy
edit or s: t he FIS Edit or , t he Member ship Funct ion Edit or , and t he Rule Edit or
fr om t he ANFIS Edit or GUI, (which allows an FIS st r uct ur e t o be loaded fr om
t he disk or t he wor kspace), or fr om t he command line funct ion, genfis1 (for
which you only need t o give number s and t ypes of member ship funct ions). The
FIS st r uct ur e cont ains bot h t he model st r uct ur e, (which specifies such it ems as
t he number of r ules in t he FIS, t he number of member ship funct ions for each
input , et c.), and t he par amet er s, (which specify t he shapes of member ship
funct ions). Ther e ar e t wo methods t hat anfis lear ning employs for updat ing
member ship funct ion par amet er s: backpr opagat ion for all par amet er s (a
st eepest descent met hod), and a hybr id met hod consist ing of backpr opagat ion
for t he par amet er s associat ed wit h t he input member ship funct ions, and least
squar es est imat ion for t he par amet er s associat ed wit h t he out put member ship
funct ions. As a r esult , t he t r aining er r or decr eases, at least locally, t hr oughout
t he lear ning pr ocess. Ther efor e, t he mor e t he init ial member ship funct ions
r esemble t he opt imal ones, t he easier it will be for t he model par amet er
t r aining t o conver ge. Human exper t ise about t he t ar get syst em t o be modeled
may aid in set t ing up t hese init ial member ship funct ion par amet er s in t he FIS
st r uct ur e.
Not e t hat genfis1 pr oduces an FIS st r uct ur e based on a fixed number of
member ship funct ions. This invokes t he socalled curse of dimensionality, and
causes an explosion of t he number of r ules when t he number of input s is
moder at ely lar ge, t hat is, mor e t han four or five. The Fuzzy Logic Toolbox offer s
a met hod t hat will pr ovide for some dimension r educt ion in t he fuzzy infer ence
syst em: you can gener at e an FIS st r uct ur e using t he clust er ing algor it hm
discussed in Subt r act ive Clust er ing on page 2123. Fr om t he ANFIS Edit or
GUI, t his algor it hm is select ed wit h a r adio but t on befor e t he FIS is gener at ed.
This subt r act ive clust er ing met hod par t it ions t he dat a int o gr oups called
clust er s, and gener at es an FIS wit h t he minimum number r ules r equir ed t o
dist inguish t he fuzzy qualit ies associat ed wit h each of t he clust er s.
2 Tutorial
2116
Training Options
The ANFIS Edit or GUI t ool allows you t o choose your desir ed er r or t oler ance
and number of t r aining epochs.
Tr aining opt ion trnOpt for t he command line anfis is a vect or t hat specifies
t he st opping cr it er ia and t he st epsize adapt at ion st r at egy:
trnOpt(1): number of t r aining epochs, default = 10.
trnOpt(2): er r or t oler ance, default = 0.
trnOpt(3): init ial st epsize, default = 0.01.
trnOpt(4): st epsize decr ease r at e, default = 0.9.
trnOpt(5): st epsize incr ease r at e, default = 1.1.
If any element of trnOpt is an NaN or missing, t hen t he default value is t aken.
The t r aining pr ocess st ops if t he designat ed epoch number is r eached or t he
er r or goal is achieved, whichever comes fir st .
Usually we want t he st epsize pr ofile t o be a cur ve t hat incr eases init ially,
r eaches some maximum, and t hen decr eases for t he r emainder of t he t r aining.
This ideal st epsize pr ofile is achieved by adjust ing t he init ial st epsize and t he
incr ease and decr ease r at es (trnOpt(3)  trnOpt(5)). The default values ar e
set up t o cover a wide r ange of lear ning t asks. For any specific applicat ion, you
may want t o modify t hese st epsize opt ions in or der t o opt imize t he t r aining.
However , as we ment ioned pr eviously, t her e ar e no user specified st epsize
opt ions for t r aining t he adapt ive neur o fuzzy infer ence syst em gener at ed using
t he ANFIS Edit or GUI.
Display Options
Display opt ions only apply t o t he command line funct ion, anfis.
For t he command line anfis, t he display opt ions argument, dispOpt, is a vect or
of eit her ones or zer os t hat specifies what infor mat ion t o display, (pr int in t he
MATLAB command line window), befor e, dur ing, and aft er t he t r aining
pr ocess. One is used t o denot e print this option, wher eas zer o denot es dont
print this option.
dispOpt(1): display ANFIS infor mat ion, default = 1.
dispOpt(2): display er r or (each epoch), default = 1.
dispOpt(3): display st epsize (each epoch), default = 1.
dispOpt(4): display final r esult s, default = 1.
anfis and the ANFIS Editor GUI
2117
The default mode is displays all available infor mat ion. If any element of
dispOpt is NaN or missing, t he default value will be t aken.
Method
Bot h t he ANFIS Edit or GUI and t he command line anfis apply eit her a
backpr opagat ion for m of t he st eepest descent met hod for member ship funct ion
par amet er est imat ion, or a combinat ion of backpr opagat ion and t he
least squar es met hod t o est imat e member ship funct ion par amet er s. The
choices for t his ar gument ar e hybrid or backpropagation. These met hod
choices ar e designat ed in t he command line funct ion, anfis, by 1 and 0,
r espect ively.
Output FIS Structure for Training Data
fismat1 is t he out put FIS st r uct ur e cor r esponding t o a minimal t r aining er r or .
This is t he FIS st r uct ur e t hat you will use t o r epr esent t he fuzzy syst em when
t her e is no checking dat a used for model cr ossvalidat ion. This dat a also
r epr esent s t he FIS st r uct ur e t hat is saved by t he ANFIS Edit or GUI when t he
checking dat a opt ion is not used.
When t he checking dat a opt ion is used, t he out put saved is t hat associat ed wit h
t he minimum checking er r or .
Training Error
The t r aining er r or is t he differ ence bet ween t he t r aining dat a out put value,
and t he out put of t he fuzzy infer ence syst em cor r esponding t o t he same
t r aining dat a input value, (t he one associat ed wit h t hat t r aining dat a out put
value). The t r aining er r or trnError r ecor ds t he r oot mean squar ed er r or
(RMSE) of t he t r aining dat a set at each epoch. fismat1 is t he snapshot of t he
FIS st r uct ur e when t he t r aining er r or measur e is at it s minimum. The ANFIS
Edit or GUI will plot t he t r aining er r or vs. epochs cur ve as t he syst em is
t r ained.
Stepsize
You cannot cont r ol t he st epsize opt ions wit h t he ANFIS Edit or GUI. Using t he
command line anfis, t he st epsize ar r ay ss r ecor ds t he st epsize dur ing t he
t r aining. Plot t ing ss gives t he st epsize pr ofile, which ser ves as a r efer ence for
adjust ing t he init ial st epsize and t he cor r esponding decr ease and incr ease
2 Tutorial
2118
r at es. The st epsize (ss) for t he command line funct ion anfis is updat ed
accor ding t o t he following guidelines:
If t he er r or under goes four consecut ive r educt ions, incr ease t he st epsize by
mult iplying it by a const ant (ssinc) gr eat er t han one.
If t he er r or under goes t wo consecut ive combinat ions of one incr ease and one
r educt ion, decr ease t he st epsize by mult iplying it by a const ant (ssdec) less
t han one.
The default value for t he init ial st epsize is 0.01; t he default values for ssinc
and ssdec ar e 1.1 and 0.9, r espect ively. All t he default values can be changed
via t he t r aining opt ion for t he command line anfis.
Checking Data
The checking dat a, chkData, is used for t est ing t he gener alizat ion capabilit y of
t he fuzzy infer ence syst em at each epoch. The checking dat a has t he same
for mat as t hat of t he t r aining dat a, and it s element s ar e gener ally dist inct fr om
t hose of t he t r aining dat a.
The checking dat a is impor t ant for lear ning t asks for which t he input number
is lar ge, and/or t he dat a it self is noisy. In gener al we want a fuzzy infer ence
syst em t o t r ack a given input /out put dat a set well. Since t he model st r uct ur e
used for anfis is fixed, t her e is a t endency for t he model t o over fit t he dat a on
which is it t r ained, especially for a lar ge number of t r aining epochs. If
over fit t ing does occur , we cannot expect t he fuzzy infer ence syst em t o r espond
well t o ot her independent dat a set s, especially if t hey ar e cor r upt ed by noise. A
validat ion or checking dat a set can be useful for t hese sit uat ions. This dat a set
is used t o cr ossvalidat e t he fuzzy infer ence model. This cr ossvalidat ion is
accomplished by applying t he checking dat a t o t he model, and seeing how well
t he model r esponds t o t his dat a.
When t he checking dat a opt ion is used wit h anfis, eit her via t he command
line, or using t he ANFIS Edit or GUI, t he checking dat a is applied t o t he model
at each t r aining epoch. When t he command line anfis is invoked, t he model
par amet er s t hat cor r espond t o t he minimum checking er r or ar e r et ur ned via
t he out put ar gument fismat2. The FIS member ship funct ion par amet er s
comput ed using t he ANFIS Edit or GUI when bot h t r aining and checking dat a
ar e loaded ar e associat ed wit h t he t r aining epoch t hat has a minimum checking
er r or .
anfis and the ANFIS Editor GUI
2119
The use of t he minimum checking dat a er r or epoch t o set t he member ship
funct ion par amet er s assumes
The checking dat a is similar enough t o t he t r aining dat a t hat t he checking
dat a er r or will decr ease as t he t r aining begins
The checking dat a incr eases at some point in t he t r aining, aft er which dat a
over fit t ing has occur r ed.
As discussed in ANFIS Edit or GUI Example 2: Checking Dat a Doesnt
Validat e Model on page 2106, depending on t he behavior of t he checking dat a
er r or , t he r esult ing FIS may or may not be t he one you should be using.
Output FIS Structure for Checking Data
The out put of t he command line anfis, fismat2, is t he out put FIS st r uct ur e
wit h t he minimum checking er r or . This is t he FIS st r uct ur e t hat should be
used for fur t her calculat ion if checking dat a is used for cr oss validat ion.
Checking Error
The checking er r or is t he differ ence bet ween t he checking dat a out put value,
and t he out put of t he fuzzy infer ence syst em cor r esponding t o t he same
checking dat a input value, (t he one associat ed wit h t hat checking dat a out put
value). The checking er r or chkError r ecor ds t he RMSE for t he checking dat a
at each epoch. fismat2 is t he snapshot of t he FIS st r uct ur e when t he checking
er r or is at it s minimum. The ANFIS Edit or GUI will plot t he checking er r or vs.
epochs cur ve as t he syst em is t r ained.
2 Tutorial
2120
Fuzzy Clustering
Clust er ing of numer ical dat a for ms t he basis of many classificat ion and syst em
modeling algor it hms. The pur pose of clust er ing is t o ident ify nat ur al gr oupings
of dat a fr om a lar ge dat a set t o pr oduce a concise r epr esent at ion of a syst ems
behavior . The Fuzzy Logic Toolbox is equipped wit h some t ools t hat allow you
t o find clust er s in input out put t r aining dat a. You can use t he clust er
infor mat ion t o gener at e a Sugenot ype fuzzy infer ence syst em t hat best models
t he dat a behavior using a minimum number of r ules. The r ules par t it ion
t hemselves accor ding t o t he fuzzy qualit ies associat ed wit h each of t he dat a
clust er s. This t ype of FIS gener at ion can be accomplished aut omat ically using
t he command line funct ion, genfis2.
Fuzzy CMeans Clustering
Fuzzy cmeans (FCM) is a dat a clust er ing t echnique wher ein each dat a point
belongs t o a clust er t o some degr ee t hat is specified by a member ship gr ade.
This t echnique was or iginally int r oduced by J im Bezdek in 1981 [Bez81] as an
impr ovement on ear lier clust er ing met hods. It pr ovides a met hod of how t o
gr oup dat a point s t hat populat e some mult idimensional space int o a specific
number of differ ent clust er s?
The Fuzzy Logic Toolbox command line funct ion fcm st ar t s wit h an init ial
guess for t he clust er cent er s, which ar e int ended t o mar k t he mean locat ion of
each clust er . The init ial guess for t hese clust er cent er s is most likely incor r ect .
Addit ionally, fcm assigns ever y dat a point a member ship gr ade for each
clust er . By it er at ively updat ing t he clust er cent er s and t he member ship gr ades
for each dat a point , fcm it er at ively moves t he clust er cent er s t o t he r ight
locat ion wit hin a dat a set . This it er at ion is based on minimizing an object ive
funct ion t hat r epr esent s t he dist ance fr om any given dat a point t o a clust er
cent er weight ed by t hat dat a point s member ship gr ade.
fcm is a command line funct ion whose out put is a list of clust er cent er s and
sever al member ship gr ades for each dat a point . You can use t he infor mat ion
r et ur ned by fcm t o help you build a fuzzy infer ence syst em by cr eat ing
member ship funct ions t o r epr esent t he fuzzy qualit ies of each clust er .
Fuzzy Clustering
2121
An Example: 2D Clusters
Let s use some quasir andom t wodimensional dat a t o illust r at e how FCM
clust er ing wor ks. Load a dat a set and t ake a look at it .
load fcmdata.dat
plot(fcmdata(:,1),fcmdata(:,2),'o')
Now we invoke t he command line funct ion, fcm, and ask it t o find t wo clust er s
in t his dat a set
[center,U,objFcn] = fcm(fcmdata,2);
Iteration count = 1, obj. fcn = 8.941176
Iteration count = 2, obj. fcn = 7.277177
and so on unt il t he object ive funct ion is no longer decr easing much at all.
The var iable center cont ains t he coor dinat es of t he t wo clust er cent er s, U
cont ains t he member ship gr ades for each of t he dat a point s, and objFcn
cont ains a hist or y of t he object ive funct ion acr oss t he it er at ions.
The fcm funct ion is an it er at ion loop built on t op of sever al ot her r out ines,
namely initfcm, which init ializes t he pr oblem, distfcm, which is used for
dist ance calculat ions, and stepfcm, which st eps t hr ough one it er at ion.
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
.
2 Tutorial
2122
Plot t ing t he object ive funct ion shows t he pr ogr ess of t he clust er ing.
plot(objFcn)
Finally her e is a plot displaying t he t wo separ at e clust er s as classified by t he
fcm r out ine. The following figur e is gener at ed using:
load fcmdata.dat
[center, U, obj_fcn] = fcm(fcmdata, 2);
maxU = max(U);
index1 = find(U(1, :) == maxU);
index2 = find(U(2, :) == maxU);
line(fcmdata(index1, 1), fcmdata(index1, 2), 'linestyle',...
'none','marker', 'o','color','g');
line(fcmdata(index2,1),fcmdata(index2,2),'linestyle',...
'none','marker', 'x','color','r');
hold on
plot(center(1,1),center(1,2),'ko','markersize',15,'LineWidth',2)
plot(center(2,1),center(2,2),'kx','markersize',15,'LineWidth',2)
1 2 3 4 5 6 7 8 9 10 11
0
1
2
3
4
5
6
7
8
9
10
objective function values
Fuzzy Clustering
2123
Clust er cent er s ar e indicat ed in t he figur e below by t he lar ge char act er s.
Subtractive Clustering
Suppose we dont have a clear idea how many clust er s t her e should be for a
given set of dat a. S ubtractive clustering, [Chi94], is a fast , onepass algor it hm
for est imat ing t he number of clust er s and t he clust er cent er s in a set of dat a.
The clust er est imat es obt ained fr om t he subclust funct ion can be used t o
init ialize it er at ive opt imizat ionbased clust er ing met hods (fcm) and model
ident ificat ion met hods (like anfis). The subclust funct ion finds t he clust er s by
using t he subt r act ive clust er ing met hod.
The genfis2 funct ion builds upon t he subclust funct ion t o pr ovide a fast ,
onepass met hod t o t ake input out put t r aining dat a and gener at e a
Sugenot ype fuzzy infer ence syst em t hat models t he dat a behavior .
An Example: Suburban Commuting
In t his example we apply t he genfis2 funct ion t o model t he r elat ionship
bet ween t he number of aut omobile t r ips gener at ed fr om an ar ea and t he ar eas
demogr aphics. Demogr aphic and t r ip dat a ar e fr om 100 t r affic analysis zones
in New Cast le Count y, Delawar e. Five demogr aphic fact or s ar e consider ed:
populat ion, number of dwelling unit s, vehicle owner ship, median household
income, and t ot al employment . Hence t he model has five input var iables and
one out put var iable.
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
2 Tutorial
2124
Load t he dat a by t yping
tripdata
subplot(2,1,1), plot(datin)
subplot(2,1,2), plot(datout)
tripdata cr eat es sever al var iables in t he wor kspace. Of t he or iginal 100 dat a
point s, we will use 75 dat a point s as t r aining dat a (datin and datout) and 25
dat a point s as checking dat a, (as well as for t est dat a t o validat e t he model).
The checking dat a input /out put pair s ar e denot ed by chkdatin and chkdatout.
The genfis2 funct ion gener at es a model fr om dat a using clust er ing, and
r equir es you t o specify a clust er r adius. The clust er r adius indicat es t he r ange
of influence of a clust er when you consider t he dat a space as a unit hyper cube.
Specifying a small clust er r adius will usually yield many small clust er s in t he
dat a, (r esult ing in many r ules). Specifying a lar ge clust er r adius will usually
yield a few lar ge clust er s in t he dat a, (r esult ing in fewer r ules). The clust er
r adius is specified as t he t hir d ar gument of genfis2. Her e we call t he genfis2
funct ion using a clust er r adius of 0.5.
fismat=genfis2(datin,datout,0.5);
genfis2 is a fast , onepass met hod t hat does not per for m any it er at ive
opt imizat ion. An FIS st r uct ur e is r et ur ned; t he model t ype for t he FIS
st r uct ur e is a fir st or der Sugeno model wit h t hr ee r ules. We can use evalfis t o
ver ify t he model.
fuzout=evalfis(datin,fismat);
trnRMSE=norm(fuzoutdatout)/sqrt(length(fuzout))
0 10 20 30 40 50 60 70 80
0
10
20
30
40
50
0 10 20 30 40 50 60 70 80
0
2
4
6
8
10
Fuzzy Clustering
2125
trnRMSE =
0.5276
The var iable trnRMSE is t he r oot mean squar e er r or of t he syst em gener at ed by
t he t r aining dat a. To validat e t he gener alizabilit y of t he model, we apply t est
dat a t o t he FIS. For t his example, we use t he checking dat a for bot h checking
and t est ing t he FIS par amet er s.
chkfuzout=evalfis(chkdatin,fismat);
chkRMSE=norm(chkfuzoutchkdatout)/sqrt(length(chkfuzout))
chkRMSE =
0.6170
Not sur pr isingly, t he model doesnt do quit e as good a job on t he t est ing dat a.
A plot of t he t est ing dat a r eveals t he differ ence.
plot(chkdatout)
hold on
plot(chkfuzout,'o')
hold off
At t his point , we can use t he opt imizat ion capabilit y of anfis t o impr ove t he
model. Fir st , we will t r y using a r elat ively shor t anfis t r aining (50 epochs)
wit hout implement ing t he checking dat a opt ion, but t est t he r esult ing FIS
model against t he t est dat a. The command line ver sion of t his is as follows:
fismat2=anfis([datin datout],fismat,[50 0 0.1]);
Aft er t he t r aining is done, we t ype:
0 5 10 15 20 25
0
1
2
3
4
5
6
7
8
9
2 Tutorial
2126
fuzout2=evalfis(datin,fismat2);
trnRMSE2=norm(fuzout2datout)/sqrt(length(fuzout2))
trnRMSE2 =
0.3407
chkfuzout2=evalfis(chkdatin,fismat2);
chkRMSE2=norm(chkfuzout2chkdatout)/sqrt(length(chkfuzout2))
chkRMSE2 =
0.5827
The model has impr oved a lot wit h r espect t o t he t r aining dat a, but only a lit t le
wit h r espect t o t he checking dat a. Her e is a plot of t he impr oved t est ing dat a.
plot(chkdatout)
hold on
plot(chkfuzout2,'o')
hold off
Her e we see t hat genfis2 can be used as a st andalone, fast met hod for
gener at ing a fuzzy model fr om dat a, or as a pr epr ocessor t o anfis for
det er mining t he init ial r ules. An impor t ant advant age of using a clust er ing
met hod t o find r ules is t hat t he r esult ant r ules ar e mor e t ailor ed t o t he input
dat a t han t hey ar e in an FIS gener at ed wit hout clust er ing. This r educes t he
pr oblem of combinat or ial explosion of r ules when t he input dat a has a high
dimension (t he dr eaded cur se of dimensionalit y).
Overfitting
Now let s consider what happens if we car r y out a longer (200 epoch) t r aining
of t his syst em using anfis, including it s checking dat a opt ion.
0 5 10 15 20 25
0
1
2
3
4
5
6
7
8
9
Fuzzy Clustering
2127
[fismat3,trnErr,stepSize,fismat4,chkErr]= ...
anfis([datin datout],fismat2,[200 0
0.1],[], ...
[chkdatin chkdatout]);
The long list of out put ar gument s r et ur ns a hist or y of t he st epsizes, t he RMSE
ver sus t he t r aining dat a, and t he RMSE ver sus t he checking dat a associat ed
wit h each t r aining epoch.
ANFIS training completed at epoch 200.
Minimal training RMSE = 0.326566
Minimal checking RMSE = 0.582545
This looks good. The er r or wit h t he t r aining dat a is t he lowest weve seen, and
t he er r or wit h t he checking dat a is also lower t han befor e, t hough not by much.
This suggest s t hat maybe we had got t en about as close as possible wit h t his
syst em alr eady. Maybe we have even gone so far as t o over fit t he syst em t o t he
t r aining dat a. Over fit t ing occur s when we fit t he fuzzy syst em t o t he t r aining
dat a so well t hat it no longer does a ver y good job of fit t ing t he checking dat a.
The r esult is a loss of gener alit y. A look at t he er r or hist or y against bot h t he
t r aining dat a and t he checking dat a r eveals much.
Her e we can see t hat t he t r aining er r or set t les at about t he 50
t h
epoch point . In
fact , t he smallest value of t he checking dat a er r or occur s at epoch 52, aft er
which it incr eases slight ly, even as anfis cont inues t o minimize t he er r or
against t he t r aining dat a all t he way t o epoch 200. Depending on t he specified
Checking Error
Training Error
0 20 40 60 80 100 120 140 160 180 200
0.3
0.35
0.4
0.45
0.5
0.55
0.6
0.65
0.7
Epochs
2 Tutorial
2128
er r or t oler ance, t his plot also indicat es t he models abilit y t o gener alize t he t est
dat a.
A Clustering GUI Tool
Ther e is also t he Clust er ing GUI, which implement s fcm and subclust, along
wit h all of t heir opt ions. It s use is fair ly selfevident .
The clust er ing GUI looks like t his, and is invoked using t he command line
funct ion, findcluster.
You can invoke findcluster wit h a dat a set dir ect ly, in or der t o open t he GUI
wit h a dat a set . The dat a set must have t he ext ension .dat. For example, t o
load t he dat a set , clusterdemo.dat, t ype findcluster('clusterdemo.dat').
You use t he pulldown t ab under Method t o change bet ween fcm (fuzzy
cmeans) and subtracti v (subt r act ive clust er ing). Mor e infor mat ion on t he
opt ions can be found in t he ent r ies for fcm on page 322, and subclust on page
372, r espect ively.
Load a data set (*.dat)
Start clustering
Options change
with method
Choose fcm
clustering method.
into your directory.
the data.
Choose two of your data
variables to be plotted on
the screen. Once the data
is loaded, select them
with the pulldown tabs.
or subtractive
Save the value of
the cluster center.
Fuzzy Clustering
2129
The Clust er ing GUI wor ks on mult idimensional dat a set s, but only displays
t wo of t hose dimensions. Use t he pulldown t abs under Xaxi s and Yaxi s t o
select which dat a dimension you want t o view.
2 Tutorial
2130
StandAlone CCode Fuzzy Inference Engine
In t he fuzzy/fuzzy dir ect or y of t he t oolbox, you can find t wo C files, fismain.c
and fis.c, which ar e pr ovided as t he sour ce codes for a st andalone fuzzy
infer ence engine. The st andalone Ccode fuzzy infer ence engine can r ead an
FIS file and an input dat a file t o per for m fuzzy infer ence dir ect ly, or it can be
embedded in ot her ext er nal applicat ions.
To compile t he st andalone fuzzy infer ence engine on a UNIX syst em, t ype
% cc O o fismain fismain.c lm
(Not e t hat % is only symbolic of a UNIX pr ompt , and t hat you do not have t o
t ype fis.c explicit ly, since it is included in fismain.c.) Upon successful
compilat ion, t ype t he execut able command t o see how it wor ks:
% fismain
This pr ompt s t he following message:
% Usage: fismain data_file fis_file
This means t hat fismain needs t wo files t o do it s wor k: a dat a file cont aining
r ows of input vect or s, and an FIS file t hat specifies t he fuzzy infer ence syst em
under consider at ion.
For example, consider an FIS st r uct ur e file named, mam21.fis. We can pr epar e
t he input dat a file using MATLAB:
[x, y] = meshgrid(5:5, 5:5);
input_data = [x(:) y(:)];
save fis_in input_data ascii
This saves all t he input dat a as a 121by2 mat r ix in t he ASCII file fis_in,
wher e each r ow of t he mat r ix r epr esent s an input vect or .
Now we can call t he st andalone code:
% fismain fis_in mam21.fis
This gener at es 121 out put s on your scr een. You can dir ect t he out put s t o
anot her file:
% fismain fis_in mam21.fis > fis_out
StandAlone CCode Fuzzy Inference Engine
2131
Now t he file fis_out cont ains a 121by1 mat r ix. In gener al, each r ow of t he
out put mat r ix r epr esent s an out put vect or . The synt ax of fismain is similar t o
it s MEXfile count er par t evalfis.m, except t hat all mat r ices ar e r eplaced wit h
files.
To compar e t he r esult s fr om t he MATLAB MEXfile and t he st andalone
execut able, t ype t he following wit hin MATLAB:
fismat = readfis('mam21');
matlab_out = evalfis(input_data, fismat);
load fis_out
max(max(matlab_out fis_out))
ans =
4.9583e13
This t iny differ ence comes fr om t he limit ed lengt h pr int out in t he file fis_out.
Ther e ar e sever al t hings you should know about t his st andalone execut able:
It is compat ible wit h bot h ANSI and K & R st andar ds for C code, as long as
__STDC__ is defined in ANSI compiler s.
Cust omized funct ions ar e not allowed in t he st andalone execut able, so you
ar e limit ed t o t he 11 member ship funct ions t hat come wit h t he t oolbox, as
well as ot her fact or y set t ings for AND, OR, IMP, and AGG funct ions.
fismain.c cont ains only t he main() funct ion and it is heavily document ed
for easy adapt at ion t o ot her applicat ions.
To add a new member ship funct ion or new r easoning mechanism int o t he
st andalone code, you need t o change t he file fis.c, which cont ains all t he
necessar y funct ions t o per for m t he fuzzy infer ence pr ocess.
For t he Macint osh, t he compiled command fismain t r ies t o find fismain.in
and fismain.fis as input dat a and FIS descr ipt ion files, r espect ively. The
out put is st or ed in fismain.out. These filenames ar e defined wit hin
Macint oshspecific #define symbols in fismain.c and can be changed if
necessar y.
2 Tutorial
2132
Glossary
This sect ion is designed t o br iefly explain some of t he specialized t er ms t hat ar e
der ived fr om fuzzy logic.
aggregati on  t he combinat ion of t he consequent s of each r ule in a Mamdani
fuzzy infer ence syst em in pr epar at ion for defuzzificat ion.
Adapt i ve NeuroFuzzy Infe rence Sys t em (ANFIS)  a t echnique for
aut omat ically t uning Sugenot ype infer ence syst ems based on t r aining dat a.
antecedent  t he init ial (or if) par t of a fuzzy r ule.
cons eque nt  t he final (or t hen) par t of a fuzzy r ule.
de fuzzi fi cati on  t he pr ocess of t r ansfor ming a fuzzy out put of a fuzzy
infer ence syst em int o a cr isp out put .
de gree of membe rshi p  t he out put of a member ship funct ion, t his value is
always limit ed t o bet ween 0 and 1. Also known as a member ship value or
member ship gr ade.
de gree of fulfi llment  see fi ri ng s trength.
fi ri ng s tre ngth  t he degr ee t o which t he ant ecedent par t of a fuzzy r ule is
sat isfied. The fir ing st r engt h may be t he r esult of an AND or an OR oper at ion,
and it shapes t he out put funct ion for t he r ule. Also known as degr ee of
fulfillment .
fuzzi fi cati on  t he pr ocess of gener at ing member ship values for a fuzzy
var iable using member ship funct ions.
fuzzy cmeans clus te ri ng  a dat a clust er ing t echnique wher ein each dat a
point belongs t o a clust er t o a degr ee specified by a member ship gr ade.
fuzzy i nfe rence system (FIS)  t he over all name for a syst em t hat uses fuzzy
r easoning t o map an input space t o an out put space.
fuzzy operators  AND, OR, and NOT oper at or s. These ar e also known as
logical connect ives.
fuzzy s et  a set which can cont ain element s wit h only a par t ial degr ee of
member ship.
fuzzy s i ngleton  a fuzzy set wit h a member ship funct ion t hat is unit y at a one
par t icular point and zer o ever ywher e else.
Glossary
2133
i mpli cati on  t he pr ocess of shaping t he fuzzy set in t he consequent based on
t he r esult s of t he ant ecedent in a Mamdanit ype FIS.
Mamdani type i nference  a t ype of fuzzy infer ence in which t he fuzzy set s
fr om t he consequent of each r ule ar e combined t hr ough t he aggr egat ion
oper at or and t he r esult ing fuzzy set is defuzzified t o yield t he out put of t he
syst em.
me mbers hi p functi on (MF)  a funct ion t hat specifies t he degr ee t o which a
given input belongs t o a set or is r elat ed t o a concept .
s i ngle ton output functi on  an out put funct ion t hat is given by a spike at a
single number r at her t han a cont inuous cur ve. In t he Fuzzy Logic Toolbox it is
only suppor t ed as par t of a zer oor der Sugeno model.
subtracti ve clusteri ng  a t echnique for aut omat ically gener at ing fuzzy
infer ence syst ems by det ect ing clust er s in input out put t r aining dat a.
Suge notype i nference  a t ype of fuzzy infer ence in which t he consequent of
each r ule is a linear combinat ion of t he input s. The out put is a weight ed linear
combinat ion of t he consequent s.
Tconorm  (also known as Snor m) a t woinput funct ion t hat descr ibes a
super set of fuzzy union (OR) oper at or s, including maximum, algebr aic sum,
and any of sever al par amet er ized Tconor ms.
Tnorm  a t woinput funct ion t hat descr ibes a super set of fuzzy int er sect ion
(AND) oper at or s, including minimum, algebr aic pr oduct , and any of sever al
par amet er ized Tnor ms.
2 Tutorial
2134
References
[Bez81] Bezdek, J .C., Pattern Recognition with Fuzzy Objective Function
Algorithms, Plenum Pr ess, New Yor k, 1981.
[Chi94] Chiu, S., Fuzzy Model Ident ificat ion Based on Clust er Est imat ion,
J ournal of Intelligent & Fuzzy S ystems, Vol. 2, No. 3, Sept . 1994.
[Dub80] Dubois, D. and H. Pr ade, Fuzzy S ets and S ystems: Theory and
Applications, Academic Pr ess, New Yor k, 1980.
[J an91] J ang, J .S. R., Fuzzy Modeling Using Gener alized Neur al Net wor ks
and Kalman Filt er Algor it hm, Proc. of the Ninth National Conf. on Artificial
Intelligence (AAAI91), pp. 762767, J uly 1991.
[J an93] J ang, J .S. R., ANFIS: Adapt iveNet wor kbased Fuzzy Infer ence
Syst ems, IEEE Transactions on S ystems, Man, and Cybernetics, Vol. 23, No.
3, pp. 665685, May 1993.
[J an94] J ang, J .S. R. and N. Gulley, Gain scheduling based fuzzy cont r oller
design, Proc. of the International J oint Conference of the North American
Fuzzy Information Processing S ociety Biannual Conference, the Industrial
Fuzzy Control and Intelligent S ystems Conference, and the NAS A J oint
Technology Workshop on Neural Networks and Fuzzy Logic, San Ant onio,
Texas, Dec. 1994.
[J an95] J ang, J .S. R. and C.T. Sun, Neur ofuzzy modeling and cont r ol,
Proceedings of the IEEE, Mar ch 1995.
[J an97] J ang, J .S. R. and C.T. Sun, NeuroFuzzy and S oft Computing: A
Computational Approach to Learning and Machine Intelligence, Pr ent ice Hall,
1997.
[Kau85] Kaufmann, A. and M.M. Gupt a, Introduction to Fuzzy Arithmetic, V.N.
Reinhold, 1985.
[Lee90] Lee, C.C., Fuzzy logic in cont r ol syst ems: fuzzy logic cont r oller par t s
1 and 2, IEEE Transactions on S ystems, Man, and Cybernetics, Vol. 20, No. 2,
pp 404435, 1990.
[Mam75] Mamdani, E.H. and S. Assilian, An exper iment in linguist ic
synt hesis wit h a fuzzy logic cont r oller , International J ournal of ManMachine
S tudies, Vol. 7, No. 1, pp. 113, 1975.
References
2135
[Mam76] Mamdani, E.H., Advances in t he linguist ic synt hesis of fuzzy
cont r oller s, International J ournal of ManMachine S tudies, Vol. 8, pp.
669678, 1976.
[Mam77] Mamdani, E.H., Applicat ions of fuzzy logic t o appr oximat e r easoning
using linguist ic synt hesis, IEEE Transactions on Computers, Vol. 26, No. 12,
pp. 11821191, 1977.
[Sch63] Schweizer , B. and A. Sklar , Associat ive funct ions and abst r act
semigr oups, Publ. Math Debrecen, 10:6981, 1963.
[Sug77] Sugeno, M., Fuzzy measur es and fuzzy int egr als: a sur vey, (M.M.
Gupt a, G. N. Sar idis, and B.R. Gaines, edit or s) Fuzzy Automata and Decision
Processes, pp. 89102, Nor t hHolland, New Yor k, 1977.
[Sug85] Sugeno, M., Industrial applications of fuzzy control, Elsevier Science
Pub. Co., 1985.
[Wan94] Wang, L.X., Adaptive fuzzy systems and control: design and stability
analysis, Pr ent ice Hall, 1994.
[WidS85] Widr ow, B. and D. St ear ns, Adaptive S ignal Processing, Pr ent ice
Hall, 1985.
[Yag80] Yager , R., On a gener al class of fuzzy connect ives, Fuzzy S ets and
S ystems, 4:235242, 1980.
[Yag94] Yager , R. and D. Filev, Gener at ion of Fuzzy Rules by Mount ain
Clust er ing, J ournal of Intelligent & Fuzzy S ystems, Vol. 2, No. 3, pp. 209219,
1994.
[Zad65] Zadeh, L.A., Fuzzy set s, Information and Control, Vol. 8, pp. 338353,
1965.
[Zad73] Zadeh, L.A., Out line of a new appr oach t o t he analysis of complex
syst ems and decision pr ocesses, IEEE Transactions on S ystems, Man, and
Cybernetics, Vol. 3, No. 1, pp. 2844, J an. 1973.
[Zad75] Zadeh, L.A., The concept of a linguist ic var iable and it s applicat ion t o
appr oximat e r easoning, Par t s 1, 2, and 3, Information S ciences, 1975,
8:199249, 8:301357, 9:4380
[Zad88] Zadeh, L.A., Fuzzy Logic, Computer, Vol. 1, No. 4, pp. 8393, 1988.
[Zad89] Zadeh, L.A., Knowledge r epr esent at ion in fuzzy logic, IEEE
Transactions on Knowledge and Data Engineering, Vol. 1, pp. 89100, 1989.
2 Tutorial
2136
3
Refer ence
GUI Tools . . . . . . . . . . . . . . . . . . . . . . 32
Member ship Funct ions . . . . . . . . . . . . . . . . 32
FIS Dat a St r uct ur e Management . . . . . . . . . . . . 33
Advanced Techniques . . . . . . . . . . . . . . . . . 34
Simulink Blocks . . . . . . . . . . . . . . . . . . . 34
Demos . . . . . . . . . . . . . . . . . . . . . . . 35
3 Reference
32
This sect ion of t he chapt er cont ains br ief descr ipt ions of all t he funct ions in t he
Fuzzy Logic Toolbox. The following t ables cont ain t he funct ions list ed by t opic.
GUI Tools
Membership Functions
Function Purpose
anfisedit ANFIS Edit or GUI.
fuzzy Basic FIS Edit or.
mfedit Member ship Funct ion Edit or.
ruleedit Rule Edit or and par ser.
ruleview Rule Viewer and fuzzy infer ence diagr am.
surfview Out put Sur face Viewer.
Function Purpose
dsigmf Differ ence of t wo sigmoid member ship funct ions.
gauss2mf Twosided Gaussian cur ve member ship funct ion.
gaussmf Gaussian cur ve member ship funct ion.
gbellmf Gener alized bell cur ve member ship funct ion.
pimf Pishaped cur ve member ship funct ion.
33
FIS Data Structure Management
psigmf Pr oduct of t wo sigmoidal member ship funct ions.
smf Sshaped cur ve member ship funct ion.
sigmf Sigmoid cur ve member ship funct ion.
trapmf Tr apezoidal member ship funct ion.
trimf Tr iangular member ship funct ion.
zmf Zshaped cur ve member ship funct ion.
Function Purpose
addmf Add member ship funct ion t o FIS.
addrule Add r ule t o FIS.
addvar Add var iable t o FIS.
defuzz Defuzzify member ship funct ion.
evalfis Per for m fuzzy infer ence calculat ion.
evalmf Gener ic member ship funct ion evaluat ion.
gensurf Gener at e FIS out put sur face.
getfis Get fuzzy syst em pr oper t ies.
mf2mf Tr anslat e par amet er s bet ween funct ions.
newfis Cr eat e new FIS.
parsrule Par se fuzzy r ules.
plotfis Display FIS input out put st r uct ur e.
plotmf Plot all of t he member ship funct ions associat ed
wit h a given var iable.
Function Purpose
3 Reference
34
Advanced Techniques
Simulink Blocks
readfis Load FIS fr om disk.
rmmf Remove member ship funct ion fr om FIS.
rmvar Remove var iable fr om FIS.
setfis Set fuzzy syst em pr oper t ies.
showfis Display annot at ed FIS.
showrule Display FIS r ules.
writefis Save FIS t o disk.
Function Purpose
anfis Tr aining r out ine for a Sugenot ype FIS (MEX only).
fcm Find clust er s wit h FCM clust er ing.
genfis1 Gener at e FIS mat r ix using gr id met hod.
genfis2 Gener at e FIS mat r ix using subt r act ive clust er ing.
subclust Find clust er cent er s wit h subt r act ive clust er ing.
Function Purpose
fuzblock Fuzzy logic cont r oller blocks and demo blocks.
sffis Fuzzy infer ence Sfunct ion.
Function Purpose
35
Demos
Function Purpose
defuzzdm Defuzzificat ion met hods.
fcmdemo FCM clust er ing demo (2D).
fuzdemos GUI for Fuzzy Logic Toolbox demos.
gasdemo ANFIS demo for fuel efficiency using subclust er ing.
juggler Balljuggler wit h Rule Viewer.
invkine Inver se kinemat ics of a r obot ar m.
irisfcm FCM clust er ing demo (4D).
noisedm Adapt ive noise cancellat ion.
slbb Ball and beam cont r ol (Simulink ).
slcp Inver t ed pendulum cont r ol (Simulink ).
sltank Wat er level cont r ol (Simulink).
sltankrule Wat er level cont r ol wit h Rule Viewer (Simulink).
sltbu Tr uck backerupper (Simulink only).
addmf
36
3addmf
Purpose Add a member ship funct ion t o an FIS.
Synopsis a = addmf(a,'varType',varIndex,'mfName','mfType',mfParams)
Description A member ship funct ion can only be added t o a var iable in an exist ing MATLAB
wor kspace FIS. Indices ar e assigned t o member ship funct ions in t he or der in
which t hey ar e added, so t he fir st member ship funct ion added t o a var iable will
always be known as member ship funct ion number one for t hat var iable. You
cannot add a member ship funct ion t o input var iable number t wo of a syst em if
only one input has been defined.
The funct ion r equir es six input ar gument s in t his or der :
1 A MATLAB var iable name of a FIS st r uct ur e in t he wor kspace
2 A st r ing r epr esent ing t he t ype of var iable you want t o add t he member ship
funct ion t o ('input' or 'output')
3 The index of t he var iable you want t o add t he member ship funct ion t o
4 A st r ing r epr esent ing t he name of t he new member ship funct ion
5 A st r ing r epr esent ing t he t ype of t he new member ship funct ion
6 The vect or of par amet er s t hat specify t he member ship funct ion
addmf
37
Example a=newfis('tipper');
a=addvar(a,'input','service',[0 10]);
a=addmf(a,'input',1,'poor','gaussmf',[1.5 0]);
a=addmf(a,'input',1,'good','gaussmf',[1.5 5]);
a=addmf(a,'input',1,'excellent','gaussmf',[1.5 10]);
plotmf(a,'input',1)
See Also addrule, addvar, plotmf, rmmf, rmvar
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
service
D
e
g
r
e
e
o
f
b
e
l
i
e
f
poor good
excellent
addrule
38
3addr ule
Purpose Add a r ule t o an FIS.
Synopsis a = addrule(a,ruleList)
Description addrule has t wo ar gument s. The fir st ar gument is t he MATLAB wor kspace
var iable FIS name. The second ar gument for addrule is a mat r ix of one or mor e
r ows, each of which r epr esent s a given r ule. The for mat t hat t he r ule list mat r ix
must t ake is ver y specific. If t her e ar e m input s t o a syst em and n out put s, t her e
must be exact ly m + n + 2 columns t o t he r ule list .
The fir st m columns r efer t o t he input s of t he syst em. Each column cont ains a
number t hat r efer s t o t he index of t he member ship funct ion for t hat var iable.
The next n columns r efer t o t he out put s of t he syst em. Each column cont ains a
number t hat r efer s t o t he index of t he member ship funct ion for t hat var iable.
The m + n + 1 column cont ains t he weight t hat is t o be applied t o t he r ule. The
weight must be a number bet ween zer o and one, and is gener ally left as one.
The m + n + 2 column cont ains a 1 if t he fuzzy oper at or for t he r ules ant ecedent
is AND. It cont ains a 2 if t he fuzzy oper at or is OR.
Example ruleList=[
1 1 1 1 1
1 2 2 1 1];
a = addrule(a,ruleList);
If t he above syst em a has t wo input s and one out put , t he fir st r ule can be
int er pr et ed as: If input 1 is MF 1 and input 2 is MF 1, t hen out put 1 is MF 1.
See Also addmf, addvar, rmmf, rmvar, parsrule, showrule
addvar
39
3addvar
Purpose Add a var iable t o an FIS.
Synopsis a = addvar(a,'varType','varName',varBounds)
Description addvar has four ar gument s in t his or der :
1 The name of a FIS st r uct ur e in t he MATLAB wor kspace
2 A st r ing r epr esent ing t he t ype of t he var iable you want t o add ('input' or
'output')
3 A st r ing r epr esent ing t he name of t he var iable you want t o add
4 The vect or descr ibing t he limit ing r ange values for t he var iable you want t o
add
Indices ar e applied t o var iables in t he or der in which t hey ar e added, so t he
fir st input var iable added t o a syst em will always be known as input var iable
number one for t hat syst em. Input and out put var iables ar e number ed
independent ly.
Example a=newfis('tipper');
a=addvar(a,'input','service',[0 10]);
getfis(a,'input',1)
MATLAB r eplies
Name = service
NumMFs = 0
MFLabels =
Range = [0 10]
See Also addmf, addrule, rmmf, rmvar
anfis
310
3anfis
Purpose Tr aining r out ine for Sugenot ype FIS (MEX only).
Synopsis [fismat,error1,stepsize] = anfis(trnData)
[fismat,error1,stepsize] = anfis(trnData,fismat)
[fismat1,error1,stepsize] = ...
anfis(trnData,fismat,trnOpt,dispOpt)
[fismat1,error1,stepsize,fismat2,error2] = ...
anfis(trnData,trnOpt,dispOpt,chkData)
[fismat1,error1,stepsize,fismat2,error2] = ...
anfis(trnData,trnOpt,dispOpt,chkData,optMethod)
Description This is t he major t r aining r out ine for Sugenot ype fuzzy infer ence syst ems.
anfis uses a hybr id lear ning algor it hm t o ident ify par amet er s of Sugenot ype
fuzzy infer ence syst ems. It applies a combinat ion of t he least squar es met hod
and t he backpr opagat ion gr adient descent met hod for t r aining FIS
member ship funct ion par amet er s t o emulat e a given t r aining dat a set . anfis
can also be invoked using an opt ional ar gument for model validat ion. The t ype
of model validat ion t hat t akes place wit h t his opt ion is a checking for model
over fit t ing, and t he ar gument is a dat a set called t he checking dat a set .
The ar gument s in t he above descr ipt ion for anfis ar e as follows:
trnData: t he name of a t r aining dat a set . This is a mat r ix wit h all but t he
last column cont aining input dat a, while t he last column cont ains a single
vect or of out put dat a.
fismat: t he name of an FIS, (fuzzy infer ence syst em) used t o pr ovide anfis
wit h an init ial set of member ship funct ions for t r aining. Wit hout t his opt ion,
anfis will use genfis1 t o implement a default init ial FIS for t r aining. This
default FIS will have t wo member ship funct ions of t he Gaussian t ype, when
invoked wit h only one ar gument . If fismat is pr ovided as a single number (or
a vect or ), it is t aken as t he number of member ship funct ions (or t he vect or
whose ent r ies ar e t he r espect ive number s of member ship funct ions
associat ed wit h each r espect ive input when t hese number s differ for each
input ). In t his case, bot h ar gument s of anfis ar e passed t o genfis1 t o
gener at e a valid FIS st r uct ur e befor e st ar t ing t he t r aining pr ocess.
anfis
311
trnOpt: vect or of t r aining opt ions. When any t r aining opt ion is ent er ed as
NaN t he default opt ions will be in for ce. These opt ions ar e as follows:
trnOpt(1): t r aining epoch number (default : 10)
trnOpt(2): t r aining er r or goal (default : 0)
trnOpt(3): init ial st ep size (default : 0.01)
trnOpt(4): st ep size decr ease r at e (default : 0.9)
trnOpt(5): st ep size incr ease r at e (default : 1.1)
dispOpt: vect or of display opt ions t hat specify what message t o display in t he
MATLAB command window dur ing t r aining. The default value for any
display opt ion is 1, which means t he cor r esponding infor mat ion is displayed.
A 0 means t he cor r esponding infor mat ion is not displayed on t he scr een.
When any display opt ion is ent er ed as NaN, t he default opt ions will be in
for ce. These opt ions ar e as follows:
dispOpt(1): ANFIS infor mat ion, such as number s of input and out put
member ship funct ions, and so on (default : 1)
dispOpt(2): er r or (default : 1)
dispOpt(3): st ep size at each par amet er updat e (default : 1)
dispOpt(4): final r esult s (default : 1)
chkData: t he name of an opt ional checking dat a set for over fit t ing model
validat ion. This dat a set is a mat r ix in t he same for mat as t he t r aining dat a
set .
optMethod: opt ional opt imizat ion met hod used in member ship funct ion
par amet er t r aining: eit her 1 for t he hybr id met hod or 0 for t he
backpr opagat ion met hod. The default met hod is t he hybr id met hod, which is
a combinat ion of least squar es est imat ion wit h backpr opagat ion. The default
met hod is invoked whenever t he ent r y for t his ar gument is anyt hing but 0.
The t r aining pr ocess st ops whenever t he designat ed epoch number is r eached
or t he t r aining er r or goal is achieved.
anfis
312
Note on anfis arguments: When anfis is invoked wit h t wo or mor e
ar gument s, any opt ional ar gument s will t ake on t heir default values if t hey
ar e ent er ed as NaNs or empt y mat r ices. Default values can be changed dir ect ly
by modifying t he file anfis.m. Eit her NaNs or empt y mat r ices must be used as
placeholder s for var iables if you dont want t o specify t hem, but do want t o
specify succeeding ar gument s, for example, when you implement t he checking
dat a opt ion of anfis.
The r ange var iables in t he above descr ipt ion for anfis ar e as follows:
fismat1 is t he FIS st r uct ur e whose par amet er s ar e set accor ding t o a
minimum t r aining er r or cr it er ion.
error1 or error2 is an ar r ay of r oot mean squar ed er r or s r epr esent ing t he
t r aining dat a er r or signal and t he checking dat a er r or signal, r espect ively.
stepsize is an ar r ay of st ep sizes. The st ep size is decr eased (by mult iplying
it wit h t he component of t he t r aining opt ion cor r esponding t o t he st ep size
decr ease r at e) if t he er r or measur e under goes t wo consecut ive combinat ions
of an incr ease followed by a decr ease. The st ep size is incr eased (by
mult iplying it wit h t he incr ease r at e) if t he er r or measur e under goes four
consecut ive decr eases.
fismat2 is t he FIS st r uct ur e whose par amet er s ar e set accor ding t o a
minimum checking er r or cr it er ion.
anfis
313
Example x = (0:0.1:10)';
y = sin(2*x)./exp(x/5);
trnData = [x y];
numMFs = 5;
mfType = 'gbellmf';
epoch_n = 20;
in_fismat = genfis1(trnData,numMFs,mfType);
out_fismat = anfis(trnData,in_fismat,20);
plot(x,y,x,evalfis(x,out_fismat));
legend('Training Data','ANFIS Output');
See Also genfis1, anfis
References J ang, J .S. R., Fuzzy Modeling Using Gener alized Neur al Net wor ks and
Kalman Filt er Algor it hm, Proc. of the Ninth National Conf. on Artificial
Intelligence (AAAI91), pp. 762767, J uly 1991.
J ang, J .S. R., ANFIS: Adapt iveNet wor kbased Fuzzy Infer ence Syst ems,
IEEE Transactions on S ystems, Man, and Cybernetics, Vol. 23, No. 3, pp.
665685, May 1993.
anfisedit
314
3anfisedit
Purpose To open t he ANFIS Edit or GUI.
Synopsis anfisedit('a')
anfisedit(a)
anfisedit
Description
Using anfisedit, you br ing up t he ANFIS Edit or GUI fr om which you can load
a dat a set and t r ain anfis. The ANFIS Edit or GUI invoked using
Test data against
the FIS model. The
plot appears in the
plot region.
Testing Data appears on the
plot in blue as
Training Data appears on
the plot in blue as
Checking Data appears on
the plot in blue as
FIS Output appears on the
screen in red as
...
o o o
+++
***
Load or save fuzzy
Sugeno system or open
new Sugeno system.
Undo
Open FIS or Edit with any
of the other GUIs.
Status of the number of inputs,
outputs, input membership functions
and output membership functions
Load either training,
testing, or checking
data from disk or
workspace, or load
demo data. Data
appears in the plot
region.
Clear Dat a unloads a loaded data
set checked under Type:.
The plot region is cleared even if other
data types are still loaded.
Load FIS or generate FIS
from loaded data using
your chosen number of MFs
and rules or fuzzy.
Train FIS after setting optimization
method, error tolerance, and number
of epochs. This generates error plots
in the plot region.
After you generate
or load a FIS, this
button allows you to
open a graphical
representation of its
input/output
structure.
Plot region
anfisedit
315
anfisedit('a'), br ings up t he ANFIS Edit or GUI fr om which you can
implement anfis using a FIS st r uct ur e st or ed as a file on your disk called,
a.fis.
anfisedit(a) oper at es t he same way for a FIS st r uct ur e a, st or ed as a var iable
in t he MATLAB wor kspace.
Refer t o anfis and t he ANFIS Edit or GUI on page 292 for mor e infor mat ion
about how t o use anfisedit.
Menu Items On t he ANFIS Edit or GUI, t her e is a menu bar t hat allows you t o open r elat ed
GUI t ools, open and save syst ems, and so on. The Fi le menu is t he same as t he
one found on t he FIS Edit or . Refer t o fuzzy on page 329 for mor e infor mat ion.
Use t he following Edi t menu it em:
Undo t o undo t he most r ecent change.
Use t he following Vi e w menu it ems:
Edi t FIS properti e s... t o invoke t he FIS Edit or .
Edi t rule s... t o invoke t he Rule Edit or .
Edi t members hi p functi ons ... t o invoke t he Member ship Funct ion Edit or .
Vi e w rules ... t o invoke t he Rule Viewer .
Vi e w surface ... t o invoke t he Sur face Viewer .
See Also fuzzy, mfedit, ruleedit, ruleview, surfview
convertfis
316
3conver t fis
Purpose Conver t a Fuzzy Logic Toolbox ver sion 1.0 FIS mat r ix t o a ver sion 2.0 FIS
st r uct ur e.
Synopsis fis_new=convertfis(fis_old)
Description convertfis t akes a ver sion 1.0 FIS mat r ix and conver t s it t o a ver sion 2.0
st r uct ur e.
defuzz
317
3defuzz
Purpose Defuzzify member ship funct ion.
Synopsis out = defuzz(x,mf,type)
Description defuzz(x,mf,type) r et ur ns a defuzzified value out, of a member ship funct ion
mf posit ioned at associat ed var iable value x, using one of sever al defuzzificat ion
st r at egies, accor ding t o t he ar gument , type. The var iable type can be one of t he
following.
centroid: cent r oid of ar ea met hod
bisector: bisect or of ar ea met hod
mom: mean of maximum met hod
som: smallest of maximum met hod
lom: lar gest of maximum met hod
If type is not one of t he above, it is assumed t o be a user defined funct ion. x and
mf ar e passed t o t his funct ion t o gener at e t he defuzzified out put .
Examples x = 10:0.1:10;
mf = trapmf(x,[10 8 4 7]);
xx = defuzz(x,mf,'centroid');
dsigmf
318
3dsigmf
Purpose Built in member ship funct ion composed of t he differ ence bet ween t wo
sigmoidal member ship funct ions.
Synopsis y = dsigmf(x,[a1 c1 a2 c2])
Description The sigmoidal member ship funct ion used her e depends on t he t wo par amet er s
a and c and is given by
The member ship funct ion dsigmf depends on four par amet er s, a1, c1, a2, and
c2, and is t he differ ence bet ween t wo of t hese sigmoidal funct ions:
f
1
(x; a1, c
1
)  f
2
(x; a2, c
2
)
The par amet er s ar e list ed in t he or der : [a1 c
1
a
2
c
2
].
Example x=0:0.1:10;
y=dsigmf(x,[5 2 5 7]);
plot(x,y)
xlabel('dsigmf, P=[5 2 5 7]')
See Also gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, psigmf, sigmf, smf, trapmf,
trimf, zmf
f x a ; c , ( )
1
1 e
a x c ( )
+
 =
0 2 4 6 8 10
0
0.25
0.5
0.75
1
dsigmf, P = [5 2 5 7]
evalfis
319
3evalfis
Purpose Per for m fuzzy infer ence calculat ions.
Synopsis output= evalfis(input,fismat)
output= evalfis(input,fismat, numPts)
[output, IRR, ORR, ARR]= evalfis(input,fismat)
[output, IRR, ORR, ARR]= evalfis(input,fismat, numPts)
Description evalfis has t he following ar gument s:
input: a number or a mat r ix specifying input values. If input is an MbyN
mat r ix, wher e N is number of input var iables, t hen evalfis t akes each r ow
of input as an input vect or and r et ur ns t he MbyL mat r ix t o t he var iable,
output, wher e each r ow is an out put vect or and L is t he number of out put
var iables.
fismat: an FIS st r uct ur e t o be evaluat ed.
numPt s: an opt ional ar gument t hat r epr esent s t he number of sample point s
on which t o evaluat e t he member ship funct ions over t he input or out put
r ange. If t his ar gument is not used, t he default value of 101 point is used.
The r ange labels for evalfis ar e as follows:
output: t he out put mat r ix of size MbyL, wher e M r epr esent s t he number of
input values specified above, and L is t he number of out put var iables for t he
FIS.
The opt ional r ange var iables for evalfis ar e only calculat ed when t he input
ar gument is a r ow vect or , (only one set of input s is applied). These opt ional
r ange var iables ar e:
IRR: t he r esult of evaluat ing t he input values t hr ough t he member ship
funct ions. This is a mat r ix of size numRulesbyN, wher e numRules is t he
number of r ules, and N is t he number of input var iables.
ORR: t he r esult of evaluat ing t he out put values t hr ough t he member ship
funct ions. This is a mat r ix of size numPtsbynumRules*L, wher e numRules
is t he number of r ules, and L is t he number of out put s. The fir st numRules
columns of t his mat r ix cor r espond t o t he fir st out put , t he next numRules
columns of t his mat r ix cor r espond t o t he second out put , and so for t h.
ARR: t he numPtsbyL mat r ix of t he aggr egat e values sampled at numPts along
t he out put r ange for each out put .
evalfis
320
When invoked wit h only one r ange var iable, t his funct ion comput es t he out put
vect or , output, of t he fuzzy infer ence syst em specified by t he st r uct ur e,
fismat, for t he input value specified by t he number or mat r ix, input.
Example fismat = readfis('tipper');
out = evalfis([2 1; 4 9],fismat)
This gener at es t he r esponse
out =
7.0169
19.6810
See Also ruleview, gensurf
evalmf
321
3evalmf
Purpose Gener ic member ship funct ion evaluat ion.
Synopsis y = evalmf(x,mfParams,mfType)
Description evalmf evaluat es any member ship funct ion, wher e x is t he var iable r ange for
t he member ship funct ion evaluat ion, mfType is a member ship funct ion fr om
t he t oolbox, and mfParams ar e appr opr iat e par amet er s for t hat funct ion.
If you want t o cr eat e your own cust om member ship funct ion, evalmf will st ill
wor k, because it evaluat es any member ship funct ion whose name it doesnt
r ecognize.
Examples x=0:0.1:10;
mfparams = [2 4 6];
mftype = 'gbellmf';
y=evalmf(x,mfparams,mftype);
plot(x,y)
xlabel('gbellmf, P=[2 4 6]')
See Also dsigmf, gaussmf, gauss2mf, gbellmf, mf2mf, pimf, psigmf, sigmf, smf, trapmf,
trimf, zmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
gbellmf, P = [2 4 6]
fcm
322
3fcm
Purpose Fuzzy cmeans clust er ing.
Synopsis [center,U,obj_fcn] = fcm(data,cluster_n)
Description [center, U, obj_fcn] = fcm(data, cluster_n) applies t he fuzzy cmeans
clust er ing met hod t o a given dat a set .
The input ar gument s of t his funct ion ar e:
data: dat a set t o be clust er ed; each r ow is a sample dat a point
cluster_n: number of clust er s (gr eat er t han one)
The out put ar gument s of t his funct ion ar e:
center: mat r ix of final clust er cent er s wher e each r ow pr ovides t he cent er
coor dinat es
U: final fuzzy par t it ion mat r ix (or member ship funct ion mat r ix)
obj_fcn: values of t he object ive funct ion dur ing it er at ions
fcm(data,cluster_n,options) uses an addit ional ar gument var iable,
options, t o cont r ol clust er ing par amet er s, int r oduce a st opping cr it er ia, and/
or set t he it er at ion infor mat ion display:
options(1): exponent for t he par t it ion mat r ix U (default : 2.0)
options(2): maximum number of it er at ions (default : 100)
options(3): minimum amount of impr ovement (default : 1e5)
options(4): info display dur ing it er at ion (default : 1)
If any ent r y of options is NaN, t he default value for t hat opt ion is used inst ead.
The clust er ing pr ocess st ops when t he maximum number of it er at ions is
r eached, or when t he object ive funct ion impr ovement bet ween t wo consecut ive
it er at ions is less t han t he minimum amount of impr ovement specified.
fcm
323
Example data = rand(100, 2);
[center,U,obj_fcn] = fcm(data, 2);
plot(data(:,1), data(:,2),'o');
maxU = max(U);
index1 = find(U(1,:) == maxU);
index2 = find(U(2, :) == maxU);
line(data(index1,1), data(index1, 2), 'linestyle', 'none',
'marker', '*',
'color', 'g');
line(data(index2,1), data(index2, 2), 'linestyle', 'none',
'marker', '*',
'color', 'r');
findcluster
324
3findclust er
Purpose Int er act ive clust er ing GUI for fuzzy cmeans and subclust er ing.
Synopsis findcluster
findcluster('file.dat')
Description findcluster br ings up a GUI t o implement fuzzy cmeans (fcm) and/or fuzzy
subt r act ive clust er ing (subtracti v) using t he pulldown t ab under Method on
t he GUI. Dat a is ent er ed using t he Load Data but t on. The opt ions for each of
t hese met hods ar e set t o default values. These can be changed. A descr ipt ion of
t he opt ions for fuzzy cmeans is found in fcm on page 322. A descr ipt ion of t he
opt ions for fuzzy subclust er ing is found in subclust on page 372.
This t ool wor ks on mult idimensional dat a set s, but only displays t wo of t hose
dimensions. Use t he pulldown t abs under Xaxi s and Yaxi s t o select which
dat a dimension you want t o view. For example, if you have dat a t hat is
fivedimensional, t his t ool labels t he dat a as data_1, data_2, data_3, data_4,
data_5, in t he or der in which t he dat a appear s in t he dat a set . Start will
per for m t he clust er ing, and Save Ce nter will save t he clust er cent er .
When oper at ing on a dat a set , file.dat, findcluster (file.dat) loads t he
dat a set aut omat ically, plot t ing up t o t he fir st t wo dimensions of t he dat a only.
findcluster
325
You can st ill choose which t wo dimensions of t he dat a you want t o clust er aft er
t he GUI comes up.
Example findcluster('clusterdemo.dat')
See Also fcm, subclust
fuzarith
326
3fuzarit h
Purpose To per for m fuzzy ar it hmet ic.
Synopsis C = fuzarith(X, A, B, operator)
Description Using int er val ar it hmet ic, C = fuzarith(X, A, B, operator) r et ur ns a fuzzy set
C as t he r esult of applying t he funct ion r epr esent ed by t he st r ing, operator,
t hat per for ms a binar y oper at ion on t he sampled convex fuzzy set s A and B. The
element s of A and B ar e der ived fr om convex funct ions of t he sampled univer se,
X.
A, B, and X ar e vect or s of t he same dimension.
operator is one of t he following st r ings: 'sum', 'sub', 'prod', and 'div'.
The r et ur ned fuzzy set C is a column vect or wit h t he same lengt h as X.
Remark Fuzzy addit ion might gener at e t he message: divide by zero, but t his will not
affect t he cor r ect ness of t his funct ion.
Example point_n = 101;% this determines MF's resolution
min_x = 20; max_x = 20;% universe is [min_x, max_x]
x = linspace(min_x, max_x, point_n)';
A = trapmf(x, [10 2 1 3]);% trapezoidal fuzzy set A
B = gaussmf(x, [2 5]);% Gaussian fuzzy set B
C1 = fuzarith(x, A, B, 'sum');
subplot(2,1,1);
plot(x, A, 'b', x, B, 'm:', x, C1, 'c');
title('fuzzy addition A+B');
C2 = fuzarith(x, A, B, 'sub');
subplot(2,1,2);
plot(x, A, 'b', x, B, 'm:', x, C2, 'c');
title('fuzzy subtraction AB');
C3 = fuzarith(x, A, B, 'prod');
fuzblock
327
3fuzblock
Purpose Simulink fuzzy logic cont r oller block.
Synopsis fuzblock
Description This command br ings up a Simulink syst em t hat , in addit ion t o some Simulink
demo blocks, cont ains t wo Simulink blocks you can use:
The Fuzzy Logic Cont r oller
The Fuzzy Logic Cont r oller Wit h Rule Viewer , (see also ruleview on page
361). This block for ces t he Rule Viewer t o pop open dur ing a Simulink
simulat ion.
The dialog box associat ed wit h eit her of t hese blocks is found by doubleclicking
on t he Fuzzy Logic Cont r oller block. This box cont ains t he name of t he FIS
st r uct ur e in t he wor kspace t hat cor r esponds t o t he desir ed fuzzy syst em you
want in your Simulink model.
To open t his dialog box for t he Fuzzy Logic Cont r oller Wit h Rule Viewer block,
you have t o
1 Doubleclick on t his block, and a Simulink diagr am wit h a Fuzzy Logic
Cont r oller block opens.
2 Doubleclick on t he second Fuzzy Logic Cont r oller block t hat pops open.
If t he fuzzy infer ence syst em has mult iple input s, t hese input s should be
mult iplexed t oget her befor e feeding t hem int o eit her t he Fuzzy Logic
Cont r oller or t he Fuzzy Logic Cont r oller Wit h Rule Viewer block. Similar ly, if
t he syst em has mult iple out put s, t hese signals will be passed out of t he block
on one mult iplexed line.
See Also sffis, ruleview
fuzdemos
328
3fuzdemos
Purpose List of all Fuzzy Logic Toolbox demos.
Synopsis fuzdemos
Description This funct ion br ings up a GUI t hat allows you t o choose bet ween any of sever al
Fuzzy Logic Toolbox demos list ed under Demos on page 35.
fuzzy
329
3fuzzy
Purpose To invoke t he basic FIS edit or .
Synopsis fuzzy
fuzzy(fismat)
This GUI t ool allows you t o edit t he highest level feat ur es of t he fuzzy infer ence
syst em, such as t he number of input and out put var iables, t he defuzzificat ion
met hod used, and so on. Refer t o The FIS Edit or on page 249 and ff., for mor e
infor mat ion about how t o use t he GUIs associat ed wit h fuzzy.
The FIS Edit or is t he highlevel display for any fuzzy logic infer ence syst em. It
allows you t o call t he var ious ot her edit or s t o oper at e on t he FIS. This int er face
allows convenient access t o all ot her edit or s wit h an emphasis on maximum
flexibilit y for int er act ion wit h t he fuzzy syst em.
The Diagram The diagr am displayed at t he t op of t he window shows t he input s, out put s, and
a cent r al fuzzy r ule pr ocessor . Click on one of t he var iable boxes t o make t he
select ed box t he cur r ent var iable. You should see t he box highlight ed in r ed.
Doubleclick on one of t he var iables t o br ing up t he Member ship Funct ion
Edit or . Doubleclick on t he fuzzy r ule pr ocessor t o br ing up t he Rule Edit or . If
fuzzy
330
a var iable exist s but is not ment ioned in t he r ule base, it is connect ed t o t he
r ule pr ocessor block wit h a dashed r at her t han a solid line.
Menu Items The FIS Edit or displays a menu bar t hat allows you t o open r elat ed GUI t ools,
open and save syst ems, and so on.
Under Fi le select :
New Mamdani FIS... t o open a new Mamdanist yle syst em wit h no
var iables and no r ules called Untitled.
New Sugeno FIS... t o open a new Sugenost yle syst em wit h no var iables
and no r ules called Untitled.
Open from di s k... t o load a syst em fr om a specified .fis file on disk.
Save to di s k t o save t he cur r ent syst em t o a .fis file on disk.
Save to di s k as... t o save t he cur r ent syst em t o disk wit h t he opt ion t o
r ename or r elocat e t he file.
Open from works pace... t o load a syst em fr om a specified FIS st r uct ur e
var iable in t he wor kspace.
Save to workspace ... t o save t he syst em t o t he cur r ent ly named FIS
st r uct ur e var iable in t he wor kspace.
Save to workspace as... t o save t he syst em t o a specified FIS st r uct ur e
var iable in t he wor kspace.
Close wi ndow t o close t he GUI.
Under Edi t select :
Add i nput t o add anot her input t o t he cur r ent syst em.
Add output t o add anot her out put t o t he cur r ent syst em.
Re move vari able t o delet e a select ed var iable.
Undo t o undo t he most r ecent change.
Under Vi e w select :
Edi t MFs ... t o invoke t he Member ship Funct ion Edit or .
Edi t rules... t o invoke t he Rule Edit or .
Edi t anfi s... t o invoke t he ANFIS Edit or for single out put Sugeno syst ems
only.
Vi e w rules ... t o invoke t he Rule Viewer .
Vi e w surface... t o invoke t he Sur face Viewer .
fuzzy
331
Inference
Method Popup
Menus
Five popup menus ar e pr ovided t o change t he funct ionalit y of t he five basic
st eps in t he fuzzy implicat ion pr ocess:
And me thod: Choose min, prod, or Custom, for a cust om oper at ion.
Or me thod: Choose max, probor (pr obabilist ic or ), or Custom, for a cust om
oper at ion.
Impli cati on me thod: Choose min, prod, or Custom, for a cust om oper at ion.
This select ion is not available for Sugenost yle fuzzy infer ence.
Aggre gati on method: Choose max, sum, probor, or Custom, for a cust om
oper at ion. This select ion is not available for Sugenost yle fuzzy infer ence.
De fuzzi fi cati on method: For Mamdanist yle infer ence, choose centroid,
bisector, mom (middle of maximum), som (smallest of maximum), lom
(lar gest of maximum), or Custom, for a cust om oper at ion. For Sugenost yle
infer ence, choose bet ween wtaver (weight ed aver age) or wtsum (weight ed
sum).
See Also mfedit, ruleedit, ruleview, surfview, anfisedit
gauss2mf
332
3gauss2mf
Purpose Gaussian combinat ion member ship funct ion.
Synopsis y = gauss2mf(x,[sig1 c1 sig2 c2])
Description The Gaussian function depends on two parameters sig and c as given by
The funct ion gauss2mf is a combinat ion of t wo of t hese. The fir st funct ion,
specified by sig1 and c1, det er mines t he shape of t he left most cur ve. The second
funct ion specified by sig2 and c2 det er mines t he shape of t he r ight most cur ve.
Whenever c1 < c2, t he gauss2mf funct ion r eaches a maximum value of 1.
Ot her wise, t he maximum value is less t han one. The par amet er s ar e list ed in
t he or der :
[sig1, c1, sig2, c2].
f x ; c , ( ) e
x c ( )
2
2
2

=
gauss2mf
333
Examples x = (0:0.1:10)';
y1 = gauss2mf(x, [2 4 1 8]);
y2 = gauss2mf(x, [2 5 1 7]);
y3 = gauss2mf(x, [2 6 1 6]);
y4 = gauss2mf(x, [2 7 1 5]);
y5 = gauss2mf(x, [2 8 1 4]);
plot(x, [y1 y2 y3 y4 y5]);
set(gcf, 'name', 'gauss2mf', 'numbertitle', 'off');
See Also dsigmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, psigmf, sigmf, smf, trapmf,
trimf, zmf
gaussmf
334
3gaussmf
Purpose Gaussian cur ve built in member ship funct ion.
Synopsis y = gaussmf(x,[sig c])
Description The symmet r ic Gaussian funct ion depends on t wo par amet er s and c as given
by
The par amet er s for gaussmf r epr esent t he par amet er s and c list ed in or der
in t he vect or [sig c].
Example x=0:0.1:10;
y=gaussmf(x,[2 5]);
plot(x,y)
xlabel('gaussmf, P=[2 5]')
See Also dsigmf, gaussmf, gbellmf, evalmf, mf2mf, pimf, psigmf, sigmf, smf, trapmf,
trimf, zmf
f x ; c , ( ) e
x c ( )
2
2
2

=
0 2 4 6 8 10
0
0.25
0.5
0.75
1
gaussmf, P = [2 5]
gbellmf
335
3gbellmf
Purpose Gener alized bellshaped built in member ship funct ion.
Synopsis y = gbellmf(x,params)
Description The gener alized bell funct ion depends on t hr ee par amet er s a, b, and c as given
by
wher e t he par amet er b is usually posit ive. The par amet er c locat es t he cent er
of t he cur ve. Ent er t he par amet er vect or params, t he second ar gument for
gbellmf, as t he vect or whose ent r ies ar e a, b, and c, r espect ively.
Example x=0:0.1:10;
y=gbellmf(x,[2 4 6]);
plot(x,y)
xlabel('gbellmf, P=[2 4 6]')
See Also dsigmf, gaussmf, gauss2mf, evalmf, mf2mf, pimf, psigmf, sigmf, smf, trapmf,
trimf, zmf
f x a ; b c , , ( )
1
1
x c
a

2b
+
 =
0 2 4 6 8 10
0
0.25
0.5
0.75
1
gbellmf, P = [2 4 6]
genfis1
336
3genfis1
Purpose Gener at e an FIS st r uct ur e fr om dat a wit hout dat a clust er ing.
Synopsis fismat = genfis1(data)
fismat = genfis1(data,numMFs,inmftype, outmftype)
Description genfis1 gener at es a Sugenot ype FIS st r uct ur e used as init ial condit ions
(init ializat ion of t he member ship funct ion par amet er s) for anfis t r aining.
genfis1(data, numMFs, inmftype, outmftype) gener at es a FIS st r uct ur e fr om a
t r aining dat a set , data, using a gr id par t it ion on t he dat a (no clust er ing).
The ar gument s for genfis1 ar e as follows:
data is t he t r aining dat a mat r ix, which must be ent er ed wit h all but t he last
columns r epr esent ing input dat a, and t he last column r epr esent ing t he
single out put .
numMFs is a vect or whose coor dinat es specify t he number of member ship
funct ions associat ed wit h each input . If you want t he same number of
member ship funct ions t o be associat ed wit h each input , t hen it suffices t o
make numMFs a single number .
inmftype is a st r ing ar r ay in which each r ow specifies t he member ship
funct ion t ype associat ed wit h each input . Again, t his can be a
onedimensional single st r ing if t he t ype of member ship funct ions associat ed
wit h each input is t he same.
outmftype is a st r ing t hat specifies t he member ship funct ion t ype associat ed
wit h t he out put . Ther e can only be one out put , since t his is a Sugenot ype
syst em. The out put member ship funct ion t ype must be eit her linear or
constant.
The number of member ship funct ions associat ed wit h t he out put is t he same
as t he number of r ules gener at ed by genfis1. The default number of
member ship funct ions, numMFs, is 2; t he default input or out put member ship
funct ion t ype is 'gbellmf'. These ar e used whenever genfis1 is invoked
wit hout t he last t hr ee ar gument s.
genfis1
337
Example data = [rand(10,1) 10*rand(10,1)5 rand(10,1)];
numMFs = [3 7];
mfType = str2mat('pimf','trimf');
fismat = genfis1(data,numMFs,mfType);
[x,mf] = plotmf(fismat,'input',1);
subplot(2,1,1), plot(x,mf);
xlabel('input 1 (pimf)');
[x,mf] = plotmf(fismat,'input',2);
subplot(2,1,2), plot(x,mf);
xlabel('input 2 (trimf)');
See Also anfis
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
input 1 (pimf )
5 4 3 2 1 0 1 2 3 4 5
0
0.2
0.4
0.6
0.8
1
input 2 (trimf)
genfis2
338
3genfis2
Purpose Gener at e an FIS st r uct ur e fr om dat a using subt r act ive clust er ing.
Synopsis fismat = genfis2(Xin,Xout,radii)
fismat = genfis2(Xin,Xout,radii,xBounds)
fismat = genfis2(Xin,Xout,radii,xBounds,options)
Description Given separ at e set s of input and out put dat a, genfis2 gener at es an FIS using
fuzzy subt r act ive clust er ing. When t her e is only one out put , genfis2 may be
used t o gener at e an init ial FIS for anfis t r aining by fir st implement ing
subt r act ive clust er ing on t he dat a. genfis2 accomplishes t his by ext r act ing a
set of r ules t hat models t he dat a behavior . The r ule ext r act ion met hod fir st
uses t he subclust funct ion t o det er mine t he number of r ules and ant ecedent
member ship funct ions and t hen uses linear least squar es est imat ion t o
det er mine each r ules consequent equat ions. This funct ion r et ur ns an FIS
st r uct ur e t hat cont ains a set of fuzzy r ules t o cover t he feat ur e space.
The ar gument s for genfis2 ar e as follows:
Xin is a mat r ix in which each r ow cont ains t he input values of a dat a point .
Xout is a mat r ix in which each r ow cont ains t he out put values of a dat a point .
radii is a vect or t hat specifies a clust er cent er s r ange of influence in each of
t he dat a dimensions, assuming t he dat a falls wit hin a unit hyper box. For
example, if t he dat a dimension is 3 (e.g., Xin has t wo columns and Xout has
one column), radii = [0.5 0.4 0.3] specifies t hat t he r anges of influence in t he
fir st , second, and t hir d dat a dimensions (i.e., t he fir st column of Xin, t he
second column of Xin, and t he column of Xout) ar e 0.5, 0.4, and 0.3 t imes t he
widt h of t he dat a space, r espect ively. If radii is a scalar , t hen t he scalar
value is applied t o all dat a dimensions, i.e., each clust er cent er will have a
spher ical neighbor hood of influence wit h t he given r adius.
xBounds is a 2byN opt ional mat r ix t hat specifies how t o map t he dat a in Xin
and Xout int o a unit hyper box, wher e N is t he dat a (r ow) dimension. The fir st
r ow of xBounds cont ains t he minimum axis r ange values and t he second r ow
cont ains t he maximum axis r ange values for scaling t he dat a in each
dimension. For example, xBounds = [10 0 1; 10 50 1] specifies t hat dat a
values in t he fir st dat a dimension ar e t o be scaled fr om t he r ange [10 +10]
int o values in t he r ange [0 1]; dat a values in t he second dat a dimension ar e
t o be scaled fr om t he r ange [0 50]; and dat a values in t he t hir d dat a
genfis2
339
dimension ar e t o be scaled fr om t he r ange [1 +1]. If xBounds is an empt y
mat r ix or not pr ovided, t hen xBounds default s t o t he minimum and
maximum dat a values found in each dat a dimension.
options is an opt ional vect or for specifying algor it hm par amet er s t o over r ide
t he default values. These par amet er s ar e explained in t he help t ext for
subclust on page 372. Default values ar e in place when t his ar gument is not
specified.
Examples fismat = genfis2(Xin,Xout,0.5)
This is t he minimum number of ar gument s needed t o use t his funct ion. Her e a
r ange of influence of 0.5 is specified for all dat a dimensions.
fismat = genfis2(Xin,Xout,[0.5 0.25 0.3])
This assumes t he combined dat a dimension is 3. Suppose Xin has t wo columns
and Xout has one column, t hen 0.5 and 0.25 ar e t he r anges of influence for each
of t he Xin dat a dimensions, and 0.3 is t he r ange of influence for t he Xout dat a
dimension.
fismat = genfis2(Xin,Xout,0.5,[10 5 0; 10 5 20])
This specifies how t o nor malize t he dat a in Xin and Xout int o values in t he
r ange [0 1] for pr ocessing. Suppose Xin has t wo columns and Xout has one
column, t hen t he dat a in t he fir st column of Xin ar e scaled fr om [10 +10], t he
dat a in t he second column of Xin ar e scaled fr om [5 +5], and t he dat a in Xout
ar e scaled fr om [0 20].
See Also subclust
gensurf
340
3gensur f
Purpose Gener at e an FIS out put sur face.
Synopsis gensurf(fis)
gensurf(fis,inputs,output)
gensurf(fis,inputs,output,grids,refinput)
Description gensurf(fis) gener at es a plot of t he out put sur face of a given fuzzy infer ence
syst em (fis) using t he fir st t wo input s and t he fir st out put .
gensurf(fis,inputs,output) gener at es a plot using t he input s (one or t wo)
and out put (only one is allowed) given, r espect ively, by t he vect or , inputs, and
t he scalar , output.
gensurf(fis,inputs,output,grids) allows you t o specify t he number of gr ids
in t he X (fir st , hor izont al) and Y (second, ver t ical) dir ect ions. If grids is a t wo
element vect or , t he gr ids in t he X and Y dir ect ions can be set independent ly.
gensurf(fis,inputs,output,grids,refinput) can be used if t her e ar e mor e
t han t wo out put s. The lengt h of t he vect or refinput is t he same as t he number
of input s.
Ent er NaNs for t he ent r ies of refinput cor r esponding t o t he input s whose
sur face is being displayed.
Ent er r eal double scalar s t o fix t he values of ot her input s.
[x,y,z]=gensurf(...) r et ur ns t he var iables t hat define t he out put sur face
and suppr esses aut omat ic plot t ing.
gensurf
341
Example 1 a = readfis('tipper');
gensurf(a)
Example 2 a = gensurf(Temp,[1 2],1,[20 20],[nan nan 0.2]);
gener at es t he sur face of a t hr eeinput FIS named Temp fr om it s fir st t wo input s
t o it s fir st out put , while fixing a r efer ence value for t he t hir d input at .2.
See Also evalfis, surfview
0
2
4
6
8
10
0
2
4
6
8
10
5
10
15
20
25
service
food
t
i
p
getfis
342
3get fis
Purpose Get fuzzy syst em pr oper t ies.
Synopsis getfis(a)
getfis(a,'fisprop')
getfis(a,'vartype',varindex,'varprop')
getfis(a,'vartype',varindex,'mf',mfindex)
getfis(a,'vartype',varindex,'mf',mfindex,'mfprop')
Description This is t he fundament al access funct ion for t he FIS st r uct ur e. Wit h t his one
funct ion you can lear n about ever y par t of t he fuzzy infer ence syst em.
The ar gument s for getfis ar e as follows:
a: t he name of a wor kspace var iable FIS st r uct ur e.
'vartype': a st r ing indicat ing t he t ype of var iable you want (input or
output).
varindex: an int eger indicat ing t he index of t he var iable you want (1, for
input 1, for example).
'mf': a r equir ed st r ing t hat indicat es you ar e sear ching for member ship
funct ion infor mat ion.
mfindex: t he index of t he member ship funct ion for which you ar e seeking
infor mat ion.
getfis
343
Examples One input ar gument (out put is t he empt y set )
a = readfis('tipper');
getfis(a)
Name = tipper
Type = mamdani
NumInputs = 2
InLabels =
service
food
NumOutputs = 1
OutLabels =
tip
NumRules = 3
AndMethod = min
OrMethod = max
ImpMethod = min
AggMethod = max
DefuzzMethod = centroid
Two input ar gument s
getfis(a,'type')
ans =
mamdani
Thr ee input ar gument s (out put is t he empt y set )
getfis(a,'input',1)
Name = service
NumMFs = 3
MFLabels =
poor
good
excellent
Range = [0 10]
Four input ar gument s
getfis(a,'input',1,'name')
ans =
service
getfis
344
Five input ar gument s
getfis(a,'input',1,'mf',2)
Name = good
Type = gaussmf
Params =
1.5000 5.0000
Six input ar gument s
getfis(a,'input',1,'mf',2,'name')
ans =
good
See Also setfis, showfis
mam2sug
345
3mam2sug
Purpose Tr ansfor m Mamdani FIS int o a Sugeno FIS.
Synopsis sug_fis=mam2sug(mam_fis)
Description mam2sug(mam_fis) t r ansfor ms a (not necessar ily single out put ) Mamdani FIS
st r uct ur e mam_fis int o a Sugeno FIS st r uct ur e sug_fis. The r et ur ned Sugeno
syst em has const ant out put member ship funct ions. These const ant s ar e
det er mined by t he cent r oids of t he consequent member ship funct ions of t he
or iginal Mamdani syst em. The ant ecedent r emains unchanged.
Examples mam_fismat = readfis('mam22.fis');
sug_fismat = mam2sug(mam_fismat);
subplot(2,2,1); gensurf(mam_fismat, [1 2], 1);
title('Mamdani system (Output 1)');
subplot(2,2,2); gensurf(sug_fismat, [1 2], 1);
title('Sugeno system (Output 1)');
subplot(2,2,3); gensurf(mam_fismat, [1 2], 2);
title('Mamdani system (Output 2)');
subplot(2,2,4); gensurf(sug_fismat, [1 2], 2);
title('Sugeno system (Output 2)');
mf2mf
346
3mf2mf
Purpose Tr anslat es par amet er s bet ween member ship funct ions.
Synopsis outParams = mf2mf(inParams,inType,outType)
Description This funct ion t r anslat es any built in member ship funct ion t ype int o anot her ,
in t er ms of it s par amet er set . In pr inciple, mf2mf mimics t he symmet r y point s
for bot h t he new and old member ship funct ions. Occasionally t his t r anslat ion
r esult s in lost infor mat ion, so t hat if t he out put par amet er s ar e t r anslat ed back
int o t he or iginal member ship funct ion t ype, t he t r ansfor med member ship
funct ion will not look t he same as it did or iginally.
The input ar gument s for mf2mf ar e as follows:
inParams: t he par amet er s of t he member ship funct ion you ar e t r ansfor ming
inType: a st r ing name for t he t ype of member ship funct ion you ar e
t r ansfor ming
outType: a st r ing name for t he new member ship funct ion you ar e
t r ansfor ming t o
Examples x=0:0.1:5;
mfp1 = [1 2 3];
mfp2 = mf2mf(mfp1,'gbellmf','trimf');
plot(x,gbellmf(x,mfp1),x,trimf(x,mfp2))
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, pimf, psigmf, sigmf, smf,
trapmf, trimf, zmf
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
mfedit
347
3mfedit
Purpose Member ship funct ion edit or .
Synopsis mfedit('a')
mfedit(a)
mfedit
Description
mfedit('a') gener at es a member ship funct ion edit or t hat allows you t o
inspect and modify all t he member ship funct ions for your FIS st or ed in t he file,
a.fis.
mfedit(a) oper at es on a MATLAB wor kspace var iable, for a FIS st r uct ur e, a.
mfedit alone br ings up t he member ship funct ion edit or wit h no FIS loaded.
For each member ship funct ion you can change t he name, t he t ype, and t he
par amet er s. Eleven built in member ship funct ions ar e pr ovided for you t o
choose fr om, alt hough of cour se you can always cr eat e your own specialized
ver sions. Refer t o The Member ship Funct ion Edit or on page 252 for mor e
infor mat ion about how t o use mfedit.
mfedit
348
Select t he icon for t he var iable on t he upper left side of t he diagr am (under t he
heading FIS Var iables) t o display it s associat ed member ship funct ions in t he
plot r egion. Select member ship funct ions by clicking once on t hem or t heir
labels.
Menu Items On t he Member ship Funct ion Edit or , t her e is a menu bar t hat allows you t o
open r elat ed GUI t ools, open and save syst ems, and so on. The Fi le menu for
t he Member ship Funct ion Edit or is t he same as t he one found on t he FIS
Edit or . Refer t o fuzzy on page 329 for mor e infor mat ion.
Under Edi t , select :
Add MF... t o add member ship funct ions t o t he cur r ent var iable.
Add cus tom MF... t o add a cust omized member ship funct ion t o t he cur r ent
var iable.
Remove current MF t o delet e t he cur r ent member ship funct ion.
Remove all MFs t o delet e all member ship funct ions of t he cur r ent var iable.
Undo t o undo t he most r ecent change.
Under Vi e w, select :
Edi t FIS properti es ... t o invoke t he FIS Edit or .
Edi t rule s... t o invoke t he Rule Edit or .
Vi ew rule s... t o invoke t he Rule Viewer .
Vi ew s urface ... t o invoke t he Sur face Viewer .
Membership
Function
Popup Menu
Ther e ar e 11 built in member ship funct ions t o choose fr om, and you also have
t he opt ion of inst alling a cust omized member ship funct ion.
See Also fuzzy, ruleedit, ruleview, surfview
newfis
349
3newfis
Purpose Cr eat e new FIS.
Synopsis a=newfis(fisName,fisType,andMethod,orMethod,impMethod, ...
aggMethod,defuzzMethod)
Description This funct ion cr eat es new FIS st r uct ur es. newfis has up t o seven input
ar gument s, and t he out put ar gument is an FIS st r uct ur e. The seven input
ar gument s ar e as follows:
fisName is t he st r ing name of t he FIS st r uct ur e, fisName.fis you cr eat e.
fisType is t he t ype of FIS.
andMethod, orMethod, impMethod, aggMethod, and defuzzMethod,
r espect ively pr ovide t he met hods for AND, OR, implicat ion, aggr egat ion, and
defuzzificat ion.
Examples The following example shows what t he default s ar e for each of t he met hods:
a=newfis('newsys');
getfis(a)
r et ur ns
Name = newsys
Type = mamdani
NumInputs = 0
InLabels =
NumOutputs = 0
OutLabels =
NumRules 0
AndMethod min
OrMethod max
ImpMethod min
AggMethod max
DefuzzMethod centroid
ans =
[newsys]
See Also readfis, writefis
parsrule
350
3par srule
Purpose Par se fuzzy r ules.
Synopsis fis2 = parsrule(fis,txtRuleList)
fis2 = parsrule(fis,txtRuleList,ruleFormat)
fis2 = parsrule(fis,txtRuleList,ruleFormat,lang)
Description This funct ion par ses t he t ext t hat defines t he r ules (txtRuleList) for a
MATLAB wor kspace FIS var iable, fis, and r et ur ns a FIS st r uct ur e wit h t he
appr opr iat e r ule list in place. If t he or iginal input FIS st r uct ur e, fis, has any
r ules init ially, t hey ar e r eplaced in t he new st r uct ur e, fis2. Thr ee differ ent
r ule for mat s (indicat ed by ruleFormat) ar e suppor t ed: 'verbose', symbolic,
and indexed. The default for mat is ver bose. When t he opt ional language
ar gument , lang, is used, t he r ules ar e par sed in ver bose mode, assuming t he
key wor ds ar e in t he language, lang. This language must be eit her 'english',
'fr ancais', or 'deut sch'. The key language wor ds in English ar e: if, t hen, is, AND,
OR, and NOT.
Examples a = readfis('tipper');
ruleTxt = 'if service is poor then tip is generous';
a2 = parsrule(a,ruleTxt,'verbose');
showrule(a2)
ans =
1. If (service is poor) then (tip is generous) (1)
See Also addrule, ruleedit, showrule
pimf
351
3pimf
Purpose shaped built in member ship funct ion.
Synopsis y = pimf(x,[a b c d])
Description This splinebased cur ve is so named because of it s shape. This member ship
funct ion is evaluat ed at t he point s det er mined by t he vect or x. The par amet er s
a and d locat e t he feet of t he cur ve, while b and c locat e it s shoulder s.
Examples x=0:0.1:10;
y=pimf(x,[1 4 5 10]);
plot(x,y)
xlabel('pimf, P=[1 4 5 10]')
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, psigmf, sigmf, smf,
trapmf, trimf, zmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
pimf, P = [1 4 5 10]
plotfis
352
3plot fis
Purpose Plot an FIS.
Synopsis plotfis(fismat)
Description This funct ion displays a high level diagr am of an FIS, fismat. Input s and t heir
member ship funct ions appear t o t he left of t he FIS st r uct ur al char act er ist ics,
while out put s and t heir member ship funct ions appear on t he r ight .
Examples a = readfis('tipper');
plotfis(a)
See Also evalmf, plotmf
plotmf
353
3plot mf
Purpose Plot all of t he member ship funct ions for a given var iable.
Synopsis plotmf(fismat,varType,varIndex)
Description This funct ion plot s all of t he member ship funct ions in t he FIS called fismat
associat ed wit h a given var iable whose t ype and index ar e r espect ively given
by varType ('input' or 'output'), and varIndex. This funct ion can also be
used wit h t he MATLAB funct ion, subplot.
Examples a = readfis('tipper');
plotmf(a,'input',1)
See Also evalmf, plotfis
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
service
D
e
g
r
e
e
o
f
b
e
l
i
e
f
poor good excellent
psigmf
354
3psigmf
Purpose Built in member ship funct ion composed of t he pr oduct of t wo
sigmoidallyshaped member ship funct ions.
Synopsis y = psigmf(x,[a1 c1 a2 c2])
Description The sigmoid cur ve plot t ed for t he vect or x depends on t wo par amet er s a and c
as given by
psigmf is simply t he pr oduct of t wo such cur ves plot t ed for t he values of t he
vect or x
f
1
(x; a1, c
1
) * f
2
(x; a2, c
2
)
The par amet er s ar e list ed in t he or der : [a1 c
1
a
2
c
2
].
Examples x=0:0.1:10;
y=psigmf(x,[2 3 5 8]);
plot(x,y)
xlabel('psigmf, P=[2 3 5 8]')
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, sigmf, smf, trapmf,
trimf, zmf
f x a ; c , ( )
1
1 e
a x c ( )
+
 =
0 2 4 6 8 10
0
0.25
0.5
0.75
1
psigmf, P = [2 3 5 8]
readfis
355
3readfis
Purpose Load an FIS fr om t he disk.
Synopsis fismat = readfis('filename')
Description Read a fuzzy infer ence syst em fr om a .fis file (named filename) on t he disk
and br ing t he r esult ing file int o t he wor kspace.
fismat = readfis (no input ar gument s) br ings up a uigetfile dialog box t o
assist wit h t he name and dir ect or y locat ion of t he file.
Examples fismat = readfis('tipper');
getfis(fismat)
r et ur ns
Name = tipper
Type = mamdani
NumInputs = 2
InLabels =
service
food
NumOutputs = 1
OutLabels =
tip
NumRules = 3
AndMethod = min
OrMethod = max
ImpMethod = min
AggMethod = max
DefuzzMethod = centroid
ans =
tipper
See Also writefis
rmmf
356
3rmmf
Purpose To r emove member ship funct ion fr om an FIS.
Synopsis fis = rmmf(fis,'varType',varIndex,'mf',mfIndex)
Description fis = rmmf(fis,varType,varIndex,'mf',mfIndex) r emoves t he member ship
funct ion, mfIndex, of var iable t ype, varType, of index varIndex, fr om t he fuzzy
infer ence syst em associat ed wit h t he wor kspace FIS st r uct ur e, fis:
The st r ing varType must be 'input' or 'output'.
varIndex is an int eger for t he index of t he var iable. This index r epr esent s t he
or der in which t he var iables ar e list ed.
The ar gument 'mf' is a st r ing r epr esent ing t he member ship funct ion.
mfIndex is an int eger for t he index of t he member ship funct ion. This index
r epr esent s t he or der in which t he member ship funct ions ar e list ed.
Examples a = newfis('mysys');
a = addvar(a,'input','temperature',[0 100]);
a = addmf(a,'input',1,'cold','trimf',[0 30 60]);
getfis(a,'input',1)
r et ur ns
Name = temperature
NumMFs = 1
MFLabels =
cold
Range = [0 100]
b = rmmf(a,'input',1,'mf',1);
getfis(b,'input',1)
r et ur ns
Name = temperature
NumMFs = 0
MFLabels =
Range = [0 100]
See Also addmf, addrule, addvar, plotmf, rmvar
rmvar
357
3rmvar
Purpose To r emove var iables fr om an FIS.
Synopsis [fis2,errorStr] = rmvar(fis,'varType',varIndex)
fis2 = rmvar(fis,'varType',varIndex)
Description fis2 = rmvar(fis,'varType',varIndex) r emoves t he var iable 'varType', of
index varIndex, fr om t he fuzzy infer ence syst em associat ed wit h t he
wor kspace FIS st r uct ur e, fis:
The st r ing varType must be 'input' or 'output'.
varIndex is an int eger for t he index of t he var iable. This index r epr esent s t he
or der in which t he var iables ar e list ed.
[fis2,errorStr] = rmvar(fis,'varType',varIndex) r et ur ns any er r or
messages t o t he st r ing, errorStr.
This command aut omat ically alt er s t he r ule list t o keep it s size consist ent wit h
t he cur r ent number of var iables. You must delet e fr om t he FIS any r ule t hat
cont ains a var iable you want t o r emove, befor e r emoving it . You cannot r emove
a fuzzy var iable cur r ent ly in use in t he r ule list .
Examples a = newfis('mysys');
a = addvar(a,'input','temperature',[0 100]);
getfis(a)
rmvar
358
r et ur ns
Name = mysys
Type = mamdani
NumInputs = 1
InLabels =
temperature
NumOutputs = 0
OutLabels =
NumRules = 0
AndMethod = min
OrMethod = max
ImpMethod = min
AggMethod = max
DefuzzMethod = centroid
ans =
mysys
b = rmvar(a,'input',1);
getfis(b)
r et ur ns
Name = mysys
Type = mamdani
NumInputs = 0
InLabels =
NumOutputs = 0
OutLabels =
NumRules = 0
AndMethod = min
OrMethod = max
ImpMethod = min
AggMethod = max
DefuzzMethod = centroid
ans =
mysys
See Also addmf, addrule, addvar, rmmf
ruleedit
359
3ruleedit
Purpose Rule edit or and par ser .
Synopsis ruleedit('a')
ruleedit(a)
Description
The Rule Edit or , when invoked using ruleedit('a'), is used t o modify t he
r ules of an FIS st r uct ur e st or ed in a file, a.fis. It can also be used t o inspect
t he r ules being used by a fuzzy infer ence syst em.
To use t his edit or t o cr eat e r ules, you must fir st define all of t he input and
out put var iables you want t o use wit h t he FIS edit or . You can cr eat e t he r ules
using t he list box and check box choices for input and out put var iables,
connect ions, and weight s. Refer t o The Rule Edit or on page 256 for mor e
infor mat ion about how t o use ruleedit.
The synt ax ruleedit(a) is used when you want t o oper at e on a wor kspace
var iable for an FIS st r uct ur e called a.
Language and Format
are options on this
GUI. Languages are
English, Deutsch, and
Francais. Formats are
verbose, symbolic,
and indexed.
ruleedit
360
Menu Items On t he Rule Edit or , t her e is a menu bar t hat allows you t o open r elat ed GUI
t ools, open and save syst ems, and so on. The Fi le menu for t he Rule Edit or is
t he same as t he one found on t he FIS Edit or . Refer t o fuzzy on page 329 for
mor e infor mat ion.
Use t he following Edi t menu it em:
Undo t o undo t he most r ecent change.
Use t he following Vi ew menu it ems:
Edi t FIS properti e s... t o invoke t he FIS Edit or .
Edi t membe rshi p functi ons... t o invoke t he Member ship Funct ion
Edit or .
Vi e w rules ... t o invoke t he Rule Viewer .
Vi e w surface... t o invoke t he Sur face Viewer .
Use t he Opti ons menu it ems:
Language t o select t he language: Engli sh, Deutsch, and Francai s
Format t o select t he for mat :
` verbose uses t he wor ds if, t hen, AND, OR, and so on t o cr eat e
act ual sent ences.
` s ymboli c subst it ut es some symbols for t he wor ds used in t he ver bose
mode. For example, if A AND B t hen C becomes A & B => C.
` i ndexe d mir r or s how t he r ule is st or ed in t he FIS st r uct ur e.
See Also addrule, fuzzy, mfedit, parsrule, ruleview, showrule, surfview
ruleview
361
3ruleview
Purpose Rule viewer and fuzzy infer ence diagr am.
Synopsis ruleview('a')
Description
The Rule Viewer invoked using ruleview('a') depict s t he fuzzy infer ence
diagr am for an FIS st or ed in a file, a.fis. It is used t o view t he ent ir e
implicat ion pr ocess fr om beginning t o end. You can move ar ound t he line
indices t hat cor r espond t o t he input s and t hen wat ch t he syst em r eadjust and
comput e t he new out put . Refer t o The Rule Viewer on page 259 for mor e
infor mat ion about how t o use ruleview.
Menu Items On t he Rule Viewer , t her e is a menu bar t hat allows you t o open r elat ed GUI
t ools, open and save syst ems, and so on. The Fi le menu for t he Rule Viewer is
ruleview
362
t he same as t he one found on t he FIS Edit or . Refer t o fuzzy on page 329 for
mor e infor mat ion.
Use t he Vi e w menu it ems:
Edi t FIS properti es ... t o invoke t he FIS Edit or
Edi t me mbers hi p functi ons ... t o invoke t he Member ship Funct ion Edit or
Edi t rule s... t o invoke t he Rule Edit or
Vi ew s urface... t o invoke t he Sur face Viewer
Use t he Opti ons menu it em:
Rule di splay format t o set t he for mat in which t he r ule appear s. If you
click on t he r ule number s on t he left side of t he fuzzy infer ence diagr am,
t he r ule associat ed wit h t hat number will appear in t he St at us Bar at t he
bot t om of t he Rule Viewer .
See Also fuzzy, mfedit, ruleedit, surfview
setfis
363
3set fis
3
Purpose Set fuzzy syst em pr oper t ies.
Synopsis a = setfis(a,'fispropname','newfisprop')
a = setfis(a,'vartype',varindex,'varpropname','newvarprop')
a = setfis(a,'vartype',varindex,'mf',mfindex, ...
'mfpropname','newmfprop');
Description The command setfis can be called wit h t hr ee, five, or seven input ar gument s,
depending on whet her you want t o set a pr oper t y of t he ent ir e FIS st r uct ur e,
for a par t icular var iable belonging t o t hat FIS st r uct ur e, or for a par t icular
member ship funct ion belonging t o one of t hose var iables. The ar gument s ar e:
a a var iable name of an FIS fr om t he wor kspace
'vartype' a st r ing indicat ing t he var iable t ype: input or output
varindex t he index of t he input or out put var iable
'mf' a r equir ed st r ing for t he four t h ar gument of a 7ar gument call for
setfis, indicat ing t his var iable is a member ship funct ion
mfindex t he index of t he member ship funct ion belonging t o t he chosen
var iable
'fispropname' a st r ing indicat ing t he pr oper t y of t he FIS field you want
t o set : name, type, andmethod, ormethod, impmethod, aggmethod,
defuzzmethod
'newfisprop' a st r ing descr ibing t he name of t he FIS pr oper t y or met hod
you want t o set
'varpropname' a st r ing indicat ing t he name of t he var iable field you want
t o set : name or range
'newvarprop' a st r ing descr ibing t he name of t he var iable you want t o set
(for name), or an ar r ay descr ibing t he r ange of t hat var iable (for range)
'mfpropname' a st r ing indicat ing t he name of t he member ship funct ion
field you want t o set : name, type, or params.
'newmfprop' a st r ing descr ibing t he name or t ype of t he member ship
funct ion field want t o set (for name or type), or an ar r ay descr ibing t he r ange
of t he par amet er s (for params)
setfis
364
Examples Called wit h t hr ee ar gument s,
a = readfis('tipper');
a2 = setfis(a, 'name', 'eating');
getfis(a2, 'name');
Result s in
out =
eating
If used wit h five ar gument s, setfis will updat e t wo var iable pr oper t ies.
a2 = setfis(a,'input',1,'name','help');
getfis(a2,'input',1,'name')
ans =
help
If used wit h seven ar gument s, setfis will updat e any of sever al member ship
funct ion pr oper t ies.
a2 = setfis(a,'input',1,'mf',2,'name','wretched');
getfis(a2,'input',1,'mf',2,'name')
ans =
wretched
See Also getfis
sffis
365
3sffis
Purpose Fuzzy infer ence Sfunct ion for Simulink.
Synopsis output = sffis(t,x,u,flag,fismat)
Description This MEXfile is used by Simulink t o under t ake t he calculat ion nor mally
per for med by evalfis. It has been opt imized t o wor k in t he Simulink
envir onment . This means, among ot her t hings, t hat sffis builds a dat a
st r uct ur e in memor y dur ing t he init ializat ion phase of a Simulink simulat ion,
which it t hen cont inues t o use unt il t he simulat ion is complet e.
The ar gument s t, x, and flag ar e st andar d Simulink Sfunct ion ar gument s
(see Chapt er 8, SFunct ions in t he Using S imulink document at ion). The
ar gument u is t he input t o t he MATLAB wor kspace FIS st r uct ur e, fismat. If,
for example, t her e ar e t wo input s t o fismat, t hen u will be a t woelement
vect or .
See Also evalfis, fuzblock
showfis
366
3showfis
Purpose Display annot at ed FIS.
Synopsis showfis(fismat)
Description showfis(fismat) pr int s a ver sion of t he MATLAB wor kspace var iable FIS,
fismat, allowing you t o see t he significance and cont ent s of each field of t he
st r uct ur e.
Examples a = readfis('tipper');
showfis(a)
r et ur ns
1. Name tipper
2. Type mamdani
3. Inputs/Outputs [2 1]
4. NumInputMFs [3 2]
5. NumOutputMFs 3
6. NumRules 3
7. AndMethod min
8. OrMethod max
9. ImpMethod min
10. AggMethod max
11. DefuzzMethod centroid
12. InLabels service
13. food
14. OutLabels tip
15. InRange [0 10]
16. [0 10]
17. OutRange [0 30]
18. InMFLabels poor
19. good
20. excellent
21. rancid
22. delicious
23. OutMFLabels cheap
24. average
25. generous
26. InMFTypes gaussmf
27. gaussmf
showfis
367
28. gaussmf
29. trapmf
30. trapmf
31. OutMFTypes trimf
32. trimf
33. trimf
34. InMFParams [1.5 0 0 0]
35. [1.5 5 0 0]
36. [1.5 10 0 0]
37. [0 0 1 3]
38. [7 9 10 10]
39. OutMFParams [0 5 10 0]
40. [10 15 20 0]
41. [20 25 30 0]
42. Rule Antecedent [1 1]
43. [2 0]
44. [3 2]
42. Rule Consequent 1
43. 2
44. 3
42. Rule Weigth 1
43. 1
44. 1
42. Rule Connection 2
43. 1
44. 2
See Also getfis
showrule
368
3showr ule
Purpose Display FIS r ules.
Synopsis showrule(fis)
showrule(fis,indexList)
showrule(fis,indexList,format)
showrule(fis,indexList,format,Lang)
Description This command is used t o display t he r ules associat ed wit h a given syst em. It
can be invoked wit h one t o four ar gument s. The fir st ar gument , fis, is
r equir ed. This is t he MATLAB wor kspace var iable name for a FIS st r uct ur e.
The second (opt ional) ar gument indexList is t he vect or of r ules you want t o
display. The t hir d ar gument (opt ional) is t he st r ing r epr esent ing t he for mat in
which t he r ules ar e r et ur ned. showrule can r et ur n t he r ule in any of t hr ee
differ ent for mat s: 'verbose' (t he default mode, for which English is t he default
language), 'symbolic', and 'indexed', for member ship funct ion index
r efer encing.
When used wit h four ar gument s, t he for t h ar gument must be ver bose, and
showrule(fis,indexList,format,lang) displays t he r ules in t he language
given by lang, which must be eit her 'english', 'francais', or 'deutsch'.
showrule
369
Examples a = readfis('tipper');
showrule(a,1)
ans =
1. If (service is poor) or (food is rancid) then (tip is cheap) (1)
showrule(a,2)
ans =
2. If (service is good) then (tip is average) (1)
showrule(a,[3 1],'symbolic')
ans =
3. (service==excellent)  (food==delicious) => (tip=generous) (1)
1. (service==poor)  (food==rancid) => (tip=cheap) (1)
showrule(a,1:3,'indexed')
ans =
1 1, 1 (1) : 2
2 0, 2 (1) : 1
3 2, 3 (1) : 2
See Also parsrule, ruleedit, addrule
sigmf
370
3sigmf
Purpose Sigmoidallyshaped built in member ship funct ion.
Synopsis y = sigmf(x,[a c])
Description The sigmoidal funct ion, sigmf(x,[a c]), as given below by , is a
mapping on a vect or x, and depends on t wo par amet er s a and c:
Depending on t he sign of t he par amet er a, t he sigmoidal member ship funct ion
is inher ent ly open t o t he r ight or t o t he left , and t hus is appr opr iat e for
r epr esent ing concept s such as ver y lar ge or ver y negat ive. Mor e
convent ionallooking member ship funct ions can be built by t aking eit her t he
pr oduct or differ ence of t wo differ ent sigmoidal member ship funct ions. You can
find out mor e about t his in t his chapt er s ent r ies for dsigmf and psigmf.
Examples x=0:0.1:10;
y=sigmf(x,[2 4]);
plot(x,y)
xlabel('sigmf, P=[2 4]')
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, psigmf, smf,
trapmf, trimf, zmf
f x a c , , ( )
f x a c , , ( )
1
1 e
a x c ( )
+
 =
0 2 4 6 8 10
0
0.25
0.5
0.75
1
sigmf, P = [2 4]
smf
371
3smf
Purpose Sshaped built in member ship funct ion.
Synopsis y = smf(x,[a b])
Description This splinebased cur ve is a mapping on t he vect or x, and is named because of
it s Sshape. The par amet er s a and b locat e t he ext r emes of t he sloped por t ion
of t he cur ve.
Examples x=0:0.1:10;
y=smf(x,[1 8]);
plot(x,y)
xlabel('smf, P=[1 8]')
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, psigmf, sigmf,
trapmf, trimf, zmf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
smf, P = [1 8]
subclust
372
3subclust
Purpose Find clust er cent er s wit h subt r act ive clust er ing.
Synopsis [C,S] = subclust(X,radii,xBounds,options)
Description This funct ion est imat es t he clust er cent er s in a set of dat a by using t he
subt r act ive clust er ing met hod. The subt r act ive clust er ing met hod assumes
each dat a point is a pot ent ial clust er cent er and calculat es a measur e of t he
likelihood t hat each dat a point would define t he clust er cent er , based on t he
densit y of sur r ounding dat a point s. The algor it hm
Select s t he dat a point wit h t he highest pot ent ial t o be t he fir st clust er cent er
Removes all dat a point s in t he vicinit y of t he fir st clust er cent er (as
det er mined by radii), in or der t o det er mine t he next dat a clust er and it s
cent er locat ion
It er at es on t his pr ocess unt il all of t he dat a is wit hin radii of a clust er cent er
The subt r act ive clust er ing met hod is an ext ension of t he mount ain clust er ing
met hod pr oposed by R. Yager .
The mat r ix X cont ains t he dat a t o be clust er ed; each r ow of X is a dat a point .
The var iable radii is a vect or of ent r ies bet ween 0 and 1 t hat specifies a clust er
cent er s r ange of influence in each of t he dat a dimensions, assuming t he dat a
falls wit hin a unit hyper box. Small radii values gener ally r esult in finding a
few lar ge clust er s. Good values for radii ar e usually bet ween 0.2 and 0.5.
For example, if t he dat a dimension is t wo (X has t wo columns),
radii = [0.5 0.25] specifies t hat t he r ange of influence in t he fir st dat a
dimension is half t he widt h of t he dat a space and t he r ange of influence in t he
second dat a dimension is one quar t er t he widt h of t he dat a space. If radii is a
scalar , t hen t he scalar value is applied t o all dat a dimensions, i.e., each clust er
cent er will have a spher ical neighbor hood of influence wit h t he given r adius.
xBounds is a 2byN mat r ix t hat specifies how t o map t he dat a in X int o a unit
hyper box, wher e N is t he dat a dimension. This ar gument is opt ional if X is
alr eady nor malized. The fir st r ow cont ains t he minimum axis r ange values and
t he second r ow cont ains t he maximum axis r ange values for scaling t he dat a in
each dimension. For example, xBounds = [10 5; 10 5] specifies t hat dat a values
in t he fir st dat a dimension ar e t o be scaled fr om t he r ange [10 +10] int o values
in t he r ange [0 1]; dat a values in t he second dat a dimension ar e t o be scaled
fr om t he r ange [5 +5] int o values in t he r ange [0 1]. If xBounds is an empt y
subclust
373
mat r ix or not pr ovided, t hen xBounds default s t o t he minimum and maximum
dat a values found in each dat a dimension.
The options vect or can be used for specifying clust er ing algor it hm par amet er s
t o over r ide t he default values. These component s of t he vect or options ar e
specified as follows:
options(1) = quashFactor: This is t he fact or used t o mult iply t he r adii
values t hat det er mine t he neighbor hood of a clust er cent er , so as t o quash
t he pot ent ial for out lying point s t o be consider ed as par t of t hat clust er .
(default : 1.25)
options(2) = acceptRatio: This set s t he pot ent ial, as a fr act ion of t he
pot ent ial of t he fir st clust er cent er , above which anot her dat a point will be
accept ed as a clust er cent er . (default : 0.5)
options(3) = rejectRatio: This set s t he pot ent ial, as a fr act ion of t he
pot ent ial of t he fir st clust er cent er , below which a dat a point will be r eject ed
as a clust er cent er . (default : 0.15)
options(4) = verbose: If t his t er m is not zer o, t hen pr ogr ess infor mat ion
will be pr int ed as t he clust er ing pr ocess pr oceeds. (default : 0)
The funct ion r et ur ns t he clust er cent er s in t he mat r ix C; each r ow of C cont ains
t he posit ion of a clust er cent er . The r et ur ned S vect or cont ains t he sigma values
t hat specify t he r ange of influence of a clust er cent er in each of t he dat a
dimensions. All clust er cent er s shar e t he same set of sigma values.
Examples [C,S] = subclust(X,0.5)
This is t he minimum number of ar gument s needed t o use t his funct ion. Ar ange
of influence of 0.5 has been specified for all dat a dimensions.
[C,S] = subclust(X,[0.5 0.25 0.3],[],[2.0 0.8 0.7])
This assumes t he dat a dimension is 3 (X has 3 columns) and uses a r ange of
influence of 0.5, 0.25, and 0.3 for t he fir st , second and t hir d dat a dimension,
r espect ively. The scaling fact or s for mapping t he dat a int o a unit hyper box will
be obt ained fr om t he minimum and maximum dat a values. The squashFactor
is set t o 2.0, indicat ing t hat we only want t o find clust er s t hat ar e far fr om each
ot her . The acceptRatio is set t o 0.8, indicat ing t hat we will only accept dat a
point s t hat have a ver y st r ong pot ent ial for being clust er cent er s. The
subclust
374
rejectRatio is set t o 0.7, indicat ing t hat we want t o r eject all dat a point s
wit hout a st r ong pot ent ial.
See Also genfis2
References Chiu, S., Fuzzy Model Ident ificat ion Based on Clust er Est imat ion, J ournal of
Intelligent & Fuzzy S ystems, Vol. 2, No. 3, Sept . 1994.
Yager , R. and D. Filev, Gener at ion of Fuzzy Rules by Mount ain Clust er ing,
J ournal of Intelligent & Fuzzy S ystems, Vol. 2, No. 3, pp. 209219, 1994.
surfview
375
3sur fview
Purpose Out put sur face viewer .
Synopsis surfview('a')
Description
The Sur face Viewer invoked using surfview('a') is a GUI t ool t hat let s you
examine t he out put sur face of an FIS st or ed in a file, a.fis, for any one or t wo
input s. Since it does not alt er t he fuzzy syst em or it s associat ed FIS st r uct ur e
in any way, it is a r eadonly edit or . Using t he popup menus, you select t he t wo
input var iables you want assigned t o t he t wo input axes (X and Y), as well t he
out put var iable you want assigned t o t he out put (or Z) axis. Select t he
Evaluate but t on t o per for m t he calculat ion and plot t he out put sur face.
By clicking on t he plot axes and dr agging t he mouse, you can manipulat e t he
sur face so t hat you can view it fr om differ ent angles.
If t her e ar e mor e t han t wo input s t o your syst em, you must supply t he const ant
values associat ed wit h any unspecified input s in t he r efer ence input sect ion.
Refer t o The Sur face Viewer on page 261 for mor e infor mat ion about how t o
use surfview.
surfview
376
Menu Items On t he Sur face Viewer , t her e is a menu bar t hat allows you t o open r elat ed GUI
t ools, open and save syst ems, and so on. The Fi le menu for t he Sur face Viewer
is t he same as t he one found on t he FIS Edit or . Refer t o fuzzy on page 329 for
mor e infor mat ion.
Use t he Vi e w menu it ems:
Edi t FIS properti es ... t o invoke t he FIS Edit or .
Edi t me mbers hi p functi ons ... t o invoke t he Member ship Funct ion Edit or .
Edi t rule s... t o invoke t he Rule Edit or .
Vi ew rule s... t o invoke t he Rule Viewer .
Use t he Opti ons menu it ems:
Plot t o choose among eight differ ent kinds of plot st yles.
Color Map t o choose among sever al differ ent color schemes.
Always evaluate t o aut omat ically evaluat e and plot a new sur face ever y
t ime you make a change t hat affect s t he plot (like changing t he number of
gr id point s). This is t he default opt ion. To deselect t his opt ion, select it once
mor e.
See Also anfisedit, fuzzy, gensurf, mfedit, ruleedit, ruleview
trapmf
377
3t r apmf
Purpose Tr apezoidalshaped built in member ship funct ion.
Synopsis y = trapmf(x,[a b c d])
Description The t r apezoidal cur ve is a funct ion of a vect or , x, and depends on four scalar
par amet er s a, b, c, and d, as given by
or , mor e compact ly, by
The par amet er s a and d locat e t he feet of t he t r apezoid and t he par amet er s b
and c locat e t he shoulder s.
Examples x=0:0.1:10;
y=trapmf(x,[1 5 7 8]);
plot(x,y)
xlabel('trapmf, P=[1 5 7 8]')
f x a ; b c d , , , ( )
0, x a
x a
b a
, a x b
1, b x c
d x
d c
, c x d
0, d x
' ;
=
f x a ; b c d , , , ( ) max min
x a
b a
 1
d x
d c
 , ,
,
_
0 ,
,
_
=
0 2 4 6 8 10
0
0.25
0.5
0.75
1
trapmf, P = [1 5 7 8]
trapmf
378
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, psigmf, sigmf, smf,
trimf, zmf
trimf
379
3t r imf
Purpose Tr iangular shaped built in member ship funct ion.
Synopsis y = trimf(x,params)
y = trimf(x,[a b c])
Description The t r iangular cur ve is a funct ion of a vect or , x, and depends on t hr ee scalar
par amet er s a, b, and c, as given by
or , mor e compact ly, by
The par amet er s a and c locat e t he feet of t he t r iangle and t he par amet er c
locat es t he peak.
Examples x=0:0.1:10;
y=trimf(x,[3 6 8]);
plot(x,y)
xlabel('trimf, P=[3 6 8]')
f x a ; b c , , ( )
0, x a
x a
b a
, a x b
c x
c b
, b x c
0, c x
' ;
=
f x a ; b c , , ( ) max min
x a
b a

c x
c b
  ,
,
_
0 ,
,
_
=
0 2 4 6 8 10
0
0.25
0.5
0.75
1
trimf, P = [3 6 8]
trimf
380
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, psigmf, sigmf, smf,
trapmf
writefis
381
3wr it efis
Purpose Save an FIS t o t he disk.
Synopsis writefis(fismat)
writefis(fismat,'filename')
writefis(fismat,'filename','dialog'
Description writefis saves a MATLAB wor kspace FIS st r uct ur e, fismat, as a .fis file on
disk.
writefis(fismat) br ings up a dialog box t o assist wit h t he naming and
dir ect or y locat ion of t he file.
writefis(fismat,'filename') wr it es a .fis file cor r esponding t o t he FIS
st r uct ur e, fismat, t o a disk file called filename.fis. No dialog box is used and
t he file is saved t o t he cur r ent dir ect or y.
writefis(fismat,'filename','dialog') br ings up a dialog box wit h t he
default name filename.fis supplied.
The ext ension .fis is only added t o filename if it is not alr eady included in t he
name.
Examples a = newfis('tipper');
a = addvar(a,'input','service',[0 10]);
a = addmf(a,'input',1,'poor','gaussmf',[1.5 0]);
a = addmf(a,'input',1,'good','gaussmf',[1.5 5]);
a = addmf(a,'input',1,'excellent','gaussmf',[1.5 10]);
writefis(a,'my_file')
See Also readfis
zmf
382
3zmf
Purpose Zshaped built in member ship funct ion.
Synopsis y = zmf(x,[a b])
Description This splinebased funct ion of x is so named because of it s Zshape. The
par amet er s a and b locat e t he ext r emes of t he sloped por t ion of t he cur ve.
Examples x=0:0.1:10;
y=zmf(x,[3 7]);
plot(x,y)
xlabel('zmf, P=[3 7]')
See Also dsigmf, gaussmf, gauss2mf, gbellmf, evalmf, mf2mf, pimf, psigmf, sigmf, smf,
trapmf, trimf
0 2 4 6 8 10
0
0.25
0.5
0.75
1
zmf, P = [3 7]
I1
Index
A
addmf 72, 76, 36
addrule 72, 76, 38
addvar 76, 39
aggr egat ion 36, 40, 44, 60, 63, 86, 132, 133
AND 30, 37, 63, 103
ANFIS 93
anfis 7, 92, 95, 104, 109, 112, 114, 125, 310
opt ions 116
ANFIS Edit or GUI 7, 45, 92, 95, 106, 109, 114,
314
anfisedit 67, 93, 95, 314
ant ecedent 35, 37, 59, 74, 86, 88, 132
B
backpr opagat ion 104
C
chaot ic t ime ser ies 120
checking dat a 94, 118
checking er r or 119
clust er ing 120, 121, 128, 132
clust er ing algor it hms 133
clust er ing GUI 128
consequent 32, 35, 40, 59, 74, 86, 132
ant ecedent 37
convertfis 316
D
defuzz 317
defuzzificat ion 32, 36, 40, 49, 63, 95, 132
defuzzify 32, 41
degr ee of member ship 20, 24, 33, 35, 38
distfcm 121
dsigmf 27, 318
E
er r or t oler ance 104
evalfis 73, 126, 319, 326
evalmf 321
F
fcm (fuzzy cmeans) 120, 128, 322
findcluster 128, 324
FIS 43, 47, 49, 53, 58, 65, 67, 73, 84, 92, 95, 109,
125, 132, 310
Ccode 130
Edit or 45, 49, 68, 115
files 76
gener at ing 100
Mamdanit ype 49, 86, 91
mat r ix 73
saving a FIS 62
st r uct ur e 93, 115, 117
Sugenot ype 86, 88, 95
Sugenot ype S ee also Sugenot ype infer ence
97
fuzblock 83, 327
fuzdemos 328
fuzzificat ion 32, 37, 42, 49, 132
fuzzy 329
fuzzy clust er ing 115, 120
fuzzy cmeans clust er ing 322
Fuzzy Infer ence Syst em (FIS) 19, 45, 132
fuzzy oper at or s 29, 32, 37, 39, 44, 58, 63, 71, 131
fuzzy set 20, 23, 26, 35, 38, 40, 60, 86, 88, 132
Index
I2
G
gauss2mf 27, 332
gaussian 27
gaussmf 27, 334
gbellmf 27, 335
genfis 111
genfis1 101, 336
genfis2 101, 126, 338
gensurf 70, 88, 90, 340
getfis 66, 76, 89, 342
glossar y 132
gr id par t it ion 100
H
hybr id met hod 104
I
ift hen r ules 32
ant ecedent 32
consequent 32
implicat ion 32, 35, 37, 39, 43, 60, 63, 86
implicat ion S ee also ift hen r ules 32, 133
initfcm 121
L
logical oper at ions 28
M
mam2sug 345
Mamdanis met hod 36
Mamdanist yle infer ence 133
Mamdanit ype infer ence 35, 49, 86, 90
max 41, 43
member ship funct ion 23, 28, 35, 53, 55, 118, 133
mf edit or 103
Member ship Funct ion Edit or 45, 47, 52
member ship funct ions
bell 27
cust om 63
Gaussian 27
Pi 27
S 27
sigmoidal 27
Z 27
MF S ee also member ship funct ion
mf2mf 346
mfedit 347
min 43
model validat ion 94, 98
N
neur ofuzzy infer ence 93
newfis 72, 349
NOT 30, 103
O
OR 30, 37, 43, 103
P
parsrule 350
pimf 28, 351
plotfis 68, 352
plotmf 68, 90, 353
pr obabilist ic OR 39
pr obor 41
psigmf 27, 354
Index
I3
R
readfis 65, 73, 88, 355
rmmf 76, 356
rmvar 76, 357
Rule Edit or 45, 56
r ule for mat s 315, 360
Rule Viewer 45, 47, 59
ruleedit 359
ruleview 361
S
setfis 66, 76, 363
sffis 84, 365
showfis 67, 74, 76, 366
showrule 368
sigmf 27, 370
Simulink blocks
fuzzy cont r oller wit h r uleviewer 81
Fuzzy Logic Cont r oller 79, 83
Simulink, wor king wit h 78
singlet on 36
sltank 79
smf 28, 371
st andalone Ccode 130
st andalone fuzzy infer ence engine 130
st ep size 117
structure.field synt ax 66, 73
subclust 372
subt r act ive clust er ing 100, 123, 128
Sugeno 123
Sugenot ype FIS S ee also Sugenot ype infer ence
101
Sugenot ype infer ence 37, 45, 50, 86, 88, 120, 124,
133
sum 41
Sur face Viewer 45, 47, 61
surfview 375
T
Tconor m 31, 133
t est ing dat a 94, 97
Tnor m 31, 133
t r aining dat a 95, 99, 115
t r aining er r or 117
t r apezoidal 26
trapmf 26, 377
trimf 379
W
writefis 381
Z
zmf 28, 382