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