How to extract Fuzzy Rules from Data and determine their adequacy for classification

6 views (last 30 days)
I have created fuzzy inference system for classification using mamdani type FIS. How can i extract rules for FIS from given data? How do i know these rules are good enough for classification?

Answers (1)

Sam Chak
Sam Chak on 26 Apr 2025
If the data size is relatively small and non-chaotic, then both tunefis() and anfis() algorithms can be used to to uncover the underlying relationships within data. You will know the rules are good if you can easily comprehend them and the predicted outcomes are faily accurate. Whether it is overfitting or underfitting, that would be a story between the training data and the test data. With tunefis() training methods, both Mamdani and Sugeno fuzzy systems can be trained.
In the example of training an ANFIS model to reproduce the shape of the McDonald's logo, which features two golden arches, we can start with two Gaussian membership functions and then increase this number by the end of the loop. The loop will iterate until the computed root mean squared error between the ANFIS predicted array and the observed McDonald's array is less than the specified accuracy.
It is unnecessary to use 27 identical, uniformly spaced Gaussian membership functions as demonstrated in this example.
%% The McDonald's Logo
x = linspace(-6.5, 6.5, 261)';
y = 6*abs(x) - x.^2 + 3.25;
%% ANFIS script
% initial settings of the loop
Error = Inf;
numMFs = 2; % initial number of membership functions
while Error > 0.1
% set up initial FIS
genOpt = genfisOptions('GridPartition');
genOpt.NumMembershipFunctions = numMFs;
genOpt.InputMembershipFunctionType = 'gaussmf';
genOpt.OutputMembershipFunctionType = 'constant';
iniFIS = genfis(x, y, genOpt);
% specify ANFIS options for tuning fuzzy systems
opt = anfisOptions('InitialFIS', iniFIS, 'EpochNumber', 500);
opt.DisplayANFISInformation = 0;
opt.DisplayErrorValues = 0;
opt.DisplayStepSize = 0;
opt.DisplayFinalResults = 0;
% tune Sugeno FIS using training data
outFIS = anfis([x y], opt);
% evaluate the root mean squared error between the predicted array and the observed array.
Error = rmse(evalfis(outFIS, x), y);
% plot results
figure
plotmf(outFIS, 'input', 1, 1301),
grid on, ylim([-0.5, 1.5])
xlabel('Input, x')
title(sprintf('%d Input Gaussian MFs', numMFs))
delete(findobj(gca, 'Type', 'text'));
figure
x1 = linspace(-6.5, 6.5, 27*3)';
y1 = 6*abs(x1) - x1.^2 + 3.25;
plot(x1, y1, 'o'), hold on
plot(x, evalfis(outFIS, x), 'linewidth', 1.5), hold off
grid on, ylim([-1 13])
legend('Training Data', 'ANFIS Output', 'location', 'south')
axis equal
xlabel('x'), ylabel('y')
title(sprintf('Fitting McDonald''s Logo with %d rules', numMFs))
numMFs = numMFs + 1;
end
figure
showrule(outFIS)
ans = 6x53 char array
'1. If (input1 is in1mf1) then (output is out1mf1) (1)' '2. If (input1 is in1mf2) then (output is out1mf2) (1)' '3. If (input1 is in1mf3) then (output is out1mf3) (1)' '4. If (input1 is in1mf4) then (output is out1mf4) (1)' '5. If (input1 is in1mf5) then (output is out1mf5) (1)' '6. If (input1 is in1mf6) then (output is out1mf6) (1)'
outFIS.Outputs(1).MembershipFunctions
ans =
1x6 fismf array with properties: Type Parameters Name Details: Name Type Parameters _________ __________ __________ 1 "out1mf1" "constant" -18.872 2 "out1mf2" "constant" 38.328 3 "out1mf3" "constant" 1.0923 4 "out1mf4" "constant" 3.6009 5 "out1mf5" "constant" 38.526 6 "out1mf6" "constant" -19.07
plotrule(outFIS)
figure
plotfiserr(outFIS, x, y), grid on

Categories

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

Community Treasure Hunt

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

Start Hunting!