How to input a NaN (as a nonexistent input variable) when evaluating a fuzzy system using evalfis

15 views (last 30 days)
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 Comments
NaN
NaN on 28 Feb 2024
My model is actually a tree like the attached image. x3 only exists if x5>10.
if I execute
options.InputIndex = [1 2];
options.ReferenceInputs = [NaN NaN NaN];
gensurf(fis_2, options)
I get a pretty surface (do not get an error). Here x3 is NaN
if I execute
options.InputIndex = [1 2];
options.ReferenceInputs = [NaN NaN 1];
gensurf(fis_2, options)
also get a pretty surface, different from the previous one. Here x3 exists
If I execute
options.InputIndex = [1 4];
options.ReferenceInputs = [NaN 0 NaN NaN];
gensurf(fis_1, options)
Matlab returns an ugly flat surface = 0.5. Does not return error. Here x3 is NaN
If I execute
options.InputIndex = [1 5];
options.ReferenceInputs = [NaN 0 0.5 0 NaN];
gensurf(fuzzTree, options)
I get a pretty surface. However, if I execute
options.InputIndex = [1 5];
options.ReferenceInputs = [NaN 0 NaN 0 NaN];
gensurf(fuzzTree, options)
Matlab returns an error. x3 can be NaN when evaluating fis1 (ugly result but valid), when evaluating fis2 (pretty result) but not when evaluating the tree.
I need to investigate a bit more what is going on.
Sam Chak
Sam Chak on 28 Feb 2024
Hi @LD,
I'm a bit confused. What computation is resulting in those NaN values? It shouldn't be due to the FIS itself, as FIS is not capable of generating NaN values, correct? Also, what is the universe of discourse for ? The range of values should be finite, right?

Sign in to comment.

Answers (1)

Sam Chak
Sam Chak on 21 Apr 2025
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)

Categories

Find more on Fuzzy Logic in Simulink in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!