How to train membership functions and rules of the Mamdani FIS

3 views (last 30 days)
I have created a 5-input 1-output mamdani type FIS providing a custom rule-base analyzing the data. The number of MFs and type of MFs is decided depending on the data range and distribution. However, I am unable to find how to train it? Converting my mamdani FIS to sugeno type using mam2sug() does not help.

Answers (1)

Sam Chak
Sam Chak on 16 Apr 2025
At the time your question was posted, there was no built-in function in the Fuzzy Logic Toolbox to tune the Mamdani FIS for modeling complex relationships between inputs and outputs, particularly when dealing with imprecise data. The only available tuning method was anfis(), which supports the tuning of type-1 Sugeno FIS with one output variable.
The versatile tunefis() function was later introduced in 2019 and can be used to tune Mamdani FIS, Sugeno FIS, type-2 Mamdani FIS, and type-2 Sugeno FIS based on various tuning algorithms, such as genetic algorithms, particle swarm optimization, pattern search, simulated annealing, and adaptive neuro-fuzzy techniques. Since the R2023b release, it has also been possible to tune membership functions and rule parameters of the FIS tree, which consists of fuzzy systems arranged in hierarchical tree structures.
tic
%% Generate data of a Compounding Bell function
x = linspace(-2, +2, 41)';
y = exp(1)*exp(-cosh(1/2*(3/2*x).^2)); % compounding bell, cbell
y2 = 1/(1 + abs((x)/1).^7); % generalized bell, gbell
%% Set up initial FIS options
opt = genfisOptions('FCMClustering', 'FISType', 'mamdani');
opt.NumClusters = 4;
opt.Verbose = 0;
inifis = genfis(x, y, opt);
[in, out, rule] = getTunableSettings(inifis);
%% Set up tuning method and tune the specified Tunable Settings
options = tunefisOptions('Method', 'ga', 'OptimizationType', 'tuning', 'NumMaxRules', 8, "Display", "none");
options.MethodOptions.MaxGenerations = 60;
outfis = tunefis(inifis, [in; out; rule], x, y, options);
%% Plot results
subplot(2,1,1)
plotmf(outfis, 'input', 1, 1001);
xlabel('Membership Functions for Input 1')
subplot(2,1,2)
plotmf(outfis, 'output', 1, 1001);
xlabel('Membership Functions for Output')
figure
plotrule(outfis)
figure
opt = gensurfOptions('NumGridPoints', 401);
[X, ~, Y] = gensurf(outfis, opt);
plot(x, y), hold on
plot(X, Y), hold off
grid on, ylim([-0.5, 1.5])
legend('Training Data', 'ANFIS Output', 'location', 'best')
xlabel('x'), ylabel('y')
title('Chak Bell')
toc
Elapsed time is 68.727914 seconds.

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!