How to create multiple Fuzzy Inference Systems (FIS) simultaneously without using a for-loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am continuously changing my membership function values in my code. I can run a loop and create as many Fuzzy Inference systems(FISs) as I want. But I want to create all of them simultaneously so that I can cut down on the execution time. I looked up the codes of many inbuilt functions like newfis,addvar etc. They support the creation of one FIS at a time. So is there any other way of solving this problem without having to modify the inbuilt functions?
Thanks in advance.
0 commentaires
Réponses (2)
Sam Chak
le 16 Avr 2025
Hi @Spurthi
You can create multiple FIS models simultaneously without using a for-loop by leveraging MATLAB's capability to handle arrays of FIS models. To create FIS models, you can utilize the genfis, mamfis, sugfis, mamfistype2, and sugfistype2 functions.
In this example, cellfun() is employed to simultaneously apply the genfis() function to each set of genfisOptions in the cell arrays, thereby creating multiple FIS models without an explicit loop. Each FIS model is stored in the cell array Cfis.
inputData = [rand(10, 1), 10*rand(10, 1)-5];
outputData = rand(10, 1);
%% Define genfisOptions for multiple FIS models
opt1 = genfisOptions('GridPartition');
opt1.NumMembershipFunctions = [ 3, 5 ];
opt1.InputMembershipFunctionType = ["gaussmf", "trimf"];
opt2 = genfisOptions('GridPartition');
opt2.NumMembershipFunctions = [ 4, 4 ];
opt2.InputMembershipFunctionType = ["gaussmf", "trimf"];
opt3 = genfisOptions('GridPartition');
opt3.NumMembershipFunctions = [ 5, 3 ];
opt3.InputMembershipFunctionType = ["gaussmf", "trimf"];
%% Create cell arrays to hold multiple genfisOptions
opt = {opt1, opt2, opt3};
%% Create FIS models and store in the cell array Cfis
Cfis = cellfun(@(opt) genfis(inputData, outputData, opt), opt, 'UniformOutput', false);
%% Display the fuzzy sets of the created FIS models
figure
subplot(2,1,1)
plotmf(Cfis{1}, 'input', 1)
subplot(2,1,2)
plotmf(Cfis{1}, 'input', 2)
sgtitle('Input fuzzy sets of FIS 1')
figure
subplot(2,1,1)
plotmf(Cfis{2}, 'input', 1)
subplot(2,1,2)
plotmf(Cfis{2}, 'input', 2)
sgtitle('Input fuzzy sets of FIS 2')
figure
subplot(2,1,1)
plotmf(Cfis{3}, 'input', 1)
subplot(2,1,2)
plotmf(Cfis{3}, 'input', 2)
sgtitle('Input fuzzy sets of FIS 3')
0 commentaires
Sam Chak
le 16 Avr 2025
Here is the for-loop approach to create multiple FIS models.
inputData = [rand(10, 1), 10*rand(10, 1)-5];
outputData = rand(10, 1);
n = 3;
for i = 1:n
opt = genfisOptions('GridPartition');
opt.NumMembershipFunctions = [ i+2, 6-i ];
opt.InputMembershipFunctionType = ["gaussmf", "trimf"];
fis(i) = genfis(inputData, outputData, opt);
end
figure
subplot(2,1,1)
plotmf(fis(1), 'input', 1)
subplot(2,1,2)
plotmf(fis(1), 'input', 2)
sgtitle('Input fuzzy sets of FIS 1')
figure
subplot(2,1,1)
plotmf(fis(2), 'input', 1)
subplot(2,1,2)
plotmf(fis(2), 'input', 2)
sgtitle('Input fuzzy sets of FIS 2')
figure
subplot(2,1,1)
plotmf(fis(3), 'input', 1)
subplot(2,1,2)
plotmf(fis(3), 'input', 2)
sgtitle('Input fuzzy sets of FIS 3')
0 commentaires
Voir également
Catégories
En savoir plus sur Fuzzy Logic in Simulink dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!