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

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