How to input a NaN (as a nonexistent input variable) when evaluating a fuzzy system using evalfis
Mostrar comentarios más antiguos
Hi all
I have designed a fuzzy logic model using the fuzzy logic toolbox.
The model has four input variables [x1, x2, x3, x4], and the variable x3 does not exist when x1<10. The rules have been designed to take this into account.
In the app, I can generate a surface for [NaN, 0, 0, NaN], which will plot the output as a function of x1 and x4 when x2 = 0 and x3 = 0. I can also create a surface for [NaN, 0, NaN, NaN] in which it is assumed x3 is absent. These surfaces look ok.
Now, I want to evaluate my model from the command line with evalfis
output = evalfis(myfuzzy, [x1 x2 x3 x4])
I have no idea how to input that the variable x3 is absent. I have tried
output = evalfis(myfuzzy, [x1 x2 nan x4])
but I get an error, any idea how to do this?
8 comentarios
NaN
el 27 de Feb. de 2024
To be honest, I haven't encountered such a problem before, but it does sound intriguing. Would you be able to provide a mock-up of a 2-input or 3-input fuzzy system that leads to one of the fuzzy inputs becoming NaN after defuzzification?
fis = mamfis('Name', "mockupFIS");
% Fuzzy Input #1
fis = addInput(fis, [0 10], 'Name', 'in1');
fis = addMF(fis, 'in1', 'linzmf', [3 7], 'Name', 'Low'); % Low
fis = addMF(fis, 'in1', 'linsmf', [3 7], 'Name', 'High'); % High
% Fuzzy Input #2
fis = addInput(fis, [0 10], 'Name', 'in2');
fis = addMF(fis, 'in2', 'linzmf', [3 7], 'Name', 'Low'); % Low
fis = addMF(fis, 'in2', 'linsmf', [3 7], 'Name', 'High'); % High
% Plot MFs for inputs
figure(1)
subplot(2,1,1)
plotmf(fis, 'input', 1), grid on, title('Input 1')
subplot(2,1,2)
plotmf(fis, 'input', 2), grid on, title('Input 2')
% Fuzzy Output
fis = addOutput(fis, [0 10], 'Name', 'out');
fis = addMF(fis, 'out', 'linzmf', [3 5 ], 'Name', 'Low'); % Low
fis = addMF(fis, 'out', 'trimf', [3 5 7], 'Name', 'Med'); % Medium
fis = addMF(fis, 'out', 'linsmf', [ 5 7], 'Name', 'High'); % High
figure(2)
plotmf(fis, 'output', 1), grid on, title('Output')
NaN
el 28 de Feb. de 2024
Respuestas (1)
Hi @NaN
I am revisiting the problem after more than a year and believe that two fuzzy systems (fis11 and fis12) should be created separately, mimicking the concept of a piecewise linear function. The fuzzy system fis11 takes four inputs {x1, x2, x3, x4} and returns a non-zero output when x1 < 10. If x1 ≥ 10, fis11 returns 0. The fuzzy system fis12 takes three inputs {x1, x2, x4} and returns a non-zero output when x1 ≥ 10. If x1 < 10, fis12 returns 0. The fuzzy system fis1 functions as an additive operation but actually returns either the output of fis11 or the output of fis12.
%% fis11 works when x1 < 10 and x3 is defined
% When x1 >= 10, fis1 should output 0
fis11 = mamfis('Name', 'fis11', 'NumInputs', 4, 'NumOutputs', 1);
fis11.Inputs(1).Name = "x1";
fis11.Inputs(2).Name = "x2";
fis11.Inputs(3).Name = "x3";
fis11.Inputs(4).Name = "x4";
fis11.Outputs(1).Name = "y1";
%% fis12 works when x1 >= 10 and x3 is undefined
% When x1 < 10, fis2 should output 0
fis12 = mamfis('Name', 'fis12', 'NumInputs', 3, 'NumOutputs', 1);
fis12.Inputs(1).Name = "x1";
fis12.Inputs(2).Name = "x2";
fis12.Inputs(3).Name = "x4";
fis12.Outputs(1).Name = "y2";
%% fis1 decides on either output of fis11 or output of fis12
fis1 = mamfis('Name', 'fis1', 'NumInputs', 2, 'NumOutputs', 1);
fis1.Inputs(1).Name = "y1";
fis1.Inputs(2).Name = "y2";
fis1.Outputs(1).Name = "y3";
%% fis2 is the 2nd stage computation that takes the output of fis1
fis2 = mamfis('Name', 'fis2', 'NumInputs', 3, 'NumOutputs', 1);
fis2.Inputs(1).Name = "x3";
fis2.Inputs(2).Name = "y3";
fis2.Inputs(3).Name = "x5";
fis2.Outputs(1).Name = "y4";
%% connections
con1 = ["fis11/x1", "fis12/x1"];
con2 = ["fis11/x2", "fis12/x2"];
con3 = ["fis11/x4", "fis12/x4"];
con4 = ["fis11/y1", "fis1/y1"];
con5 = ["fis12/y2", "fis1/y2"];
con6 = ["fis11/x3", "fis2/x3"];
con7 = ["fis1/y3", "fis2/y3"];
%% create a FIS Tree
tree = fistree([fis11 fis12 fis1 fis2], [con1; con2; con3; con4; con5; con6; con7]);
plotfis(tree)
Categorías
Más información sobre Fuzzy Logic in Simulink en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



