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

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 commentaires

Hi @NaN, I don't understand. Can you show your 4-input fuzzy system (myfuzzy.fis)? You can put the fis file in a zipped file and attach it using the paperclip icon
Hi @Sam Chak Unfortunatelly I cannot share the model due to confidentiality.
No worries, @NaN. I'm just trying to assist. Could you please explain how you devised the rules in such a way that the variable disappears in the fuzzy system when ? Having NaN doesn't mean the variable simply disappears without a trace.
NaN
NaN le 27 Fév 2024
Déplacé(e) : Sam Chak le 27 Fév 2024
Will try to explain the idea. Imagine I have a system with two inputs:
x1 = low(0-5), high(5-10)
x2 = low(0-5), high(5-10)
the output is
y = low, medium, high
the rules are;
if x1 is low => y is low --> this assumes x2 is none
if x1 is high => y is high --> this assumes x2 is none
if x1 is high and x2 is low = y is medium --> this assumes x2 is low
Now, if I want to evaluate this, I can do
y = evalfis(myfuzzy, [10 0]) and y should be medium
now I want to evaluate it with x2 = none
y = evalfis(myfuzzy, [10 ??]) and y should be high
how do I input that x2 is none (does not exist)?
NaN
NaN le 27 Fév 2024
Modifié(e) : NaN le 27 Fév 2024
Lets assume that x1 = [0 100]
In the app, I can generate two different surfaces
Surface 1 is calculated giving x3 a value. x1 spans 0-100
Surface 2 is calculated giving x3 =NaN. x1 spans 0-100, however, only the part of the surface corresponding to x1=[0 10] is valid.
The surfaces look fine to me, my question is simply how to input the none in the command line
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')
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.
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?

Connectez-vous pour commenter.

Réponses (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)

Catégories

En savoir plus sur Fuzzy Logic in Simulink dans Centre d'aide et File Exchange

Produits

Version

R2023b

Question posée :

NaN
le 27 Fév 2024

Community Treasure Hunt

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

Start Hunting!

Translated by