Daniel@0: function minima = som_dmatminima(sM,U,Ne) Daniel@0: Daniel@0: %SOM_DMATMINIMA Find clusters based on local minima of U-matrix. Daniel@0: % Daniel@0: % minima = som_dmatminima(sM,[U],[Ne]) Daniel@0: % Daniel@0: % Input and output arguments ([]'s are optional): Daniel@0: % sM (struct) map struct Daniel@0: % U (matrix) the distance matrix from which minima is Daniel@0: % searched from Daniel@0: % size msize(1) x ... x msize(end) or Daniel@0: % 2*msize(1)-1 x 2*msize(2)-1 or Daniel@0: % munits x 1 Daniel@0: % Ne (matrix) neighborhood connections matrix Daniel@0: % Daniel@0: % minima (vector) indeces of the map units where locla minima of Daniel@0: % of U-matrix (or other distance matrix occured) Daniel@0: % Daniel@0: % See also KMEANS_CLUSTERS, SOM_CLLINKAGE, SOM_CLSTRUCT. Daniel@0: Daniel@0: % Copyright (c) 2000 by Juha Vesanto Daniel@0: % Contributed to SOM Toolbox on June 16th, 2000 by Juha Vesanto Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta juuso 220800 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: % map Daniel@0: if isstruct(sM), Daniel@0: switch sM.type, Daniel@0: case 'som_map', M = sM.codebook; mask = sM.mask; Daniel@0: case 'som_data', M = sM.data; mask = ones(size(M,2),1); Daniel@0: end Daniel@0: else Daniel@0: M = sM; mask = ones(size(M,2),1); Daniel@0: end Daniel@0: [munits dim] = size(M); Daniel@0: Daniel@0: % distances between map units Daniel@0: if nargin<2, U = []; end Daniel@0: Daniel@0: % neighborhoods Daniel@0: if nargin<3, Ne = som_neighbors(sM); end Daniel@0: Daniel@0: % distance matrix Daniel@0: if nargin<2 | isempty(U), U = som_dmat(sM,Ne,'median'); end Daniel@0: if prod(size(U))>munits, U = U(1:2:size(U,1),1:2:size(U,2)); end Daniel@0: U = U(:); Daniel@0: if length(U) ~= munits, error('Distance matrix has incorrect size.'); end Daniel@0: Daniel@0: % find local minima Daniel@0: minima = []; Daniel@0: for i=1:munits, Daniel@0: ne = find(Ne(i,:)); Daniel@0: if all(U(i)<=U(ne)) & ~anycommon(ne,minima), minima(end+1)=i; end Daniel@0: end Daniel@0: Daniel@0: return; Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function t = anycommon(i1,i2) Daniel@0: if isempty(i1) | isempty(i2), t = 0; Daniel@0: else Daniel@0: m = max(max(i1),max(i2)); Daniel@0: t = any(sparse(i1,1,1,m,1) & sparse(i2,1,1,m,1)); Daniel@0: end Daniel@0: return; Daniel@0: