In the example Fuzzy PID Control with Type-2 FIS, there is nothing that explain how to save the converted fuzzy type 1 system (the fis2). I tried to do the example but I could not manage to find the fis2. Am I missing something?
MATLAB: How to save Type 2 Fuzzy system
Fuzzy Logic Toolboxfuzzy type 2save fis
Related Solutions
There were a couple of issues that needed fixing.
- Every FIS needs to have its Inputs, Outputs and MFs defined separately.
- FIS3 would not have two MFs at its inputs. All it gets from FIS1 or FIS2 is a number. It decides what that number means based on the MF defined on its (FIS3's) inputs. So, yes, in your case you would have to redefine FIS1 and FIS2 output MFs as the MFs for the two inputs to FIS3.
- The error that you see - “Error using FuzzyInferenceSystem/addRule (line 1148). Invalid input membership function name in rule description.” is because the inputs of FIS3 are instantiated, by default, to have 3 MFs called 'mf1', 'mf2', 'mf3' for both the inputs. You can see this by typing the following in the command window after executing the script until the line that errors out:
fis3.Inputs(1).MembershipFunctionsfis3.Inputs(2).MembershipFunctions
They have these default member functions because fis3 was created in your script with the following command:
fis3 = mamfis('Name','fis3','NumInputs',2,'NumOutputs',1);
Here's the code with a couple of changes. You should be able to adapt this for your use:
% Fuzzy model 1
fis1 = mamfis('Name',"tipper1");fis1 = addInput(fis1,[0 10],'Name',"service");fis1 = addMF(fis1,"service","gaussmf",[1.5 0],'Name',"poor");fis1 = addMF(fis1,"service","gaussmf",[1.5 5],'Name',"good");fis1 = addMF(fis1,"service","gaussmf",[1.5 10],'Name',"excellent");fis1 = addInput(fis1,[0 10],'Name',"food");fis1 = addMF(fis1,"food","trapmf",[-2 0 1 3],'Name',"rancid");fis1 = addMF(fis1,"food","trapmf",[7 9 10 12],'Name',"delicious");fis1 = addOutput(fis1,[0 30],'Name',"tip1");fis1 = addMF(fis1,"tip1","trimf",[0 5 10],'Name',"cheap");fis1 = addMF(fis1,"tip1","trimf",[10 15 20],'Name',"average");fis1 = addMF(fis1,"tip1","trimf",[20 25 30],'Name',"generous");rulefis1a = "service==poor | food==rancid => tip1=cheap";rulefis1b = "service==good => tip1=average";rulefis1c = "service==excellent | food==delicious => tip1=generous";rulefis1d = [rulefis1a rulefis1b rulefis1c];fis1b = addRule(fis1,rulefis1d); %Fuzzy model 2
fis2 = mamfis('Name',"tipper2");fis2 = addInput(fis2,[0 10],'Name',"service");fis2 = addMF(fis2,"service","gaussmf",[1.5 0],'Name',"poor");fis2 = addMF(fis2,"service","gaussmf",[1.5 5],'Name',"good");fis2 = addMF(fis2,"service","gaussmf",[1.5 10],'Name',"excellent");fis2 = addInput(fis2,[0 10],'Name',"food");fis2 = addMF(fis2,"food","trapmf",[-2 0 1 3],'Name',"rancid");fis2 = addMF(fis2,"food","trapmf",[7 9 10 12],'Name',"delicious");fis2 = addOutput(fis2,[0 30],'Name',"tip2");fis2 = addMF(fis2,"tip2","trimf",[0 5 10],'Name',"cheap");fis2 = addMF(fis2,"tip2","trimf",[10 15 20],'Name',"average");fis2 = addMF(fis2,"tip2","trimf",[20 25 30],'Name',"generous");rulefis2a = "service==poor | food==rancid => tip2=cheap";rulefis2b = "service==good => tip2=average";rulefis2c = "service==excellent | food==delicious => tip2=generous";rulefis2d = [rulefis2a rulefis2b rulefis2c];fis2b = addRule(fis2,rulefis2d);%Fuzzy model 3
fis3 = mamfis('Name','fis3');fis3 = addInput(fis3,[0 30],'Name',"tip1");fis3 = addMF(fis3,"tip1","trimf",[0 5 10],'Name',"cheap");fis3 = addMF(fis3,"tip1","trimf",[10 15 20],'Name',"average");fis3 = addMF(fis3,"tip1","trimf",[20 25 30],'Name',"generous");fis3 = addInput(fis3,[0 30],'Name',"tip2");fis3 = addMF(fis3,"tip2","trimf",[0 5 10],'Name',"cheap");fis3 = addMF(fis3,"tip2","trimf",[10 15 20],'Name',"average");fis3 = addMF(fis3,"tip2","trimf",[20 25 30],'Name',"generous");fis3.Outputs(1).Name = "final_tip";fis3 = addMF(fis3,"final_tip","trapmf",[-2 0 1 3],'Name',"low");fis3 = addMF(fis3,"final_tip","trapmf",[7 9 10 12],'Name',"high");rulefis3a = "tip1==cheap | tip2==average => final_tip=low";rulefis3b = "tip1==average => final_tip=low";rulefis3c = "tip1==generous | tip2==generous => final_tip=high";rulefis3d = [rulefis3a rulefis3b rulefis3c];fis3b = addRule(fis3,rulefis3d);con1 = ["tipper1/tip1" "fis3/tip1"];con2 = ["tipper2/tip2" "fis3/tip2"];aggTree = fistree([fis1b fis2b fis3],[con1;con2]);aggTree.FIS(3) = addRule(aggTree.FIS(3), rulefis3d)output = evalfis(aggTree,[0.2 0.25 0.3 0.2])
You have to evaluate your Fuzzy Inference System with the testing Inputs, and the output responses have to be compared against the testing outputs.
In order to Evaluate Fuzzy Inference System
Step 1: Load the Fuzzy Inference System
fis = readfis(filename)
Step 2: Read the csv file
input = readmatrix(filename.csv)
Output = evalfis(fis, input)
The output of the fuzzy system is obtained.In order to know the accuracy of FIS, Measure the error between real outputs and output responses or you can also test all possible combinations of inputs and verify that the outputs of the fuzzy inference system you developed is operating accordingly.
Best Answer