annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_dmat.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function dmat = som_dmat(sM,Ne,mode)
wolffd@0 2
wolffd@0 3 %SOM_DMAT Find distance to neighbors for each map unit.
wolffd@0 4 %
wolffd@0 5 % dmat = som_dmat(sM,[Ne],[mode])
wolffd@0 6 %
wolffd@0 7 % Input and output arguments ([]'s are optional):
wolffd@0 8 % sM (struct) map or data struct
wolffd@0 9 % (matrix) data matrix, size n x dim
wolffd@0 10 % [Ne] (matrix) neighborhood connections matrix
wolffd@0 11 % (string) 'Nk' (on map) or 'kNN' (any vector set)
wolffd@0 12 % where k = some number, e.g. 'N1' or '10NN'
wolffd@0 13 % (empty) use default
wolffd@0 14 % [mode] (string) 'min', 'median', 'mean', 'max', or
wolffd@0 15 % some arbitrary scalar function of
wolffd@0 16 % a set of vectors
wolffd@0 17 %
wolffd@0 18 % dmat (vector) size n x 1, distance associated with each vector
wolffd@0 19 %
wolffd@0 20 % See also KMEANS_CLUSTERS, SOM_CLLINKAGE, SOM_CLSTRUCT.
wolffd@0 21
wolffd@0 22 % Copyright (c) 2000 by Juha Vesanto
wolffd@0 23 % Contributed to SOM Toolbox on June 16th, 2000 by Juha Vesanto
wolffd@0 24 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 25
wolffd@0 26 % Version 2.0beta juuso 220800
wolffd@0 27
wolffd@0 28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 29
wolffd@0 30 % map
wolffd@0 31 if isstruct(sM),
wolffd@0 32 switch sM.type,
wolffd@0 33 case 'som_map', M = sM.codebook; mask = sM.mask;
wolffd@0 34 case 'som_data', M = sM.data; mask = ones(size(M,2),1);
wolffd@0 35 end
wolffd@0 36 else
wolffd@0 37 M = sM; mask = ones(size(M,2),1);
wolffd@0 38 end
wolffd@0 39 [n dim] = size(M);
wolffd@0 40
wolffd@0 41 % neighborhoods
wolffd@0 42 if nargin<2 | isempty(Ne), Ne = som_neighbors(sM);
wolffd@0 43 elseif ischar(Ne), Ne = som_neighbors(sM,Ne);
wolffd@0 44 end
wolffd@0 45 l = size(Ne,1); Ne([0:l-1]*l+[1:l]) = 0; % set diagonal elements = 0
wolffd@0 46
wolffd@0 47 % mode
wolffd@0 48 if nargin<3 | isempty(mode), mode = 'median'; end
wolffd@0 49 calc = sprintf('%s(x)',mode);
wolffd@0 50
wolffd@0 51 % distances
wolffd@0 52 dmat = zeros(n,1);
wolffd@0 53 for i=1:n,
wolffd@0 54 ne = find(Ne(i,:));
wolffd@0 55 if any(ne),
wolffd@0 56 [dummy,x] = som_bmus(M(ne,:),M(i,:),[1:length(ne)],mask);
wolffd@0 57 dmat(i) = eval(calc);
wolffd@0 58 else
wolffd@0 59 dmat(i) = NaN;
wolffd@0 60 end
wolffd@0 61 end
wolffd@0 62
wolffd@0 63 return;
wolffd@0 64
wolffd@0 65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 66
wolffd@0 67
wolffd@0 68