FCM - The Fuzzy C-Means Clustering Algorithm
FCM - The Fuzzy C-Means Clustering Algorithm
Key Words: Cluster analysis, Cluster validity, Fuzzy clustering, Fuzzy QMODEL, Least-squared errors.
INTRODUCTION
In general, cluster analysis refers to a broad spectrum
of methods which try to subdivide a data set X into
c subsets (clusters) which are pairwise disjoint, all
nonempty, and reproduce X. via union. The clusters
then are termed a hard (i.e., nonfuzzy) c-partition of
X. Many algorithms, each with its own mathematical
clustering criterion for identifying "optimal" clusters,
are discussed in the excellent monograph of Duda
and Hart (1973). A significant fact about this type of
algorithm is the defect in the underlying axiomatic
model that each point in X is unequivocally grouped
with other members of "its" cluster, and thus bears
no apparent similarity to other members of X. One
such manner to characterize an individual point's
similarity to all the clusters was introduced in 1965
by Zadeh (1965). The key to Zadeh's idea is to
represent the similarity a point shares with each
cluster with a function (termed the membership
function) whose values (called memberships) are between zero and one. Each sample will have a membership in every cluster, memberships close to unity
signify a high degree of similarity between the sample
and a cluster while memberships close to zero imply
little similarity between the sample and that cluster.
The history, philosophy, and derivation of such
mathematical systems are documented in Bezdek
(1981). The net effect of such a function for clustering
is to produce fuzzy c-partitions of a given data set. A
fuzzy c-partition of X is one which characterizes the
membership of each sample point in all the clusters
by a membership function which ranges between
zero and one. Additionally, the sum of the memberships for each sample point must be unity.
Let Y = {Yl, Y2. . . . .
y~} be a sample of N
observations in R n (n-dimensional Euclidean space);
Yk is the k-th feature vector; Ykj the j-th feature of Yk.
If C is an integer, 2 ~< c < n, a conventional (or
"hard") c-partition of Y is a c-tuple (YI, Y2 . . . . . Yc)
of subsets of Y that satisfies three conditions:
Y~=~'
1 <i~<c;
(la)
(lb)
U Y, : Y
(lc)
i=l
192
(3a)
FUZZY CLUSTERING
1; yk E Y~ l
Ui(Yk)-~ Rik =
O;
otherwise)
(2a)
U~k>O
for a l l i ;
(2b)
U~k = 1
for all k.
(2c)
i=1
N
i=1
193
(4)
i=l
c = n u m b e r of clusters in Y;
m = weighting exponent;
1 ~< m < 0%
(5b)
(5c)
U E Mfc
(5d)
U = fuzzy c-partition of Y;
v = (v~, v2 . . . . .
2 ~< c < n,
(5a)
(5e)
(5f)
(5g)
(5h)
(9a)
cy = Z ykIN;
k=l
N
d2k = IlYk --
o, ll~ = (yk -
v O r h ( Y k - v~).
(6)
(9b)
k~1
The weight attached to each squared error is ( u a ) " ,
the mth power of ykS membership in cluster i. The
vectors {v~} in equation (5f) are viewed as "cluster
centers" or centers of mass of the partitioning subsets.
If m = 1, it can be shown that Jm minimizes only at
hard U's E M~, and corresponding v~s are just the
geometric centroids of the Iris. With these observations, we can decompose J~ into its basic elements
to see what property of the points {Yk} it measures:
d~=
m
(ua) d i k -
i=1
k=l
i=1
--
m2
(Uik) dik = sum of squared A-errors due to yks
partial replacement by all c of the
centers {vi}.
(7c)
,~2
(ua) dik = overall weighted sum of generalized
A-errors due to replacing Y by v.
(7d)
(10a)
(10b)
A = C ; ~ ~ Mahalonobis Norm.
(10c)
l < ~ i < ~ c;
(1 la)
k=l
'.
]
(lib)
194
F u z z y c-Means ( F C M ) Algorithms
(A1)
(A)
LMAX.
(A3)
(A4)
Fc((/) = ~ ~ (~ik)2/N;
k=l
(12a)
iffil
N
(12b)
(13a)
(13b)
1
~
Fc <~ 1;
NS = number of vectors in Y = N.
ND = number of features in Yk = n.
Present dimensions will accomodate up to c = 20
clusters, N = 500 data points, and n = 20 features.
Input variables ICON specifies the weight matrix A
as in equation (10):
ICON= I~A
=I
ICON=2~A=D;
ICON = 3 ~ A
I.
C~-I .
kffil iffil
H~(O) = - ~ ~ (t~ikIoga(a~k))/N.
ALGORITHMIC PROTOCOLS
<~Hc <~log~(c).
(13c)
Control Parameters
EPS = Termination criterion E in (A4).
LMAX = Maximum number iterations at each c in
(A1).
Current values of EPS and LMAX are 0.01 and 50.
Lowering EPS almost always results in more iterations
to termination.
Input Y
Compute Feature Means. Vector FM(ND) is the
mean vector cy of equation (9a).
Compute Scaling Matrix. Matrix CC(ND, ND) is
matrix A of equation (10), depending upon the choice
made for ICON. The inverse is constructed in the
main to avoid dependence upon peripheral subs.
Matrix CM --- A*A -I calculated as a check on the
computed inverse, but no residual is calculated; nor
does the FCM routine contain a flag if CM is not
"close" to L The construction of weight matrices
other than the three choices allowed depends on user
definition.
Loop Control. NCLUS = c is the current number
of clusters: QQ is the weighting exponent m.
Initial Guess. A pseudo-random initial guess for
U0 is generated in this block at each access.
Cluster Centers. Calculation of current centers
V(NC, ND) via equation (1 la).
Update Memberships. Calculations with equation
(1 lb); W(NC, ND) is the updated membership matrix.
The special situation m = 1 is not accounted for
here. Many programs are available for this situation
for example see Ball (1965). The authors will furnish
a listing for hard c-means upon request. Note that
this block does not have a transfer in situation Yk
= ~ for some k and i. This eventuality to our
knowledge, has never occurred in nearly 10 years of
computing experience. If a check and assignment are
desired, the method for assigning t~/s in any column
k where such a singularity occurs is arbitrary, as long
as constraints in equation (2) are satisfied. For example, one may, in this instance, place equal weights
(that sum to one) on every row where Yk = V~, and
zero weights otherwise. This will continue the algorithm, and roundoff error alone should carry the
sequence away from such points.
Error Criteria and Cutoffs. The criterion used to
terminate iteration at fixed NC is
ERRMAX = max{l~ k+l) -
a~fl} <
EPS.
vV ~
/.-,, ,/,." ,,
1
LoCke
(14)
Coordinates
No.
i,k
195
I0
II
12
13
14
15
16
Ykl
Yk2
0
0
1
2
3
2
2
1
4
3
5
4
3
2
1
0
5
6
7
5
7
6
6
8
5
5
6
3
3
2
l
]
196
NCLUS=c
QQ=rn
EPS=E
1, 2, 3
0.01
2
3
2
t
2
2-6
1.25, 2.00
1.25-2.00
0.01
0.01
i = 1,2 . . . . .
(Uo)u = ( c +/~);
j=c+l
.....
(Uo)0 = ( c +/3);
otherwise
c
n
a = 1 - (q~/2);
/3 --- q~12.
The starting value for Fc using this Uo is always the
midpoint of [l/c, 1), the range of Fc, that is f~(Uo)
= ((1/c) + 1)/2. In real applications it is, of course,
important to run FCM for several different Uos, as
the iteration method used, like all descent methods,
is susceptible to local stagnations. If different Uos
result in different (0, fi)s, one thing is certain: further
analysis should be made before one places much
confidence in any algorithmicaUy suggested substructure in Y.
Table l shows that maximizing Fc is equivalent to
minimizing/arc but this behavior is not equivalent to
minimizing Jm- Several examples of the general dilemma are documented in Bezdek (1981). Observe
that all three partitions of Y are (qualitatively) more
or less equivalent. Lower membership generally cor-
Table 1. Variation in ((7, b) due to changes in Norm. There are only two clusters, hence 02k = (1 -- O,k)
as the sum of the tickequals one. Terminal membership U~k
ICON = I
A=I
ICON = 2
A= DyI
ICON = 3
A= Cyl
0.92
0.95
0.86
0.91
0.80
0.95
0.86
0.82
0.88
0.93
O. 78
0.88
0.84
0,88
0.72
0,67
0.89
0.92
0.82
0.93
0.84
0.82
0.~5
0.62
9
I0
II
12
13
14
15
16
0.22
0.12
0.18
O.lO
0.02
0.06
0.16
0.15
0,35
0,26
0,32
0,08
0,03
0,09
0,24
0.21
0.43
0.33
0.37
0.09
0.04
0.06
0.19
0.19
'~'11
6.18
5,99
5.96
3.15
2,95
2.75
I'.44
1,67
1,73
2.83
3,01
3,19
0.80
0.71
0.71
Data
Point
912
~22
F
c
H
c
J
0.35
0.45
0.45
51.65
13.69
13.69
Iter.
]2
197
Table 2. Variation in (t~, ~) due to changes in m (two cluster example). Terminal membership Uik: U2k
=
Data
Point
(1
~,k)
QQ = m = 1.25
QQ = m = 2.00
1.00
1.00
l. O0
1.00
l. O0
l.O0
1.00
1.00
0.92
0.95
O. 86
0.9l
O.80
0.95
0.86
0.82
9
lO
II
12
13
14
15
16
0.00
0.00
0.00
O.O0
0.00
0.00
0.00
0.00
0.22
O. 12
0.18
O. lO
0.02
0.06
0.16
0.15
ql l
~12
6.25
6.18
3.25
3.15
"~21
1.37
1.44
~22
2.75
2.83
l.O0
0.80
F
c
H
c
Jm
Iter.
0.00
0.35
60.35
51.65
Number o f
Partition
Exponent
Clusters
Coefficient
Lower
Normalized
Bound
Entropy
(m)
(c)
(Fc)
(1-r c)
(Hc)
1.25
2
3
4
5
0.998
0.983
0.979
0.996
0.002
0.017
0.021
0.004
0.007
0.037
0.044
0.013
]. 50
2
3
4
5
0.955
0.903
0.901
0.917
0.Q45
0.097
0.099
0.083
0,I03
0.202
0.201
0.197
1.75
2
3
4
5
0.873
0.791
0.804
0.776
0.127
0.209
0.196
0.224
0.239
0.404
0.401
0.468
2.00
2
3
4
5
O. 794
0.686
O.700
O.662
O.206
0.314
O.300
O. 338
O.352
0.575
O.600
O.701
198
APPENDIX
KMEANS
FORTRAN
A 03/18183
11:05
oooclooo
00002000
000C3000
00004000
00005000
00006000
REFERENCE: "PATTERN RECOGNITION WITH FUZZY OBJECTIVE FUNCTIONSt i'
00007000
00008000
00009000
OOO10000
DESCRIPTION OF OPERATING VARIABLES:
00011000
I . INPUT VARIABLES |FROM FILE 51
00012000
C A R D I:
00013000
TITLE{20] . . . . . . . .
80 CHARACTER HEADING
00014000
C A R D 2:
00015000
FMT(20) . . . . . . . . . .
FORTRAN FORMAT {CONTAINED IN PARENTHESIS)
00016000
DESCRIBING THE INPUT FCRMAT FOR THE RAW DATAOO01?O00
UP TC 80 CHARACTERS MAY BE USED
00018000
CARD 3:
00019000
COL I : ICON. . . . . . DISTANCE MEASURE TO ,BE USED. I F : ~
00020000
ICON=I USE EUCLIDEAN NORM
00021000
ICON=2 USE DIAGONAL NORM
00022000
ICON=3 USE MAHALANOBIS "NORM
00023000
COLS 2 - 7 : QO. . . . . WEIGHTING EXPONENT FOR FCM
00024000
COLS B - g : ND. . . . . NUMBER OF FEATURES PER INPUT VECTOR
00025000
JAMES BEZDEK~ PLENUM, NEW YORK, 1981.
199
IT.
FILE:
KMEANS
12321
C
C
.
FCRTRAN
A 03/18183
11:05
00057000
00058000
00059000
00060000
00061000
00062000
00063000
00064000
00065000
00066000
00067000
00068300
CONTROL PARAMETERS.
.
00069000
00070000
00071000
00072000
00073000
EP S= . Ol
NS=I
LMAX=50
C
C
C2021
410
1459
I
399
12738
lllll
C
C
C
C
00026000
00027000
00028000
00029000
00030000
00031000
00032000
00033000
00034000
00335000
00036000
00037000
00038000
00339000
00040000
00041300
00042000
00043000
00044000
00045000
00046000
00047000
00048000
00049000
00050000
00051000
00052000
00053000
000 540 O0
00055000
DIMENSIGN F M ( 5 O I , F V A R ( 5 0 ) , F ( 2 0 )
DIMENSION B B ( 5 0 ) , C C C ( 5 0 ) , H ( 2 0 ) , D I F ( 2 0 ) , I T T ( 2 0 )
DIMENSION Y ( 5 0 0 , 2 ) , U ( 2 0 , 5 0 0 1 , W ( 2 0 , 5 0 0 )
DIMENSICN A A ( 5 0 , 5 0 ) , A I ( 5 0 , 5 0 )
DIMENSION C C ( 5 0 , 5 0 ) , C M ( 5 0 , 5 0 ) , S T ( 5 0 , 5 0 }
DIMENSION V ( 2 0 , 5 0 ) , V J M ( 2 0 )
DIMENSION F M T ( 2 0 ) , T I T L E ( 2 0 }
READ(5,1458)
(TITLE(1),I=I,20)
FORMAT(2OA4)
READ(5,12321) ( F M T ( 1 ) , I = I , 2 0 )
FORMAT(2OA4)
1458
C.
00074000
READ FEATURE VECTORS ( Y ( I , J ) ) .
REAO{5,202I) ICON,QQ,ND,KBEGIN,KCEASE
FORMAT(I1,F6.3,312)
WRITE(6,410)
FORMAT(///IH , ' * * *
* * * BEGIN FUZZY C-MEANS OUTPUT * * *
WRITE(6,1459) ( T I T L E ( I I I ) , I I I = I , 2 0 )
FORMAT(IOX,2OA4///)
READ(5,399,END=3)IY(NS,J),J=I,ND)
FORMAT ( 2 F 1 . 0 )
WRITE(6,I2738I(Y(NS,J),J=I,ND)
FORMAT(2(IOX,IO(F7.2,1X)/))
NS=NS+I
GO TO 1
NS=NS-I
NDIM=ND
NSAMP=NS
WRITE(6,I[III)
NSAMP
FORMAT(10X,'NUMBER
OF S A M P L E S = ',I5)
ANSAMP=NSAMP
***')
00075000
00076000
00077000
000?8000
O0079000
00080000
00081000
00082000
00083000
00084000
00085000
0008600O
00087000
00088000
00089000
00090000
00091000
00092000
00093000
00094000
00095000
000$60C0
00097000
00098000
00099000
200
OOIO0000
001CI000
OOIG2000
O0 350 I=I,NOIM
FM(I)=O.
35I
350
C .....
C
C. . . . . .
DO 35t J=I,NSAMP
FM(II=FM(II+YIJ,II
OOtC3000
00104000
00105000
001060G0
00107000
FMII)=FM(II/ANSAMP
FEATURE
VARIANCES.
O0 352 I=[,NOIM
001C8000
00109000
00110000
FVAR(II=O.
00 353 J=I,NSAMP
FILE:
KMEANS
353
352
FVAR{II=FVAR{If'+((Y(J,I)-FM(II)**2)
FVARII)=FVAR(II/ANSAMP
IF(ICON-I)380,38C,382
DO 381 I = I t N O I M
DO 3 8 1 J = I , N D I M
CC(I,J):O.
00 370 I = I , N D I M
CC(I,I}=I.
GO TO 390
IF(ICON-2|384,384,386
DO 385 I : I , N D I M
00 385 J = I , N D I M
CC(I,J)=O.
00 371 I=I,NOIM
CC(I,I)=I./FM(1)
GO TO BgO
00 360 I=I,NDIM
DO 360 J=I,NDIM
AA{I,JI=O.
DO 361 K = I , N S A M P
A A I I , J ) = A A ( I , J I + ( ( Y ( K , I | - F M ( 1 ) ) ~ ( Y ( KJ
, I-FM(J)}}
AA(I,J)=AA(I,JI/ANSAMP
DO 550 [ = I , N D I M
DO 550 J = I , N O I M
ST(I,J)=AA(I,J)
380
381
370
382
384
385
371
386
361
360
FORTRAN A 0 3 / 1 8 / 8 3
11:05
550
C
C
INVERSIONOF COVARIANCE MATPIX AA TO AI
C. . . . . . . . . . . . . . . .
NN=NDIM-I
AA(I,II=I./AA(t,tl
DO 500 M=I,NN
K=M+I
00 501 I=I,M
BBII)=O.
DO 501 J=t,M
501
BB(II=8B(I)*AA(I,JI~AA(J,K)
0=0.
DO 502 I = I , M
502
D=D+AA(K,I )~BB(I)
O=-D+AA(K,K)
AA(K,K)=I./D
DO 503 I = t , M
503
AA(I,K):-BB(II*AA(K,K)
00 504 J = t , M
CCC(J)=O.
DO 504 I = t , M
506
CCC(JI=CCC(JIAA(K,I|*AA(I,JI
00 505 J = I , M
505
AA(K,JI=-CCC(J)~AA(K,K)
00 500 I = I , M
00 500 J = I , M
500
AA(I,JI:AA(I,JI-BB(II~AA(K,J)"
00 520 I=t,NOIM
00 520 J = I , N O I M
520
AI(I,JI=AA(I,JI
F I L E : KMEANS
FORTRAN A 03118183
00 387 I = I , N O I M
DO 387 J = I , N D I M
11:05
O01ltDOO
00112000
00113000
001140C0
00115000
00116300
00117000
00118000
00119000
00120300
00121000
00122000
00123000
00124000
00125000
00126000
00127000
00128000
00129000
00130000
00131000
00132000
001330C0
00134000
00135000
00136000
00137000
00138000
00139000
00140000
00141000
00142000
00143000
00144000
00145000
00146000
00147000
00148000
00149000
00150000
00151000
001520C0
00153000
00154060
00155000
00156000
00157000
00158000
00159000
00160000
00161000
00162000
00163000
00164000
00165030
00166000
00167000
201
C
C
499
C
C
C
C
C
C
C.
llOI
1100
FILE: KMEANS
C
C
C
7000
21
20
C
C
C. . . . .
611I
ICON = ' , 1 3 , 5 X ,
DO 38 I = I , N C L U S
DO 38 J = I , N S A M P
WI I , J } = O .
A=O.
DO 3 1 L = I , N O I M
DO 3I M=I,NDIM
OOt 6 8 0 0 0
001 6 9 0 0 0
001 7 0 0 0 2
001 7 1 0 0 0
001 72000
001 7 3 0 0 3
001 7 4 0 0 0
OOI 7 5 0 0 0
001 7 c 0 0 0
001 7 7 0 0 0
OOt 78000
001 7 9 0 0 0
OOI 8 0 0 0 0
00181000
00182000
00183300
00184000
00185000
001860C0
00187000
00188000
00189000
00190000
00191300
00192000
0013000
00194000
00155000
00196000
00157000
00198000
00199000
00200000
00201000
00202000
00203000
00204000
00205000
00206000
.00257000
.
.
.
00208000
00209003
002 10000
00211000
002 12000
00213000
00214000
00215000
00216000
00217000
00218000
00219000
00220000
00221000
00222000
00223000
00224000
00225000
00226000
00227000
00228000
00229000
00230000
00231000
00232000
00233000
00234000
00235000
00236000
00237000
00238000
00239000
00240000
202
31
33
32
38
C
C
C
9000
40
400
42
43
C
C
C .....
6000
FILE:
IOl
IO0
ITTINCLUS)=IT
F(NCLUS)=O.O
KMEANS
FORTRAN A 0 3 1 1 8 / 8 3
11:05
00241000
00242000
00243000
00244000
00245000
00246000
00247000
00248000
00249000
00250000
00251000
00252000
00253000
00254000
00255000
00256000
00257000
00258000
00259000
00260000
00261000
00282000
00263000
00264000
00265000
00266000
00267000
00268000
00269000
00270000
00271000
00272000
00273000
00274000
00275000
HINCLUS)=O.O
DO TO0 I=ItNCLUS
00 tO0 K=I,NSAMP
AU=U(I,K)
F(NCLUSI=F(NCLUS)AU**2/ANSAMP
IF ( A U I l O O , l O 0 , l O l
H(NCLUS)=H(NCLUSI-AU*ALOG(~UI/ANSAMP
CONTINUE
DIF(NCLUSI=I.0-F(NCLUS!
C. . . . . . . .
C
CALCULATION OF OBJECTIVE FUhCTION
C. . . . . . . . .
A=O.
DO BO I = I , N C L L S
00 80 J = I , N S A M P
OIST=O.
DO 8 1 L = , N D I M
DO 8 M=I,NDIM
81
OIST=OISTI(YIJtL)-V(I,LII*CC(L,MI*(Y(J,M|-V|I,M)II
A=A+(IUII,J)**QQ)*DIST)
80
VJM(NCLUS)=A
C.........
C
OUTPUT BLOCK FOR CURRENT NCLUS
C
WRITE(6,40I)
~Ol
FORNAT(' ,1//.
FSTOP.,TX,eI-FSTOpo,5X,.ENTROpyet5X,ipAYOFFe,SX,/)
WRITE(6,699)
F(NCLUSItOIF(hCLUS)tH|NCLUS)tVJM(NCLUS|
699
FORMATIIH ,2|F6.3,4XI,4X,FE.3,5X,E8.3|
WRITE(6t591
59
FORMATilXtlOO(*-e)//I
WRITEI6t402)
402
FORMAT(II/t15X,~CLUSTER
CENTERS V I I , J ) * , l / l ~ .
DO 4 1 5 I = I , N C L U S
415
WRITE{6,404|
(I,J,V(I,J)tJ=ItNOINI
~0~
FORMAT(* I = ' , I 3 t 3 X ~ ' J = i , 1 3 , 3 X , ' V I I , J ) = ' p J F 8 . 4 )
405
FORMAT(IH t T ( F 6 . 4 , 3 X ) )
WR17E{6,59)
WRITE|6,406)
00276000
00277000
00278000
00279000
00280000
00281000
00282000
00283000
00284000
00285000
00286000
00287000
00288000
00289000
00290000
002~I000
00292000
002~3000
00294000
00295000
00296000
00297000
00298000
00299000
O03000 O0
00301000
003G2000
00303000
003 G4000
00305000
003C6000
00307000
003C8000
00309000
00310000
00311000
00312000
0 0 3 13000
The ~zzyc-meansclustefingalgofithm
406
FILE: KMEANS
FORTRAN
A 03118/8Z 11:05
203
00314000
00315000
00316000
00317000
00318000
00319000
00320000
00321000
00322000
00323000
00324000
00325000
00326000
0032?000
00328000
00329000
00330000
00331000
WRITE(6,464| ICON
00332000
FORMAT{IHO,'NORM THIS RUN ICCN = ' ~ I i )
00333000
WRITE(6,465) OQ
00334000
465
FORMAt(I~O,'WEIGHTINGEXPONENT M = . ' , F 4 . 2 I
00335000
I F ( I T . L E . 4 9 ) GO TO 4 7 6
00336000
WRITE(6,70107)
?0107 FORMAT(' ','CONVERGENCE FLAG: UNABLE TO ACHIEVE SATISFACTORY CLUSTO03 3 7 0 0 0
00338000
IERS AFTER 50 ITERATIONS.')
00339000
476
WRITE{6,466)
00340000
466
FORMAT(' ' / I '
NO. OF CLUSTERS',3X,'PART. COEFF.',SX,
00341000
C'LOWER 80UND',SX,'ENTROPY',5X,'NUMBER OF ITERATIONS')
00342000
WRITE(6,467I
00343000
467
FORMAT(IHO,6X,'C',I7X,'F',I5X,'I-F',I2X,'H',IOXw'IT')
00344000
O0 4 6 8 J=KBEGIN,KCEASE
00345000
468
WRITE(6,4691 J , F ( J ) , D I F ( J ) , F ( J I , I T T ( J )
00346000
469
FORMAT(IH , 6 X , I 2 , 1 4 X , F 6 . 3 , 1 1 X , F 6 . 3 , T X , F 6 . 3 , B X , 1 4 )
00347000
55556 C O N T I N U E
00348000
616
WRITE(6,411)
00349000
411
FORMAT(////IH , ' * * * * ~ NORMAL END OF JOB ~ * ~ * ~ ' )
00350000
STOP
00351000
END
464