annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_clget.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 a = som_clget(sC, mode, ind)
wolffd@0 2
wolffd@0 3 %SOM_CLGET Get properties of specified clusters.
wolffd@0 4 %
wolffd@0 5 % a = som_clget(sC, mode, ind)
wolffd@0 6 %
wolffd@0 7 % inds = som_clget(sC,'dinds',20);
wolffd@0 8 % col = som_clget(sC,'depth',[1 2 3 20 54]);
wolffd@0 9 %
wolffd@0 10 % Input and output arguments:
wolffd@0 11 % sC (struct) clustering struct
wolffd@0 12 % mode (string) what kind of property is requested
wolffd@0 13 % 'binds' (a union over) indeces of base clusters
wolffd@0 14 % belonging to the specified cluster(s)
wolffd@0 15 % 'dinds' (a union over) indeces of the data vectors
wolffd@0 16 % belonging to the specified cluster(s)
wolffd@0 17 % 'dlen' number of data vectors belonging
wolffd@0 18 % to each of the specified cluster(s)
wolffd@0 19 % 'depth' depths of the specified clusters
wolffd@0 20 % (depth of the root cluster is 0,
wolffd@0 21 % depth of its children are 1, etc.)
wolffd@0 22 % 'child' (a union over) children clusters
wolffd@0 23 % of specified cluster(s), including
wolffd@0 24 % the clusters themselves
wolffd@0 25 % 'base' base partitioning based on given
wolffd@0 26 % clusters
wolffd@0 27 % ind (vector) indeces of the clusters
wolffd@0 28 %
wolffd@0 29 % a (vector) the answer
wolffd@0 30 %
wolffd@0 31 % See also SOM_CLSTRUCT, SOM_CLPLOT.
wolffd@0 32
wolffd@0 33 % Copyright (c) 2000 by the SOM toolbox programming team.
wolffd@0 34 % Contributed to SOM Toolbox on XXX by Juha Vesanto
wolffd@0 35 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 36
wolffd@0 37 % Version 2.0beta juuso 180800
wolffd@0 38
wolffd@0 39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 40
wolffd@0 41 clen = size(sC.tree,1)+1;
wolffd@0 42
wolffd@0 43 switch mode,
wolffd@0 44 case 'binds',
wolffd@0 45 a = [];
wolffd@0 46 for i=1:length(ind), a = [a, getbaseinds(sC.tree,ind(i))]; end
wolffd@0 47 a = unique(a);
wolffd@0 48 case 'dinds',
wolffd@0 49 b = [];
wolffd@0 50 for i=1:length(ind), b = [b, getbaseinds(sC.tree,ind(i))]; end
wolffd@0 51 b = unique(b);
wolffd@0 52 a = zeros(length(sC.base),1);
wolffd@0 53 for i=1:length(b), a(find(sC.base==b(i)))=1; end
wolffd@0 54 a = find(a);
wolffd@0 55 case 'dlen',
wolffd@0 56 a = zeros(length(ind),1);
wolffd@0 57 for i=1:length(ind),
wolffd@0 58 b = getbaseinds(sC.tree,ind(i));
wolffd@0 59 for j=1:length(b), a(i) = a(i) + sum(sC.base==b(j)); end
wolffd@0 60 end
wolffd@0 61 case 'depth',
wolffd@0 62 a = getdepth(sC.tree);
wolffd@0 63 a = a(ind);
wolffd@0 64 case 'child',
wolffd@0 65 a = getchildren(sC.tree,ind);
wolffd@0 66 case 'base',
wolffd@0 67 a = sC.base*0;
wolffd@0 68 ind = -sort(-ind);
wolffd@0 69 for i=1:length(ind), a(som_clget(sC,'dinds',ind(i))) = ind(i); end
wolffd@0 70 end
wolffd@0 71
wolffd@0 72 return;
wolffd@0 73
wolffd@0 74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 75
wolffd@0 76 function ch = getchildren(Z,ind)
wolffd@0 77
wolffd@0 78 clen = size(Z,1)+1;
wolffd@0 79 ch = ind; cho = ind;
wolffd@0 80 while any(cho),
wolffd@0 81 i = cho(1); cho = cho(2:end);
wolffd@0 82 j = Z(i-clen,1); k = Z(i-clen,2);
wolffd@0 83 if j>clen, cho(end+1) = j; end
wolffd@0 84 if k>clen, cho(end+1) = k; end
wolffd@0 85 ch(end+1) = j; ch(end+1) = k;
wolffd@0 86 end
wolffd@0 87 return;
wolffd@0 88
wolffd@0 89 function binds = getbaseinds(Z,ind)
wolffd@0 90
wolffd@0 91 clen = size(Z,1)+1;
wolffd@0 92 binds = ind;
wolffd@0 93 while binds(1)>clen,
wolffd@0 94 i = binds(1);
wolffd@0 95 binds = binds(2:end);
wolffd@0 96 j = Z(i-clen,1); k = Z(i-clen,2);
wolffd@0 97 if j>clen, binds = [j binds]; else binds(end+1) = j; end
wolffd@0 98 if k>clen, binds = [k binds]; else binds(end+1) = k; end
wolffd@0 99 end
wolffd@0 100 return;
wolffd@0 101
wolffd@0 102 function depth = getdepth(Z)
wolffd@0 103
wolffd@0 104 clen = size(Z,1)+1;
wolffd@0 105 depth = zeros(2*clen-1,1);
wolffd@0 106 ch = 2*clen-1; % active nodes
wolffd@0 107 while any(ch),
wolffd@0 108 c = ch(1); ch = ch(2:end);
wolffd@0 109 if c>clen & isfinite(Z(c-clen,3)),
wolffd@0 110 chc = Z(c-clen,1:2); % children of c
wolffd@0 111 depth(chc) = depth(c) + 1; % or +(ind==chc(1))
wolffd@0 112 ch = [ch, chc];
wolffd@0 113 end
wolffd@0 114 end
wolffd@0 115 return;