Home > gmmbayestb-v1.0 > gmmb_cmeans.m

gmmb_cmeans

PURPOSE ^

GMMB_CMEANS simple c-means clustering

SYNOPSIS ^

function [pclass, clust]=gmmb_cmeans(pdata,nclust,count);

DESCRIPTION ^

 GMMB_CMEANS  simple c-means clustering

 T = CMEANS(data, nclust, count)
 [T, CLUST] = CMEANS(...)

 data    input data, N x D matrix
 nclust  number of clusters
 count   number of iterations

 T       output, data labels, 1 x N vector
 CL      output, cluster centers, nclust x D matrix

 Author: Jarmo Ilonen
 Editor: Pekka Paalanen

 $Name:  $ $Id: gmmb_cmeans.m,v 1.1 2004/11/02 08:32:22 paalanen Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % GMMB_CMEANS  simple c-means clustering
0002 %
0003 % T = CMEANS(data, nclust, count)
0004 % [T, CLUST] = CMEANS(...)
0005 %
0006 % data    input data, N x D matrix
0007 % nclust  number of clusters
0008 % count   number of iterations
0009 %
0010 % T       output, data labels, 1 x N vector
0011 % CL      output, cluster centers, nclust x D matrix
0012 %
0013 % Author: Jarmo Ilonen
0014 % Editor: Pekka Paalanen
0015 %
0016 % $Name:  $ $Id: gmmb_cmeans.m,v 1.1 2004/11/02 08:32:22 paalanen Exp $
0017 
0018 function [pclass, clust]=gmmb_cmeans(pdata,nclust,count);
0019 
0020 rp = randperm(size(pdata,1));
0021 clust = pdata(rp(1:nclust),:);
0022 
0023 for kierros=1:count,
0024     % compute squared distance from every point to every cluster center.
0025     for i=1:nclust,
0026         vd = pdata - repmat(clust(i,:),size(pdata,1),1);
0027         cet(:,i) = sum(abs(vd).^2, 2);
0028     end;
0029 
0030     % compute new cluster centers
0031     [a, pclass]=min(cet');
0032 
0033     for i=1:nclust,
0034         clust(i,:) = mean( pdata(find(pclass==i), :) );
0035     end;
0036 end;

Generated on Thu 14-Apr-2005 13:50:22 by m2html © 2003