annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_dmatminima.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function minima = som_dmatminima(sM,U,Ne)
wolffd@0 2
wolffd@0 3 %SOM_DMATMINIMA Find clusters based on local minima of U-matrix.
wolffd@0 4 %
wolffd@0 5 % minima = som_dmatminima(sM,[U],[Ne])
wolffd@0 6 %
wolffd@0 7 % Input and output arguments ([]'s are optional):
wolffd@0 8 % sM (struct) map struct
wolffd@0 9 % U (matrix) the distance matrix from which minima is
wolffd@0 10 % searched from
wolffd@0 11 % size msize(1) x ... x msize(end) or
wolffd@0 12 % 2*msize(1)-1 x 2*msize(2)-1 or
wolffd@0 13 % munits x 1
wolffd@0 14 % Ne (matrix) neighborhood connections matrix
wolffd@0 15 %
wolffd@0 16 % minima (vector) indeces of the map units where locla minima of
wolffd@0 17 % of U-matrix (or other distance matrix occured)
wolffd@0 18 %
wolffd@0 19 % See also KMEANS_CLUSTERS, SOM_CLLINKAGE, SOM_CLSTRUCT.
wolffd@0 20
wolffd@0 21 % Copyright (c) 2000 by Juha Vesanto
wolffd@0 22 % Contributed to SOM Toolbox on June 16th, 2000 by Juha Vesanto
wolffd@0 23 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 24
wolffd@0 25 % Version 2.0beta juuso 220800
wolffd@0 26
wolffd@0 27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 28
wolffd@0 29 % map
wolffd@0 30 if isstruct(sM),
wolffd@0 31 switch sM.type,
wolffd@0 32 case 'som_map', M = sM.codebook; mask = sM.mask;
wolffd@0 33 case 'som_data', M = sM.data; mask = ones(size(M,2),1);
wolffd@0 34 end
wolffd@0 35 else
wolffd@0 36 M = sM; mask = ones(size(M,2),1);
wolffd@0 37 end
wolffd@0 38 [munits dim] = size(M);
wolffd@0 39
wolffd@0 40 % distances between map units
wolffd@0 41 if nargin<2, U = []; end
wolffd@0 42
wolffd@0 43 % neighborhoods
wolffd@0 44 if nargin<3, Ne = som_neighbors(sM); end
wolffd@0 45
wolffd@0 46 % distance matrix
wolffd@0 47 if nargin<2 | isempty(U), U = som_dmat(sM,Ne,'median'); end
wolffd@0 48 if prod(size(U))>munits, U = U(1:2:size(U,1),1:2:size(U,2)); end
wolffd@0 49 U = U(:);
wolffd@0 50 if length(U) ~= munits, error('Distance matrix has incorrect size.'); end
wolffd@0 51
wolffd@0 52 % find local minima
wolffd@0 53 minima = [];
wolffd@0 54 for i=1:munits,
wolffd@0 55 ne = find(Ne(i,:));
wolffd@0 56 if all(U(i)<=U(ne)) & ~anycommon(ne,minima), minima(end+1)=i; end
wolffd@0 57 end
wolffd@0 58
wolffd@0 59 return;
wolffd@0 60
wolffd@0 61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 62
wolffd@0 63 function t = anycommon(i1,i2)
wolffd@0 64 if isempty(i1) | isempty(i2), t = 0;
wolffd@0 65 else
wolffd@0 66 m = max(max(i1),max(i2));
wolffd@0 67 t = any(sparse(i1,1,1,m,1) & sparse(i2,1,1,m,1));
wolffd@0 68 end
wolffd@0 69 return;
wolffd@0 70