Rules formation method using fuzzy c means clustering method.

44 visualizaciones (últimos 30 días)
Mamta
Mamta el 27 de Dic. de 2023
Comentada: Sam Chak el 17 de En. de 2026 a las 4:53
I want to know about tool that automatically genreate the rules on the basis of dataset with fuzzy c means clustering method .Please explain with any dataset to generate rules automatically .It is very urgent for my study .

Respuesta aceptada

Sam Chak
Sam Chak el 27 de Dic. de 2023
Here is a simple example of automatically generating fuzzy rules from data using the FCM clustering method. The data is randomly generated. For more information, you can look up the 'genfis()' command. Please note that this method requires the Fuzzy Logic Toolbox.
Let me know if the proposed approach in the Answer is helpful.
%% Data with 2 inputs and 1 output
inputData = [2*rand(100,1) 3*rand(100,1)-1.5]; % input data
outputData = 5*rand(100,1); % output data
%% Generate fuzzy rules from data using FCM clustering
opt = genfisOptions('FCMClustering', 'FISType', 'mamdani'); % set method & FIS type
opt.NumClusters = 'auto'; % set auto or specify a fixed number of FCM clusters
opt.Verbose = 0;
fis = genfis(inputData, outputData, opt); % generate FIS from the data
showrule(fis)
ans = 9×83 char array
'1. If (in1 is in1cluster1) and (in2 is in2cluster1) then (out1 is out1cluster1) (1)' '2. If (in1 is in1cluster2) and (in2 is in2cluster2) then (out1 is out1cluster2) (1)' '3. If (in1 is in1cluster3) and (in2 is in2cluster3) then (out1 is out1cluster3) (1)' '4. If (in1 is in1cluster4) and (in2 is in2cluster4) then (out1 is out1cluster4) (1)' '5. If (in1 is in1cluster5) and (in2 is in2cluster5) then (out1 is out1cluster5) (1)' '6. If (in1 is in1cluster6) and (in2 is in2cluster6) then (out1 is out1cluster6) (1)' '7. If (in1 is in1cluster7) and (in2 is in2cluster7) then (out1 is out1cluster7) (1)' '8. If (in1 is in1cluster8) and (in2 is in2cluster8) then (out1 is out1cluster8) (1)' '9. If (in1 is in1cluster9) and (in2 is in2cluster9) then (out1 is out1cluster9) (1)'
%% Plot data
figure
scatter3(inputData(:,1), inputData(:,2), outputData), grid on
xlabel("Input 1"), ylabel("Input 2"), zlabel("Output")
%% Plot membership functions
figure
[in1, mf1] = plotmf(fis, 'input', 1);
subplot(3,1,1), plot(in1, mf1), grid on
xlabel('Membership Functions for Input 1'), ylabel('\mu')
[in2, mf2] = plotmf(fis, 'input', 2);
subplot(3,1,2), plot(in2, mf2), grid on
xlabel('Membership Functions for Input 2'), ylabel('\mu')
[out, mf3] = plotmf(fis, 'output', 1);
subplot(3,1,3), plot(out, mf3), grid on
xlabel('Membership Functions for Output'), ylabel('\mu')
  6 comentarios
Mamta
Mamta el 29 de Dic. de 2023
Number of cluster centers of data set will decide the number of rules of fis ?
I have a paper in that dataset =424 ,input=3,output=1, after using fcm on 424 data set they got 27 cluster centers and according to cluster centers they are saying that they have 27 rules.
Please answer this.
Mamta
Mamta el 29 de Dic. de 2023
AddRules — Option for automatically adding rules
"allcombinations" (default) | "none"
Option for automatically adding rules, specified as one of the following:
  • "allcombinations" — If both NumInputs and NumOutputs are greater than zero, create rules with antecedents that contain all input membership function combinations. Each rule consequent contains all the output variables and uses the first membership function of each output.
could you explain above underlined text i copied from above link.
i want to genreate all combination of rules .
i have 9 inputs (low , moderate, high) , one output (very low,low,moderate,high,very high)
how can i genreate all combinations of rules.
please answer also this question .

