How to get fuzzy output values instead of crisp output values?
조회 수: 17 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
Sam Chak
2022년 10월 4일
Hi @Hung
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")
% 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])
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
Sam Chak
2022년 10월 5일
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 "⭐".
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fuzzy Logic in Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!