[2]. Fuzzy Clustering and Inference System
[2]. Fuzzy Clustering and Inference System
2
CLUSTERING
• Clustering is grouping data or things.
• In fuzzy logic, clustering is used to define membership functions.
• The figure below to the left shows data clustered into two – red
colored cluster and blue colored cluster.
• The figure below to the right shows membership functions generated
from clusters.
MFy,2
Variable x
MFx,1 MFx,2 MFx,3
16 2 3 13
A= 5 11 10 8
9 7 6 12
4 14 15 1
M= max(A)
M= 16 14 15 13
5
BACKGROUND ON MATLAB FUNCTIONS TO HELP WITH
CLUSTERING
[MATLAB FIND FUNCTION FOR MATRICES]
How the find function works:
• It takes two row vectors in a Boolean equality expression
• Compares corresponding elements in the two vectors.
• If the Boolean expression returns true, it returns and saves that index or
subscript otherwise it skips that index or subscript
• Finally it returns indices that fulfill that criteria
16 2 3 13
A= 5 11 10 8 M= max(A) M= 16 14 15 13
9 7 6 12
4 14 15 1
Variable x
U= C2(X2,Y2,Z2) u21 u22 u23 . . u2n
9
FINDING INDICES OF DATA INSTANCES IN THE
DIFFERENT CLUSTER CENTERS IN MATLAB
Features/attributes/variables
f1 f2 f3 fn
DI11 DI12 DI13 . . DI1n
. . . . . .
DIm1 DIm2 DIm3 . . DImn
Features/attributes/variables
f1 f2 f3 fn
DI11 DI12 DI13 . . DI1n
. . . . . .
DIm1 DIm2 DIm3 . . DImn
13
DATA INSTANCES CLUSTERED AND CLUSTER
CENTERS IN MATLAB
14
CLUSTERING MAPS TO FUZZY MEMBERSHIPS
FUNCTIONS [MFS]
Triangular MFs for Variable y
Variable y Cluster 3
MFy,3 Cluster 1
MFy,1
Cluster 2
MFy,2
Variable x
MFx,1 MFx,2 MFx,3
16
FUZZY INFERENCE SYSTEM [FIS]
• Collect data
• Data instances should have values for input variables and output variables
• Cluster the data to generate membership functions
• K-means clustering
• Fuzzy C-means clustering [Our focus]
• Subtractive clustering
• Rule base
• Is a set of rules that link the input variables to output variables
• Each rule may have a weight associated with it
• The number of rules is dependent on the number of input variables [dimensionality] in the
problem and membership functions for each variable
• Equation: No. of rules = mn [m - # of membership functions; n - # of input variables]
• The curse of dimensionality. Increasing the number of input variables exponentially increases the
number of rules required to model the problem
• The rules combine on all input membership functions between variables and figures out from the data
what the matching output is.
• Output variables are not used to form the rule-base size/conditional structure of the rules
• Inferencing methods
• Mamdani [Outputs a value from defuzzification – COA, LOM, MOM, MOM]
• Sugeno [Outputs a polynomial]
17
FUZZY INFERENCE SYSTEM[S]
• Inference is similar to deduction
• Inference is also similar to reasoning
• This is why is classified under Artificial Intelligence [AI] or Machine Learning
[ML]
• FIS is a type of model that maps inputs to outputs
• In order to qualify as a model, there needs to be a mechanism that maps or
links given inputs to outputs.
• In FIS, that mechanism is referred to as a rule-base
• To be able generate a rule-base, each of the input and output variables are
represented using membership functions.
• These membership functions are permutated between variables [inputs-
inputs; inputs-outputs], to obtain a rule-base.
• A rule-base is complete when it has mn. Where m are the number of
membership functions while n is the number of fuzzy variables.
18
RULE-BASE CREATION FROM DATA
19
FUZZY MEMBERSHIP FUNCTIONS AND RULE-BASE
CREATION
Variable A Variable B Variable C
Membership Degree Membership Degree Membership Degree
Combination between input variable membership functions Structure of rules in the rule-base [mn =32]:
• A is MFA,1 is combined with each MF in B: Maps/combines Input Variable MFs
• B is MFB,1 1. A is MFA,1 and B is MFB,1 then C is ?
• B is MFB,2 ▪ Formulate the rule
2. A is MFA,1 and B is MFB,2 then C is ?
• B is MFB,3 structure:
o Condition part complete 3. A is MFA,1 and B is MFB,3 then C is ?
• A is MFA,2 is combined with each MF in B: 4. A is MFA,2 and B is MFB,1 then C is ?
o # of rules is complete
• B is MFB,1 5. A is MFA,2 and B is MFB,2 then C is ?
• B is MFB,2 6. A is MFA,2 and B is MFB,3 then C is ?
• B is MFB,3 7. A is MFA,3 and B is MFB,1 then C is ?
• A is MFA,3 is combined with each MF in B: 8. A is MFA,3 and B is MFB,2 then C is ?
• B is MFB,1 9. A is MFA,3 and B is MFB,3 then C is ?
• B is MFB,2
20
• B is MFB,3
FUZZY MEMBERSHIP FUNCTIONS AND RULE-BASE
Membership Membership Membership
Degree Degree Degree
22
USING AN FIS: LINGUISTIC INPUT VALUES INTO FIS
Membership Membership Membership
Degree Degree Degree
25
RULE FIRING: NUMERIC INPUT VALUES INTO FIS
Membership Membership Membership
Degree Degree Degree
µA,1 µB,3 µR
15 20 30 Temperature 30 50 80 Humidity Productivity
• [W1]: A is MFA,1 and B is MFB,1 then C is MFC,1
• [W2]: A is MFA,1 and B is MFB,2 then C is MFC,2 [Resulting membership, µR=max(µA,1, µB,2). It truncates the 2nd MF shape, MFc,2]
• [W3]: A is MFA,1 and B is MFB,3 then C is MFC,3 [Resulting membership, µR=max(µA,1, µB,3). It truncates the 3rd MF shape, MFc,3]
• [W4]: A is MFA,2 and B is MFB,1 then C is MFC,1
• [W5]: A is MFA,2 and B is MFB,2 then C is MFC,2
• [W6]: A is MFA,2 and B is MFB,3 then C is MFC,3
• [W7]: A is MFA,3 and B is MFB,1 then C is MFC,1
• [W8]: A is MFA,3 and B is MFB,2 then C is MFC,2
• [W9]: A is MFA,3 and B is MFB,3 then C is MFC,3
27
RULE FIRING: NUMERIC INPUT Membership
VALUES INTO
Degree
FIS
Membership Degree Membership Degree
30
CREATING THE FIS OPTIONS OBJECT
[genfisOptions]
31
FCM CLUSTERING OPTIONS [FCMClustering]
32
SUBTRACTIVE CLUSTERING OPTIONS [SubtractiveClustering]
33
GRID PARTITIONING CLUSTERING OPTIONS [GridPartition]
34
MODELING FIS IN MATLAB – CREATE THE INPUT &
OUTPUT DATA & GENFISOPTIONS
35
MODELING FIS IN MATLAB – CREATING FIS
[PREDICTIVE MODEL] AND SHOWING RULES
36
MODELING FIS IN MATLAB – PLOT THE
MEMBERSHIP FUNCTIONS FROM FIS
• Subplot function is used to plot multiple
graphs close to each other
• It has three input parameters in its
method.
• The first two specify the dimension of
matrix space reserved to plot the
graphs. It uses the roman-catholic/row-
column convention
• The last input specifies the position or
cell in the matrix where the plot is to be
inserted
• Example: subplot(2,1,1) would mean we
have two rows and one column reserved
for plotting graphs and we are going to
insert our graph in the first position or
cell in that reserved space
37
THE END
38