Iniciar sesión para comentar.

Más respuestas (3)

Sam Chak
Sam Chak el 29 de Dic. de 2023
Your observation is correct. When employing the data clustering method, the fuzzy system (FIS) will have one fuzzy rule for each cluster, and each input and output variable will have one membership function per cluster. In the following example, I have set a fixed number of clusters.
%% Data with 2 inputs and 1 output
inputData = [2*rand(100,1) 3*rand(100,1)-1.5]; % input data
outputData = 5*rand(100,1); % output data
%% Generate fuzzy rules from data using FCM clustering
opt = genfisOptions('FCMClustering', 'FISType', 'mamdani'); % set method & FIS type
opt.NumClusters = 3; % set a fixed number of FCM clusters
opt.Verbose = 0;
myFIS = genfis(inputData, outputData, opt); % generate FIS from the data
showrule(myFIS)
ans = 3×83 char array
'1. If (in1 is in1cluster1) and (in2 is in2cluster1) then (out1 is out1cluster1) (1)' '2. If (in1 is in1cluster2) and (in2 is in2cluster2) then (out1 is out1cluster2) (1)' '3. If (in1 is in1cluster3) and (in2 is in2cluster3) then (out1 is out1cluster3) (1)'
%% Plot membership functions
figure
[in1, mf1] = plotmf(myFIS, 'input', 1);
subplot(3,1,1), plot(in1, mf1), grid on
xlabel('Membership Functions for Input 1'), ylabel('\mu')
[in2, mf2] = plotmf(myFIS, 'input', 2);
subplot(3,1,2), plot(in2, mf2), grid on
xlabel('Membership Functions for Input 2'), ylabel('\mu')
[out, mf3] = plotmf(myFIS, 'output', 1);
subplot(3,1,3), plot(out, mf3), grid on
xlabel('Membership Functions for Output'), ylabel('\mu')
  1 comentario
Mamta
Mamta el 30 de Dic. de 2023
Editada: Mamta el 30 de Dic. de 2023
In this input/output contains numeric data.
can we use string like low, medium, high in input/output dataset.
Please answer this.If yes please explain with example.

Iniciar sesión para comentar.


Sam Chak
Sam Chak el 29 de Dic. de 2023
Hi @Mamta,
Here is the 3rd answer at your request. If you want to generate rules with antecedents that contain all possible combinations of the input membership function, then you must use the Grid Partition method. However, this "non-clustering" method will produce only the Sugeno FIS, which, in my opinion, is more powerful than the classic Mamdani FIS.
Don't forget to vote for other answers as tokens of appreciation for providing explanations and guidance.
%% Data with 2 inputs and 1 output
inputData = [2*rand(100,1) 3*rand(100,1)-1.5]; % input data
outputData = 5*rand(100,1); % output data
%% Generate fuzzy rules from data using FCM clustering
opt = genfisOptions('GridPartition'); % will create Sugeno FIS
opt.NumMembershipFunctions = [3 3]; % specify number of MFs for each input
opt.InputMembershipFunctionType = "gaussmf";
myFIS = genfis(inputData, outputData, opt); % generate Sugeno FIS from the data
showrule(myFIS)
ans = 9×76 char array
'1. If (input1 is in1mf1) and (input2 is in2mf1) then (output is out1mf1) (1)' '2. If (input1 is in1mf1) and (input2 is in2mf2) then (output is out1mf2) (1)' '3. If (input1 is in1mf1) and (input2 is in2mf3) then (output is out1mf3) (1)' '4. If (input1 is in1mf2) and (input2 is in2mf1) then (output is out1mf4) (1)' '5. If (input1 is in1mf2) and (input2 is in2mf2) then (output is out1mf5) (1)' '6. If (input1 is in1mf2) and (input2 is in2mf3) then (output is out1mf6) (1)' '7. If (input1 is in1mf3) and (input2 is in2mf1) then (output is out1mf7) (1)' '8. If (input1 is in1mf3) and (input2 is in2mf2) then (output is out1mf8) (1)' '9. If (input1 is in1mf3) and (input2 is in2mf3) then (output is out1mf9) (1)'
%% Plot membership functions
figure
[in1, mf1] = plotmf(myFIS, 'input', 1);
subplot(2,1,1), plot(in1, mf1), grid on
xlabel('Membership Functions for Input 1'), ylabel('\mu')
[in2, mf2] = plotmf(myFIS, 'input', 2);
subplot(2,1,2), plot(in2, mf2), grid on
xlabel('Membership Functions for Input 2'), ylabel('\mu')

