Rules formation method using fuzzy c means clustering method.

8 次查看(过去 30 天)
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 .

采纳的回答

Sam Chak
Sam Chak 2023-12-27
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 个评论
Mamta
Mamta 2023-12-29
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 2023-12-29
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 .

请先登录,再进行评论。

更多回答(3 个)

Sam Chak
Sam Chak 2023-12-29
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 个评论
Mamta
Mamta 2023-12-30
编辑:Mamta 2023-12-30
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.

请先登录,再进行评论。


Sam Chak
Sam Chak 2023-12-29
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 2023-12-30
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)
  3 个评论
Mamta
Mamta 2024-1-6
编辑:Mamta 2024-1-6
sir please explain about rules .after clustering got 4 rules and i am very confuse that whole system depends only these 4 rules .
should i enter manually all possible rules in rule base .
Sam Chak
Sam Chak 2024-1-15
The benefit is that FCM allows for flexibility in the number of clusters to be formed, and therefore, rules can be generated for an arbitrary number of clusters. Regarding why it generated 4 rules, it is because the membership values obtained from FCM can be interpreted as the strength of association of a data point with different clusters. Something like "If the input is similar to cluster A, then the output is associated with class A."
The real question is, "Did the FCM produce a fairly accurate fuzzy system with only 4 rules to predict the input-output pair?" If it didn't, the data may exhibit a complex pattern that can be better captured by a varying number of clusters. Therefore, multiple runs with different initializations may be necessary.
If you want to manually enter all possible rules for 9 inputs of three membership functions for each input, then you will have to decide on the outputs of number of rules. How accurate it will be? That's another story.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fuzzy Inference System Modeling 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by