Error with Fuzzy Tree Model

12 visualizaciones (últimos 30 días)
Dzung Nguyen
Dzung Nguyen el 29 de Dic. de 2020
Respondida: Layla Mohammad el 28 de Jul. de 2023
Hello everyone,
I create a fuzzy tree (aggregated structure) in Matlab and I have an error which I hope to be supported.
My fuzzy tree has 3 fuzzy models (fis1, fis2, fis3). fis1 is the tipper1 and it has 2 inputs: service and food. Fis2 is tipper2 and it has 2 input: service and food. Outputs of fis1 and fis2 are Inputs of fis3. However, when I run it, the error is “Error using FuzzyInferenceSystem/addRule (line 1148). Invalid input membership function name in rule description.”
I think maybe error comes because I don’t create membership function for inputs of fis3. But I have already created membership function for outputs of fis1 and fis2, so if I create membership function for fis3, the inputs of fis3 will have 2 times of membership function. Could you support me with this issue? Thank you.
% 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','NumInputs',2,'NumOutputs',1);
fis3.Outputs(1).Name = "final_tip";
con1 = ["tipper1/tip1" "fis3/input1"];
con2 = ["tipper2/tip2" "fis3/input2"];
fis3 = addMF(fis3,"final_tip","trapmf",[-2 0 1 3],'Name',"rancid");
fis3 = addMF(fis3,"final_tip","trapmf",[7 9 10 12],'Name',"delicious");
rulefis3a = "input1==cheap | input2==average => final_tip=rancid";
rulefis3b = "input1==average => final_tip=rancid";
rulefis3c = "input1==generous | input2==generous => final_tip=delicious";
rulefis3d = [rulefis3a rulefis3b rulefis3c];
fis3b = addRule(fis3,rulefis3d);
aggTree = fistree([fis1b fis2b fis3b],[con1;con2]);
output = evalfis(aggTree,[0.2 0.25 0.3 0.2]);

Respuesta aceptada

Asvin Kumar
Asvin Kumar el 14 de Feb. de 2021
There were a couple of issues that needed fixing.
  1. Every FIS needs to have its Inputs, Outputs and MFs defined separately.
  2. 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.
  3. 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).MembershipFunctions
fis3.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])
  1 comentario
Dzung Nguyen
Dzung Nguyen el 27 de Feb. de 2021
Dear Asvin,
Thank you so much for your clear explaination.
Best regards,

Iniciar sesión para comentar.

Más respuestas (1)

Layla Mohammad
Layla Mohammad el 28 de Jul. de 2023
I have exactly the same concept but different application Area
Please note that I have already designed the first 2 FISs using fuzzylogic designer
The only step needed is the aggregation part
How can i do that?

Categorías

Más información sobre Fuzzy Logic Toolbox en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by