Home > subfunctions > ccl_math_kc.m

ccl_math_kc

PURPOSE ^

[M,dist_new] = ccl_math_kc (X, K)

SYNOPSIS ^

function [M,dist_new] = ccl_math_kc (X, K)

DESCRIPTION ^

 [M,dist_new] = ccl_math_kc (X, K)

 Initialisation: randomly select K points as the centre

 Input:

   X                   Input signals
   K                   Number of Gaussian distributions

 Output:

   M                   Mean value of the K Gaussians
   dist_new            sum of overall distance in between K clusters and
                       the input data set

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [M,dist_new] = ccl_math_kc (X, K)
0002 % [M,dist_new] = ccl_math_kc (X, K)
0003 %
0004 % Initialisation: randomly select K points as the centre
0005 %
0006 % Input:
0007 %
0008 %   X                   Input signals
0009 %   K                   Number of Gaussian distributions
0010 %
0011 % Output:
0012 %
0013 %   M                   Mean value of the K Gaussians
0014 %   dist_new            sum of overall distance in between K clusters and
0015 %                       the input data set
0016 
0017 
0018 
0019 
0020 % CCL: A MATLAB library for Constraint Consistent Learning
0021 % Copyright (C) 2007  Matthew Howard
0022 % Contact: matthew.j.howard@kcl.ac.uk
0023 %
0024 % This library is free software; you can redistribute it and/or
0025 % modify it under the terms of the GNU Lesser General Public
0026 % License as published by the Free Software Foundation; either
0027 % version 2.1 of the License, or (at your option) any later version.
0028 %
0029 % This library is distributed in the hope that it will be useful,
0030 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0031 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0032 % Lesser General Public License for more details.
0033 %
0034 % You should have received a copy of the GNU Library General Public
0035 % License along with this library; if not, write to the Free
0036 % Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0037 
0038 N        = size(X,2) ;
0039 ind      = randperm(N) ;
0040 ind      = ind(1:K) ;
0041 M        = X(:,ind) ;
0042 dist_old = realmax ;
0043 
0044 for iter= 0:1000
0045     D             = ccl_math_distances(M,X);
0046     [mD,ind]      = min(D);
0047     emptyClusters = [];
0048     
0049     for k = 1 : K
0050         ix = find(ind == k);
0051         if ~isempty(ix)
0052             M(:,k) = mean(X(:,ix),2);
0053         else
0054             emptyClusters = [emptyClusters k];
0055         end
0056     end
0057     
0058     dist_new = sum(mD);
0059     
0060     if isempty (emptyClusters)
0061         if abs (dist_old-dist_new) < 1e-10;
0062             return;
0063         end
0064     else
0065         [sD, ind] = sort(mD, 2,'descend');
0066         for k=1:length(emptyClusters)
0067             M(:,emptyClusters(k)) = X(:,ind(k));
0068         end
0069     end
0070     dist_old = dist_new;
0071 end
0072 end
0073

Generated on Mon 01-Jan-2018 15:49:39 by m2html © 2005