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