Vous êtes sur la page 1sur 15

Fuzzy Control HW2

Fuzzy C-Mean Clustering

Professor
Student
Student ID

: Wen-June Wang
: Wahyu Rahmaniar
: 102521604

Do the Exercise (1) if your student number is odd (except 5), Do the Exercise (2) if
your student number is even (except 0); Do the Exercise (3) if your student number is 0
or 5.
Exercise (1). Please classify 100 points in (a, b) space to 6 clusters, where the 100
points are generated from random Generator in Matlab and -30<a<30, 0<b<30.
Exercise (2). Please classify 100 points in (a, b) space to 5 clusters, where the 100
points are generated from random Generator in Matlab and -20<a<10, -15<b<20.
Exercise (3). Please classify 100 points in (a, b) space to 4 clusters, where the 100
points are generated from random Generator in Matlab and 10<a<20, 10<b<40.
Your report should contain the program, and statements explanation, a figure with 100
points, and a figure with clusters and 100 points. Furthermore, a discussion and a
conclusion.

(1) Problem description


Use classification "fuzzy C-mean clustering" to process data points, first with
MATLAB randomly generated 100 points and set the starting random attribution of the
Uo. Uo calculated by the center of gravity of each cluster point vi (equation 1), then Uo
order to update the membership degree for each data point (equation 2), compare the
new data corresponding with Uo to determine whether the program needs to continue to
update the membership degree , and calculate the cost function (equation 3). The
equation as follows:

1.Center of gravity : vi

