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