Sam Chak
Sam Chak el 30 de Dic. de 2023
Here is an example to demonstrate how to change the names of the membership functions to 'low,' 'med,' and 'high' for Input 1. Don't forget to vote on the Answer.
%% Data with 2 inputs and 1 output
inputData = [2*rand(50,1) 3*rand(50,1)-1.5]; % input data
outputData = 5*rand(50,1); % output data
%% Generate fuzzy rules from data using FCM clustering
opt = genfisOptions('FCMClustering', 'FISType', 'mamdani'); % set method & FIS type
opt.NumClusters = 3; % set auto or specify a fixed number of FCM clusters
opt.Verbose = 0;
myFIS = genfis(inputData, outputData, opt) % generate FIS from the data
myFIS =
mamfis with properties: Name: "mamdani21" AndMethod: "min" OrMethod: "max" ImplicationMethod: "min" AggregationMethod: "max" DefuzzificationMethod: "centroid" DisableStructuralChecks: 0 Inputs: [1×2 fisvar] Outputs: [1×1 fisvar] Rules: [1×3 fisrule] See 'getTunableSettings' method for parameter optimization.
%% genfis auto-assigned the names of the fuzzy sets as in1cluster1, in1cluster2, in1cluster3
plotmf(myFIS, 'input', 1)
%% Check the names of the fuzzy sets of Input 2
myFIS.Inputs(2).MembershipFunctions
ans =
1×3 fismf array with properties: Type Parameters Name Details: Name Type Parameters _____________ _________ ___________________ 1 "in2cluster1" "gaussmf" 0.52096 -0.18857 2 "in2cluster2" "gaussmf" 0.51323 0.090115 3 "in2cluster3" "gaussmf" 0.51528 -0.32533
%% The names of the fuzzy sets can be renamed using this syntax
myFIS.Inputs(1).MembershipFunctions(1).Name = "low";
myFIS.Inputs(1).MembershipFunctions(2).Name = "med";
myFIS.Inputs(1).MembershipFunctions(3).Name = "high";
plotmf(myFIS, 'input', 1)
  5 comentarios
jahan jahan
jahan jahan el 14 de En. de 2026 a las 10:46
Hi,
how can I make a forecast from an FIS-trained model?
it mean there is a MATLAB command used for prediction from a fuzzy model in MATLAB version 2018?
Thank you in advance
JJ
Sam Chak
Sam Chak el 17 de En. de 2026 a las 4:53
The "Deep Learning Toolbox," "Statistics and Machine Learning Toolbox," and "System Identification Toolbox" all include the predict() command to compute model outputs. In the "Fuzzy Logic Toolbox," the evalfis() command is used to evaluate the .fis file for the input values and return the corresponding output values. This command is capable of more than just returning outputs; it can also provide intermediate results from the fuzzy decision-making process.
However, in the context of data science, the concept of "prediction" strongly implies a comparison between the predicted output and the actual data, particularly during the model development and validation phases. Simply obtaining the model outputs does not effectively indicate the accuracy of the predictions.
If you have an initial FIS and a trained FIS, you can use the comparefis() command to evaluate each FIS and display the simulated output values in a stacked plot. If you wish to compare the fuzzy model output with reference actual output data, you may use the plotfiserr() command. You can also calculate the mean squared error (MSE) between the predicted output vector X and the actual output data vector Y. If you have the "Image Processing Toolbox" installed, you can use the immse(X, Y) command directly.

Iniciar sesión para comentar.

Categorías

Más información sobre Fuzzy Logic in Simulink en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by