user3051460
user3051460

Reputation: 1485

How to generate fixed cluster of Fuzzy C mean in matlab

I am using FCM library code in matlab (ref code). To genertate partition matrix, we can use

 MF=initfcm(ncluster,imgsiz); %imgsiz is size of input image

where initfcm is function in Matlab library:

function U = initfcm(cluster_n, data_n)
%INITFCM Generate initial fuzzy partition matrix for fuzzy c-means clustering.
%   U = INITFCM(CLUSTER_N, DATA_N) randomly generates a fuzzy partition
%   matrix U that is CLUSTER_N by DATA_N, where CLUSTER_N is number of
%   clusters and DATA_N is number of data points. The summation of each
%   column of the generated U is equal to unity, as required by fuzzy
%   c-means clustering.
%
%       See also DISTFCM, FCMDEMO, IRISFCM, STEPFCM, FCM.

%   Roger Jang, 12-1-94.
%   Copyright 1994-2002 The MathWorks, Inc. 
%   $Revision: 1.11 $  $Date: 2002/04/14 22:21:58 $

U = rand(cluster_n, data_n);
col_sum = sum(U);
U = U./col_sum(ones(cluster_n, 1), :);

We can see that fuzzy partition matrix is created randomly, so result is not fixed by difference time that mean it will depends on cluster matrix. How to create fixed ouput with difference time?

Thank you

Upvotes: 0

Views: 730

Answers (1)

Shai
Shai

Reputation: 114886

You need to set the state of the random number generator before you call rand:

rng('default'); % add this
U = rand( cluster_n, data_n );

For more details, see the third example here.

Upvotes: 1

Related Questions