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