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