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