How to extract Fuzzy Rules from Data and determine their adequacy for classification
6 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Sam Chak
on 26 Apr 2025
Hi @eman
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)
outFIS.Outputs(1).MembershipFunctions
plotrule(outFIS)
figure
plotfiserr(outFIS, x, y), grid on
0 Comments
See Also
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!