(
k 1

(
k 1

2.Update of membership :

) xk

( p) m
ik

ik

ik( p 1)

c xk vi( p ) m21
(
)
( p)
j 1 xk v j

3. Cost function =

,1 i c

( p) m

J m (U ,V ) ( ik ) m xk vi

k 1 i 1

Algorithm of Fuzzy C-mean Clustering:


1. Initialize U=[uij] matrix, U(0)
2. At k-step: calculate the centers vectors C(k)=[cj] with U(k) (eq.1)
3. Update U(k) , U(k+1) (eq.2)
4. If objective function (eq.3) || U(k+1) - U(k)||< error rate then STOP; otherwise
return to step 2.

(2) 100 data points and their plot locations in the X-Y space
Table 1. Initial Point of 100 Randomly Generated
n-points

0
10
20
30
40
50
60
70
80
90

x
y
x
y
x
y
x
y
x
y
x
y
x
y
x
y
x
y
x
y

1+n

2+n

3+n

4+n

5+n

6+n

7+n

8+n

9+n

10+n

-11.107

-7.591

-5.607

-19.568

7.1623

1.2108

5.506

-14.957

3.308

2.503

5.949

-13.048

-8.047

-12.387

7.0693

13.476

18.585

3.1903

15.257

2.0514

-15.978

-12.689

-9.0718

-17.106

4.962

-11.718

-2.174

6.4787

-6.717

9.008

3.933

8.874

-5.1907

-4.0398

19.0057

3.609

-4.165

0.3103

12.644

-7.691

-16.154

-1.937

-7.554

-1.264

-1.9009

7.952

-3.657

-14.9202

-9.0163

7.579

-12.153

12.134

2.439

6.8405

-9.3511

-1.0107

3.4788

5.768

-2.783

-11.848

-10.061

6.833

1.877

5.196

-11.538

4.384

-11.736

-9.111

-0.0468

-6.517

0.105

-1.4995

7.7006

-7.826

-6.4293

16.632

18.3062

-12.602

3.945

8.086

-3.7705

7.578

-15.281

-4.529

-3.829

-1.412

-7.0045

-19.1602

-15.586

1.277

-12.587

-10.756

-2.033

-5.4801

-0.0042

19.7513

-4.858

-12.6605

-0.413

7.446

-6.4116

-10.223

-6.663

-0.5503

-3.9607

-18.998

-12.115

-18.263

-15.654

9.098

-12.969

0.767

19.372

6.513

-1.5095

14.366

13.838

-13.457

-6.429

4.7709

-7.199

-1.341

7.572

-2.457

7.097

-10.903

-19.224

9.752

-3.012

0.201

-5.201

-12.37

-0.625

-2.927

6.143

12.304

-10.185

-10.513

11.393

8.984

-12.374

-12.017

1.784

5.0309

-18.456

-3.126

-15.612

6.553

2.907

-4.687

14.595

-7.0711

-3.308

-14.338

-4.237

-8.197

8.504

-7.662

19.165

12.057

-3.518

-15.969

-2.368

-10.138

7.978

-10.7019

5.974

-8.698

-9.231

0.5403

18.932

19.9508

12.211

-4.305

1.153

-3.392

-10.829

-9.778

-2.289

4.409

4.525

-10.342

-16.71

-1.7604

-1.5128

-3.3896

-3.0693

-5.9102

-10.901

-3.689

1.113

-9.5604

4.804

-14.495

-4.368

4.2602

-1.365

-7.308

-13.496

-1.466

Fig 1. The initial of 100 data points randomly generated


4

(3) Initial and Final Clustering matrices U


Table 2. Random Generated of Initial Uo
n-points c 1+n 2+n 3+n 4+n
1 0.4521 0.0744 0.1256 0.045
2 0.08
0

0.2813

5+n

6+n

7+n

8+n

9+n 10+n

0.0309

0.0124

0.0863

0.0107

0.033

0.0277

0.1515

0.0438

0.8978

0.0216

0.7806

0.1222

0.0454

0.928

3 0.0062 0.06

0.1561

0.0997

0.0019

0.9503

0.018

0.0365

0.0366

0.0271

4 0.436

0.2447

0.7965

0.0256

0.0098

0.0157

0.8092

0.0167

0.0162

5 0.0257 0.4582 0.322

0.015

0.0438

0.0059

0.0995

0.0215

0.8683

0.001

1 0.2343 0.0128 0.004

0.0317

0.5036

0.0068

0.2926

0.0006

0.0273

0.0963

0.1262

2 0.1382 0.0712 0.1233 0.0112 0.0079 0.1233 0.0336 0.2774 0.0241 0.387
10

3 0.0218 0.1841 0.8165 0.0264 0.1618 0.0228 0.376

0.0185

0.8767

0.1225

4 0.6038 0.0673 0.002

0.8934

0.0119

0.1977

0.0045

0.6437

0.0429

0.1856

5 0.002

0.6646

0.0541

0.0373

0.3149

0.6493

0.2933

0.0599

0.0289

0.2085

1 0.916

0.1472

0.1562

0.8067

0.7031

0.0264

0.8298

0.5186

0.3999

0.0185

2 0.0245 0.0053 0.0254 0.0374 0.1197 0.7663 0.0011 0.0094 0.1467 0.4239
20

3 0.0018 0.0347 0.44

0.0173

0.0083

0.0198

0.0115

0.0008

0.1827

0.027

4 0.0568 0.071

0.1294

0.055

0.0163

0.0071

0.4223

0.196

0.2385

0.3345

5 0.0009 0.7418 0.0438 0.0091 0.1139 0.1712 0.1505 0.0488 0.0748 0.2922

30

1 0.0791 0.0881 0.0106 0.0024 0.001

0.091

0.5034

0.4738

0.8078

0.0039

2 0.1709 0.0355 0.023

0.0012

0.0278

0.3271

0.026

0.0034

0.1195

3 0.0059 0.1729 0.0405 0.005

0.0003

0.5898

0.0101

0.0154

0.0116

0.0003

4 0.7355 0.2037 0.0703 0.017

0.0259

0.0829

0.4772

0.0015

0.8587

0.0017

5 0.0085 0.4997 0.8556 0.9738 0.9975 0.2655 0.0764 0.0076 0.1758 0.0177
1 0.0276 0.0276 0.0915 0.0133 0.7433 0.081
40

0.028

0.0046

0.5791

0.0181

2 0.0232 0.1638 0.2517 0.0018 0.1322 0.2181 0.003

0.8112

0.2861

0.0191

3 0.9196 0.6055 0.0107 0.0037 0.0677 0.1947 0.7678 0.0414 0.1092 0.9326
4 0.0181 0.083

50

0.0278

0.0062

0.1952

0.0105

0.0061

0.0241

5 0.0115 0.1201 0.0674 0.003

0.029

0.5

0.006

0.1322

0.0195

0.0061

1 0.055

0.0016

0.9443

0.7434

0.4691

0.0264

0.1423

2 0.2214 0.6683 0.1699 0.1062 0.6981 0.0001 0.002

0.1722

0.0215

0.4105

3 0.1176 0.0109 0.1899 0.0133 0.0028 0

0.0229

0.0205

0.2596

0.0447

4 0.1953 0.01

0.2984

0.5787

0.1548

0.0394

0.4207

0.0143

0.0057

0.0029

0.1306

0.581

0.229

0.4455

0.2918

0.0556

0.2288

0.2076

0.1115

0.1735

1 0.0249 0.2695 0.2116 0.1215 0.2192 0.0166 0.0013 0.545

0.0744

0.0227

2 0.0282 0.125

5 0.4108 0.0124 0.446


60

0.9783

0.4067

0.5582

0.5144

0.0997

3 0.9366 0.0035 0.1063 0.2182 0.1126 0.39


5

0.09

0.3888

0.0233

0.9403

0.0435

0.0621

0.0044

0.0342

4 0.0095 0.3477 0.1246 0.0838 0.1089 0.4431 0.0021 0.0039 0.065

0.0008

5 0.0008 0.2542 0.1509 0.0183 0.045

0.0021

0.0506

0.8632

0.0002

0.8329

1 0.1259 0.0696 0.1357 0.4788 0.1341 0.0595 0.1132 0.0487 0.2059 0.1907
2 0.0599 0.0698 0.7308 0.241
70

0.4269

0.0924

0.0811

0.033

0.4008

0.0761

3 0.4113 0.0246 0.0188 0.0649 0.1268 0.533

0.506

0.2284

0.1169

0.0275

4 0.265

0.0923

0.0858

0.0353

0.0133

0.074

0.0254

0.0427

0.2667

0.0807

5 0.138

0.7437

0.0289

0.1801

0.2989

0.2411

0.2744

0.6473

0.0096

0.625

1 0.3348 0.5666 0.1476 0.8179 0.0642 0.7671 0.1409 0.1401 0.0839 0.2898
2 0.0613 0.2366 0.0104 0.0678 0.0194 0.1281 0.0551 0.1484 0.1244 0.0276
80

3 0.1329 0.0308 0.1805 0.08

0.0188

0.0018

0.4753

0.5336

0.7007

0.4906

4 0.0883 0.1515 0.2035 0.0274 0.2084 0.0205 0.0135 0.0571 0.0486 0.1709
5 0.3828 0.0145 0.458

0.0069

1 0.0578 0.0079 0.7122 0.007

0.6892

0.0826

0.3152

0.1209

0.0424

0.0211

0.0043

0.0239

0.0123

0.7735

0.2311

0.6981

2 0.2789 0.4667 0.0077 0.0585 0.1216 0.9661 0.0382 0.0074 0.2254 0.1076
90

3 0.6107 0.4469 0.0478 0.3722 0.0034 0.004

0.0716

4 0.0018 0.0446 0.1711 0.5582 0.0007 0.0057 0.84

0.0558

0.0904

0.1315

0.0814

0.4502

0.0088

0.0029

0.054

5 0.0509 0.0339 0.0612 0.0041 0.8701 0.0003 0.0378 0.082

U randomly generated initial value of the position of each row uij [0, 1], and satisfies
the equation

.
Table 3. Final Clustering Matrices

n-points c 1+n
1 0
0

10

2+n

3+n

4+n

5+n

6+n

7+n

8+n

9+n 10+n

0.0001

0.9995

0.0262

2 0.0005 0

0.9818

0.0005

0.0001

0.0001

3 0.0017 1

0.9989

0.9999

4 0.9978 0

0.018

0.0008

0.0001

5 0

0.0001

0.9737

1 0.0017 0.0009 0.0009 0

0.9999

0.0003

2 0

0.028

0.0281

0.0006

0.9997

3 0

0.3752

0.3052

0.006

4 0

0.5948

0.6649

0.9933

0.0001

1 0.9259 0.0607 0.0001 0.0001 0.9921 0.9998 0.9648 0

0.0003

2 0.0006 0.0067 0

5 0.9983 0.0011 0.001


20

0.0003

0.0073

3 0.0001 0.0133 0.0001 0.9983 0


6

0.0001

0.0349

0.525

0.0001

4 0

30

40

50

60

70

80

0.0008

0.4746

5 0.0734 0.9185 0.9998 0.0005 0.0005 0.0002 0.0002 0

1 0

0.0011

0.0003

0.0005

0.0001

0.0011

2 0

0.0003

0.9999

0.0031

0.0071

0.0005

3 0

0.0878

0.0063

0.9999

0.9865

0.7293

4 1

0.0002

0.0001

0.0078

0.9929

0.0006

5 0

0.9106

0.9933

0.0021

0.9999

0.2684

1 0

0.0057

0.0134

0.0141

0.0001

0.9999

0.9717

2 0

0.0005

0.9864

0.0017

0.0001

0.0182

0.0279

3 1

0.9604

0.0088

0.9926

0.0001

4 0

0.039

0.0002

0.0003

0.0002

0.9817

0.0001

5 0

0.0001

0.9942

0.9751

0.007

0.0003

1 0

0.0001

0.0004

0.0003

2 0

0.0011

0.0001

0.0043

0.0001

0.0002

0.0004

3 1

0.9116

0.9663

0.9982

0.969

0.9823

4 0

0.087

0.9999

0.0279

0.0016

0.0002

0.0172

5 0

0.0002

0.001

0.0001

0.0302

0.0001

1 0

0.0033

0.9993

0.0205

0.0002

0.7212

2 0

0.9349

0.0007

0.0004

0.0193

3 0

0.9997

0.0027

0.9953

0.0031

4 0

0.0586

0.0005

0.0008

5 1

0.0002

0.0005

0.9794

0.0035

0.2555

1 0

0.0014

0.0002

0.3831

0.9996

2 0

0.0001

0.001

0.0001

0.0004

0.6163

0.0003

3 0.9998 0.001

0.0001

0.9705

0.0002

4 0

0.9999

0.999

0.0001

0.9994

0.0003

5 0.0001 0.9975 0

0.0291

0.0003

0.0001

1 1

0.0041

0.0001

0.9996

0.3394

2 0

0.0008

0.0001

0.0065

0.0003

0.6602

3 0

0.0183

0.99

0.0016

4 0

0.0002

0.0002

0.9935

0.9981

0.0002

5 0

0.9766

0.0096

0.0004

0.0002

0.9999

0.0062

0.9878

0.7799

2 0.0001 0.7637 0.0001 0

0.0001

0.0001

0.0003

3 0.0003 0.0001 0.9989 0.9996 0

0.0001

4 0

1 0.0019 0.0002 0
90

0.2361

5 0.9976 0

0.0008

0.0001

0.0009

0.0002

0.0001

0.0002

0.9937

0.012

0.2197

(4) Program and Explanation


clc;clear;close all;
%%%Inputs
P = 100;% Points random
Range_a = -20:10;
Range_b = -15:20;
c=5;% Classify points to 5 clusters
m=1.25; %weight
e=0.01;

%%%Clustering Program
U0=zeros(c,P);
[ra,ca]=size(Range_a);
[rb,cb]=size(Range_b);
cost_f = [];
iter=1;

%%% Random generate the first generation


for i=1:P
ab(1,i)=Range_a(1)+(ca-1)*rand;
ab(2,i)=Range_b(1)+(cb-1)*rand;
Rc=randperm(5);
for k=1:c
if k==c
U0(Rc(k),i)=1-sum(U0(:,i));
else
U0(Rc(k),i)=rand*(1-sum(U0(:,i)));
end
end
end

%%% Clustering
while 1
hold off
%Drawing data points clustering
for i=1:P
[val,ind]=sort(U0(:,i));

if ind(c)==1
plot(ab(1,i),ab(2,i),'ro')
elseif ind(c)==2
plot(ab(1,i),ab(2,i),'g^')
elseif ind(c)==3
plot(ab(1,i),ab(2,i),'b+')
elseif ind(c)==4
plot(ab(1,i),ab(2,i),'k*')
elseif ind(c)==5
plot(ab(1,i),ab(2,i),'msquare')
end
hold on;
end

Uold = U0;
%Center of gravity
for i = 1:c
v(1,i) = sum(ab(1,:).*(U0(i,:).^m) ) ./ sum(U0(i,:).^m);
v(2,i) = sum(ab(2,:).*(U0(i,:).^m) ) ./ sum(U0(i,:).^m);
end
%Draw the change of center of gravity
plot(v(1,1),v(2,1),'p','Markersize',10,'MarkerFaceColor','r')
plot(v(1,2),v(2,2),'p','Markersize',10,'MarkerFaceColor','g')
plot(v(1,3),v(2,3),'p','Markersize',10,'MarkerFaceColor','b')
plot(v(1,4),v(2,4),'p','Markersize',10,'MarkerFaceColor','k')
plot(v(1,5),v(2,5),'p','Markersize',10,'MarkerFaceColor','m')
pause(0.1+(iter==1)*0.9);

%Calculated the cost function of center of gravity


for j = 1:P
for i = 1:c
for k = 1:c
nU0(k) =
(norm(ab(:,j)-v(:,i))/norm(ab(:,j)-v(:,k)))^(2/(m-1));
end
U0(i,j) = (sum(nU0))^(-1);
ncost(i) = ((U0(i,j))^m)*(norm(ab(:,j)-v(:,i)))^2 ;
end

cost(j) = sum(ncost);
end
cost_f(iter) = sum(cost);% Each iteration of the cost function

% Attribution error at the end of Clustering


for i=1:c
E=(sum(Uold(i,:))-sum(U0(i,:)) <= e);
if E==0
break;
end
end

if E==1
%Draw the focus point
plot(v(1,1),v(2,1),'p','Markersize',15,'MarkerFaceColor','r')
plot(v(1,2),v(2,2),'p','Markersize',15,'MarkerFaceColor','g')
plot(v(1,3),v(2,3),'p','Markersize',15,'MarkerFaceColor','b')
plot(v(1,4),v(2,4),'p','Markersize',15,'MarkerFaceColor','k')
plot(v(1,5),v(2,5),'p','Markersize',15,'MarkerFaceColor','m')
pause(1)

%Draw cost function


figure,plot(cost_f,'b.-')
xlabel('iteration');ylabel('cost function');
title('Fuzzy C-mean');
break;
end
iter = iter + 1;
end

10

(5) Use different colors to show the points of different clusters in the X-Y
space
Using different color and symbols , , , , + represents a different grouping of data
points on behalf of small convergence trajectory focus of value changes, large
the focus of the last representatives. Weight m = 1.25 and error rate = 0.01 randomly
generated clustering results 100 points.

Fig 2. Focus point during the changes of clustering process

11

Fig 3. Ultimate center of gravity position and clustering results

Fig 4. Cost function with weights 1.25

12

(6) Discussion and Conclusion


(a) The impact of the different weights for the center of gravity and cost function
value:
The larger weight, the value of cost function convergence being smaller.
The difference of convergence center value will generate an error, then to find
the correct value of the convergence center, weight values must be reasonable.

Fig 5a. The change of Center of Gravity, weight = 3

Fig 6a. The change of Center of Gravity, weight = 5

Fig 5b. Cost function, weight = 3

Fig 6b. Cost function, weight = 5

(b) The impact of different initial Uo for the cost function:


Different data points with different initial Uo affects the convergence speed, the cost
function being slower.
13

Fig 7a. Generate 100 random data points

Fig 7b. Result of change focus point

Fig 8. Cost function of different initial Uo

14

Conclusion:
-

In the "fuzzy C-mean clustering method" in order to generate different random


initial data point Uo, find the considerable degree of information that would
significantly affect the algorithm convergence speed.

In the "fuzzy C-mean clustering method", the selection of the weights need the
reasonable value, generally choose weight = 1.25 and it cant be less than or equal
to 1, otherwise it will affect the center of gravity.

15

Vous aimerez peut-être aussi