wolffd@0: function [base,seed] = som_dmatclusters(sM,linkage,neigh,ignore) wolffd@0: wolffd@0: % SOM_DMATCLUSTERS Cluster map based on neighbor distance matrix. wolffd@0: % wolffd@0: % base = som_dmatclusters(sM,linkage,neigh,ignore) wolffd@0: % wolffd@0: % sM (struct) map or data struct wolffd@0: % (matrix) data matrix, size n x dim wolffd@0: % [linkage] (string) 'closest', 'single', 'average', 'complete', wolffd@0: % 'centroid', 'ward', and 'neighf' (last for SOM only) wolffd@0: % default is 'centroid' wolffd@0: % [neigh] (string) 'kNN' or 'Nk' (which is valid for a SOM only) wolffd@0: % for example '6NN' or 'N1' wolffd@0: % default is '10NN' for a data set and 'N1' for SOM wolffd@0: % (matrix) 0/1 matrix of size size n x n, 1=connection exists wolffd@0: % [ignore] (vector) indeces of vectors to be ignored in the spreading wolffd@0: % phase, empty vector by default wolffd@0: % wolffd@0: % base (vector) size n x 1, cluster indeces (1...c) wolffd@0: % seed (vector) size c x 1, indeces of seed units for the clusters wolffd@0: % wolffd@0: % See also SOM_NEIGHBORS, KMEANS_CLUSTERS, SOM_DMATMINIMA. wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% input arguments wolffd@0: wolffd@0: if nargin<2 | isempty(linkage), linkage = 'centroid'; end wolffd@0: wolffd@0: if nargin<3 | isempty(neigh), wolffd@0: if isstruct(sM) & strcmp(sM.type,'som_map'), wolffd@0: neigh = 'N1'; wolffd@0: else wolffd@0: neigh = '10NN'; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: if nargin<4, ignore = []; end wolffd@0: n = size(sM.codebook,1); wolffd@0: wolffd@0: % neighborhoods wolffd@0: if ischar(neigh), wolffd@0: Ne = som_neighbors(sM,neigh); wolffd@0: else wolffd@0: Ne = neigh; wolffd@0: end wolffd@0: wolffd@0: % find seed points wolffd@0: seed = som_dmatminima(sM,[],Ne); wolffd@0: wolffd@0: % make partition wolffd@0: base = zeros(n,1); wolffd@0: base(seed) = 1:length(seed); wolffd@0: if any(ignore), base(ignore) = NaN; end wolffd@0: base = som_clspread(sM,base,linkage,Ne,0); wolffd@0: wolffd@0: % assign the ignored units, too wolffd@0: base(isnan(base)) = 0; wolffd@0: if any(base==0), base = som_clspread(sM,base,linkage,Ne,0); end wolffd@0: wolffd@0: return; wolffd@0: