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