comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_dmatclusters.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 [base,seed] = som_dmatclusters(sM,linkage,neigh,ignore)
2
3 % SOM_DMATCLUSTERS Cluster map based on neighbor distance matrix.
4 %
5 % base = som_dmatclusters(sM,linkage,neigh,ignore)
6 %
7 % sM (struct) map or data struct
8 % (matrix) data matrix, size n x dim
9 % [linkage] (string) 'closest', 'single', 'average', 'complete',
10 % 'centroid', 'ward', and 'neighf' (last for SOM only)
11 % default is 'centroid'
12 % [neigh] (string) 'kNN' or 'Nk' (which is valid for a SOM only)
13 % for example '6NN' or 'N1'
14 % default is '10NN' for a data set and 'N1' for SOM
15 % (matrix) 0/1 matrix of size size n x n, 1=connection exists
16 % [ignore] (vector) indeces of vectors to be ignored in the spreading
17 % phase, empty vector by default
18 %
19 % base (vector) size n x 1, cluster indeces (1...c)
20 % seed (vector) size c x 1, indeces of seed units for the clusters
21 %
22 % See also SOM_NEIGHBORS, KMEANS_CLUSTERS, SOM_DMATMINIMA.
23
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 %% input arguments
26
27 if nargin<2 | isempty(linkage), linkage = 'centroid'; end
28
29 if nargin<3 | isempty(neigh),
30 if isstruct(sM) & strcmp(sM.type,'som_map'),
31 neigh = 'N1';
32 else
33 neigh = '10NN';
34 end
35 end
36
37 if nargin<4, ignore = []; end
38 n = size(sM.codebook,1);
39
40 % neighborhoods
41 if ischar(neigh),
42 Ne = som_neighbors(sM,neigh);
43 else
44 Ne = neigh;
45 end
46
47 % find seed points
48 seed = som_dmatminima(sM,[],Ne);
49
50 % make partition
51 base = zeros(n,1);
52 base(seed) = 1:length(seed);
53 if any(ignore), base(ignore) = NaN; end
54 base = som_clspread(sM,base,linkage,Ne,0);
55
56 % assign the ignored units, too
57 base(isnan(base)) = 0;
58 if any(base==0), base = som_clspread(sM,base,linkage,Ne,0); end
59
60 return;
61