How to get fuzzy output values instead of crisp output values?

15 views (last 30 days)
Hello,
I am following the fuzzy tool box designer example Build Fuzzy Systems Using Fuzzy Logic Designer - MATLAB & Simulink - MathWorks Nordic and have two questions:
1/ The tool showed the output result in crisp value after defuzzification, but are there ways to show the output in fuzzied values (0-1)?
2/ Are there ways to "look up" output value from 2 known input values from the 3D surface as mentioned in the video?
Thank you!

Accepted Answer

Sam Chak
Sam Chak on 4 Oct 2022
The crisp out does not have an equivalent scalar fuzzy value. So, I think you probably mean finding the Aggregated output fuzzy set that the crisp value is calculated using the Centroid method. See Example below:
fis = mamfis('Name', "Fuzzy_Demo_2in1out")
fis =
mamfis with properties: Name: "Fuzzy_Demo_2in1out" AndMethod: "min" OrMethod: "max" ImplicationMethod: "min" AggregationMethod: "max" DefuzzificationMethod: "centroid" DisableStructuralChecks: 0 Inputs: [0×0 fisvar] Outputs: [0×0 fisvar] Rules: [0×0 fisrule] See 'getTunableSettings' method for parameter optimization.
% Fuzzy Input #1
fis = addInput(fis, [-1 1], 'Name', 'in1');
fis = addMF(fis, 'in1', 'gaussmf', [0.5 -1], 'Name', 'N');
fis = addMF(fis, 'in1', 'gaussmf', [0.5 1], 'Name', 'P');
% Fuzzy Input #2
fis = addInput(fis, [-1 1], 'Name', 'in2');
fis = addMF(fis, 'in2', 'gaussmf', [0.5 -1], 'Name', 'N');
fis = addMF(fis, 'in2', 'gaussmf', [0.5 1], 'Name', 'P');
cross = 0.125;
sigma = 0.5*(2.5 - 0)/sqrt(-2*log(cross));
% Fuzzy Output
fis = addOutput(fis, [-2.5 2.5], 'Name', 'out');
fis = addMF(fis, 'out', 'gaussmf', [sigma -2.5], 'Name', 'N');
fis = addMF(fis, 'out', 'gaussmf', [sigma 0.0], 'Name', 'Z');
fis = addMF(fis, 'out', 'gaussmf', [sigma 2.5], 'Name', 'P');
% Plot membership functions
figure(1)
subplot(2,1,1)
plotmf(fis, 'input', 1), grid on, title('in1 and in2')
subplot(2,1,2)
plotmf(fis, 'output', 1), grid on, title('U')
% Fuzzy Rules
rules = [...
"in1==N & in2==N => out=N"; ...
"in1==N & in2==P => out=Z"; ...
"in1==P & in2==N => out=Z"; ...
"in1==P & in2==P => out=P"; ...
];
fis = addRule(fis, rules);
% Generate output surface of MamFIS
figure(2)
opt = gensurfOptions('NumGridPoints', 41);
gensurf(fis, opt), title('Output Surface')
% Plot Aggregated output fuzzy set and Defuzzified output (Crisp value)
% find crisp output when in1 = -0.25 and in2 = -0.25
figure(3)
[output, fuzzifiedIn, ruleOut, aggregatedOut, ruleFiring] = evalfis(fis, [-0.25 -0.5])
output = -1.3279
fuzzifiedIn = 4×2
0.3247 0.6065 0.3247 0.0111 0.0439 0.6065 0.0439 0.0111
ruleOut = 101×4
0.3247 0.0002 0.0002 0.0000 0.3247 0.0003 0.0003 0.0000 0.3247 0.0005 0.0005 0.0000 0.3247 0.0006 0.0006 0.0000 0.3247 0.0009 0.0009 0.0000 0.3247 0.0012 0.0012 0.0000 0.3247 0.0016 0.0016 0.0000 0.3247 0.0021 0.0021 0.0000 0.3247 0.0028 0.0028 0.0000 0.3247 0.0037 0.0037 0.0000
aggregatedOut = 101×1
0.3247 0.3247 0.3247 0.3247 0.3247 0.3247 0.3247 0.3247 0.3247 0.3247
ruleFiring = 4×1
0.3247 0.0111 0.0439 0.0111
outputRange = linspace(fis.output.range(1), fis.output.range(2), length(aggregatedOut))';
plot(outputRange, aggregatedOut, [output output], [0 1]), grid on
xlabel('output')
ylabel('Output Membership')
legend('Aggregated output fuzzy set', 'Defuzzified output')
The blue curve is the Aggregated output fuzzy set. The vertical red line marks the Defuzzified output that is computed from the Centroid Defuzzification method.
  3 Comments
Sam Chak
Sam Chak on 5 Oct 2022
You are welcome, @Hung. If you find the example / explanation helpful, please consider accepting ✔ and voting 👍 the Answer. Thanks!
If you want to understand better, I think the graphic on this link explains the process of fuzzy inference. There is a single output from the fuzzy system and it is the crisp value calculated from the centroid of the aggregated output fuzzy set.
Regarding the 2nd question, the designer coincidentally set the risk score range from 0 to 1, but they are not really fuzzy value. In fact, some designer may set the risk score range from 0 to 5 "⭐".
Hung
Hung on 5 Oct 2022
@Sam Chak Thank you very much. I understand now :-)
I have voted and acepted your answer :D
Good day!

Sign in to comment.

More Answers (0)

Categories

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

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!