Upload
others
View
32
Download
0
Embed Size (px)
Citation preview
Matlab Fuzzy ToolboxMatlab Fuzzy Toolboxyy
Prepared by :Prepared by :Prepared by :Prepared by :Waleed AliProf. Dr. Siti MariyamAssoc. Prof. Dr Siti Zaiton
outlineoutline
Working Using Fuzzy GUI ToolsWorking Using Fuzzy GUI ToolsPractical Example of GUI ToolsWorking From Command LinePractical Example of Fuzzy FromPractical Example of Fuzzy From
Command Line
Working Using GUI ToolsWorking Using GUI Tools
Matlab Fuzzy Toolbox consist of two useful Tools:
• FIS Editor:• FIS Editor:This Editor in combination with 4 other editors provides a powerful environment to define and modify Fuzzy Inference System (FIS) variable.
• Fuzzy Controller:This is a block in Fuzzy Toolbox Library in Simulink environment. This Block y yadmits FIS variable produced by FIS Editor and implements the desirable rules
Fuzzy Inference System (FIS)Fuzzy Inference System (FIS)
FIS EditFIS Editor
>> fuzzy
Membership Function EditorMembership Function Editor
Rule EditorRule Editor
R le Vie erRule Viewer
The Surface ViewerThe Surface Viewer
* Evaluation
A Si l E lA Simple Example
A i l lA simple example
W ’ll i h b i d i i f i i iWe’ll start with a basic description of a two-input, :one-output tipping problem•Given a number between 0 and 10 that represents the quality of service at p q ya restaurant (where 10 is excellent)•Given number between 0 and 10 that represents the quality of the food at that restaurant (again 10 is excellent)that restaurant (again, 10 is excellent)•The starting point is to write down the three golden rules of tipping1. If the service is poor or the food is rancid, then tip is cheap.p , p p2. If the service is good, then tip is average.3. If the service is excellent or the food is delicious, then tip is generous.•Assume that an average tip is 15%, a generous tip is 25%, and a cheap tip is 5%.
The two inputs in our example are service and food. The one output is tip. >> fuzzy
1-Select Edit > Add variable > Input/output.
2 Edit th N fi ld d2-Edit the Name field and press Enter.
1 Select the input variables. Set both the Range and the Display Range to the vector [0 10]10].2 Select Remove All MFs from the Edit menumenu. 3 Select Add MFs. from the Edit menu
To call up theTo call up theRule Editor, go to the Edit menu and
l t R lselect Rules
Working from the Command LineWorking from the Command Line
1- creates new FIS structures using newfis function
Syntaxa=newfis(fisName,fisType,andMethod,orMethod,impMethod,aggMethod,defuzzMethod) ;
fisName is the name of the FIS structure.fisType is the type of FIS.yp ypandMethod, orMethod, impMethod, aggMethod, and defuzzMethod, respectively,provide the
methods for AND, OR, implication, aggregation, and defuzzification
example:a=newfis('newsys');
tfi ( )getfis(a)
2 Add i bl FIS d d i b hi F i2-Add variables to FIS and and its membership Functions using addvar and addmf functions
SyntaxSyntaxa = addvar(a,'varType','varName',varBounds) ;a = addmf(a,'varType',varIndex,'mfName','mfType',mfParams)
a is the name of a FIS structurevarType is the type of the variable ('input' or 'output')y y ( )varType is the name of the variable you want to addvarBounds is the vector describing the limiting range values for the variablevarIndex is the index of the variable you want to add the membership function toy pmfName the name of the new membership functionmfType is the type of the new membership functionmfParams is the vector of parameters that specify the membership functiona a s s t e ecto o pa a ete s t at spec y t e e be s p u ct o
• Examplea = 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, good , gaussmf ,[1.5 5]);a = addmf(a,'input',1,'excellent','gaussmf',[1.5 10]);plotmf(a,'input',1)p ( , p , )
3-Add rules to the FISSyntaxa = addrule(a,ruleList) a is the name of a FIS structureruleList is a matrix of one or more rows each of which represents a given ruleruleList is a matrix of one or more rows, each of which represents a given rule.Notes
The format that the rule list matrix must take is very specific. Th t b tl 2 l t th l li t f i t d t tThere must be exactly m + n + 2 columns to the rule list for m inputs and n outputs .The first m columns refer to the inputs of the system. Each column contains a number that refers to the index of the membership function for that variable.The next n columns refer to the outputs of the system Each column contains aThe next n columns refer to the outputs of the system. Each column contains a number that refers to the index of the membership function for that variable.The m + n + 1 column contains the weight of the rule in range[0,1]. The m + n + 2 column contains a 1 if the fuzzy operator for the rule's antecedent isThe m + n + 2 column contains a 1 if the fuzzy operator for the rule s antecedent is AND. It contains a 2 if the fuzzy operator is OR.
• ExampleIf the system a has two inputs and one output index number for the
membership function
ruleList=[1 1 1 1 1
associated with input 1
index number for the membership functionassociated with input 21 1 1 1 1
1 2 2 1 1];
associated with input 2
index number for the membership functionassociated with output 1
a = addrule(a,ruleList); the weight associated with rule (typically 1)
the first rule can be interpreted as:
"If Input 1 is MF 1 and Input 2 is MF 1 then Output 1 is MF 1 "
specifies the connective used (where AND = 1 and OR = 2)
If Input 1 is MF 1 and Input 2 is MF 1, then Output 1 is MF 1.
Our example : tipping problemOur example : tipping problem
% FIS% creates new FIS structures a=newfis('tipper');% Add input variable(Service) and its membership Functions% Add input variable(Service) and its membership Functions a=addvar(a,'input','service',[0 10]);a=addmf(a,'input',1,'poor','gaussmf',[1.5 0]);
dd f( 'i t' 1 ' d' ' f' [1 5 5])a=addmf(a,'input',1,'good','gaussmf',[1.5 5]);a=addmf(a,'input',1,'excellent','gaussmf',[1.5 10]);figure;plotmf(a,'input',1);g ( )
% Add i i bl (F d) d i b hi F i% Add input variable(Food) and its membership Functions a=addvar(a,'input','food',[0 10]);a=addmf(a,'input',2,'rancid','trapmf',[-2 0 1 3]);( , p , , , p ,[ ]);a=addmf(a,'input',2,'delicious','trapmf',[7 9 10 12]);figure;plotmf(a,'input',2);
% Add output variable(tip) and its membership Functions a=addvar(a,'output','tip',[0 30]);a=addmf(a 'output' 1 'cheap' 'trimf' [0 5 10]);a addmf(a, output ,1, cheap , trimf ,[0 5 10]);a=addmf(a,'output',1,'average','trimf',[10 15 20]);a=addmf(a,'output',1,'generous','trimf',[20 25 30]);figure;plotmf(a,'output',1);
%Add rules to the FISruleList=[ index number for the
membership function1 1 1 1 22 0 2 1 13 2 3 1 2 ]
membership functionassociated with input 1(service)
index number for the membership functionassociated with input 2(food)
3 2 3 1 2 ];a=addrule(a,ruleList); index number for the
membership functionassociated with output 1the weight associatedthe weight associated
with rule (typically 1)specifies the connective used (where AND = 1 and OR = 2)
%plot the created FISfigure;plotfis(a);