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

조회 수: 17 (최근 30일)
Hung
Hung 2022년 10월 4일
댓글: Hung 2022년 10월 5일
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!

채택된 답변

Sam Chak
Sam Chak 2022년 10월 4일
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
Sam Chak
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 "⭐".
Hung
Hung 2022년 10월 5일
@Sam Chak Thank you very much. I understand now :-)
I have voted and acepted your answer :D
Good day!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fuzzy Logic in Simulink에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by